Bug 855975 part.10 Move nsWindow::DispatchPluginEvent() to nsWindowBase r=jimm
authorMasayuki Nakano <masayuki@d-toybox.com>
Wed, 29 May 2013 15:34:48 +0900
changeset 133237 13350f2b2f04f0d8b6de3bb1b927696214294806
parent 133236 60420c75c496793fc1c994920b519ae0ea0feff3
child 133238 658bfe5bb0eac39bfb5233018f6a585635ca8441
push id28671
push usermasayuki@d-toybox.com
push dateWed, 29 May 2013 06:35:17 +0000
treeherdermozilla-inbound@57461a161f93 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimm
bugs855975
milestone24.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 855975 part.10 Move nsWindow::DispatchPluginEvent() to nsWindowBase r=jimm
widget/windows/nsWindow.cpp
widget/windows/nsWindow.h
widget/windows/nsWindowBase.h
widget/windows/winrt/MetroWidget.h
--- a/widget/windows/nsWindow.cpp
+++ b/widget/windows/nsWindow.cpp
@@ -146,19 +146,16 @@
 #if !defined(WINABLEAPI)
 #include <winable.h>
 #endif // !defined(WINABLEAPI)
 #endif // defined(ACCESSIBILITY)
 
 #include "nsIWinTaskbar.h"
 #define NS_TASKBAR_CONTRACTID "@mozilla.org/windows-taskbar;1"
 
-// Windowless plugin support
-#include "npapi.h"
-
 #include "nsWindowDefs.h"
 
 #include "nsCrashOnException.h"
 #include "nsIXULRuntime.h"
 
 #include "nsIContent.h"
 
 #include "mozilla/HangMonitor.h"
@@ -3728,40 +3725,23 @@ void nsWindow::DispatchPendingEvents()
     // Dispatch pending paints for topWnd and all its descendant windows.
     // Note: EnumChildWindows enumerates all descendant windows not just
     // the children (but not the window itself).
     nsWindow::DispatchStarvedPaints(topWnd, 0);
     ::EnumChildWindows(topWnd, nsWindow::DispatchStarvedPaints, 0);
   }
 }
 
-// Deal with plugin events
-bool nsWindow::DispatchPluginEvent(const MSG &aMsg)
-{
-  if (!PluginHasFocus())
-    return false;
-
-  nsPluginEvent event(true, NS_PLUGIN_INPUT_EVENT, this);
-  nsIntPoint point(0, 0);
-  InitEvent(event, &point);
-  NPEvent pluginEvent;
-  pluginEvent.event = aMsg.message;
-  pluginEvent.wParam = aMsg.wParam;
-  pluginEvent.lParam = aMsg.lParam;
-  event.pluginEvent = (void *)&pluginEvent;
-  event.retargetToFocusedDocument = true;
-  return DispatchWindowEvent(&event);
-}
-
 bool nsWindow::DispatchPluginEvent(UINT aMessage,
                                      WPARAM aWParam,
                                      LPARAM aLParam,
                                      bool aDispatchPendingEvents)
 {
-  bool ret = DispatchPluginEvent(WinUtils::InitMSG(aMessage, aWParam, aLParam));
+  bool ret = nsWindowBase::DispatchPluginEvent(
+               WinUtils::InitMSG(aMessage, aWParam, aLParam));
   if (aDispatchPendingEvents) {
     DispatchPendingEvents();
   }
   return ret;
 }
 
 void nsWindow::RemoveMessageAndDispatchPluginEvent(UINT aFirstMsg,
                  UINT aLastMsg, nsFakeCharMessage* aFakeCharMessage)
@@ -3770,17 +3750,17 @@ void nsWindow::RemoveMessageAndDispatchP
   if (aFakeCharMessage) {
     if (aFirstMsg > WM_CHAR || aLastMsg < WM_CHAR) {
       return;
     }
     msg = aFakeCharMessage->GetCharMessage(mWnd);
   } else {
     WinUtils::GetMessage(&msg, mWnd, aFirstMsg, aLastMsg);
   }
