Bug 1304052 - Disable APZ zooming when the document has any fullscreen state. r=botond, a=ritu
authorKartikaya Gupta <kgupta@mozilla.com>
Wed, 21 Sep 2016 16:19:10 -0400
changeset 350398 5d734d96dc24cd7107bfeda30451f93d963ee9a5
parent 350397 c8d78d3fa2018955b230a21c6824cb66ab3fc328
child 350399 bdc62dc8c7d1167f8e9cf5c25f67c8b95bb63bc3
push id1230
push userjlund@mozilla.com
push dateMon, 31 Oct 2016 18:13:35 +0000
treeherdermozilla-release@5e06e3766db2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbotond, ritu
bugs1304052
milestone50.0
Bug 1304052 - Disable APZ zooming when the document has any fullscreen state. r=botond, a=ritu MozReview-Commit-ID: 5V1zFUTpnPq
layout/base/ZoomConstraintsClient.cpp
--- a/layout/base/ZoomConstraintsClient.cpp
+++ b/layout/base/ZoomConstraintsClient.cpp
@@ -24,16 +24,17 @@
 
 #define ZCC_LOG(...)
 // #define ZCC_LOG(...) printf_stderr("ZCC: " __VA_ARGS__)
 
 NS_IMPL_ISUPPORTS(ZoomConstraintsClient, nsIDOMEventListener, nsIObserver)
 
 static const nsLiteralString DOM_META_ADDED = NS_LITERAL_STRING("DOMMetaAdded");
 static const nsLiteralString DOM_META_CHANGED = NS_LITERAL_STRING("DOMMetaChanged");
+static const nsLiteralString FULLSCREEN_CHANGED = NS_LITERAL_STRING("mozfullscreenchange");
 static const nsLiteralCString BEFORE_FIRST_PAINT = NS_LITERAL_CSTRING("before-first-paint");
 static const nsLiteralCString NS_PREF_CHANGED = NS_LITERAL_CSTRING("nsPref:changed");
 
 using namespace mozilla;
 using namespace mozilla::layers;
 
 ZoomConstraintsClient::ZoomConstraintsClient() :
   mDocument(nullptr),
@@ -70,16 +71,17 @@ ZoomConstraintsClient::Destroy()
     return;
   }
 
   ZCC_LOG("Destroying %p\n", this);
 
   if (mEventTarget) {
     mEventTarget->RemoveEventListener(DOM_META_ADDED, this, false);
     mEventTarget->RemoveEventListener(DOM_META_CHANGED, this, false);
+    mEventTarget->RemoveEventListener(FULLSCREEN_CHANGED, this, false);
     mEventTarget = nullptr;
   }
 
   nsCOMPtr<nsIObserverService> observerService = mozilla::services::GetObserverService();
   if (observerService) {
     observerService->RemoveObserver(this, BEFORE_FIRST_PAINT.Data());
   }
 
@@ -109,16 +111,17 @@ ZoomConstraintsClient::Init(nsIPresShell
   mDocument = aDocument;
 
   if (nsCOMPtr<nsPIDOMWindowOuter> window = mDocument->GetWindow()) {
     mEventTarget = window->GetParentTarget();
   }
   if (mEventTarget) {
     mEventTarget->AddEventListener(DOM_META_ADDED, this, false);
     mEventTarget->AddEventListener(DOM_META_CHANGED, this, false);
+    mEventTarget->AddEventListener(FULLSCREEN_CHANGED, this, false);
   }
 
   nsCOMPtr<nsIObserverService> observerService = mozilla::services::GetObserverService();
   if (observerService) {
     observerService->AddObserver(this, BEFORE_FIRST_PAINT.Data(), false);
   }
 
   Preferences::AddStrongObserver(this, "browser.ui.zoom.force-user-scalable");
@@ -131,16 +134,19 @@ ZoomConstraintsClient::HandleEvent(nsIDO
   event->GetType(type);
 
   if (type.Equals(DOM_META_ADDED)) {
     ZCC_LOG("Got a dom-meta-added event in %p\n", this);
     RefreshZoomConstraints();
   } else if (type.Equals(DOM_META_CHANGED)) {
     ZCC_LOG("Got a dom-meta-changed event in %p\n", this);
     RefreshZoomConstraints();
+  } else if (type.Equals(FULLSCREEN_CHANGED)) {
+    ZCC_LOG("Got a fullscreen-change event in %p\n", this);
+    RefreshZoomConstraints();
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 ZoomConstraintsClient::Observe(nsISupports* aSubject, const char* aTopic, const char16_t* aData)
 {
@@ -204,16 +210,22 @@ ZoomConstraintsClient::RefreshZoomConstr
   }
 
   nsViewportInfo viewportInfo = mDocument->GetViewportInfo(
     ViewAs<ScreenPixel>(screenSize, PixelCastJustification::LayoutDeviceIsScreenForBounds));
 
   mozilla::layers::ZoomConstraints zoomConstraints =
     ComputeZoomConstraintsFromViewportInfo(viewportInfo);
 
+  if (mDocument->Fullscreen()) {
+    ZCC_LOG("%p is in fullscreen, disallowing zooming\n", this);
+    zoomConstraints.mAllowZoom = false;
+    zoomConstraints.mAllowDoubleTapZoom = false;
+  }
+
   if (zoomConstraints.mAllowDoubleTapZoom) {
     // If the CSS viewport is narrower than the screen (i.e. width <= device-width)
     // then we disable double-tap-to-zoom behaviour.
     CSSToLayoutDeviceScale scale =
         mPresShell->GetPresContext()->CSSToDevPixelScale();
     if ((viewportInfo.GetSize() * scale).width <= screenSize.width) {
       zoomConstraints.mAllowDoubleTapZoom = false;
     }