Coverage Report

Created: 2018-09-25 14:53

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