Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set sw=2 ts=8 et tw=80 : */
3 : /* This Source Code Form is subject to the terms of the Mozilla Public
4 : * License, v. 2.0. If a copy of the MPL was not distributed with this
5 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 :
7 : #ifndef mozilla_layers_OverscrollHandoffChain_h
8 : #define mozilla_layers_OverscrollHandoffChain_h
9 :
10 : #include <vector>
11 : #include "mozilla/RefPtr.h" // for RefPtr
12 : #include "nsISupportsImpl.h" // for NS_INLINE_DECL_THREADSAFE_REFCOUNTING
13 : #include "APZUtils.h" // for CancelAnimationFlags
14 : #include "mozilla/layers/LayersTypes.h" // for Layer::ScrollDirection
15 : #include "Units.h" // for ScreenPoint
16 :
17 : namespace mozilla {
18 :
19 : class InputData;
20 :
21 : namespace layers {
22 :
23 : class AsyncPanZoomController;
24 :
25 : /**
26 : * This class represents the chain of APZCs along which overscroll is handed off.
27 : * It is created by APZCTreeManager by starting from an initial APZC which is
28 : * the target for input events, and following the scroll parent ID links (often
29 : * but not always corresponding to parent pointers in the APZC tree), then
30 : * adjusting for scrollgrab.
31 : */
32 0 : class OverscrollHandoffChain
33 : {
34 : protected:
35 : // Reference-counted classes cannot have public destructors.
36 : ~OverscrollHandoffChain();
37 : public:
38 : // Threadsafe so that the controller and compositor threads can both maintain
39 : // nsRefPtrs to the same handoff chain.
40 : // Mutable so that we can pass around the class by
41 : // RefPtr<const OverscrollHandoffChain> and thus enforce that, once built,
42 : // the chain is not modified.
43 0 : NS_INLINE_DECL_THREADSAFE_REFCOUNTING(OverscrollHandoffChain)
44 :
45 : /*
46 : * Methods for building the handoff chain.
47 : * These should be used only by AsyncPanZoomController::BuildOverscrollHandoffChain().
48 : */
49 : void Add(AsyncPanZoomController* aApzc);
50 : void SortByScrollPriority();
51 :
52 : /*
53 : * Methods for accessing the handoff chain.
54 : */
55 0 : uint32_t Length() const { return mChain.size(); }
56 : const RefPtr<AsyncPanZoomController>& GetApzcAtIndex(uint32_t aIndex) const;
57 : // Returns Length() if |aApzc| is not on this chain.
58 : uint32_t IndexOf(const AsyncPanZoomController* aApzc) const;
59 :
60 : /*
61 : * Convenience methods for performing operations on APZCs in the chain.
62 : */
63 :
64 : // Flush repaints all the way up the chain.
65 : void FlushRepaints() const;
66 :
67 : // Cancel animations all the way up the chain.
68 : void CancelAnimations(CancelAnimationFlags aFlags = Default) const;
69 :
70 : // Clear overscroll all the way up the chain.
71 : void ClearOverscroll() const;
72 :
73 : // Snap back the APZC that is overscrolled on the subset of the chain from
74 : // |aStart| onwards, if any.
75 : void SnapBackOverscrolledApzc(const AsyncPanZoomController* aStart) const;
76 :
77 : // Determine whether the given APZC, or any APZC further in the chain,
78 : // has room to be panned.
79 : bool CanBePanned(const AsyncPanZoomController* aApzc) const;
80 :
81 : // Determine whether the given APZC, or any APZC further in the chain,
82 : // can scroll in the given direction.
83 : bool CanScrollInDirection(const AsyncPanZoomController* aApzc,
84 : ScrollDirection aDirection) const;
85 :
86 : // Determine whether any APZC along this handoff chain is overscrolled.
87 : bool HasOverscrolledApzc() const;
88 :
89 : // Determine whether any APZC along this handoff chain has been flung fast.
90 : bool HasFastFlungApzc() const;
91 :
92 : RefPtr<AsyncPanZoomController> FindFirstScrollable(const InputData& aInput) const;
93 :
94 : private:
95 : std::vector<RefPtr<AsyncPanZoomController>> mChain;
96 :
97 : typedef void (AsyncPanZoomController::*APZCMethod)();
98 : typedef bool (AsyncPanZoomController::*APZCPredicate)() const;
99 : void ForEachApzc(APZCMethod aMethod) const;
100 : bool AnyApzc(APZCPredicate aPredicate) const;
101 : };
102 :
103 : /**
104 : * This class groups the state maintained during overscroll handoff.
105 : */
106 : struct OverscrollHandoffState {
107 0 : OverscrollHandoffState(const OverscrollHandoffChain& aChain,
108 : const ScreenPoint& aPanDistance,
109 : ScrollSource aScrollSource)
110 0 : : mChain(aChain),
111 : mChainIndex(0),
112 : mPanDistance(aPanDistance),
113 0 : mScrollSource(aScrollSource)
114 0 : {}
115 :
116 : // The chain of APZCs along which we hand off scroll.
117 : // This is const to indicate that the chain does not change over the
118 : // course of handoff.
119 : const OverscrollHandoffChain& mChain;
120 :
121 : // The index of the APZC in the chain that we are currently giving scroll to.
122 : // This is non-const to indicate that this changes over the course of handoff.
123 : uint32_t mChainIndex;
124 :
125 : // The total distance since touch-start of the pan that triggered the
126 : // handoff. This is const to indicate that it does not change over the
127 : // course of handoff.
128 : // The x/y components of this are non-negative.
129 : const ScreenPoint mPanDistance;
130 :
131 : ScrollSource mScrollSource;
132 : };
133 :
134 : /*
135 : * This class groups the state maintained during fling handoff.
136 : */
137 0 : struct FlingHandoffState {
138 : // The velocity of the fling being handed off.
139 : ParentLayerPoint mVelocity;
140 :
141 : // The chain of APZCs along which we hand off the fling.
142 : // Unlike in OverscrollHandoffState, this is stored by RefPtr because
143 : // otherwise it may not stay alive for the entire handoff.
144 : RefPtr<const OverscrollHandoffChain> mChain;
145 :
146 : // Whether handoff has happened by this point, or we're still process
147 : // the original fling.
148 : bool mIsHandoff;
149 :
150 : // The single APZC that was scrolled by the pan that started this fling.
151 : // The fling is only allowed to scroll this APZC, too.
152 : // Used only if immediate scroll handoff is disallowed.
153 : RefPtr<const AsyncPanZoomController> mScrolledApzc;
154 : };
155 :
156 : } // namespace layers
157 : } // namespace mozilla
158 :
159 : #endif /* mozilla_layers_OverscrollHandoffChain_h */
|