Bug 1501665 Part 4: Use the new function as a replacement for APZAllowZooming. r=botond
authorBrad Werth <bwerth@mozilla.com>
Mon, 18 Mar 2019 14:56:55 +0000
changeset 464839 7a7781e568c2a8509de7a51dbb68878514d99417
parent 464838 c947824bd2d893bb162cb7a5ed92ba64a7996829
child 464840 05efd157254b238c0bcb14807bf8ce2ddec20250
push id35727
push userdvarga@mozilla.com
push dateTue, 19 Mar 2019 09:48:59 +0000
treeherdermozilla-central@70baa37ae1eb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbotond
bugs1501665
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1501665 Part 4: Use the new function as a replacement for APZAllowZooming. r=botond Differential Revision: https://phabricator.services.mozilla.com/D19239
gfx/layers/apz/src/APZInputBridge.cpp
gfx/layers/apz/src/AsyncPanZoomController.cpp
gfx/layers/apz/util/APZCCallbackHelper.cpp
layout/base/MobileViewportManager.cpp
layout/base/PresShell.cpp
layout/base/TouchManager.cpp
layout/base/ZoomConstraintsClient.cpp
layout/base/nsLayoutUtils.cpp
widget/cocoa/nsChildView.mm
--- a/gfx/layers/apz/src/APZInputBridge.cpp
+++ b/gfx/layers/apz/src/APZInputBridge.cpp
@@ -59,16 +59,18 @@ nsEventStatus APZInputBridge::ReceiveInp
         UpdateWheelTransaction(mouseEvent.mRefPoint, mouseEvent.mMessage);
       }
 
       // If zooming is enabled, mark the mouse event as "ignore root
       // scroll frame". This ensures that the main-thread hit test the
       // mouse event undergoes (in PositionedEventTargeting.cpp) uses
       // the IGNORE_ROOT_SCROLL_FRAME flag, which is needed for correct
       // hit testing in a zoomed-in or zoomed-out state.