-  DispatchPluginEvent(msg);
+  nsWindowBase::DispatchPluginEvent(msg);
 }
 
 // Deal with all sort of mouse event
 bool nsWindow::DispatchMouseEvent(uint32_t aEventType, WPARAM wParam,
                                     LPARAM lParam, bool aIsContextMenuKey,
                                     int16_t aButton, uint16_t aInputSource)
 {
   bool result = false;
@@ -4407,17 +4387,17 @@ nsWindow::ProcessMessageForPlugin(const 
     case WM_UNDO:
       break;
 
     default:
       return false;
   }
 
   if (!eventDispatched)
-    aCallDefWndProc = !DispatchPluginEvent(aMsg);
+    aCallDefWndProc = !nsWindowBase::DispatchPluginEvent(aMsg);
   DispatchPendingEvents();
   return true;
 }
 
 static void ForceFontUpdate()
 {
   // update device context font cache
   // Dirty but easiest way:
@@ -6563,17 +6543,17 @@ LRESULT nsWindow::OnKeyDown(const MSG &a
     // If prevent default set for keydown, do same for keypress
     WinUtils::GetMessage(&msg, mWnd, msg.message, msg.message);
 
     if (msg.message == WM_DEADCHAR) {
       if (!PluginHasFocus())
         return false;
 
       // We need to send the removed message to focused plug-in.
-      DispatchPluginEvent(msg);
+      nsWindowBase::DispatchPluginEvent(msg);
       return noDefault;
     }
 
     PR_LOG(gWindowsLog, PR_LOG_ALWAYS,
            ("%s charCode=%d scanCode=%d\n",
             msg.message == WM_SYSCHAR ? "WM_SYSCHAR" : "WM_CHAR",
             msg.wParam, HIWORD(msg.lParam) & 0xFF));
 
--- a/widget/windows/nsWindow.h
+++ b/widget/windows/nsWindow.h
@@ -218,21 +218,16 @@ public:
   typedef void            (WindowEnumCallback)(nsWindow*);
   static void             EnumAllWindows(WindowEnumCallback aCallback);
 
   /**
    * Misc.
    */
   virtual bool            AutoErase(HDC dc);
   nsIntPoint*             GetLastPoint() { return &mLastPoint; }
-  // needed in nsIMM32Handler.cpp
-  bool                    PluginHasFocus()
-  {
-    return (mInputContext.mIMEState.mEnabled == IMEState::PLUGIN);
-  }
   bool                    IsTopLevelWidget() { return mIsTopWidgetWindow; }
   /**
    * Start allowing Direct3D9 to be used by widgets when GetLayerManager is
    * called.
    *
    * @param aReinitialize Call GetLayerManager on widgets to ensure D3D9 is
    *                      initialized, this is usually called when this function
    *                      is triggered by timeout and not user/web interaction.
@@ -321,17 +316,16 @@ protected:
   bool                    HasGlass() const {
     return mTransparencyMode == eTransparencyGlass ||
            mTransparencyMode == eTransparencyBorderlessGlass;
   }
 
   /**
    * Event processing helpers
    */
-  bool                    DispatchPluginEvent(const MSG &aMsg);
   void                    DispatchFocusToTopLevelWindow(bool aIsActivate);
   bool                    DispatchStandardEvent(uint32_t aMsg);
   bool                    DispatchCommandEvent(uint32_t aEventCommand);
   void                    RelayMouseEvent(UINT aMsg, WPARAM wParam, LPARAM lParam);
   static void             RemoveNextCharMessage(HWND aWnd);
   void                    RemoveMessageAndDispatchPluginEvent(UINT aFirstMsg,
                             UINT aLastMsg,
                             nsFakeCharMessage* aFakeCharMessage = nullptr);
@@ -452,17 +446,16 @@ protected:
   bool                  mHideChrome;
   bool                  mIsRTL;
   bool                  mFullscreenMode;
   bool                  mMousePresent;
   bool                  mDestroyCalled;
   uint32_t              mBlurSuppressLevel;
   DWORD_PTR             mOldStyle;
   DWORD_PTR             mOldExStyle;
-  InputContext mInputContext;
   nsNativeDragTarget*   mNativeDragTarget;
   HKL                   mLastKeyboardLayout;
   nsSizeMode            mOldSizeMode;
   nsSizeMode            mLastSizeMode;
   WindowHook            mWindowHook;
   DWORD                 mAssumeWheelIsZoomUntil;
   uint32_t              mPickerDisplayCount;
   HICON                 mIconSmall;
--- a/widget/windows/nsWindowBase.h
+++ b/widget/windows/nsWindowBase.h
@@ -2,16 +2,18 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef nsWindowBase_h_
 #define nsWindowBase_h_
 
 #include "nsBaseWidget.h"
+#include "nsGUIEvent.h"
+#include "npapi.h"
 #include <windows.h>
 
 /*
  * nsWindowBase - Base class of common methods other classes need to access
  * in both win32 and winrt window classes.
  */
 
 class nsWindowBase : public nsBaseWidget
@@ -28,11 +30,42 @@ public:
    * Init a standard gecko event for this widget.
    */
   virtual void InitEvent(nsGUIEvent& aEvent, nsIntPoint* aPoint = nullptr) = 0;
 
   /*
    * Dispatch a gecko event for this widget.
    */
   virtual bool DispatchWindowEvent(nsGUIEvent* aEvent) = 0;
+
+  /*
+   * Dispatch a plugin event with the message.
+   */
+  virtual bool DispatchPluginEvent(const MSG &aMsg) MOZ_FINAL
+  {
+    if (!PluginHasFocus()) {
+      return false;
+    }
+    nsPluginEvent pluginEvent(true, NS_PLUGIN_INPUT_EVENT, this);
+    nsIntPoint point(0, 0);
+    InitEvent(pluginEvent, &point);
+    NPEvent npEvent;
+    npEvent.event = aMsg.message;
+    npEvent.wParam = aMsg.wParam;
+    npEvent.lParam = aMsg.lParam;
+    pluginEvent.pluginEvent = (void *)&npEvent;
+    pluginEvent.retargetToFocusedDocument = true;
+    return DispatchWindowEvent(&pluginEvent);
+  }
+
+  /*
+   * Returns true if a plugin has focus on this widget.  Otherwise, false.
+   */
+  virtual bool PluginHasFocus() const MOZ_FINAL
+  {
+    return (mInputContext.mIMEState.mEnabled == IMEState::PLUGIN);
+  }
+
+protected:
+  InputContext mInputContext;
 };
 
 #endif // nsWindowBase_h_
--- a/widget/windows/winrt/MetroWidget.h
+++ b/widget/windows/winrt/MetroWidget.h
@@ -199,11 +199,10 @@ protected:
   OleInitializeWrapper mOleInitializeWrapper;
   WindowHook mWindowHook;
   Microsoft::WRL::ComPtr<FrameworkView> mView;
   nsTransparencyMode mTransparencyMode;
   nsIntRegion mInvalidatedRegion;
   nsCOMPtr<nsIdleService> mIdleService;
   HWND mWnd;
   WNDPROC mMetroWndProc;
-  nsIWidget::InputContext mInputContext;
   bool mTempBasicLayerInUse;
 };