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_APZUtils_h
8 #define mozilla_layers_APZUtils_h
9
10 #include <stdint.h> // for uint32_t
11 #include "FrameMetrics.h"
12 #include "LayersTypes.h"
13 #include "UnitTransforms.h"
14 #include "mozilla/gfx/CompositorHitTestInfo.h"
15 #include "mozilla/gfx/Point.h"
16 #include "mozilla/EnumSet.h"
17 #include "mozilla/FloatingPoint.h"
18
19 namespace mozilla {
20 namespace layers {
21
22 enum CancelAnimationFlags : uint32_t {
23 Default = 0x0, /* Cancel all animations */
24 ExcludeOverscroll = 0x1, /* Don't clear overscroll */
25 ScrollSnap = 0x2, /* Snap to snap points */
26 ExcludeWheel = 0x4, /* Don't stop wheel smooth-scroll animations */
27 TriggeredExternally = 0x8, /* Cancellation was not triggered by APZ in
28 response to an input event */
29 };
30
31 inline CancelAnimationFlags operator|(CancelAnimationFlags a,
32 CancelAnimationFlags b) {
33 return static_cast<CancelAnimationFlags>(static_cast<int>(a) |
34 static_cast<int>(b));
35 }
36
37 typedef EnumSet<ScrollDirection> ScrollDirections;
38
39 // clang-format off
40 enum class ScrollSource {
41 // scrollTo() or something similar.
42 DOM,
43
44 // Touch-screen or trackpad with gesture support.
45 Touch,
46
47 // Mouse wheel.
48 Wheel,
49
50 // Keyboard
51 Keyboard,
52 };
53 // clang-format on
54
55 typedef uint32_t TouchBehaviorFlags;
56
57 // Epsilon to be used when comparing 'float' coordinate values
58 // with FuzzyEqualsAdditive. The rationale is that 'float' has 7 decimal
59 // digits of precision, and coordinate values should be no larger than in the
60 // ten thousands. Note also that the smallest legitimate difference in page
61 // coordinates is 1 app unit, which is 1/60 of a (CSS pixel), so this epsilon
62 // isn't too large.
63 const float COORDINATE_EPSILON = 0.01f;
64
65 template <typename Units>
IsZero(const gfx::PointTyped<Units> & aPoint)66 static bool IsZero(const gfx::PointTyped<Units>& aPoint) {
67 return FuzzyEqualsAdditive(aPoint.x, 0.0f, COORDINATE_EPSILON) &&
68 FuzzyEqualsAdditive(aPoint.y, 0.0f, COORDINATE_EPSILON);
69 }
70
71 // Deem an AsyncTransformComponentMatrix (obtained by multiplying together
72 // one or more AsyncTransformComponentMatrix objects) as constituting a
73 // complete async transform.
CompleteAsyncTransform(const AsyncTransformComponentMatrix & aMatrix)74 inline AsyncTransformMatrix CompleteAsyncTransform(
75 const AsyncTransformComponentMatrix& aMatrix) {
76 return ViewAs<AsyncTransformMatrix>(
77 aMatrix, PixelCastJustification::MultipleAsyncTransforms);
78 }
79
80 struct TargetConfirmationFlags {
TargetConfirmationFlagsTargetConfirmationFlags81 explicit TargetConfirmationFlags(bool aTargetConfirmed)
82 : mTargetConfirmed(aTargetConfirmed),
83 mRequiresTargetConfirmation(false) {}
84
TargetConfirmationFlagsTargetConfirmationFlags85 explicit TargetConfirmationFlags(gfx::CompositorHitTestInfo aHitTestInfo)
86 : mTargetConfirmed(
87 aHitTestInfo != gfx::CompositorHitTestInfo::eInvisibleToHitTest &&
88 !(aHitTestInfo & gfx::CompositorHitTestInfo::eDispatchToContent)),
89 mRequiresTargetConfirmation(
90 aHitTestInfo &
91 gfx::CompositorHitTestInfo::eRequiresTargetConfirmation) {}
92
93 bool mTargetConfirmed : 1;
94 bool mRequiresTargetConfirmation : 1;
95 };
96
97 namespace apz {
98
99 /**
100 * Initializes the global state used in AsyncPanZoomController.
101 * This is normally called when it is first needed in the constructor
102 * of APZCTreeManager, but can be called manually to force it to be
103 * initialized earlier.
104 */
105 void InitializeGlobalState();
106
107 /**
108 * See AsyncPanZoomController::CalculatePendingDisplayPort. This
109 * function simply delegates to that one, so that non-layers code
110 * never needs to include AsyncPanZoomController.h
111 */
112 const ScreenMargin CalculatePendingDisplayPort(
113 const FrameMetrics& aFrameMetrics, const ParentLayerPoint& aVelocity);
114
115 } // namespace apz
116
117 } // namespace layers
118 } // namespace mozilla
119
120 #endif // mozilla_layers_APZUtils_h
121