+      // FIXME: bug 1525793 -- this may need to handle zooming or not on a
+      // per-document basis.
       if (gfxPrefs::APZAllowZooming()) {
         mouseEvent.mIgnoreRootScrollFrame = true;
       }
 
       if (WillHandleMouseEvent(mouseEvent)) {
         MouseInput input(mouseEvent);
         input.mOrigin =
             ScreenPoint(mouseEvent.mRefPoint.x, mouseEvent.mRefPoint.y);
--- a/gfx/layers/apz/src/AsyncPanZoomController.cpp
+++ b/gfx/layers/apz/src/AsyncPanZoomController.cpp
@@ -1520,16 +1520,18 @@ nsEventStatus AsyncPanZoomController::On
   // Start tracking panning distance and velocity.
   if (!mZoomConstraints.mAllowZoom) {
     mX.StartTouch(aEvent.mLocalFocusPoint.x, aEvent.mTime);
     mY.StartTouch(aEvent.mLocalFocusPoint.y, aEvent.mTime);
   }
 
   // For platforms that don't support APZ zooming, dispatch a message to the
   // content controller, it may want to do something else with this gesture.
+  // FIXME: bug 1525793 -- this may need to handle zooming or not on a
+  // per-document basis.
   if (!gfxPrefs::APZAllowZooming()) {
     if (RefPtr<GeckoContentController> controller =
             GetGeckoContentController()) {
       controller->NotifyPinchGesture(aEvent.mType, GetGuid(), 0,
                                      aEvent.modifiers);
     }
   }
 
@@ -1564,16 +1566,18 @@ nsEventStatus AsyncPanZoomController::On
   // Tracking panning distance and velocity.
   // UpdateWithTouchAtDevicePoint() acquires the tree lock, so
   // it cannot be called while the mRecursiveMutex lock is held.
   if (!allowZoom) {
     mX.UpdateWithTouchAtDevicePoint(aEvent.mLocalFocusPoint.x, aEvent.mTime);
     mY.UpdateWithTouchAtDevicePoint(aEvent.mLocalFocusPoint.y, aEvent.mTime);
   }
 
+  // FIXME: bug 1525793 -- this may need to handle zooming or not on a
+  // per-document basis.
   if (!gfxPrefs::APZAllowZooming()) {
     if (RefPtr<GeckoContentController> controller =
             GetGeckoContentController()) {
       controller->NotifyPinchGesture(
           aEvent.mType, GetGuid(),
           ViewAs<LayoutDevicePixel>(
               aEvent.mCurrentSpan - aEvent.mPreviousSpan,
               PixelCastJustification::LayoutDeviceIsParentLayerForRCDRSF),
@@ -1697,16 +1701,18 @@ nsEventStatus AsyncPanZoomController::On
 
   mPinchPaintTimerSet = false;
 
   if (HasReadyTouchBlock() &&
       !GetCurrentTouchBlock()->TouchActionAllowsPinchZoom()) {
     return nsEventStatus_eIgnore;
   }
 
+  // FIXME: bug 1525793 -- this may need to handle zooming or not on a
+  // per-document basis.
   if (!gfxPrefs::APZAllowZooming()) {
     if (RefPtr<GeckoContentController> controller =
             GetGeckoContentController()) {
       controller->NotifyPinchGesture(aEvent.mType, GetGuid(), 0,
                                      aEvent.modifiers);
     }
   }
 
@@ -4069,16 +4075,18 @@ AsyncTransform AsyncPanZoomController::G
 AsyncTransform
 AsyncPanZoomController::GetCurrentAsyncTransformForFixedAdjustment(
     AsyncTransformConsumer aMode) const {
   RecursiveMutexAutoLock lock(mRecursiveMutex);
 
   // Use the layout viewport to adjust fixed position elements if and only if
   // it's larger than the visual viewport (assuming we're scrolling the RCD-RSF
   // with apz.allow_zooming enabled).
+  // FIXME: bug 1525793 -- this may need to handle zooming or not on a
+  // per-document basis.
   return (gfxPrefs::APZAllowZooming() && Metrics().IsRootContent() &&
           Metrics().GetVisualViewport().Size() <=
               Metrics().GetLayoutViewport().Size())
              ? GetCurrentAsyncViewportTransform(aMode)
              : GetCurrentAsyncTransform(aMode);
 }
 
 AsyncTransformComponentMatrix
--- a/gfx/layers/apz/util/APZCCallbackHelper.cpp
+++ b/gfx/layers/apz/util/APZCCallbackHelper.cpp
@@ -302,17 +302,18 @@ void APZCCallbackHelper::UpdateRootFrame
     return;
   }
 
   nsCOMPtr<nsIPresShell> shell = GetPresShell(content);
   if (!shell || aRequest.GetPresShellId() != shell->GetPresShellId()) {
     return;
   }
 
-  if (gfxPrefs::APZAllowZooming() && aRequest.GetScrollOffsetUpdated()) {
+  if (nsLayoutUtils::AllowZoomingForDocument(shell->GetDocument()) &&
+      aRequest.GetScrollOffsetUpdated()) {
     // If zooming is disabled then we don't really want to let APZ fiddle
     // with these things. In theory setting the resolution here should be a
     // no-op, but setting the visual viewport size is bad because it can cause a
     // stale value to be returned by window.innerWidth/innerHeight (see bug
     // 1187792).
     //
     // We also skip this codepath unless the metrics has a scroll offset update
     // type other eNone, because eNone just means that this repaint request
@@ -666,17 +667,18 @@ static bool PrepareForSetTargetAPZCNotif
     nsIWidget* aWidget, const ScrollableLayerGuid& aGuid, nsIFrame* aRootFrame,
     const LayoutDeviceIntPoint& aRefPoint,
     nsTArray<ScrollableLayerGuid>* aTargets) {
   ScrollableLayerGuid guid(aGuid.mLayersId, 0,
                            ScrollableLayerGuid::NULL_SCROLL_ID);
   nsPoint point = nsLayoutUtils::GetEventCoordinatesRelativeTo(
       aWidget, aRefPoint, aRootFrame);
   EnumSet<FrameForPointOption> options;
-  if (gfxPrefs::APZAllowZooming()) {
+  if (nsLayoutUtils::AllowZoomingForDocument(
+          aRootFrame->PresShell()->GetDocument())) {
     // If zooming is enabled, we need IgnoreRootScrollFrame for correct
     // hit testing. Otherwise, don't use it because it interferes with
     // hit testing for some purposes such as scrollbar dragging (this will
     // need to be fixed before enabling zooming by default on desktop).
     options += FrameForPointOption::IgnoreRootScrollFrame;
   }
   nsIFrame* target =
       nsLayoutUtils::GetFrameForPoint(aRootFrame, point, options);
--- a/layout/base/MobileViewportManager.cpp
+++ b/layout/base/MobileViewportManager.cpp
@@ -501,17 +501,17 @@ void MobileViewportManager::RefreshViewp
     return;
   }
 
   // If it's the first-paint or the viewport changed, we need to update
   // various APZ properties (the zoom and some things that might depend on it)
   MVM_LOG("%p: Updating properties because %d || %d\n", this, mIsFirstPaint,
           mMobileViewportSize != viewport);
 
-  if (gfxPrefs::APZAllowZooming()) {
+  if (nsLayoutUtils::AllowZoomingForDocument(mDocument)) {
     UpdateResolution(viewportInfo, displaySize, viewport,
                      displayWidthChangeRatio, UpdateType::ViewportSize);
   } else {
     // Even without zoom, we need to update that the visual viewport size
     // has changed.
     RefreshVisualViewportSize();
   }
   if (gfxPlatform::AsyncPanZoomEnabled()) {
@@ -540,18 +540,18 @@ void MobileViewportManager::RefreshViewp
 }
 
 void MobileViewportManager::ShrinkToDisplaySizeIfNeeded(
     nsViewportInfo& aViewportInfo, const ScreenIntSize& aDisplaySize) {
   if (!mPresShell) {
     return;
   }
 
-  if (!gfxPrefs::APZAllowZooming()) {
-    // If the APZ is disabled, we don't scale down wider contents to fit them
+  if (!nsLayoutUtils::AllowZoomingForDocument(mDocument)) {
+    // If zoom is disabled, we don't scale down wider contents to fit them
     // into device screen because users won't be able to zoom out the tiny
     // contents.
     return;
   }
 
   nsIScrollableFrame* rootScrollableFrame =
       mPresShell->GetRootScrollFrameAsScrollable();
   if (rootScrollableFrame) {
--- a/layout/base/PresShell.cpp
+++ b/layout/base/PresShell.cpp
@@ -10497,19 +10497,20 @@ nsresult PresShell::SetIsActive(bool aIs
       accService->PresShellActivated(this);
     }
   }
 #endif
   return rv;
 }
 
 void PresShell::UpdateViewportOverridden(bool aAfterInitialization) {
-  // Determine if we require a MobileViewportManager.
-  bool needMVM = nsLayoutUtils::ShouldHandleMetaViewport(mDocument) ||
-                 gfxPrefs::APZAllowZooming();
+  // Determine if we require a MobileViewportManager. This logic is
+  // equivalent to ShouldHandleMetaViewport, which will check gfxPrefs if
+  // there are not meta viewport overrides.
+  bool needMVM = nsLayoutUtils::ShouldHandleMetaViewport(mDocument);
 
   if (needMVM == !!mMobileViewportManager) {
     // Either we've need one and we've already got it, or we don't need one
     // and don't have it. Either way, we're done.
     return;
   }
 
   if (needMVM) {
--- a/layout/base/TouchManager.cpp
+++ b/layout/base/TouchManager.cpp
@@ -109,17 +109,18 @@ nsIFrame* TouchManager::SetupTarget(Widg
     // All touch events except for touchstart use a captured target.
     return aFrame;
   }
 
   uint32_t flags = 0;
   // Setting this flag will skip the scrollbars on the root frame from
   // participating in hit-testing, and we only want that to happen on
   // zoomable platforms (for now).
-  if (gfxPrefs::APZAllowZooming()) {
+  dom::Document* doc = aFrame->PresContext()->Document();
+  if (nsLayoutUtils::AllowZoomingForDocument(doc)) {
     flags |= INPUT_IGNORE_ROOT_SCROLL_FRAME;
   }
 
   nsIFrame* target = aFrame;
   for (int32_t i = aEvent->mTouches.Length(); i;) {
     --i;
     dom::Touch* touch = aEvent->mTouches[i];
 
--- a/layout/base/ZoomConstraintsClient.cpp
+++ b/layout/base/ZoomConstraintsClient.cpp
@@ -163,20 +163,20 @@ ZoomConstraintsClient::Observe(nsISuppor
 }
 
 void ZoomConstraintsClient::ScreenSizeChanged() {
   ZCC_LOG("Got a screen-size change notification in %p\n", this);
   RefreshZoomConstraints();
 }
 
 static mozilla::layers::ZoomConstraints ComputeZoomConstraintsFromViewportInfo(
-    const nsViewportInfo& aViewportInfo) {
+    const nsViewportInfo& aViewportInfo, Document* aDocument) {
   mozilla::layers::ZoomConstraints constraints;
-  constraints.mAllowZoom =
-      aViewportInfo.IsZoomAllowed() && gfxPrefs::APZAllowZooming();
+  constraints.mAllowZoom = aViewportInfo.IsZoomAllowed() &&
+                           nsLayoutUtils::AllowZoomingForDocument(aDocument);
   constraints.mAllowDoubleTapZoom =
       constraints.mAllowZoom && gfxPrefs::APZAllowDoubleTapZooming();
   if (constraints.mAllowZoom) {
     constraints.mMinZoom.scale = aViewportInfo.GetMinZoom().scale;
     constraints.mMaxZoom.scale = aViewportInfo.GetMaxZoom().scale;
   } else {
     constraints.mMinZoom.scale = aViewportInfo.GetDefaultZoom().scale;
     constraints.mMaxZoom.scale = aViewportInfo.GetDefaultZoom().scale;
@@ -204,17 +204,17 @@ void ZoomConstraintsClient::RefreshZoomC
                                            screenSize)) {
     return;
   }
 
   nsViewportInfo viewportInfo = mDocument->GetViewportInfo(ViewAs<ScreenPixel>(
       screenSize, PixelCastJustification::LayoutDeviceIsScreenForBounds));
 
   mozilla::layers::ZoomConstraints zoomConstraints =
-      ComputeZoomConstraintsFromViewportInfo(viewportInfo);
+      ComputeZoomConstraintsFromViewportInfo(viewportInfo, mDocument);
 
   if (mDocument->Fullscreen()) {
     ZCC_LOG("%p is in fullscreen, disallowing zooming\n", this);
     zoomConstraints.mAllowZoom = false;
     zoomConstraints.mAllowDoubleTapZoom = false;
   }
 
   if (zoomConstraints.mAllowDoubleTapZoom) {
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -9346,17 +9346,18 @@ static void UpdateDisplayPortMarginsForP
     return;
   }
 
   nsCOMPtr<nsIPresShell> shell = GetPresShell(content);
   if (!shell) {
     return;
   }
 
-  if (gfxPrefs::APZAllowZooming() && aMetrics.IsRootContent()) {
+  if (nsLayoutUtils::AllowZoomingForDocument(shell->GetDocument()) &&
+      aMetrics.IsRootContent()) {
     // See APZCCallbackHelper::UpdateRootFrame for details.
     float presShellResolution = shell->GetResolution();
     if (presShellResolution != aMetrics.GetPresShellResolution()) {
       return;
     }
   }
 
   nsIScrollableFrame* frame =
--- a/widget/cocoa/nsChildView.mm
+++ b/widget/cocoa/nsChildView.mm
@@ -3673,16 +3673,17 @@ NSEvent* gLastDragMouseDownEvent = nil;
 // Pinch zoom gesture.
 - (void)magnifyWithEvent:(NSEvent*)anEvent {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
 
   if (!mGeckoChild) {
     return;
   }
 
+  // FIXME: bug 1525793 -- this may need to handle zooming or not on a per-document basis.
   if (gfxPrefs::APZAllowZooming()) {
     NSPoint locationInWindow = nsCocoaUtils::EventLocationForWindow(anEvent, [self window]);
     ScreenPoint position =
         ViewAs<ScreenPixel>([self convertWindowCoordinatesRoundDown:locationInWindow],
                             PixelCastJustification::LayoutDeviceIsScreenForUntransformedEvent);
     ExternalPoint screenOffset =
         ViewAs<ExternalPixel>(mGeckoChild->WidgetToScreenOffset(),
                               PixelCastJustification::LayoutDeviceIsScreenForUntransformedEvent);