Bug 819613 - Move app command code to nsWindowBase so it can be shared between win32 and metro widgets (plus missing include fix). r=tabraldes
authorJim Mathies <jmathies@mozilla.com>
Wed, 05 Feb 2014 09:36:59 -0600
changeset 166970 d0e1eff200975c5dbce1c2e8b1f0d49796b2a3f8
parent 166969 124eee46ccb642de279a4d7ac9435e205a2bad84
child 166971 5fd318a789f6a57d3ff8d52b723b042f2cc17512
push id4857
push userjmathies@mozilla.com
push dateWed, 05 Feb 2014 15:37:17 +0000
treeherderfx-team@5fd318a789f6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstabraldes
bugs819613
milestone30.0a1
Bug 819613 - Move app command code to nsWindowBase so it can be shared between win32 and metro widgets (plus missing include fix). r=tabraldes
widget/windows/nsWindow.cpp
widget/windows/nsWindow.h
widget/windows/nsWindowBase.cpp
widget/windows/nsWindowBase.h
widget/windows/winrt/MetroWidget.cpp
--- a/widget/windows/nsWindow.cpp
+++ b/widget/windows/nsWindow.cpp
@@ -3690,80 +3690,16 @@ bool nsWindow::DispatchWindowEvent(Widge
 
 bool nsWindow::DispatchWindowEvent(WidgetGUIEvent* event,
                                    nsEventStatus& aStatus)
 {
   DispatchEvent(event, aStatus);
   return ConvertStatus(aStatus);
 }
 
-bool nsWindow::DispatchCommandEvent(uint32_t aEventCommand)
-{
-  nsCOMPtr<nsIAtom> command;
-  switch (aEventCommand) {
-    case APPCOMMAND_BROWSER_BACKWARD:
-      command = nsGkAtoms::Back;
-      break;
-    case APPCOMMAND_BROWSER_FORWARD:
-      command = nsGkAtoms::Forward;
-      break;
-    case APPCOMMAND_BROWSER_REFRESH:
-      command = nsGkAtoms::Reload;
-      break;
-    case APPCOMMAND_BROWSER_STOP:
-      command = nsGkAtoms::Stop;
-      break;
-    case APPCOMMAND_BROWSER_SEARCH:
-      command = nsGkAtoms::Search;
-      break;
-    case APPCOMMAND_BROWSER_FAVORITES:
-      command = nsGkAtoms::Bookmarks;
-      break;
-    case APPCOMMAND_BROWSER_HOME:
-      command = nsGkAtoms::Home;
-      break;
-    case APPCOMMAND_CLOSE:
-      command = nsGkAtoms::Close;
-      break;
-    case APPCOMMAND_FIND:
-      command = nsGkAtoms::Find;
-      break;
-    case APPCOMMAND_HELP:
-      command = nsGkAtoms::Help;
-      break;
-    case APPCOMMAND_NEW:
-      command = nsGkAtoms::New;
-      break;
-    case APPCOMMAND_OPEN:
-      command = nsGkAtoms::Open;
-      break;
-    case APPCOMMAND_PRINT:
-      command = nsGkAtoms::Print;
-      break;
-    case APPCOMMAND_SAVE:
-      command = nsGkAtoms::Save;
-      break;
-    case APPCOMMAND_FORWARD_MAIL:
-      command = nsGkAtoms::ForwardMail;
-      break;
-    case APPCOMMAND_REPLY_TO_MAIL:
-      command = nsGkAtoms::ReplyToMail;
-      break;
-    case APPCOMMAND_SEND_MAIL:
-      command = nsGkAtoms::SendMail;
-      break;
-    default:
-      return false;
-  }
-  WidgetCommandEvent event(true, nsGkAtoms::onAppCommand, command, this);
-
-  InitEvent(event);
-  return DispatchWindowEvent(&event);
-}
-
 // Recursively dispatch synchronous paints for nsIWidget
 // descendants with invalidated rectangles.
 BOOL CALLBACK nsWindow::DispatchStarvedPaints(HWND aWnd, LPARAM aMsg)
 {
   LONG_PTR proc = ::GetWindowLongPtrW(aWnd, GWLP_WNDPROC);
   if (proc == (LONG_PTR)&nsWindow::WindowProc) {
     // its one of our windows so check to see if it has a
     // invalidated rect. If it does. Dispatch a synchronous
@@ -5084,79 +5020,18 @@ nsWindow::ProcessMessage(UINT msg, WPARA
       result = 
         DispatchMouseEvent(NS_MOUSE_BUTTON_UP, 0, lParamToClient(lParam),
                            false, WidgetMouseEvent::eLeftButton,
                            MOUSE_INPUT_SOURCE());
       DispatchPendingEvents();
       break;
 
     case WM_APPCOMMAND:
-    {
-      uint32_t appCommand = GET_APPCOMMAND_LPARAM(lParam);
-      uint32_t contentCommandMessage = NS_EVENT_NULL;
-      // XXX After we implement KeyboardEvent.key, we should dispatch the
-      //     key event if (GET_DEVICE_LPARAM(lParam) == FAPPCOMMAND_KEY) is.
-      switch (appCommand)
-      {
-        case APPCOMMAND_BROWSER_BACKWARD:
-        case APPCOMMAND_BROWSER_FORWARD:
-        case APPCOMMAND_BROWSER_REFRESH:
-        case APPCOMMAND_BROWSER_STOP:
-        case APPCOMMAND_BROWSER_SEARCH:
-        case APPCOMMAND_BROWSER_FAVORITES:
-        case APPCOMMAND_BROWSER_HOME:
-        case APPCOMMAND_CLOSE:
-        case APPCOMMAND_FIND:
-        case APPCOMMAND_HELP:
-        case APPCOMMAND_NEW:
-        case APPCOMMAND_OPEN:
-        case APPCOMMAND_PRINT:
-        case APPCOMMAND_SAVE:
-        case APPCOMMAND_FORWARD_MAIL:
-        case APPCOMMAND_REPLY_TO_MAIL:
-        case APPCOMMAND_SEND_MAIL:
-          // We shouldn't consume the message always because if we don't handle
-          // the message, the sender (typically, utility of keyboard or mouse)
-          // may send other key messages which indicate well known shortcut key.
-          if (DispatchCommandEvent(appCommand)) {
-            // tell the driver that we handled the event
-            *aRetValue = 1;
-            result = true;
-          }
-          break;
-
-        // Use content command for following commands:
-        case APPCOMMAND_COPY:
-          contentCommandMessage = NS_CONTENT_COMMAND_COPY;
-          break;
-        case APPCOMMAND_CUT:
-          contentCommandMessage = NS_CONTENT_COMMAND_CUT;
-          break;
-        case APPCOMMAND_PASTE:
-          contentCommandMessage = NS_CONTENT_COMMAND_PASTE;
-          break;
-        case APPCOMMAND_REDO:
-          contentCommandMessage = NS_CONTENT_COMMAND_REDO;
-          break;
-        case APPCOMMAND_UNDO:
-          contentCommandMessage = NS_CONTENT_COMMAND_UNDO;
-          break;
-      }
-
-      if (contentCommandMessage) {
-        WidgetContentCommandEvent contentCommand(true, contentCommandMessage,
-                                                 this);
-        DispatchWindowEvent(&contentCommand);
-        // tell the driver that we handled the event
-        *aRetValue = 1;
-        result = true;
-      }
-      // default = false - tell the driver that the event was not handled
-    }
-    break;
+      result = HandleAppCommandMsg(wParam, lParam, aRetValue);
+      break;
 
     // The WM_ACTIVATE event is fired when a window is raised or lowered,
     // and the loword of wParam specifies which. But we don't want to tell
     // the focus system about this until the WM_SETFOCUS or WM_KILLFOCUS
     // events are fired. Instead, set either the sJustGotActivate or
     // gJustGotDeactivate flags and activate/deactivate once the focus
     // events arrive.
     case WM_ACTIVATE:
--- a/widget/windows/nsWindow.h
+++ b/widget/windows/nsWindow.h
@@ -352,17 +352,16 @@ protected:
   }
 
 
   /**
    * Event processing helpers
    */
   void                    DispatchFocusToTopLevelWindow(bool aIsActivate);
   bool                    DispatchStandardEvent(uint32_t aMsg);
-  bool                    DispatchCommandEvent(uint32_t aEventCommand);
   void                    RelayMouseEvent(UINT aMsg, WPARAM wParam, LPARAM lParam);
   virtual bool            ProcessMessage(UINT msg, WPARAM &wParam,
                                          LPARAM &lParam, LRESULT *aRetValue);
   bool                    ExternalHandlerProcessMessage(
                                          UINT aMessage, WPARAM& aWParam,
                                          LPARAM& aLParam, MSGResult& aResult);
   bool                    ProcessMessageForPlugin(const MSG &aMsg,
                                                   MSGResult& aResult);
--- a/widget/windows/nsWindowBase.cpp
+++ b/widget/windows/nsWindowBase.cpp
@@ -1,17 +1,17 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* 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/. */
 
 #include "nsWindowBase.h"
 
 #include "mozilla/MiscEvents.h"
-
+#include "nsGkAtoms.h"
 #include "WinUtils.h"
 #include "npapi.h"
 
 using namespace mozilla;
 using namespace mozilla::widget;
 
 static const wchar_t kUser32LibName[] =  L"user32.dll";
 bool nsWindowBase::sTouchInjectInitialized = false;
@@ -189,9 +189,141 @@ nsWindowBase::ClearNativeTouchSequence()
   // cancel all input points
   mActivePointers.Enumerate(CancelTouchPoints, (void*)this);
 
   nsBaseWidget::ClearNativeTouchSequence();
 
   return NS_OK;
 }
 
+bool
+nsWindowBase::DispatchCommandEvent(uint32_t aEventCommand)
+{
+  nsCOMPtr<nsIAtom> command;
+  switch (aEventCommand) {
+    case APPCOMMAND_BROWSER_BACKWARD:
+      command = nsGkAtoms::Back;
+      break;
+    case APPCOMMAND_BROWSER_FORWARD:
+      command = nsGkAtoms::Forward;
+      break;
+    case APPCOMMAND_BROWSER_REFRESH:
+      command = nsGkAtoms::Reload;
+      break;
+    case APPCOMMAND_BROWSER_STOP:
+      command = nsGkAtoms::Stop;
+      break;
+    case APPCOMMAND_BROWSER_SEARCH:
+      command = nsGkAtoms::Search;
+      break;
+    case APPCOMMAND_BROWSER_FAVORITES:
+      command = nsGkAtoms::Bookmarks;
+      break;
+    case APPCOMMAND_BROWSER_HOME:
+      command = nsGkAtoms::Home;
+      break;
+    case APPCOMMAND_CLOSE:
+      command = nsGkAtoms::Close;
+      break;
+    case APPCOMMAND_FIND:
+      command = nsGkAtoms::Find;
+      break;
+    case APPCOMMAND_HELP:
+      command = nsGkAtoms::Help;
+      break;
+    case APPCOMMAND_NEW:
+      command = nsGkAtoms::New;
+      break;
+    case APPCOMMAND_OPEN:
+      command = nsGkAtoms::Open;
+      break;
+    case APPCOMMAND_PRINT:
+      command = nsGkAtoms::Print;
+      break;
+    case APPCOMMAND_SAVE:
+      command = nsGkAtoms::Save;
+      break;
+    case APPCOMMAND_FORWARD_MAIL:
+      command = nsGkAtoms::ForwardMail;
+      break;
+    case APPCOMMAND_REPLY_TO_MAIL:
+      command = nsGkAtoms::ReplyToMail;
+      break;
+    case APPCOMMAND_SEND_MAIL:
+      command = nsGkAtoms::SendMail;
+      break;
+    default:
+      return false;
+  }
+  WidgetCommandEvent event(true, nsGkAtoms::onAppCommand, command, this);
 
+  InitEvent(event);
+  return DispatchWindowEvent(&event);
+}
+
+bool
+nsWindowBase::HandleAppCommandMsg(WPARAM aWParam,
+                                  LPARAM aLParam,
+                                  LRESULT *aRetValue)
+{
+  uint32_t appCommand = GET_APPCOMMAND_LPARAM(aLParam);
+  uint32_t contentCommandMessage = NS_EVENT_NULL;
+  // XXX After we implement KeyboardEvent.key, we should dispatch the
+  //     key event if (GET_DEVICE_LPARAM(lParam) == FAPPCOMMAND_KEY) is.
+  switch (appCommand)
+  {
+    case APPCOMMAND_BROWSER_BACKWARD:
+    case APPCOMMAND_BROWSER_FORWARD:
+    case APPCOMMAND_BROWSER_REFRESH:
+    case APPCOMMAND_BROWSER_STOP:
+    case APPCOMMAND_BROWSER_SEARCH:
+    case APPCOMMAND_BROWSER_FAVORITES:
+    case APPCOMMAND_BROWSER_HOME:
+    case APPCOMMAND_CLOSE:
+    case APPCOMMAND_FIND:
+    case APPCOMMAND_HELP:
+    case APPCOMMAND_NEW:
+    case APPCOMMAND_OPEN:
+    case APPCOMMAND_PRINT:
+    case APPCOMMAND_SAVE:
+    case APPCOMMAND_FORWARD_MAIL:
+    case APPCOMMAND_REPLY_TO_MAIL:
+    case APPCOMMAND_SEND_MAIL:
+      // We shouldn't consume the message always because if we don't handle
+      // the message, the sender (typically, utility of keyboard or mouse)
+      // may send other key messages which indicate well known shortcut key.
+      if (DispatchCommandEvent(appCommand)) {
+        // tell the driver that we handled the event
+        *aRetValue = 1;
+        return true;
+      }
+      break;
+
+    // Use content command for following commands:
+    case APPCOMMAND_COPY:
+      contentCommandMessage = NS_CONTENT_COMMAND_COPY;
+      break;
+    case APPCOMMAND_CUT:
+      contentCommandMessage = NS_CONTENT_COMMAND_CUT;
+      break;
+    case APPCOMMAND_PASTE:
+      contentCommandMessage = NS_CONTENT_COMMAND_PASTE;
+      break;
+    case APPCOMMAND_REDO:
+      contentCommandMessage = NS_CONTENT_COMMAND_REDO;
+      break;
+    case APPCOMMAND_UNDO:
+      contentCommandMessage = NS_CONTENT_COMMAND_UNDO;
+      break;
+  }
+
+  if (contentCommandMessage) {
+    WidgetContentCommandEvent contentCommand(true, contentCommandMessage,
+                                              this);
+    DispatchWindowEvent(&contentCommand);
+    // tell the driver that we handled the event
+    *aRetValue = 1;
+    return true;
+  }
+
+  // default = false - tell the driver that the event was not handled
+  return false;
+}
--- a/widget/windows/nsWindowBase.h
+++ b/widget/windows/nsWindowBase.h
@@ -73,28 +73,35 @@ public:
   /*
    * Returns true if a plugin has focus on this widget.  Otherwise, false.
    */
   virtual bool PluginHasFocus() const MOZ_FINAL
   {
     return (mInputContext.mIMEState.mEnabled == IMEState::PLUGIN);
   }
 
-public:
   /*
    * Touch input injection apis
    */
   virtual nsresult SynthesizeNativeTouchPoint(uint32_t aPointerId,
                                               TouchPointerState aPointerState,
                                               nsIntPoint aPointerScreenPoint,
                                               double aPointerPressure,
                                               uint32_t aPointerOrientation);
   virtual nsresult ClearNativeTouchSequence();
 
+  /*
+   * WM_APPCOMMAND common handler. Sends events via DispatchWindowEvent.
+   */
+  virtual bool HandleAppCommandMsg(WPARAM aWParam,
+                                   LPARAM aLParam,
+                                   LRESULT *aRetValue);
+
 protected:
+  bool DispatchCommandEvent(uint32_t aEventCommand);
   static bool InitTouchInjection();
   bool InjectTouchPoint(uint32_t aId, nsIntPoint& aPointerScreenPoint,
                         POINTER_FLAGS aFlags, uint32_t aPressure = 1024,
                         uint32_t aOrientation = 90);
 
   class PointerInfo
   {
   public:
--- a/widget/windows/winrt/MetroWidget.cpp
+++ b/widget/windows/winrt/MetroWidget.cpp
@@ -884,16 +884,20 @@ MetroWidget::WindowProcedure(HWND aWnd, 
     case WM_INPUTLANGCHANGE:
     {
       KeyboardLayout::GetInstance()->
         OnLayoutChange(reinterpret_cast<HKL>(aLParam));
       processResult = 1;
       break;
     }
 
+    case WM_APPCOMMAND:
+      processDefault = HandleAppCommandMsg(aWParam, aLParam, &processResult);
+      break;
+
     case WM_GETOBJECT:
     {
       DWORD dwObjId = (LPARAM)(DWORD) aLParam;
       // Passing this to CallWindowProc can result in a failure due to a timing issue
       // in winrt core window server code, so we call it directly here. Also, it's not
       // clear Windows::UI::Core::WindowServer::OnAutomationProviderRequestedEvent is
       // compatible with metro enabled desktop browsers, it makes an initial call to
       // UiaReturnRawElementProvider passing the return result from FrameworkView