Add weak reference support to nsBaseWidget. (bug 1133150, r=roc)
authorDavid Anderson <danderson@mozilla.com>
Tue, 17 Feb 2015 22:27:53 -0800
changeset 229677 71d030563b18097639ea2bcef8f4242ffa5864af
parent 229676 36a3cbc746f50d61a572b4b5b392aab02e238d74
child 229678 4ba0059e72204f38a0b882fdbfdb5f1dd360b5af
push id28294
push userryanvm@gmail.com
push dateThu, 19 Feb 2015 01:30:38 +0000
treeherderautoland@360b5f211180 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs1133150
milestone38.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
Add weak reference support to nsBaseWidget. (bug 1133150, r=roc)
widget/PuppetWidget.cpp
widget/PuppetWidget.h
widget/gonk/nsWindow.cpp
widget/gonk/nsWindow.h
widget/gtk/nsWindow.cpp
widget/gtk/nsWindow.h
widget/nsBaseWidget.cpp
widget/nsBaseWidget.h
widget/qt/nsWindow.cpp
widget/qt/nsWindow.h
widget/windows/nsWindow.cpp
--- a/widget/PuppetWidget.cpp
+++ b/widget/PuppetWidget.cpp
@@ -62,22 +62,20 @@ MightNeedIMEFocus(const nsWidgetInitData
   // shouldn't try to mess with IME state.
 #ifdef MOZ_CROSS_PROCESS_IME
   return !IsPopup(aInitData);
 #else
   return false;
 #endif
 }
 
-
 // Arbitrary, fungible.
 const size_t PuppetWidget::kMaxDimension = 4000;
 
