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.
37 // Similar to |Absolute|, but even if there's an active async scroll animation
38 // the position update will NOT cancel the async scroll animation.
42 enum class ScrollTriggeredByScript
: bool { No
, Yes
};
45 * This class represents an update to the scroll position that is initiated by
46 * something on the main thread. A list of these classes is accumulated by
47 * scrollframes on the main thread, and the list is sent over as part of a
48 * paint transaction to the compositor. The compositor can then iterate through
49 * the scroll updates and apply/merge them with scrolling that has already
50 * occurred independently on the compositor side.
52 class ScrollPositionUpdate
{
53 friend struct IPC::ParamTraits
<mozilla::ScrollPositionUpdate
>;
56 // Constructor for IPC use only.
57 explicit ScrollPositionUpdate();
59 // Create a ScrollPositionUpdate for a newly created (or reconstructed)
61 static ScrollPositionUpdate
NewScrollframe(nsPoint aInitialPosition
);
62 // Create a ScrollPositionUpdate for a new absolute/instant scroll, to
63 // the given destination.
64 static ScrollPositionUpdate
NewScroll(ScrollOrigin aOrigin
,
65 nsPoint aDestination
);
66 // Create a ScrollPositionUpdate for a new relative/instant scroll, with
67 // the given source/destination.
68 static ScrollPositionUpdate
NewRelativeScroll(nsPoint aSource
,
69 nsPoint aDestination
);
70 // Create a ScrollPositionUpdate for a new absolute/smooth scroll, which
71 // animates smoothly to the given destination from whatever the current
72 // scroll position is in the receiver.
73 // If the smooth operation involves snapping to |aDestination|,
74 // |aSnapTargetIds| has snap-target-ids for snapping. Once after this smooth
75 // scroll finished on the target APZC, the ids will be reported back to the
76 // main-thread as the last snap target ids which will be used for re-snapping
77 // to the same snapped element(s).
78 static ScrollPositionUpdate
NewSmoothScroll(
79 ScrollMode aMode
, ScrollOrigin aOrigin
, nsPoint aDestination
,
80 ScrollTriggeredByScript aTriggeredByScript
,
81 UniquePtr
<ScrollSnapTargetIds
> aSnapTargetIds
);
82 // Create a ScrollPositionUpdate for a new pure-relative scroll. The
83 // aMode parameter controls whether or not this is a smooth animation or
84 // instantaneous scroll.
85 static ScrollPositionUpdate
NewPureRelativeScroll(ScrollOrigin aOrigin
,
87 const nsPoint
& aDelta
);
89 static ScrollPositionUpdate
NewMergeableScroll(ScrollOrigin aOrigin
,
90 nsPoint aDestination
);
92 bool operator==(const ScrollPositionUpdate
& aOther
) const;
94 MainThreadScrollGeneration
GetGeneration() const;
95 ScrollUpdateType
GetType() const;
96 ScrollMode
GetMode() const;
97 ScrollOrigin
GetOrigin() const;
98 // GetDestination is only valid for Absolute and Relative types; it asserts
100 CSSPoint
GetDestination() const;
101 // GetSource is only valid for the Relative type; it asserts otherwise.
102 CSSPoint
GetSource() const;
103 // GetDelta is only valid for the PureRelative type; it asserts otherwise.
104 CSSPoint
GetDelta() const;
106 ScrollTriggeredByScript
GetScrollTriggeredByScript() const {
107 return mTriggeredByScript
;
109 bool WasTriggeredByScript() const {
110 return mTriggeredByScript
== ScrollTriggeredByScript::Yes
;
112 const ScrollSnapTargetIds
& GetSnapTargetIds() const { return mSnapTargetIds
; }
114 friend std::ostream
& operator<<(std::ostream
& aStream
,
115 const ScrollPositionUpdate
& aUpdate
);
118 MainThreadScrollGeneration mScrollGeneration
;
119 // Refer to the ScrollUpdateType documentation for what the types mean.
120 // All fields are populated for all types, except as noted below.
121 ScrollUpdateType mType
;
122 ScrollMode mScrollMode
;
123 ScrollOrigin mScrollOrigin
;
124 // mDestination is not populated when mType == PureRelative.
125 CSSPoint mDestination
;
126 // mSource is not populated when mType == Absolute || mType == PureRelative.
128 // mDelta is not populated when mType == Absolute || mType == Relative.
130 ScrollTriggeredByScript mTriggeredByScript
;
131 ScrollSnapTargetIds mSnapTargetIds
;
134 } // namespace mozilla
136 #endif // mozilla_ScrollPositionUpdate_h_