Bug 1590551. Allow nsPresContext::GetNearestWidget to work when there is no frame tree. r=botond
authorTimothy Nikkel <tnikkel@gmail.com>
Wed, 23 Oct 2019 23:37:11 +0000
changeset 498804 91756881b7abd409a7350d6880118f0141427b66
parent 498803 c09df0d0e60c7a9e3b2db185bae6aba42edadcfe
child 498805 33ab77afa21f69235471fc264d3fdb45a92149b1
push id98700
push usertnikkel@mozilla.com
push dateWed, 23 Oct 2019 23:37:45 +0000
treeherderautoland@91756881b7ab [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbotond
bugs1590551
milestone72.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 1590551. Allow nsPresContext::GetNearestWidget to work when there is no frame tree. r=botond Differential Revision: https://phabricator.services.mozilla.com/D50135
layout/base/PresShell.cpp
layout/base/nsPresContext.cpp
layout/base/nsPresContext.h
--- a/layout/base/PresShell.cpp
+++ b/layout/base/PresShell.cpp
@@ -10501,22 +10501,20 @@ nsresult PresShell::SetIsActive(bool aIs
 
 RefPtr<MobileViewportManager> PresShell::GetMobileViewportManager() const {
   return mMobileViewportManager;
 }
 
 bool UseMobileViewportManager(PresShell* aPresShell, Document* aDocument) {
   // If we're not using APZ, we won't be able to zoom, so there is no
   // point in having an MVM.
-  if (nsViewManager* viewManager = aPresShell->GetViewManager()) {
-    if (nsView* view = viewManager->GetRootView()) {
-      if (nsIWidget* widget = view->GetNearestWidget(nullptr)) {
-        if (!widget->AsyncPanZoomEnabled()) {
-          return false;
-        }
+  if (nsPresContext* presContext = aPresShell->GetPresContext()) {
+    if (nsIWidget* widget = presContext->GetNearestWidget()) {
+      if (!widget->AsyncPanZoomEnabled()) {
+        return false;
       }
     }
   }
   return nsLayoutUtils::ShouldHandleMetaViewport(aDocument) ||
          nsLayoutUtils::AllowZoomingForDocument(aDocument);
 }
 
 void PresShell::UpdateViewportOverridden(bool aAfterInitialization) {
--- a/layout/base/nsPresContext.cpp
+++ b/layout/base/nsPresContext.cpp
@@ -812,19 +812,21 @@ nsPresContext* nsPresContext::GetTopleve
     nsPresContext* parent = pc->GetParentPresContext();
     if (!parent || parent->IsChrome()) return pc;
     pc = parent;
   }
 }
 
 nsIWidget* nsPresContext::GetNearestWidget(nsPoint* aOffset) {
   NS_ENSURE_TRUE(mPresShell, nullptr);
-  nsIFrame* frame = mPresShell->GetRootFrame();
-  NS_ENSURE_TRUE(frame, nullptr);
-  return frame->GetView()->GetNearestWidget(aOffset);
+  nsViewManager* vm = mPresShell->GetViewManager();
+  NS_ENSURE_TRUE(vm, nullptr);
+  nsView* rootView = vm->GetRootView();
+  NS_ENSURE_TRUE(rootView, nullptr);
+  return rootView->GetNearestWidget(aOffset);
 }
 
 nsIWidget* nsPresContext::GetRootWidget() const {
   NS_ENSURE_TRUE(mPresShell, nullptr);
   nsViewManager* vm = mPresShell->GetViewManager();
   if (!vm) {
     return nullptr;
   }
--- a/layout/base/nsPresContext.h
+++ b/layout/base/nsPresContext.h
@@ -187,17 +187,17 @@ class nsPresContext : public nsISupports
 
   /**
    * Returns the prescontext of the toplevel content document that contains
    * this presentation, or null if there isn't one.
    */
   nsPresContext* GetToplevelContentDocumentPresContext();
 
   /**
-   * Returns the nearest widget for the root frame of this.
+   * Returns the nearest widget for the root frame or view of this.
    *
    * @param aOffset     If non-null the offset from the origin of the root
    *                    frame's view to the widget's origin (usually positive)
    *                    expressed in appunits of this will be returned in
    *                    aOffset.
    */
   nsIWidget* GetNearestWidget(nsPoint* aOffset = nullptr);