Source code

Revision control

Other Tools

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
#include "mozilla/layers/APZUtils.h"
8
9
#include "AsyncPanZoomController.h"
10
11
namespace mozilla {
12
namespace layers {
13
namespace apz {
14
15
/*static*/ void InitializeGlobalState() {
16
MOZ_ASSERT(NS_IsMainThread());
17
AsyncPanZoomController::InitializeGlobalState();
18
}
19
20
/*static*/ const ScreenMargin CalculatePendingDisplayPort(
21
const FrameMetrics& aFrameMetrics, const ParentLayerPoint& aVelocity) {
22
return AsyncPanZoomController::CalculatePendingDisplayPort(aFrameMetrics,
23
aVelocity);
24
}
25
26
/*static*/ bool IsCloseToHorizontal(float aAngle, float aThreshold) {
27
return (aAngle < aThreshold || aAngle > (M_PI - aThreshold));
28
}
29
30
/*static*/ bool IsCloseToVertical(float aAngle, float aThreshold) {
31
return (fabs(aAngle - (M_PI / 2)) < aThreshold);
32
}
33
34
/* static */ gfxFloat IntervalOverlap(gfxFloat aTranslation, gfxFloat aMin,
35
gfxFloat aMax) {
36
if (aTranslation > 0) {
37
return std::max(0.0, std::min(aMax, aTranslation) - std::max(aMin, 0.0));
38
}
39
40
return std::min(0.0, std::max(aMin, aTranslation) - std::min(aMax, 0.0));
41
}
42
43
/* static */ bool IsStuckAtBottom(gfxFloat aTranslation,
44
const LayerRectAbsolute& aInnerRange,
45
const LayerRectAbsolute& aOuterRange) {
46
gfxFloat diff =
47
(IntervalOverlap(aTranslation, aOuterRange.Y(), aOuterRange.YMost()) -
48
IntervalOverlap(aTranslation, aInnerRange.Y(), aInnerRange.YMost())) -
49
aTranslation;
50
51
// `inner.YMost() < 0` means the sticky layer is stuck at top of the target
52
// scroll layer?
53
return diff == 0.0f && aInnerRange.YMost() >= 0;
54
}
55
56
} // namespace apz
57
} // namespace layers
58
} // namespace mozilla