Bug 743975 - add a getpresshell method to the widget listener, r=tn
authorNeil Deakin <neil@mozilla.com>
Wed, 15 Aug 2012 14:52:42 -0400
changeset 107930 4aca82dc0d41007d1fdf231d1c3be86705132d73
parent 107929 448410c2035ef7bce315bb6b3c46f60fb909145e
child 107931 54badf5d08b073d45b0f8a5da272021118dd9f99
push id1490
push userakeybl@mozilla.com
push dateMon, 08 Oct 2012 18:29:50 +0000
treeherdermozilla-beta@f335e7dacdc1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstn
bugs743975
milestone17.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 743975 - add a getpresshell method to the widget listener, r=tn
view/src/nsView.cpp
widget/nsIWidgetListener.h
widget/xpwidgets/nsBaseWidget.cpp
xpfe/appshell/src/nsWebShellWindow.cpp
xpfe/appshell/src/nsWebShellWindow.h
--- a/view/src/nsView.cpp
+++ b/view/src/nsView.cpp
@@ -44,16 +44,21 @@ class ViewWrapper MOZ_FINAL : public nsI
     ViewWrapper(nsView* aView) : mView(aView) {}
 
     nsView* GetView() { return mView; }
   private:
     nsView* mView;
 
   public:
 