-NS_IMPL_ISUPPORTS_INHERITED(PuppetWidget, nsBaseWidget,
-                            nsISupportsWeakReference)
+NS_IMPL_ISUPPORTS_INHERITED0(PuppetWidget, nsBaseWidget)
 
 PuppetWidget::PuppetWidget(TabChild* aTabChild)
   : mTabChild(aTabChild)
   , mDPI(-1)
   , mDefaultScale(-1)
   , mNativeKeyCommandsValid(false)
 {
   MOZ_COUNT_CTOR(PuppetWidget);
--- a/widget/PuppetWidget.h
+++ b/widget/PuppetWidget.h
@@ -16,34 +16,32 @@
 #define mozilla_widget_PuppetWidget_h__
 
 #include "mozilla/gfx/2D.h"
 #include "mozilla/RefPtr.h"
 #include "nsBaseScreen.h"
 #include "nsBaseWidget.h"
 #include "nsIScreenManager.h"
 #include "nsThreadUtils.h"
-#include "nsWeakReference.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/EventForwards.h"
 
 class gfxASurface;
 
 namespace mozilla {
 
 namespace dom {
 class TabChild;
 }
 
 namespace widget {
 
 struct AutoCacheNativeKeyCommands;
 
-class PuppetWidget : public nsBaseWidget,
-                     public nsSupportsWeakReference
+class PuppetWidget : public nsBaseWidget
 {
   typedef mozilla::dom::TabChild TabChild;
   typedef mozilla::gfx::DrawTarget DrawTarget;
   typedef nsBaseWidget Base;
 
   // The width and height of the "widget" are clamped to this.
   static const size_t kMaxDimension;
 
--- a/widget/gonk/nsWindow.cpp
+++ b/widget/gonk/nsWindow.cpp
@@ -124,17 +124,17 @@ static void
 displayEnabledCallback(bool enabled)
 {
     HwcComposer2D::GetInstance()->EnableVsync(enabled);
     NS_DispatchToMainThread(enabled ? sScreenOnEvent : sScreenOffEvent);
 }
 
 } // anonymous namespace
 
-NS_IMPL_ISUPPORTS_INHERITED(nsWindow, nsBaseWidget, nsISupportsWeakReference)
+NS_IMPL_ISUPPORTS_INHERITED0(nsWindow, nsBaseWidget)
 
 nsWindow::nsWindow()
 {
     mFramebuffer = nullptr;
 
     if (sScreenInitialized)
         return;
 
--- a/widget/gonk/nsWindow.h
+++ b/widget/gonk/nsWindow.h
@@ -14,17 +14,16 @@
  */
 
 #ifndef nsWindow_h
 #define nsWindow_h
 
 #include "InputData.h"
 #include "nsBaseWidget.h"
 #include "nsRegion.h"
-#include "nsWeakReference.h"
 #include "nsIIdleServiceInternal.h"
 #include "Units.h"
 
 extern nsIntRect gScreenBounds;
 
 namespace mozilla {
 namespace gl {
 class GLContext;
@@ -40,17 +39,17 @@ namespace android {
 class FramebufferNativeWindow;
 }
 
 namespace widget {
 struct InputContext;
 struct InputContextAction;
 }
 
-class nsWindow : public nsBaseWidget, public nsSupportsWeakReference
+class nsWindow : public nsBaseWidget
 {
 public:
     nsWindow();
     virtual ~nsWindow();
 
     NS_DECL_ISUPPORTS_INHERITED
 
     static void DoDraw(void);
--- a/widget/gtk/nsWindow.cpp
+++ b/widget/gtk/nsWindow.cpp
@@ -340,16 +340,18 @@ UpdateLastInputEventTime(void *aGdkEvent
 
     guint timestamp = gdk_event_get_time(static_cast<GdkEvent*>(aGdkEvent));
     if (timestamp == GDK_CURRENT_TIME)
         return;
 
     sLastUserInputTime = timestamp;
 }
 
+NS_IMPL_ISUPPORTS_INHERITED0(nsWindow, nsBaseWidget)
+
 nsWindow::nsWindow()
 {
     mIsTopLevel       = false;
     mIsDestroyed      = false;
     mNeedsResize      = false;
     mNeedsMove        = false;
     mListenForResizes = false;
     mIsShown          = false;
@@ -418,19 +420,16 @@ nsWindow::ReleaseGlobals()
 #else
       gdk_cursor_unref(gCursorCache[i]);
 #endif
       gCursorCache[i] = nullptr;
     }
   }
 }
 
-NS_IMPL_ISUPPORTS_INHERITED(nsWindow, nsBaseWidget,
-                            nsISupportsWeakReference)
-
 void
 nsWindow::CommonCreate(nsIWidget *aParent, bool aListenForResizes)
 {
     mParent = aParent;
     mListenForResizes = aListenForResizes;
     mCreated = true;
 }
 
--- a/widget/gtk/nsWindow.h
+++ b/widget/gtk/nsWindow.h
@@ -8,17 +8,16 @@
 #ifndef __nsWindow_h__
 #define __nsWindow_h__
 
 #include "mozilla/ipc/SharedMemorySysV.h"
 
 #include "nsAutoPtr.h"
 
 #include "mozcontainer.h"
-#include "nsWeakReference.h"
 
 #include "nsIDragService.h"
 #include "nsITimer.h"
 #include "nsGkAtoms.h"
 
 #include "nsBaseWidget.h"
 #include <gdk/gdk.h>
 #include <gtk/gtk.h>
@@ -63,17 +62,17 @@ class gfxASurface;
 class gfxPattern;
 class nsDragService;
 class nsPluginNativeWindowGtk;
 #if defined(MOZ_X11) && defined(MOZ_HAVE_SHAREDMEMORYSYSV)
 #  define MOZ_HAVE_SHMIMAGE
 class nsShmImage;
 #endif
 
-class nsWindow : public nsBaseWidget, public nsSupportsWeakReference
+class nsWindow : public nsBaseWidget
 {
 public:
     nsWindow();
 
     static void ReleaseGlobals();
 
     NS_DECL_ISUPPORTS_INHERITED
     
--- a/widget/nsBaseWidget.cpp
+++ b/widget/nsBaseWidget.cpp
@@ -89,35 +89,33 @@ nsIContent* nsBaseWidget::mLastRollup = 
 // in NativeWindowTheme.
 bool            gDisableNativeTheme               = false;
 
 // Async pump timer during injected long touch taps
 #define TOUCH_INJECT_PUMP_TIMER_MSEC 50
 #define TOUCH_INJECT_LONG_TAP_DEFAULT_MSEC 1500
 int32_t nsIWidget::sPointerIdCounter = 0;
 
-// nsBaseWidget
-NS_IMPL_ISUPPORTS(nsBaseWidget, nsIWidget)
-
-
 nsAutoRollup::nsAutoRollup()
 {
   // remember if mLastRollup was null, and only clear it upon destruction
   // if so. This prevents recursive usage of nsAutoRollup from clearing
   // mLastRollup when it shouldn't.
   wasClear = !nsBaseWidget::mLastRollup;
 }
 
 nsAutoRollup::~nsAutoRollup()
 {
   if (nsBaseWidget::mLastRollup && wasClear) {
     NS_RELEASE(nsBaseWidget::mLastRollup);
   }
 }
 
+NS_IMPL_ISUPPORTS(nsBaseWidget, nsIWidget, nsISupportsWeakReference)
+
 //-------------------------------------------------------------------------
 //
 // nsBaseWidget constructor
 //
 //-------------------------------------------------------------------------
 
 nsBaseWidget::nsBaseWidget()
 : mWidgetListener(nullptr)
--- a/widget/nsBaseWidget.h
+++ b/widget/nsBaseWidget.h
@@ -13,16 +13,17 @@
 #include "nsIFile.h"
 #include "nsString.h"
 #include "nsCOMPtr.h"
 #include "nsAutoPtr.h"
 #include "nsIRollupListener.h"
 #include "nsIObserver.h"
 #include "nsIWidgetListener.h"
 #include "nsPIDOMWindow.h"
+#include "nsWeakReference.h"
 #include <algorithm>
 class nsIContent;
 class nsAutoRollup;
 class gfxContext;
 
 namespace mozilla {
 #ifdef ACCESSIBILITY
 namespace a11y {
@@ -74,17 +75,17 @@ public:
  * Common widget implementation used as base class for native
  * or crossplatform implementations of Widgets. 
  * All cross-platform behavior that all widgets need to implement 
  * should be placed in this class. 
  * (Note: widget implementations are not required to use this
  * class, but it gives them a head start.)
  */
 
-class nsBaseWidget : public nsIWidget
+class nsBaseWidget : public nsIWidget, public nsSupportsWeakReference
 {
   friend class nsAutoRollup;
 
 protected:
   typedef base::Thread Thread;
   typedef mozilla::layers::BasicLayerManager BasicLayerManager;
   typedef mozilla::layers::BufferMode BufferMode;
   typedef mozilla::layers::CompositorChild CompositorChild;
--- a/widget/qt/nsWindow.cpp
+++ b/widget/qt/nsWindow.cpp
@@ -84,16 +84,18 @@ using mozilla::gl::GLContext;
 // Qt
 static const int WHEEL_DELTA = 120;
 static bool gGlobalsInitialized = false;
 static bool sAltGrModifier = false;
 
 static void find_first_visible_parent(QWindow* aItem, QWindow*& aVisibleItem);
 static bool is_mouse_in_window (MozQWidget* aWindow, double aMouseX, double aMouseY);
 
+NS_IMPL_ISUPPORTS_INHERITED0(nsWindow, nsBaseWidget)
+
 nsWindow::nsWindow()
 {
     LOG(("%s [%p]\n", __PRETTY_FUNCTION__, (void *)this));
 
     mIsTopLevel       = false;
     mIsDestroyed      = false;
     mIsShown          = false;
     mEnabled          = true;
@@ -1372,20 +1374,16 @@ nsWindow::DispatchResizeEvent(nsIntRect 
     if (mWidgetListener &&
         mWidgetListener->WindowResized(this, aRect.width, aRect.height)) {
         aStatus = nsEventStatus_eConsumeNoDefault;
     }
 }
 
 ///////////////////////////////////// OLD GECKO ECENTS need to Sort ///////////////////
 
-NS_IMPL_ISUPPORTS_INHERITED(nsWindow, nsBaseWidget, nsISupportsWeakReference)
-
-
-
 void
 nsWindow::ClearCachedResources()
 {
     if (mLayerManager &&
         mLayerManager->GetBackendType() == mozilla::layers::LayersBackend::LAYERS_BASIC) {
         mLayerManager->ClearCachedResources();
     }
     for (nsIWidget* kid = mFirstChild; kid; ) {
--- a/widget/qt/nsWindow.h
+++ b/widget/qt/nsWindow.h
@@ -9,18 +9,16 @@
 #define __nsWindow_h__
 
 #include <QPointF>
 
 #include "nsAutoPtr.h"
 #include "nsBaseWidget.h"
 #include "mozilla/EventForwards.h"
 
-#include "nsWeakReference.h"
-
 #include "nsGkAtoms.h"
 #include "nsIIdleServiceInternal.h"
 #include "nsIRunnable.h"
 #include "nsThreadUtils.h"
 
 #ifdef MOZ_LOGGING
 
 #include "prlog.h"
@@ -72,18 +70,17 @@ class QResizeEvent;
 class QShowEvent;
 class QTabletEvent;
 class QTouchEvent;
 class QWheelEvent;
 
 namespace mozilla {
 namespace widget {
 class MozQWidget;
-class nsWindow : public nsBaseWidget,
-                 public nsSupportsWeakReference
+class nsWindow : public nsBaseWidget
 {
 public:
     nsWindow();
 
     NS_DECL_ISUPPORTS_INHERITED
 
     //
     // nsIWidget
--- a/widget/windows/nsWindow.cpp
+++ b/widget/windows/nsWindow.cpp
@@ -4327,19 +4327,19 @@ LRESULT CALLBACK nsWindow::WindowProcInt
   // Get the window which caused the event and ask it to process the message
   nsWindow *targetWindow = WinUtils::GetNSWindowPtr(hWnd);
   NS_ASSERTION(targetWindow, "nsWindow* is null!");
   if (!targetWindow)
     return ::DefWindowProcW(hWnd, msg, wParam, lParam);
 
   // Hold the window for the life of this method, in case it gets
   // destroyed during processing, unless we're in the dtor already.
-  nsCOMPtr<nsISupports> kungFuDeathGrip;
+  nsCOMPtr<nsIWidget> kungFuDeathGrip;
   if (!targetWindow->mInDtor)
-    kungFuDeathGrip = do_QueryInterface((nsBaseWidget*)targetWindow);
+    kungFuDeathGrip = targetWindow;
 
   targetWindow->IPCWindowProcHandler(msg, wParam, lParam);
 
   // Create this here so that we store the last rolled up popup until after
   // the event has been processed.
   nsAutoRollup autoRollup;
 
   LRESULT popupHandlingResult;