1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef mozilla_ScrollPositionUpdate_h_
6 #define mozilla_ScrollPositionUpdate_h_
12 #include "mozilla/ScrollGeneration.h"
13 #include "mozilla/ScrollOrigin.h"
14 #include "mozilla/ScrollSnapTargetId.h"
15 #include "mozilla/ScrollTypes.h"
25 enum class ScrollUpdateType
{
26 // A scroll update to a specific destination, regardless of the current
29 // A scroll update by a specific amount, based off a given starting scroll
30 // position. XXX Fold this into PureRelative, it should be relatively
31 // straightforward after bug 1655733.
33 // A scroll update by a specific amount, where only the delta is provided.
34 // The delta should be applied to whatever the current scroll position is
35 // on the receiver side.
39 enum class ScrollTriggeredByScript
: bool { No
, Yes
};
42 * This class represents an update to the scroll position that is initiated by
43 * something on the main thread. A list of these classes is accumulated by
44 * scrollframes on the main thread, and the list is sent over as part of a
45 * paint transaction to the compositor. The compositor can then iterate through
46 * the scroll updates and apply/merge them with scrolling that has already
47 * occurred independently on the compositor side.
49 class ScrollPositionUpdate
{
50 friend struct IPC::ParamTraits
<mozilla::ScrollPositionUpdate
>;
53 // Constructor for IPC use only.
54 explicit ScrollPositionUpdate();
56 // Create a ScrollPositionUpdate for a newly created (or reconstructed)
58 static ScrollPositionUpdate
NewScrollframe(nsPoint aInitialPosition
);
59 // Create a ScrollPositionUpdate for a new absolute/instant scroll, to
60 // the given destination.
61 static ScrollPositionUpdate
NewScroll(ScrollOrigin aOrigin
,
62 nsPoint aDestination
);
63 // Create a ScrollPositionUpdate for a new relative/instant scroll, with
64 // the given source/destination.
65 static ScrollPositionUpdate
NewRelativeScroll(nsPoint aSource
,
66 nsPoint aDestination
);
67 // Create a ScrollPositionUpdate for a new absolute/smooth scroll, which
68 // animates smoothly to the given destination from whatever the current
69 // scroll position is in the receiver.
70 // If the smooth operation involves snapping to |aDestination|,
71 // |aSnapTargetIds| has snap-target-ids for snapping. Once after this smooth
72 // scroll finished on the target APZC, the ids will be reported back to the
73 // main-thread as the last snap target ids which will be used for re-snapping
74 // to the same snapped element(s).
75 static ScrollPositionUpdate
NewSmoothScroll(
76 ScrollMode aMode
, ScrollOrigin aOrigin
, nsPoint aDestination
,
77 ScrollTriggeredByScript aTriggeredByScript
,
78 UniquePtr
<ScrollSnapTargetIds
> aSnapTargetIds
);
79 // Create a ScrollPositionUpdate for a new pure-relative scroll. The
80 // aMode parameter controls whether or not this is a smooth animation or
81 // instantaneous scroll.
82 static ScrollPositionUpdate
NewPureRelativeScroll(ScrollOrigin aOrigin
,
84 const nsPoint
& aDelta
);
86 bool operator==(const ScrollPositionUpdate
& aOther
) const;
88 MainThreadScrollGeneration
GetGeneration() const;
89 ScrollUpdateType
GetType() const;
90 ScrollMode
GetMode() const;
91 ScrollOrigin
GetOrigin() const;
92 // GetDestination is only valid for Absolute and Relative types; it asserts
94 CSSPoint
GetDestination() const;
95 // GetSource is only valid for the Relative type; it asserts otherwise.
96 CSSPoint
GetSource() const;
97 // GetDelta is only valid for the PureRelative type; it asserts otherwise.
98 CSSPoint
GetDelta() const;
100 ScrollTriggeredByScript
GetScrollTriggeredByScript() const {
101 return mTriggeredByScript
;
103 bool WasTriggeredByScript() const {
104 return mTriggeredByScript
== ScrollTriggeredByScript::Yes
;
106 const ScrollSnapTargetIds
& GetSnapTargetIds() const { return mSnapTargetIds
; }
108 friend std::ostream
& operator<<(std::ostream
& aStream
,
109 const ScrollPositionUpdate
& aUpdate
);
112 MainThreadScrollGeneration mScrollGeneration
;
113 // Refer to the ScrollUpdateType documentation for what the types mean.
114 // All fields are populated for all types, except as noted below.
115 ScrollUpdateType mType
;
116 ScrollMode mScrollMode
;
117 ScrollOrigin mScrollOrigin
;
118 // mDestination is not populated when mType == PureRelative.
119 CSSPoint mDestination
;
120 // mSource is not populated when mType == Absolute || mType == PureRelative.
122 // mDelta is not populated when mType == Absolute || mType == Relative.
124 ScrollTriggeredByScript mTriggeredByScript
;
125 ScrollSnapTargetIds mSnapTargetIds
;
128 } // namespace mozilla
130 #endif // mozilla_ScrollPositionUpdate_h_