Bug 1763869 [wpt PR 33577] - Fix adb command to find webview package, a=testonly
[gecko.git] / layout / generic / ScrollPositionUpdate.cpp
blobd2bd41f2a01fda78bfd73eaa47736463616bd5c3
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 #include "ScrollPositionUpdate.h"
7 #include <ostream>
9 #include "mozilla/Assertions.h"
11 namespace mozilla {
13 static ScrollGenerationCounter sGenerationCounter;
15 ScrollPositionUpdate::ScrollPositionUpdate()
16 : mType(ScrollUpdateType::Absolute),
17 mScrollMode(ScrollMode::Normal),
18 mScrollOrigin(ScrollOrigin::None),
19 mTriggeredByScript(ScrollTriggeredByScript::No) {}
21 /*static*/
22 ScrollPositionUpdate ScrollPositionUpdate::NewScrollframe(
23 nsPoint aInitialPosition) {
24 ScrollPositionUpdate ret;
25 ret.mScrollGeneration = sGenerationCounter.NewMainThreadGeneration();
26 ret.mScrollMode = ScrollMode::Instant;
27 ret.mDestination = CSSPoint::FromAppUnits(aInitialPosition);
28 return ret;
31 /*static*/
32 ScrollPositionUpdate ScrollPositionUpdate::NewScroll(ScrollOrigin aOrigin,
33 nsPoint aDestination) {
34 MOZ_ASSERT(aOrigin != ScrollOrigin::NotSpecified);
35 MOZ_ASSERT(aOrigin != ScrollOrigin::None);
37 ScrollPositionUpdate ret;
38 ret.mScrollGeneration = sGenerationCounter.NewMainThreadGeneration();
39 ret.mType = ScrollUpdateType::Absolute;
40 ret.mScrollMode = ScrollMode::Instant;
41 ret.mScrollOrigin = aOrigin;
42 ret.mDestination = CSSPoint::FromAppUnits(aDestination);
43 return ret;
46 /*static*/
47 ScrollPositionUpdate ScrollPositionUpdate::NewRelativeScroll(
48 nsPoint aSource, nsPoint aDestination) {
49 ScrollPositionUpdate ret;
50 ret.mScrollGeneration = sGenerationCounter.NewMainThreadGeneration();
51 ret.mType = ScrollUpdateType::Relative;
52 ret.mScrollMode = ScrollMode::Instant;
53 ret.mScrollOrigin = ScrollOrigin::Relative;
54 ret.mDestination = CSSPoint::FromAppUnits(aDestination);
55 ret.mSource = CSSPoint::FromAppUnits(aSource);
56 return ret;
59 /*static*/
60 ScrollPositionUpdate ScrollPositionUpdate::NewSmoothScroll(
61 ScrollOrigin aOrigin, nsPoint aDestination,
62 ScrollTriggeredByScript aTriggeredByScript) {
63 MOZ_ASSERT(aOrigin != ScrollOrigin::NotSpecified);
64 MOZ_ASSERT(aOrigin != ScrollOrigin::None);
66 ScrollPositionUpdate ret;
67 ret.mScrollGeneration = sGenerationCounter.NewMainThreadGeneration();
68 ret.mType = ScrollUpdateType::Absolute;
69 ret.mScrollMode = ScrollMode::SmoothMsd;
70 ret.mScrollOrigin = aOrigin;
71 ret.mDestination = CSSPoint::FromAppUnits(aDestination);
72 ret.mTriggeredByScript = aTriggeredByScript;
73 return ret;
76 /*static*/
77 ScrollPositionUpdate ScrollPositionUpdate::NewPureRelativeScroll(
78 ScrollOrigin aOrigin, ScrollMode aMode, const nsPoint& aDelta) {
79 MOZ_ASSERT(aOrigin != ScrollOrigin::NotSpecified);
80 MOZ_ASSERT(aOrigin != ScrollOrigin::None);
82 ScrollPositionUpdate ret;
83 ret.mScrollGeneration = sGenerationCounter.NewMainThreadGeneration();
84 ret.mType = ScrollUpdateType::PureRelative;
85 ret.mScrollMode = aMode;
86 ret.mScrollOrigin = aOrigin;
87 ret.mDelta = CSSPoint::FromAppUnits(aDelta);
88 return ret;
91 bool ScrollPositionUpdate::operator==(
92 const ScrollPositionUpdate& aOther) const {
93 // instances are immutable, and all the fields are set when the generation
94 // is set. So if the generation matches, these instances are identical.
95 return mScrollGeneration == aOther.mScrollGeneration;
98 MainThreadScrollGeneration ScrollPositionUpdate::GetGeneration() const {
99 return mScrollGeneration;
102 ScrollUpdateType ScrollPositionUpdate::GetType() const { return mType; }
104 ScrollMode ScrollPositionUpdate::GetMode() const { return mScrollMode; }
106 ScrollOrigin ScrollPositionUpdate::GetOrigin() const { return mScrollOrigin; }
108 CSSPoint ScrollPositionUpdate::GetDestination() const {
109 MOZ_ASSERT(mType == ScrollUpdateType::Absolute ||
110 mType == ScrollUpdateType::Relative);
111 return mDestination;
114 CSSPoint ScrollPositionUpdate::GetSource() const {
115 MOZ_ASSERT(mType == ScrollUpdateType::Relative);
116 return mSource;
119 CSSPoint ScrollPositionUpdate::GetDelta() const {
120 MOZ_ASSERT(mType == ScrollUpdateType::PureRelative);
121 return mDelta;
124 std::ostream& operator<<(std::ostream& aStream,
125 const ScrollPositionUpdate& aUpdate) {
126 aStream << "{ gen=" << aUpdate.mScrollGeneration
127 << ", type=" << (int)aUpdate.mType
128 << ", mode=" << (int)aUpdate.mScrollMode
129 << ", origin=" << (int)aUpdate.mScrollOrigin
130 << ", dst=" << aUpdate.mDestination << ", src=" << aUpdate.mSource
131 << ", delta=" << aUpdate.mDelta
132 << ", triggered by script=" << aUpdate.WasTriggeredByScript() << " }";
133 return aStream;
136 } // namespace mozilla