From bdba6b134a49ce1ee1a7cbd6c6d0a96252cdc643 Mon Sep 17 00:00:00 2001 From: Masayuki Nakano Date: Wed, 29 May 2013 15:34:47 +0900 Subject: [PATCH] Bug 855975 part.5 Move nsWindow::DispatchKeyEvent() to widget::NativeKey::DispatchKeyEvent() r=jimm --- widget/windows/KeyboardLayout.cpp | 35 +++++++++++++++++++++++++++++++ widget/windows/KeyboardLayout.h | 10 +++++++++ widget/windows/nsWindow.cpp | 26 +++++------------------ widget/windows/nsWindow.h | 2 -- 4 files changed, 50 insertions(+), 23 deletions(-) diff --git a/widget/windows/KeyboardLayout.cpp b/widget/windows/KeyboardLayout.cpp index 3ee20d3d899..ae9110061cd 100644 --- a/widget/windows/KeyboardLayout.cpp +++ b/widget/windows/KeyboardLayout.cpp @@ -17,8 +17,12 @@ #include "WidgetUtils.h" #include "WinUtils.h" #include "nsWindowDbg.h" +#include "nsServiceManagerUtils.h" #include "nsIDOMKeyEvent.h" +#include "nsIIdleServiceInternal.h" + +#include "npapi.h" #include #include @@ -665,11 +669,30 @@ NativeKey::InitKeyEvent(nsKeyEvent& aKeyEvent, aModKeyState.InitInputEvent(aKeyEvent); } +bool +NativeKey::DispatchKeyEvent(nsKeyEvent& aKeyEvent, + const MSG* aMsgSentToPlugin) const +{ + KeyboardLayout::NotifyIdleServiceOfUserActivity(); + + NPEvent pluginEvent; + if (aMsgSentToPlugin && + mWidget->GetInputContext().mIMEState.mEnabled == IMEState::PLUGIN) { + pluginEvent.event = aMsgSentToPlugin->message; + pluginEvent.wParam = aMsgSentToPlugin->wParam; + pluginEvent.lParam = aMsgSentToPlugin->lParam; + aKeyEvent.pluginEvent = static_cast(&pluginEvent); + } + + return mWidget->DispatchWindowEvent(&aKeyEvent); +} + /***************************************************************************** * mozilla::widget::KeyboardLayout *****************************************************************************/ KeyboardLayout* KeyboardLayout::sInstance = nullptr; +nsIIdleServiceInternal* KeyboardLayout::sIdleService = nullptr; // static KeyboardLayout* @@ -677,6 +700,10 @@ KeyboardLayout::GetInstance() { if (!sInstance) { sInstance = new KeyboardLayout(); + nsCOMPtr idleService = + do_GetService("@mozilla.org/widget/idleservice;1"); + // The refcount will be decreased at shutting down. + sIdleService = idleService.forget().get(); } return sInstance; } @@ -687,6 +714,14 @@ KeyboardLayout::Shutdown() { delete sInstance; sInstance = nullptr; + NS_IF_RELEASE(sIdleService); +} + +// static +void +KeyboardLayout::NotifyIdleServiceOfUserActivity() +{ + sIdleService->ResetIdleTimeOut(0); } KeyboardLayout::KeyboardLayout() : diff --git a/widget/windows/KeyboardLayout.h b/widget/windows/KeyboardLayout.h index f582472184b..911d2dc9f7f 100644 --- a/widget/windows/KeyboardLayout.h +++ b/widget/windows/KeyboardLayout.h @@ -34,6 +34,7 @@ #define VK_OEM_102 0xE2 #define VK_OEM_CLEAR 0xFE +class nsIIdleServiceInternal; struct nsModifierKeyState; namespace mozilla { @@ -323,6 +324,13 @@ public: InitKeyEvent(aKeyEvent, mModKeyState); } + /** + * Dispatches the key event. Returns true if the event is consumed. + * Otherwise, false. + */ + bool DispatchKeyEvent(nsKeyEvent& aKeyEvent, + const MSG* aMsgSentToPlugin = nullptr) const; + private: nsRefPtr mWidget; HKL mKeyboardLayout; @@ -369,6 +377,7 @@ private: ~KeyboardLayout(); static KeyboardLayout* sInstance; + static nsIIdleServiceInternal* sIdleService; struct DeadKeyTableListEntry { @@ -421,6 +430,7 @@ private: public: static KeyboardLayout* GetInstance(); static void Shutdown(); + static void NotifyIdleServiceOfUserActivity(); static bool IsPrintableCharKey(uint8_t aVirtualKey); diff --git a/widget/windows/nsWindow.cpp b/widget/windows/nsWindow.cpp index 3db0d9e2085..f9428d30f67 100644 --- a/widget/windows/nsWindow.cpp +++ b/widget/windows/nsWindow.cpp @@ -3615,22 +3615,6 @@ bool nsWindow::DispatchWindowEvent(nsGUIEvent* event, nsEventStatus &aStatus) { return ConvertStatus(aStatus); } -bool nsWindow::DispatchKeyEvent(nsKeyEvent& aKeyEvent, - const MSG *aMsgSentToPlugin) -{ - UserActivity(); - - NPEvent pluginEvent; - if (aMsgSentToPlugin && PluginHasFocus()) { - pluginEvent.event = aMsgSentToPlugin->message; - pluginEvent.wParam = aMsgSentToPlugin->wParam; - pluginEvent.lParam = aMsgSentToPlugin->lParam; - aKeyEvent.pluginEvent = (void *)&pluginEvent; - } - - return DispatchWindowEvent(&aKeyEvent); -} - bool nsWindow::DispatchCommandEvent(uint32_t aEventCommand) { nsCOMPtr command; @@ -6458,7 +6442,7 @@ LRESULT nsWindow::OnKeyDown(const MSG &aMsg, nsKeyEvent keydownEvent(true, NS_KEY_DOWN, this); keydownEvent.keyCode = DOMKeyCode; nativeKey.InitKeyEvent(keydownEvent); - noDefault = DispatchKeyEvent(keydownEvent, &aMsg); + noDefault = nativeKey.DispatchKeyEvent(keydownEvent, &aMsg); if (aEventDispatched) { *aEventDispatched = true; } @@ -6783,14 +6767,14 @@ LRESULT nsWindow::OnKeyDown(const MSG &aMsg, keypressEvent.charCode = uniChar; keypressEvent.alternativeCharCodes.AppendElements(altArray); nativeKey.InitKeyEvent(keypressEvent, modKeyState); - DispatchKeyEvent(keypressEvent, nullptr); + nativeKey.DispatchKeyEvent(keypressEvent); } } else { nsKeyEvent keypressEvent(true, NS_KEY_PRESS, this); keypressEvent.mFlags.Union(extraFlags); keypressEvent.keyCode = DOMKeyCode; nativeKey.InitKeyEvent(keypressEvent, aModKeyState); - DispatchKeyEvent(keypressEvent, nullptr); + nativeKey.DispatchKeyEvent(keypressEvent); } return noDefault; @@ -6818,7 +6802,7 @@ LRESULT nsWindow::OnKeyUp(const MSG &aMsg, // of IME. keyupEvent.mFlags.mDefaultPrevented = (aMsg.wParam == VK_MENU && aMsg.message != WM_SYSKEYUP); - return DispatchKeyEvent(keyupEvent, &aMsg); + return nativeKey.DispatchKeyEvent(keyupEvent, &aMsg); } // OnChar @@ -6903,7 +6887,7 @@ LRESULT nsWindow::OnChar(const MSG &aMsg, keypressEvent.keyCode = aNativeKey.GetDOMKeyCode(); } aNativeKey.InitKeyEvent(keypressEvent, modKeyState); - bool result = DispatchKeyEvent(keypressEvent, &aMsg); + bool result = aNativeKey.DispatchKeyEvent(keypressEvent, &aMsg); if (aEventDispatched) *aEventDispatched = true; return result; diff --git a/widget/windows/nsWindow.h b/widget/windows/nsWindow.h index 8d7309b5873..476d49aea0c 100644 --- a/widget/windows/nsWindow.h +++ b/widget/windows/nsWindow.h @@ -195,8 +195,6 @@ public: int16_t aButton = nsMouseEvent::eLeftButton, uint16_t aInputSource = nsIDOMMouseEvent::MOZ_SOURCE_MOUSE); virtual bool DispatchWindowEvent(nsGUIEvent*event, nsEventStatus &aStatus); - virtual bool DispatchKeyEvent(nsKeyEvent& aKeyEvent, - const MSG *aMsgSentToPlugin); void DispatchPendingEvents(); bool DispatchPluginEvent(UINT aMessage, WPARAM aWParam,