LCOV - code coverage report
Current view: top level - gfx/layers/apz/src - Axis.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 18 274 6.6 %
Date: 2017-07-14 16:53:18 Functions: 8 57 14.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2             : /* vim: set sw=2 ts=8 et 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 "Axis.h"
       8             : #include <math.h>                       // for fabsf, pow, powf
       9             : #include <algorithm>                    // for max
      10             : #include "AsyncPanZoomController.h"     // for AsyncPanZoomController
      11             : #include "mozilla/layers/APZCTreeManager.h" // for APZCTreeManager
      12             : #include "mozilla/layers/APZThreadUtils.h" // for AssertOnControllerThread
      13             : #include "FrameMetrics.h"               // for FrameMetrics
      14             : #include "mozilla/Attributes.h"         // for final
      15             : #include "mozilla/ComputedTimingFunction.h" // for ComputedTimingFunction
      16             : #include "mozilla/Preferences.h"        // for Preferences
      17             : #include "mozilla/gfx/Rect.h"           // for RoundedIn
      18             : #include "mozilla/mozalloc.h"           // for operator new
      19             : #include "mozilla/FloatingPoint.h"      // for FuzzyEqualsAdditive
      20             : #include "mozilla/StaticPtr.h"          // for StaticAutoPtr
      21             : #include "nsMathUtils.h"                // for NS_lround
      22             : #include "nsPrintfCString.h"            // for nsPrintfCString
      23             : #include "nsThreadUtils.h"              // for NS_DispatchToMainThread, etc
      24             : #include "nscore.h"                     // for NS_IMETHOD
      25             : #include "gfxPrefs.h"                   // for the preferences
      26             : 
      27             : #define AXIS_LOG(...)
      28             : // #define AXIS_LOG(...) printf_stderr("AXIS: " __VA_ARGS__)
      29             : 
      30             : namespace mozilla {
      31             : namespace layers {
      32             : 
      33             : // When we compute the velocity we do so by taking two input events and
      34             : // dividing the distance delta over the time delta. In some cases the time
      35             : // delta can be really small, which can make the velocity computation very
      36             : // volatile. To avoid this we impose a minimum time delta below which we do
      37             : // not recompute the velocity.
      38             : const uint32_t MIN_VELOCITY_SAMPLE_TIME_MS = 5;
      39             : 
      40           0 : bool FuzzyEqualsCoordinate(float aValue1, float aValue2)
      41             : {
      42           0 :   return FuzzyEqualsAdditive(aValue1, aValue2, COORDINATE_EPSILON)
      43           0 :       || FuzzyEqualsMultiplicative(aValue1, aValue2);
      44             : }
      45             : 
      46           3 : extern StaticAutoPtr<ComputedTimingFunction> gVelocityCurveFunction;
      47             : 
      48           4 : Axis::Axis(AsyncPanZoomController* aAsyncPanZoomController)
      49             :   : mPos(0),
      50             :     mVelocitySampleTimeMs(0),
      51             :     mVelocitySamplePos(0),
      52             :     mVelocity(0.0f),
      53             :     mAxisLocked(false),
      54             :     mAsyncPanZoomController(aAsyncPanZoomController),
      55             :     mOverscroll(0),
      56           4 :     mMSDModel(0.0, 0.0, 0.0, 400.0, 1.2)
      57             : {
      58           4 : }
      59             : 
      60           0 : float Axis::ToLocalVelocity(float aVelocityInchesPerMs) const {
      61           0 :   ScreenPoint velocity = MakePoint(aVelocityInchesPerMs * APZCTreeManager::GetDPI());
      62             :   // Use ToScreenCoordinates() to convert a point rather than a vector by
      63             :   // treating the point as a vector, and using (0, 0) as the anchor.
      64           0 :   ScreenPoint panStart = mAsyncPanZoomController->ToScreenCoordinates(
      65           0 :       mAsyncPanZoomController->PanStart(),
      66           0 :       ParentLayerPoint());
      67             :   ParentLayerPoint localVelocity =
      68           0 :       mAsyncPanZoomController->ToParentLayerCoordinates(velocity, panStart);
      69           0 :   return localVelocity.Length();
      70             : }
      71             : 
      72           0 : void Axis::UpdateWithTouchAtDevicePoint(ParentLayerCoord aPos, ParentLayerCoord aAdditionalDelta, uint32_t aTimestampMs) {
      73             :   // mVelocityQueue is controller-thread only
      74           0 :   APZThreadUtils::AssertOnControllerThread();
      75             : 
      76           0 :   if (aTimestampMs <= mVelocitySampleTimeMs + MIN_VELOCITY_SAMPLE_TIME_MS) {
      77             :     // See also the comment on MIN_VELOCITY_SAMPLE_TIME_MS.
      78             :     // We still update mPos so that the positioning is correct (and we don't run
      79             :     // into problems like bug 1042734) but the velocity will remain where it was.
      80             :     // In particular we don't update either mVelocitySampleTimeMs or
      81             :     // mVelocitySamplePos so that eventually when we do get an event with the
      82             :     // required time delta we use the corresponding distance delta as well.
      83             :     AXIS_LOG("%p|%s skipping velocity computation for small time delta %dms\n",
      84             :         mAsyncPanZoomController, Name(), (aTimestampMs - mVelocitySampleTimeMs));
      85           0 :     mPos = aPos;
      86           0 :     return;
      87             :   }
      88             : 
      89           0 :   float newVelocity = mAxisLocked ? 0.0f : (float)(mVelocitySamplePos - aPos + aAdditionalDelta) / (float)(aTimestampMs - mVelocitySampleTimeMs);
      90             : 
      91           0 :   newVelocity = ApplyFlingCurveToVelocity(newVelocity);
      92             : 
      93             :   AXIS_LOG("%p|%s updating velocity to %f with touch\n",
      94             :     mAsyncPanZoomController, Name(), newVelocity);
      95           0 :   mVelocity = newVelocity;
      96           0 :   mPos = aPos;
      97           0 :   mVelocitySampleTimeMs = aTimestampMs;
      98           0 :   mVelocitySamplePos = aPos;
      99             : 
     100           0 :   AddVelocityToQueue(aTimestampMs, mVelocity);
     101             : }
     102             : 
     103           0 : float Axis::ApplyFlingCurveToVelocity(float aVelocity) const {
     104           0 :   float newVelocity = aVelocity;
     105           0 :   if (gfxPrefs::APZMaxVelocity() > 0.0f) {
     106           0 :     bool velocityIsNegative = (newVelocity < 0);
     107           0 :     newVelocity = fabs(newVelocity);
     108             : 
     109           0 :     float maxVelocity = ToLocalVelocity(gfxPrefs::APZMaxVelocity());
     110           0 :     newVelocity = std::min(newVelocity, maxVelocity);
     111             : 
     112           0 :     if (gfxPrefs::APZCurveThreshold() > 0.0f && gfxPrefs::APZCurveThreshold() < gfxPrefs::APZMaxVelocity()) {
     113           0 :       float curveThreshold = ToLocalVelocity(gfxPrefs::APZCurveThreshold());
     114           0 :       if (newVelocity > curveThreshold) {
     115             :         // here, 0 < curveThreshold < newVelocity <= maxVelocity, so we apply the curve
     116           0 :         float scale = maxVelocity - curveThreshold;
     117           0 :         float funcInput = (newVelocity - curveThreshold) / scale;
     118             :         float funcOutput =
     119           0 :           gVelocityCurveFunction->GetValue(funcInput,
     120           0 :             ComputedTimingFunction::BeforeFlag::Unset);
     121           0 :         float curvedVelocity = (funcOutput * scale) + curveThreshold;
     122             :         AXIS_LOG("%p|%s curving up velocity from %f to %f\n",
     123             :           mAsyncPanZoomController, Name(), newVelocity, curvedVelocity);
     124           0 :         newVelocity = curvedVelocity;
     125             :       }
     126             :     }
     127             : 
     128           0 :     if (velocityIsNegative) {
     129           0 :       newVelocity = -newVelocity;
     130             :     }
     131             :   }
     132             : 
     133           0 :   return newVelocity;
     134             : }
     135             : 
     136           0 : void Axis::AddVelocityToQueue(uint32_t aTimestampMs, float aVelocity) {
     137           0 :   mVelocityQueue.AppendElement(std::make_pair(aTimestampMs, aVelocity));
     138           0 :   if (mVelocityQueue.Length() > gfxPrefs::APZMaxVelocityQueueSize()) {
     139           0 :     mVelocityQueue.RemoveElementAt(0);
     140             :   }
     141           0 : }
     142             : 
     143           0 : void Axis::HandleTouchVelocity(uint32_t aTimestampMs, float aSpeed) {
     144             :   // mVelocityQueue is controller-thread only
     145           0 :   APZThreadUtils::AssertOnControllerThread();
     146             : 
     147           0 :   mVelocity = ApplyFlingCurveToVelocity(aSpeed);
     148           0 :   mVelocitySampleTimeMs = aTimestampMs;
     149             : 
     150           0 :   AddVelocityToQueue(aTimestampMs, mVelocity);
     151           0 : }
     152             : 
     153           0 : void Axis::StartTouch(ParentLayerCoord aPos, uint32_t aTimestampMs) {
     154           0 :   mStartPos = aPos;
     155           0 :   mPos = aPos;
     156           0 :   mVelocitySampleTimeMs = aTimestampMs;
     157           0 :   mVelocitySamplePos = aPos;
     158           0 :   mAxisLocked = false;
     159           0 : }
     160             : 
     161           0 : bool Axis::AdjustDisplacement(ParentLayerCoord aDisplacement,
     162             :                               /* ParentLayerCoord */ float& aDisplacementOut,
     163             :                               /* ParentLayerCoord */ float& aOverscrollAmountOut,
     164             :                               bool aForceOverscroll /* = false */)
     165             : {
     166           0 :   if (mAxisLocked) {
     167           0 :     aOverscrollAmountOut = 0;
     168           0 :     aDisplacementOut = 0;
     169           0 :     return false;
     170             :   }
     171           0 :   if (aForceOverscroll) {
     172           0 :     aOverscrollAmountOut = aDisplacement;
     173           0 :     aDisplacementOut = 0;
     174           0 :     return false;
     175             :   }
     176             : 
     177           0 :   EndOverscrollAnimation();
     178             : 
     179           0 :   ParentLayerCoord displacement = aDisplacement;
     180             : 
     181             :   // First consume any overscroll in the opposite direction along this axis.
     182           0 :   ParentLayerCoord consumedOverscroll = 0;
     183           0 :   if (mOverscroll > 0 && aDisplacement < 0) {
     184           0 :     consumedOverscroll = std::min(mOverscroll, -aDisplacement);
     185           0 :   } else if (mOverscroll < 0 && aDisplacement > 0) {
     186           0 :     consumedOverscroll = 0.f - std::min(-mOverscroll, aDisplacement);
     187             :   }
     188           0 :   mOverscroll -= consumedOverscroll;
     189           0 :   displacement += consumedOverscroll;
     190             : 
     191             :   // Split the requested displacement into an allowed displacement that does
     192             :   // not overscroll, and an overscroll amount.
     193           0 :   aOverscrollAmountOut = DisplacementWillOverscrollAmount(displacement);
     194           0 :   if (aOverscrollAmountOut != 0.0f) {
     195             :     // No need to have a velocity along this axis anymore; it won't take us
     196             :     // anywhere, so we're just spinning needlessly.
     197             :     AXIS_LOG("%p|%s has overscrolled, clearing velocity\n",
     198             :       mAsyncPanZoomController, Name());
     199           0 :     mVelocity = 0.0f;
     200           0 :     displacement -= aOverscrollAmountOut;
     201             :   }
     202           0 :   aDisplacementOut = displacement;
     203           0 :   return fabsf(consumedOverscroll) > EPSILON;
     204             : }
     205             : 
     206           0 : ParentLayerCoord Axis::ApplyResistance(ParentLayerCoord aRequestedOverscroll) const {
     207             :   // 'resistanceFactor' is a value between 0 and 1/16, which:
     208             :   //   - tends to 1/16 as the existing overscroll tends to 0
     209             :   //   - tends to 0 as the existing overscroll tends to the composition length
     210             :   // The actual overscroll is the requested overscroll multiplied by this
     211             :   // factor.
     212           0 :   float resistanceFactor = (1 - fabsf(GetOverscroll()) / GetCompositionLength()) / 16;
     213           0 :   float result = resistanceFactor < 0 ? ParentLayerCoord(0) : aRequestedOverscroll * resistanceFactor;
     214           0 :   result = clamped(result, -8.0f, 8.0f);
     215           0 :   return result;
     216             : }
     217             : 
     218           0 : void Axis::OverscrollBy(ParentLayerCoord aOverscroll) {
     219           0 :   MOZ_ASSERT(CanScroll());
     220             :   // We can get some spurious calls to OverscrollBy() with near-zero values
     221             :   // due to rounding error. Ignore those (they might trip the asserts below.)
     222           0 :   if (FuzzyEqualsAdditive(aOverscroll.value, 0.0f, COORDINATE_EPSILON)) {
     223           0 :     return;
     224             :   }
     225           0 :   EndOverscrollAnimation();
     226           0 :   aOverscroll = ApplyResistance(aOverscroll);
     227           0 :   if (aOverscroll > 0) {
     228             : #ifdef DEBUG
     229           0 :     if (!FuzzyEqualsCoordinate(GetCompositionEnd().value, GetPageEnd().value)) {
     230             :       nsPrintfCString message("composition end (%f) is not equal (within error) to page end (%f)\n",
     231           0 :                               GetCompositionEnd().value, GetPageEnd().value);
     232           0 :       NS_ASSERTION(false, message.get());
     233           0 :       MOZ_CRASH("GFX: Overscroll issue > 0");
     234             :     }
     235             : #endif
     236           0 :     MOZ_ASSERT(mOverscroll >= 0);
     237           0 :   } else if (aOverscroll < 0) {
     238             : #ifdef DEBUG
     239           0 :     if (!FuzzyEqualsCoordinate(GetOrigin().value, GetPageStart().value)) {
     240             :       nsPrintfCString message("composition origin (%f) is not equal (within error) to page origin (%f)\n",
     241           0 :                               GetOrigin().value, GetPageStart().value);
     242           0 :       NS_ASSERTION(false, message.get());
     243           0 :       MOZ_CRASH("GFX: Overscroll issue < 0");
     244             :     }
     245             : #endif
     246           0 :     MOZ_ASSERT(mOverscroll <= 0);
     247             :   }
     248           0 :   mOverscroll += aOverscroll;
     249             : }
     250             : 
     251           0 : ParentLayerCoord Axis::GetOverscroll() const {
     252           0 :   return mOverscroll;
     253             : }
     254             : 
     255           0 : void Axis::StartOverscrollAnimation(float aVelocity) {
     256           0 :   aVelocity = clamped(aVelocity / 2.0f, -20.0f, 20.0f);
     257           0 :   SetVelocity(aVelocity);
     258           0 :   mMSDModel.SetPosition(mOverscroll);
     259             :   // Convert velocity from ParentLayerCoords/millisecond to ParentLayerCoords/second.
     260           0 :   mMSDModel.SetVelocity(mVelocity * 1000.0);
     261           0 : }
     262             : 
     263           0 : void Axis::EndOverscrollAnimation() {
     264           0 :   mMSDModel.SetPosition(0.0);
     265           0 :   mMSDModel.SetVelocity(0.0);
     266           0 : }
     267             : 
     268           0 : bool Axis::SampleOverscrollAnimation(const TimeDuration& aDelta) {
     269           0 :   mMSDModel.Simulate(aDelta);
     270           0 :   mOverscroll = mMSDModel.GetPosition();
     271             : 
     272           0 :   if (mMSDModel.IsFinished(1.0)) {
     273             :     // "Jump" to the at-rest state. The jump shouldn't be noticeable as the
     274             :     // velocity and overscroll are already low.
     275             :     AXIS_LOG("%p|%s oscillation dropped below threshold, going to rest\n",
     276             :       mAsyncPanZoomController, Name());
     277           0 :     ClearOverscroll();
     278           0 :     mVelocity = 0;
     279           0 :     return false;
     280             :   }
     281             : 
     282             :   // Otherwise, continue the animation.
     283           0 :   return true;
     284             : }
     285             : 
     286         116 : bool Axis::IsOverscrolled() const {
     287         116 :   return mOverscroll != 0.f;
     288             : }
     289             : 
     290           0 : void Axis::ClearOverscroll() {
     291           0 :   EndOverscrollAnimation();
     292           0 :   mOverscroll = 0;
     293           0 : }
     294             : 
     295           0 : ParentLayerCoord Axis::PanStart() const {
     296           0 :   return mStartPos;
     297             : }
     298             : 
     299           0 : ParentLayerCoord Axis::PanDistance() const {
     300           0 :   return fabs(mPos - mStartPos);
     301             : }
     302             : 
     303           0 : ParentLayerCoord Axis::PanDistance(ParentLayerCoord aPos) const {
     304           0 :   return fabs(aPos - mStartPos);
     305             : }
     306             : 
     307           0 : void Axis::EndTouch(uint32_t aTimestampMs) {
     308             :   // mVelocityQueue is controller-thread only
     309           0 :   APZThreadUtils::AssertOnControllerThread();
     310             : 
     311           0 :   mAxisLocked = false;
     312           0 :   mVelocity = 0;
     313           0 :   int count = 0;
     314           0 :   for (const auto& e : mVelocityQueue) {
     315           0 :     uint32_t timeDelta = (aTimestampMs - e.first);
     316           0 :     if (timeDelta < gfxPrefs::APZVelocityRelevanceTime()) {
     317           0 :       count++;
     318           0 :       mVelocity += e.second;
     319             :     }
     320             :   }
     321           0 :   mVelocityQueue.Clear();
     322           0 :   if (count > 1) {
     323           0 :     mVelocity /= count;
     324             :   }
     325             :   AXIS_LOG("%p|%s ending touch, computed velocity %f\n",
     326             :     mAsyncPanZoomController, Name(), mVelocity);
     327           0 : }
     328             : 
     329           0 : void Axis::CancelGesture() {
     330             :   // mVelocityQueue is controller-thread only
     331           0 :   APZThreadUtils::AssertOnControllerThread();
     332             : 
     333             :   AXIS_LOG("%p|%s cancelling touch, clearing velocity queue\n",
     334             :     mAsyncPanZoomController, Name());
     335           0 :   mVelocity = 0.0f;
     336           0 :   mVelocityQueue.Clear();
     337           0 : }
     338             : 
     339           0 : bool Axis::CanScroll() const {
     340           0 :   return GetPageLength() - GetCompositionLength() > COORDINATE_EPSILON;
     341             : }
     342             : 
     343           0 : bool Axis::CanScroll(ParentLayerCoord aDelta) const
     344             : {
     345           0 :   if (!CanScroll() || mAxisLocked) {
     346           0 :     return false;
     347             :   }
     348             : 
     349           0 :   return fabs(DisplacementWillOverscrollAmount(aDelta) - aDelta) > COORDINATE_EPSILON;
     350             : }
     351             : 
     352           0 : CSSCoord Axis::ClampOriginToScrollableRect(CSSCoord aOrigin) const
     353             : {
     354           0 :   CSSToParentLayerScale zoom = GetScaleForAxis(GetFrameMetrics().GetZoom());
     355           0 :   ParentLayerCoord origin = aOrigin * zoom;
     356             : 
     357           0 :   ParentLayerCoord result;
     358           0 :   if (origin < GetPageStart()) {
     359           0 :     result = GetPageStart();
     360           0 :   } else if (origin + GetCompositionLength() > GetPageEnd()) {
     361           0 :     result = GetPageEnd() - GetCompositionLength();
     362             :   } else {
     363           0 :     return aOrigin;
     364             :   }
     365             : 
     366           0 :   return result / zoom;
     367             : }
     368             : 
     369           0 : bool Axis::CanScrollNow() const {
     370           0 :   return !mAxisLocked && CanScroll();
     371             : }
     372             : 
     373           0 : bool Axis::FlingApplyFrictionOrCancel(const TimeDuration& aDelta,
     374             :                                       float aFriction,
     375             :                                       float aThreshold) {
     376           0 :   if (fabsf(mVelocity) <= aThreshold) {
     377             :     // If the velocity is very low, just set it to 0 and stop the fling,
     378             :     // otherwise we'll just asymptotically approach 0 and the user won't
     379             :     // actually see any changes.
     380           0 :     mVelocity = 0.0f;
     381           0 :     return false;
     382             :   } else {
     383           0 :     mVelocity *= pow(1.0f - aFriction, float(aDelta.ToMilliseconds()));
     384             :   }
     385             :   AXIS_LOG("%p|%s reduced velocity to %f due to friction\n",
     386             :     mAsyncPanZoomController, Name(), mVelocity);
     387           0 :   return true;
     388             : }
     389             : 
     390           0 : ParentLayerCoord Axis::DisplacementWillOverscrollAmount(ParentLayerCoord aDisplacement) const {
     391           0 :   ParentLayerCoord newOrigin = GetOrigin() + aDisplacement;
     392           0 :   ParentLayerCoord newCompositionEnd = GetCompositionEnd() + aDisplacement;
     393             :   // If the current pan plus a displacement takes the window to the left of or
     394             :   // above the current page rect.
     395           0 :   bool minus = newOrigin < GetPageStart();
     396             :   // If the current pan plus a displacement takes the window to the right of or
     397             :   // below the current page rect.
     398           0 :   bool plus = newCompositionEnd > GetPageEnd();
     399           0 :   if (minus && plus) {
     400             :     // Don't handle overscrolled in both directions; a displacement can't cause
     401             :     // this, it must have already been zoomed out too far.
     402           0 :     return 0;
     403             :   }
     404           0 :   if (minus) {
     405           0 :     return newOrigin - GetPageStart();
     406             :   }
     407           0 :   if (plus) {
     408           0 :     return newCompositionEnd - GetPageEnd();
     409             :   }
     410           0 :   return 0;
     411             : }
     412             : 
     413           0 : CSSCoord Axis::ScaleWillOverscrollAmount(float aScale, CSSCoord aFocus) const {
     414             :   // Internally, do computations in ParentLayer coordinates *before* the scale
     415             :   // is applied.
     416           0 :   CSSToParentLayerScale zoom = GetFrameMetrics().GetZoom().ToScaleFactor();
     417           0 :   ParentLayerCoord focus = aFocus * zoom;
     418           0 :   ParentLayerCoord originAfterScale = (GetOrigin() + focus) - (focus / aScale);
     419             : 
     420           0 :   bool both = ScaleWillOverscrollBothSides(aScale);
     421           0 :   bool minus = GetPageStart() - originAfterScale > COORDINATE_EPSILON;
     422           0 :   bool plus = (originAfterScale + (GetCompositionLength() / aScale)) - GetPageEnd() > COORDINATE_EPSILON;
     423             : 
     424           0 :   if ((minus && plus) || both) {
     425             :     // If we ever reach here it's a bug in the client code.
     426           0 :     MOZ_ASSERT(false, "In an OVERSCROLL_BOTH condition in ScaleWillOverscrollAmount");
     427             :     return 0;
     428             :   }
     429           0 :   if (minus) {
     430           0 :     return (originAfterScale - GetPageStart()) / zoom;
     431             :   }
     432           0 :   if (plus) {
     433           0 :     return (originAfterScale + (GetCompositionLength() / aScale) - GetPageEnd()) / zoom;
     434             :   }
     435           0 :   return 0;
     436             : }
     437             : 
     438           0 : bool Axis::IsAxisLocked() const {
     439           0 :   return mAxisLocked;
     440             : }
     441             : 
     442           8 : float Axis::GetVelocity() const {
     443           8 :   return mAxisLocked ? 0 : mVelocity;
     444             : }
     445             : 
     446           4 : void Axis::SetVelocity(float aVelocity) {
     447             :   AXIS_LOG("%p|%s direct-setting velocity to %f\n",
     448             :     mAsyncPanZoomController, Name(), aVelocity);
     449           4 :   mVelocity = aVelocity;
     450           4 : }
     451             : 
     452           0 : ParentLayerCoord Axis::GetCompositionEnd() const {
     453           0 :   return GetOrigin() + GetCompositionLength();
     454             : }
     455             : 
     456           0 : ParentLayerCoord Axis::GetPageEnd() const {
     457           0 :   return GetPageStart() + GetPageLength();
     458             : }
     459             : 
     460           0 : ParentLayerCoord Axis::GetScrollRangeEnd() const {
     461           0 :   return GetPageEnd() - GetCompositionLength();
     462             : }
     463             : 
     464           0 : ParentLayerCoord Axis::GetOrigin() const {
     465           0 :   ParentLayerPoint origin = GetFrameMetrics().GetScrollOffset() * GetFrameMetrics().GetZoom();
     466           0 :   return GetPointOffset(origin);
     467             : }
     468             : 
     469           0 : ParentLayerCoord Axis::GetCompositionLength() const {
     470           0 :   return GetRectLength(GetFrameMetrics().GetCompositionBounds());
     471             : }
     472             : 
     473           0 : ParentLayerCoord Axis::GetPageStart() const {
     474           0 :   ParentLayerRect pageRect = GetFrameMetrics().GetExpandedScrollableRect() * GetFrameMetrics().GetZoom();
     475           0 :   return GetRectOffset(pageRect);
     476             : }
     477             : 
     478           0 : ParentLayerCoord Axis::GetPageLength() const {
     479           0 :   ParentLayerRect pageRect = GetFrameMetrics().GetExpandedScrollableRect() * GetFrameMetrics().GetZoom();
     480           0 :   return GetRectLength(pageRect);
     481             : }
     482             : 
     483           0 : bool Axis::ScaleWillOverscrollBothSides(float aScale) const {
     484           0 :   const FrameMetrics& metrics = GetFrameMetrics();
     485           0 :   ParentLayerRect screenCompositionBounds = metrics.GetCompositionBounds()
     486           0 :                                           / ParentLayerToParentLayerScale(aScale);
     487           0 :   return GetRectLength(screenCompositionBounds) - GetPageLength() > COORDINATE_EPSILON;
     488             : }
     489             : 
     490           0 : const FrameMetrics& Axis::GetFrameMetrics() const {
     491           0 :   return mAsyncPanZoomController->GetFrameMetrics();
     492             : }
     493             : 
     494             : 
     495           2 : AxisX::AxisX(AsyncPanZoomController* aAsyncPanZoomController)
     496           2 :   : Axis(aAsyncPanZoomController)
     497             : {
     498             : 
     499           2 : }
     500             : 
     501           0 : ParentLayerCoord AxisX::GetPointOffset(const ParentLayerPoint& aPoint) const
     502             : {
     503           0 :   return aPoint.x;
     504             : }
     505             : 
     506           0 : ParentLayerCoord AxisX::GetRectLength(const ParentLayerRect& aRect) const
     507             : {
     508           0 :   return aRect.width;
     509             : }
     510             : 
     511           0 : ParentLayerCoord AxisX::GetRectOffset(const ParentLayerRect& aRect) const
     512             : {
     513           0 :   return aRect.x;
     514             : }
     515             : 
     516           0 : CSSToParentLayerScale AxisX::GetScaleForAxis(const CSSToParentLayerScale2D& aScale) const
     517             : {
     518           0 :   return CSSToParentLayerScale(aScale.xScale);
     519             : }
     520             : 
     521           0 : ScreenPoint AxisX::MakePoint(ScreenCoord aCoord) const
     522             : {
     523           0 :   return ScreenPoint(aCoord, 0);
     524             : }
     525             : 
     526           0 : const char* AxisX::Name() const
     527             : {
     528           0 :   return "X";
     529             : }
     530             : 
     531           2 : AxisY::AxisY(AsyncPanZoomController* aAsyncPanZoomController)
     532           2 :   : Axis(aAsyncPanZoomController)
     533             : {
     534             : 
     535           2 : }
     536             : 
     537           0 : ParentLayerCoord AxisY::GetPointOffset(const ParentLayerPoint& aPoint) const
     538             : {
     539           0 :   return aPoint.y;
     540             : }
     541             : 
     542           0 : ParentLayerCoord AxisY::GetRectLength(const ParentLayerRect& aRect) const
     543             : {
     544           0 :   return aRect.height;
     545             : }
     546             : 
     547           0 : ParentLayerCoord AxisY::GetRectOffset(const ParentLayerRect& aRect) const
     548             : {
     549           0 :   return aRect.y;
     550             : }
     551             : 
     552           0 : CSSToParentLayerScale AxisY::GetScaleForAxis(const CSSToParentLayerScale2D& aScale) const
     553             : {
     554           0 :   return CSSToParentLayerScale(aScale.yScale);
     555             : }
     556             : 
     557           0 : ScreenPoint AxisY::MakePoint(ScreenCoord aCoord) const
     558             : {
     559           0 :   return ScreenPoint(0, aCoord);
     560             : }
     561             : 
     562           0 : const char* AxisY::Name() const
     563             : {
     564           0 :   return "Y";
     565             : }
     566             : 
     567             : } // namespace layers
     568           9 : } // namespace mozilla

Generated by: LCOV version 1.13