Source code

Revision control

Other Tools

1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 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
27
* off. It is created by APZCTreeManager by starting from an initial APZC which
28
* is the target for input events, and following the scroll parent ID links
29
* (often but not always corresponding to parent pointers in the APZC tree),
30
* then adjusting for scrollgrab.
31
*/
32
class OverscrollHandoffChain {
33
protected:
34
// Reference-counted classes cannot have public destructors.
35
~OverscrollHandoffChain();
36
37
public:
38
// Threadsafe so that the controller and sampler 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
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(OverscrollHandoffChain)
44
45
/*
46
* Methods for building the handoff chain.
47
* These should be used only by
48
* AsyncPanZoomController::BuildOverscrollHandoffChain().
49
*/
50
void Add(AsyncPanZoomController* aApzc);
51
void SortByScrollPriority();
52
53
/*
54
* Methods for accessing the handoff chain.
55
*/
56
uint32_t Length() const { return mChain.size(); }
57
const RefPtr<AsyncPanZoomController>& GetApzcAtIndex(uint32_t aIndex) const;
58
// Returns Length() if |aApzc| is not on this chain.
59
uint32_t IndexOf(const AsyncPanZoomController* aApzc) const;
60
61
/*
62
* Convenience methods for performing operations on APZCs in the chain.
63
*/
64
65
// Flush repaints all the way up the chain.
66
void FlushRepaints() const;
67
68
// Cancel animations all the way up the chain.
69
void CancelAnimations(CancelAnimationFlags aFlags = Default) const;
70
71
// Clear overscroll all the way up the chain.
72
void ClearOverscroll() const;
73
74
// Snap back the APZC that is overscrolled on the subset of the chain from
75
// |aStart| onwards, if any.
76
void SnapBackOverscrolledApzc(const AsyncPanZoomController* aStart) const;
77
78
// Determine whether the given APZC, or any APZC further in the chain,
79
// has room to be panned.
80
bool CanBePanned(const AsyncPanZoomController* aApzc) const;
81
82
// Determine whether the given APZC, or any APZC further in the chain,
83
// can scroll in the given direction.
84
bool CanScrollInDirection(const AsyncPanZoomController* aApzc,
85
ScrollDirection aDirection) const;
86
87
// Determine whether any APZC along this handoff chain is overscrolled.
88
bool HasOverscrolledApzc() const;
89
90
// Determine whether any APZC along this handoff chain has been flung fast.
91
bool HasFastFlungApzc() const;
92
93
// Find the first APZC in this handoff chain that can be scrolled by |aInput|.
94
// Since overscroll-behavior can restrict handoff in some directions,
95
// |aOutAllowedScrollDirections| is populated with the scroll directions
96
// in which scrolling of the returned APZC is allowed.
97
RefPtr<AsyncPanZoomController> FindFirstScrollable(
98
const InputData& aInput,
99
ScrollDirections* aOutAllowedScrollDirections) const;
100
101
private:
102
std::vector<RefPtr<AsyncPanZoomController>> mChain;
103
104
typedef void (AsyncPanZoomController::*APZCMethod)();
105
typedef bool (AsyncPanZoomController::*APZCPredicate)() const;
106
void ForEachApzc(APZCMethod aMethod) const;
107
bool AnyApzc(APZCPredicate aPredicate) const;
108
};
109
110
/**
111
* This class groups the state maintained during overscroll handoff.
112
*/
113
struct OverscrollHandoffState {
114
OverscrollHandoffState(const OverscrollHandoffChain& aChain,
115
const ScreenPoint& aPanDistance,
116
ScrollSource aScrollSource)
117
: mChain(aChain),
118
mChainIndex(0),
119
mPanDistance(aPanDistance),
120
mScrollSource(aScrollSource) {}
121
122
// The chain of APZCs along which we hand off scroll.
123
// This is const to indicate that the chain does not change over the
124
// course of handoff.
125
const OverscrollHandoffChain& mChain;
126
127
// The index of the APZC in the chain that we are currently giving scroll to.
128
// This is non-const to indicate that this changes over the course of handoff.
129
uint32_t mChainIndex;
130
131
// The total distance since touch-start of the pan that triggered the
132
// handoff. This is const to indicate that it does not change over the
133
// course of handoff.
134
// The x/y components of this are non-negative.
135
const ScreenPoint mPanDistance;
136
137
ScrollSource mScrollSource;
138
};
139
140
/*
141
* This class groups the state maintained during fling handoff.
142
*/
143
struct FlingHandoffState {
144
// The velocity of the fling being handed off.
145
ParentLayerPoint mVelocity;
146
147
// The chain of APZCs along which we hand off the fling.
148
// Unlike in OverscrollHandoffState, this is stored by RefPtr because
149
// otherwise it may not stay alive for the entire handoff.
150
RefPtr<const OverscrollHandoffChain> mChain;
151
152
// Whether handoff has happened by this point, or we're still process
153
// the original fling.
154
bool mIsHandoff;
155
156
// The single APZC that was scrolled by the pan that started this fling.
157
// The fling is only allowed to scroll this APZC, too.
158
// Used only if immediate scroll handoff is disallowed.
159
RefPtr<const AsyncPanZoomController> mScrolledApzc;
160
};
161
162
} // namespace layers
163
} // namespace mozilla
164
165
#endif /* mozilla_layers_OverscrollHandoffChain_h */