+    virtual nsIPresShell* GetPresShell()
+    {
+      return mView->GetViewManager()->GetPresShell();
+    }
+
     bool WindowMoved(nsIWidget* aWidget, PRInt32 x, PRInt32 y)
     {
       nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
       if (pm && IsPopupWidget(aWidget)) {
         pm->PopupMoved(mView->GetFrame(), nsIntPoint(x, y));
         return true;
       }
 
--- a/widget/nsIWidgetListener.h
+++ b/widget/nsIWidgetListener.h
@@ -36,16 +36,17 @@
 #ifndef nsIWidgetListener_h__
 #define nsIWidgetListener_h__
 
 #include "nscore.h"
 #include "nsGUIEvent.h"
 #include "nsIXULWindow.h"
 
 class nsIView;
+class nsIPresShell;
 
 class nsIWidgetListener
 {
 public:
 
   /**
    * If this listener is for an nsIXULWindow, return it. If this is null, then
    * this is likely a listener for a view, which can be determined using
@@ -54,16 +55,21 @@ public:
   virtual nsIXULWindow* GetXULWindow() { return nullptr; }
 
   /**
    * If this listener is for an nsIView, return it.
    */
   virtual nsIView* GetView() { return nullptr; }
 
   /**
+   * Return the presshell for this widget listener.
+   */
+  virtual nsIPresShell* GetPresShell() { return nullptr; }
+
+  /**
    * Called when a window is moved to location (x, y). Returns true if the
    * notification was handled. Coordinates are outer window screen coordinates.
    */
   virtual bool WindowMoved(nsIWidget* aWidget, PRInt32 aX, PRInt32 aY) { return false; }
 
   /**
    * Called when a window is resized to (width, height). Returns true if the
    * notification was handled. Coordinates are outer window screen coordinates.
--- a/widget/xpwidgets/nsBaseWidget.cpp
+++ b/widget/xpwidgets/nsBaseWidget.cpp
@@ -19,19 +19,16 @@
 #include "nsIContent.h"
 #include "nsIServiceManager.h"
 #include "mozilla/Preferences.h"
 #include "BasicLayers.h"
 #include "LayerManagerOGL.h"
 #include "nsIXULRuntime.h"
 #include "nsIXULWindow.h"
 #include "nsIBaseWindow.h"
-#include "nsIDocShell.h"
-#include "nsView.h"
-#include "nsIViewManager.h"
 #include "nsEventStateManager.h"
 #include "nsIWidgetListener.h"
 #include "nsIGfxInfo.h"
 #include "npapi.h"
 #include "base/thread.h"
 #include "prenv.h"
 #include "mozilla/Attributes.h"
 
@@ -1340,101 +1337,85 @@ void nsBaseWidget::SetSizeConstraints(co
   // probably in the middle of a reflow.
 }
 
 const widget::SizeConstraints& nsBaseWidget::GetSizeConstraints() const
 {
   return mSizeConstraints;
 }
 
-// If widgetListener is non-null, then get the presShell from either the window
-// or the view. Otherwise, assume that this is a widget attached to a view.
-static nsIPresShell* GetPresShell(nsIWidget* aWidget, void* clientData)
-{
-  nsCOMPtr<nsIXULWindow> window =
-    aWidgetListener ? aWidgetListener->GetXULWindow() : nullptr;
-  if (window) {
-    nsCOMPtr<nsIDocShell> docShell;
-    window->GetDocShell(getter_AddRefs(docShell));
-    if (docShell) {
-      nsCOMPtr<nsIPresShell> presShell;
-      docShell->GetPresShell(getter_AddRefs(presShell));
-      return presShell.get();
-    }
-  }
-  else {
-    nsIView* view = nsView::GetViewFor(aWidget);
-    if (view) {
-      return view->GetViewManager()->GetPresShell();
-    }
-  }
- 
-  return nullptr;
-}
-
 void
 nsBaseWidget::NotifyWindowDestroyed()
 {
   if (!mWidgetListener)
     return;
 
   nsCOMPtr<nsIXULWindow> window = mWidgetListener->GetXULWindow();
   nsCOMPtr<nsIBaseWindow> xulWindow(do_QueryInterface(window));
   if (xulWindow) {
     xulWindow->Destroy();
   }
 }
 
 void
 nsBaseWidget::NotifySizeMoveDone()
 {
-  nsIPresShell* presShell = GetPresShell(this, nullptr);
+  if (!mWidgetListener || mWidgetListener->GetXULWindow())
+    return;
+
+  nsIPresShell* presShell = mWidgetListener->GetPresShell();
   if (presShell) {
     presShell->WindowSizeMoveDone();
   }
 }
 
 void
 nsBaseWidget::NotifySysColorChanged()
 {
-  nsIPresShell* presShell = GetPresShell(this, nullptr);
+  if (!mWidgetListener || mWidgetListener->GetXULWindow())
+    return;
+
+  nsIPresShell* presShell = mWidgetListener->GetPresShell();
   if (presShell) {
     presShell->SysColorChanged();
   }
 }
 
 void
 nsBaseWidget::NotifyThemeChanged()
 {
-  nsIPresShell* presShell = GetPresShell(this, nullptr);
+  if (!mWidgetListener || mWidgetListener->GetXULWindow())
+    return;
+
+  nsIPresShell* presShell = mWidgetListener->GetPresShell();
   if (presShell) {
     presShell->ThemeChanged();
   }
 }
 
 void
 nsBaseWidget::NotifyUIStateChanged(UIStateChangeType aShowAccelerators,
                                    UIStateChangeType aShowFocusRings)
 {
-  nsIPresShell* presShell = GetPresShell(this, mWidgetListener);
+  nsIPresShell* presShell = mWidgetListener->GetPresShell();
   nsIDocument* doc = presShell->GetDocument();
   if (doc) {
     nsPIDOMWindow* win = doc->GetWindow();
     if (win) {
       win->SetKeyboardIndicators(aShowAccelerators, aShowFocusRings);
     }
   }
 }
 
 #ifdef ACCESSIBILITY
 
 Accessible*
 nsBaseWidget::GetAccessible()
 {
-  nsIPresShell* presShell = GetPresShell(this, mWidgetListener);
+  nsIPresShell* presShell = mWidgetListener->GetPresShell();
   NS_ENSURE_TRUE(presShell, nullptr);
 
   // If container is null then the presshell is not active. This often happens
   // when a preshell is being held onto for fastback.
   nsPresContext* presContext = presShell->GetPresContext();
   nsCOMPtr<nsISupports> container = presContext->GetContainer();
   NS_ENSURE_TRUE(container, nullptr);
 
--- a/xpfe/appshell/src/nsWebShellWindow.cpp
+++ b/xpfe/appshell/src/nsWebShellWindow.cpp
@@ -212,16 +212,27 @@ nsresult nsWebShellWindow::Initialize(ns
                          nullptr,
                          nullptr);
     NS_ENSURE_SUCCESS(rv, rv);
   }
                      
   return rv;
 }
 
+nsIPresShell*
+nsWebShellWindow::GetPresShell()
+{
+  if (!mDocShell)
+    return nullptr;
+
+  nsCOMPtr<nsIPresShell> presShell;
+  mDocShell->GetPresShell(getter_AddRefs(presShell));
+  return presShell.get();
+}
+
 bool
 nsWebShellWindow::WindowMoved(nsIWidget* aWidget, PRInt32 x, PRInt32 y)
 {
   nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
   if (pm) {
     nsCOMPtr<nsPIDOMWindow> window = do_GetInterface(mDocShell);
     pm->AdjustPopupsOnWindowChange(window);
   }
--- a/xpfe/appshell/src/nsWebShellWindow.h
+++ b/xpfe/appshell/src/nsWebShellWindow.h
@@ -43,17 +43,17 @@ public:
   // nsIWebProgressListener
   NS_DECL_NSIWEBPROGRESSLISTENER
 
   // nsIBaseWindow
   NS_IMETHOD Destroy();
 
   // nsIWidgetListener
   virtual nsIXULWindow* GetXULWindow() { return this; }
-
+  virtual nsIPresShell* GetPresShell();
   virtual bool WindowMoved(nsIWidget* aWidget, PRInt32 x, PRInt32 y);
   virtual bool WindowResized(nsIWidget* aWidget, PRInt32 aWidth, PRInt32 aHeight);
   virtual bool RequestWindowClose(nsIWidget* aWidget);
   virtual void SizeModeChanged(nsSizeMode sizeMode);
   virtual void OSToolbarButtonPressed();
   virtual bool ZLevelChanged(bool aImmediate, nsWindowZ *aPlacement,
                              nsIWidget* aRequestBelow, nsIWidget** aActualBelow);
   virtual void WindowActivated();