APZUtils.cpp (3527B)
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 "mozilla/StaticPrefs_apz.h" 10 #include "mozilla/StaticPrefs_layers.h" 11 12 namespace mozilla { 13 namespace layers { 14 15 namespace apz { 16 17 bool IsCloseToHorizontal(float aAngle, float aThreshold) { 18 return (aAngle < aThreshold || aAngle > (M_PI - aThreshold)); 19 } 20 21 bool IsCloseToVertical(float aAngle, float aThreshold) { 22 return (fabs(aAngle - (M_PI / 2)) < aThreshold); 23 } 24 25 bool IsStuckAtBottom(gfxFloat aTranslation, 26 const LayerRectAbsolute& aInnerRange, 27 const LayerRectAbsolute& aOuterRange) { 28 // The item will be stuck at the bottom if the async scroll delta is in 29 // the range [aOuterRange.Y(), aInnerRange.Y()]. Since the translation 30 // is negated with repect to the async scroll delta (i.e. scrolling down 31 // produces a positive scroll delta and negative translation), we invert it 32 // and check to see if it falls in the specified range. 33 return aOuterRange.Y() <= -aTranslation && -aTranslation <= aInnerRange.Y(); 34 } 35 36 bool IsStuckAtTop(gfxFloat aTranslation, const LayerRectAbsolute& aInnerRange, 37 const LayerRectAbsolute& aOuterRange) { 38 // Same as IsStuckAtBottom, except we want to check for the range 39 // [aInnerRange.YMost(), aOuterRange.YMost()]. 40 return aInnerRange.YMost() <= -aTranslation && 41 -aTranslation <= aOuterRange.YMost(); 42 } 43 44 bool AboutToCheckerboard(const FrameMetrics& aPaintedMetrics, 45 const FrameMetrics& aCompositorMetrics) { 46 // The main-thread code to compute the painted area can introduce some 47 // rounding error due to multiple unit conversions, so we inflate the rect by 48 // one app unit to account for that. 49 CSSRect painted = aPaintedMetrics.GetDisplayPort() + 50 aPaintedMetrics.GetLayoutScrollOffset(); 51 painted.Inflate(CSSMargin::FromAppUnits(nsMargin(1, 1, 1, 1))); 52 53 // Inflate the rect by the danger zone. See the description of the danger zone 54 // prefs in AsyncPanZoomController.cpp for an explanation of this. 55 CSSRect visible = 56 CSSRect(aCompositorMetrics.GetVisualScrollOffset(), 57 aCompositorMetrics.CalculateBoundedCompositedSizeInCssPixels()); 58 visible.Inflate(ScreenSize(StaticPrefs::apz_danger_zone_x(), 59 StaticPrefs::apz_danger_zone_y()) / 60 aCompositorMetrics.DisplayportPixelsPerCSSPixel()); 61 62 // Clamp both rects to the scrollable rect, because having either of those 63 // exceed the scrollable rect doesn't make sense, and could lead to false 64 // positives. 65 painted = painted.Intersect(aPaintedMetrics.GetScrollableRect()); 66 visible = visible.Intersect(aPaintedMetrics.GetScrollableRect()); 67 68 return !painted.Contains(visible); 69 } 70 71 SideBits GetOverscrollSideBits(const ParentLayerPoint& aOverscrollAmount) { 72 SideBits sides = SideBits::eNone; 73 74 if (aOverscrollAmount.x < 0) { 75 sides |= SideBits::eLeft; 76 } else if (aOverscrollAmount.x > 0) { 77 sides |= SideBits::eRight; 78 } 79 80 if (aOverscrollAmount.y < 0) { 81 sides |= SideBits::eTop; 82 } else if (aOverscrollAmount.y > 0) { 83 sides |= SideBits::eBottom; 84 } 85 86 return sides; 87 } 88 89 } // namespace apz 90 } // namespace layers 91 } // namespace mozilla