From 6b2369f993ed0d95b26770c8483a0a1455fbc888 Mon Sep 17 00:00:00 2001 From: Kartikaya Gupta Date: Wed, 22 Jul 2015 23:42:08 -0400 Subject: [PATCH] Bug 1186004 - Add a pref to enable/disable APZ zooming behaviour. r=botond --- b2g/app/b2g.js | 5 ++++- dom/base/nsDocument.cpp | 4 ++-- dom/base/nsViewportInfo.h | 6 ++++++ gfx/thebes/gfxPrefs.h | 1 + layout/base/MobileViewportManager.cpp | 7 +++++-- layout/base/ZoomConstraintsClient.cpp | 4 ++-- mobile/android/app/mobile.js | 1 + modules/libpref/init/all.js | 1 + 8 files changed, 22 insertions(+), 7 deletions(-) diff --git a/b2g/app/b2g.js b/b2g/app/b2g.js index acec12093ab..38f682c5c4e 100644 --- a/b2g/app/b2g.js +++ b/b2g/app/b2g.js @@ -1040,7 +1040,10 @@ pref("security.exthelperapp.disable_background_handling", true); pref("osfile.reset_worker_delay", 5000); // APZC preferences. -// +#ifdef MOZ_WIDGET_GONK +pref("apz.allow_zooming", true); +#endif + // Gaia relies heavily on scroll events for now, so lets fire them // more often than the default value (100). pref("apz.asyncscroll.throttle", 40); diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index be086c4b587..10c1abc0825 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -7906,14 +7906,14 @@ nsDocument::GetViewportInfo(const ScreenIntSize& aDisplaySize) return nsViewportInfo(aDisplaySize, defaultScale, /*allowZoom*/false, - /*allowDoubleTapZoom*/ true); + /*allowDoubleTapZoom*/ false); } if (!gfxPrefs::MetaViewportEnabled()) { return nsViewportInfo(aDisplaySize, defaultScale, /*allowZoom*/ false, - /*allowDoubleTapZoom*/ true); + /*allowDoubleTapZoom*/ false); } // In cases where the width of the CSS viewport is less than or equal to the width diff --git a/dom/base/nsViewportInfo.h b/dom/base/nsViewportInfo.h index b0556b7163c..b4f60b9d22d 100644 --- a/dom/base/nsViewportInfo.h +++ b/dom/base/nsViewportInfo.h @@ -34,6 +34,9 @@ class MOZ_STACK_CLASS nsViewportInfo mAllowZoom(aAllowZoom), mAllowDoubleTapZoom(aAllowDoubleTapZoom) { + // Don't allow double-tap zooming unless zooming is also allowed + MOZ_ASSERT(mAllowZoom || !mAllowDoubleTapZoom); + mSize = mozilla::ScreenSize(aDisplaySize) / mDefaultZoom; mozilla::CSSToLayoutDeviceScale pixelRatio(1.0f); mMinZoom = pixelRatio * kViewportMinScale; @@ -56,6 +59,9 @@ class MOZ_STACK_CLASS nsViewportInfo mAllowZoom(aAllowZoom), mAllowDoubleTapZoom(aAllowDoubleTapZoom) { + // Don't allow double-tap zooming unless zooming is also allowed + MOZ_ASSERT(mAllowZoom || !mAllowDoubleTapZoom); + ConstrainViewportValues(); } diff --git a/gfx/thebes/gfxPrefs.h b/gfx/thebes/gfxPrefs.h index 06e3a4d8540..75a42114706 100644 --- a/gfx/thebes/gfxPrefs.h +++ b/gfx/thebes/gfxPrefs.h @@ -135,6 +135,7 @@ private: // The apz prefs are explained in AsyncPanZoomController.cpp DECL_GFX_PREF(Live, "apz.allow_checkerboarding", APZAllowCheckerboarding, bool, true); + DECL_GFX_PREF(Live, "apz.allow_zooming", APZAllowZooming, bool, false); DECL_GFX_PREF(Live, "apz.asyncscroll.throttle", APZAsyncScrollThrottleTime, int32_t, 100); DECL_GFX_PREF(Live, "apz.asyncscroll.timeout", APZAsyncScrollTimeout, int32_t, 300); DECL_GFX_PREF(Live, "apz.axis_lock.breakout_angle", APZAxisBreakoutAngle, float, float(M_PI / 8.0) /* 22.5 degrees */); diff --git a/layout/base/MobileViewportManager.cpp b/layout/base/MobileViewportManager.cpp index f36dde556d4..d29219c1e38 100644 --- a/layout/base/MobileViewportManager.cpp +++ b/layout/base/MobileViewportManager.cpp @@ -114,7 +114,11 @@ MobileViewportManager::UpdateResolution(const nsViewportInfo& aViewportInfo, / mPresShell->GetPresContext()->AppUnitsPerDevPixel()); LayoutDeviceToLayerScale res(nsLayoutUtils::GetResolution(mPresShell)); -#if defined(MOZ_WIDGET_GONK) || defined(MOZ_WIDGET_ANDROID) || defined(MOZ_WIDGET_UIKIT) + if (!gfxPrefs::APZAllowZooming()) { + return ViewTargetAs(cssToDev * res / ParentLayerToLayerScale(1), + PixelCastJustification::ScreenIsParentLayerForRoot); + } + if (mIsFirstPaint) { CSSToScreenScale defaultZoom = aViewportInfo.GetDefaultZoom(); MVM_LOG("%p: default zoom from viewport is %f\n", this, defaultZoom.scale); @@ -173,7 +177,6 @@ MobileViewportManager::UpdateResolution(const nsViewportInfo& aViewportInfo, nsLayoutUtils::SetResolutionAndScaleTo(mPresShell, newRes.scale); res = newRes; } -#endif return ViewTargetAs(cssToDev * res / ParentLayerToLayerScale(1), PixelCastJustification::ScreenIsParentLayerForRoot); diff --git a/layout/base/ZoomConstraintsClient.cpp b/layout/base/ZoomConstraintsClient.cpp index 9cb501fdcf2..648129fb3ca 100644 --- a/layout/base/ZoomConstraintsClient.cpp +++ b/layout/base/ZoomConstraintsClient.cpp @@ -137,8 +137,8 @@ mozilla::layers::ZoomConstraints ComputeZoomConstraintsFromViewportInfo(const nsViewportInfo& aViewportInfo) { mozilla::layers::ZoomConstraints constraints; - constraints.mAllowZoom = aViewportInfo.IsZoomAllowed(); - constraints.mAllowDoubleTapZoom = aViewportInfo.IsDoubleTapZoomAllowed(); + constraints.mAllowZoom = aViewportInfo.IsZoomAllowed() && gfxPrefs::APZAllowZooming(); + constraints.mAllowDoubleTapZoom = aViewportInfo.IsDoubleTapZoomAllowed() && gfxPrefs::APZAllowZooming(); constraints.mMinZoom.scale = aViewportInfo.GetMinZoom().scale; constraints.mMaxZoom.scale = aViewportInfo.GetMaxZoom().scale; return constraints; diff --git a/mobile/android/app/mobile.js b/mobile/android/app/mobile.js index 22ec2df7bb6..a909d76a51a 100644 --- a/mobile/android/app/mobile.js +++ b/mobile/android/app/mobile.js @@ -547,6 +547,7 @@ pref("layers.offmainthreadcomposition.enabled", true); pref("layers.async-video.enabled", true); #ifdef MOZ_ANDROID_APZ pref("layers.async-pan-zoom.enabled", true); +pref("apz.allow_zooming", true); #endif pref("layers.progressive-paint", true); pref("layers.low-precision-buffer", true); diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js index 2db03d76280..2068a7f2634 100644 --- a/modules/libpref/init/all.js +++ b/modules/libpref/init/all.js @@ -516,6 +516,7 @@ pref("layout.event-regions.enabled", false); // APZ preferences. For documentation/details on what these prefs do, check // gfx/layers/apz/src/AsyncPanZoomController.cpp. pref("apz.allow_checkerboarding", true); +pref("apz.allow_zooming", false); pref("apz.asyncscroll.throttle", 100); pref("apz.asyncscroll.timeout", 300);