author | Masayuki Nakano <masayuki@d-toybox.com> |
Wed, 29 May 2013 15:34:47 +0900 | |
changeset 133242 | 81aadfdcd59da90a6d922fb148a9bd81dd383e9d |
parent 133241 | f65ebd90ad9e60fcfb7e7fe97e3bec3c8c7b6d0b |
child 133243 | cfef49bc5691deeedd8393c5fb2eb9d3b4cb7950 |
push id | 24747 |
push user | emorley@mozilla.com |
push date | Wed, 29 May 2013 14:24:37 +0000 |
treeherder | mozilla-central@8d85de779506 [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | jimm |
bugs | 855975 |
milestone | 24.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
|
--- a/widget/windows/KeyboardLayout.cpp +++ b/widget/windows/KeyboardLayout.cpp @@ -12,18 +12,22 @@ #include "nsToolkit.h" #include "nsQuickSort.h" #include "nsAlgorithm.h" #include "nsGUIEvent.h" #include "nsUnicharUtils.h" #include "WidgetUtils.h" #include "WinUtils.h" #include "nsWindowDbg.h" +#include "nsServiceManagerUtils.h" #include "nsIDOMKeyEvent.h" +#include "nsIIdleServiceInternal.h" + +#include "npapi.h" #include <windows.h> #include <winuser.h> #include <algorithm> #ifndef WINABLEAPI #include <winable.h> #endif @@ -660,38 +664,69 @@ NativeKey::InitKeyEvent(nsKeyEvent& aKey { nsIntPoint point(0, 0); mWidget->InitEvent(aKeyEvent, &point); aKeyEvent.mKeyNameIndex = mKeyNameIndex; aKeyEvent.location = GetKeyLocation(); 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<void*>(&pluginEvent); + } + + return mWidget->DispatchWindowEvent(&aKeyEvent); +} + /***************************************************************************** * mozilla::widget::KeyboardLayout *****************************************************************************/ KeyboardLayout* KeyboardLayout::sInstance = nullptr; +nsIIdleServiceInternal* KeyboardLayout::sIdleService = nullptr; // static KeyboardLayout* KeyboardLayout::GetInstance() { if (!sInstance) { sInstance = new KeyboardLayout(); + nsCOMPtr<nsIIdleServiceInternal> idleService = + do_GetService("@mozilla.org/widget/idleservice;1"); + // The refcount will be decreased at shutting down. + sIdleService = idleService.forget().get(); } return sInstance; } // static void KeyboardLayout::Shutdown() { delete sInstance; sInstance = nullptr; + NS_IF_RELEASE(sIdleService); +} + +// static +void +KeyboardLayout::NotifyIdleServiceOfUserActivity() +{ + sIdleService->ResetIdleTimeOut(0); } KeyboardLayout::KeyboardLayout() : mKeyboardLayout(0), mIsOverridden(false), mIsPendingToRestoreKeyboardLayout(false) { mDeadKeyTableListHead = nullptr;
--- a/widget/windows/KeyboardLayout.h +++ b/widget/windows/KeyboardLayout.h @@ -29,16 +29,17 @@ #define VK_OEM_4 0xDB #define VK_OEM_5 0xDC #define VK_OEM_6 0xDD #define VK_OEM_7 0xDE #define VK_OEM_8 0xDF #define VK_OEM_102 0xE2 #define VK_OEM_CLEAR 0xFE +class nsIIdleServiceInternal; struct nsModifierKeyState; namespace mozilla { namespace widget { class KeyboardLayout; class ModifierKeyState { @@ -318,16 +319,23 @@ public: */ void InitKeyEvent(nsKeyEvent& aKeyEvent, const ModifierKeyState& aModKeyState) const; void InitKeyEvent(nsKeyEvent& aKeyEvent) const { 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<nsWindowBase> mWidget; HKL mKeyboardLayout; uint32_t mDOMKeyCode; KeyNameIndex mKeyNameIndex; // The message which the instance was initialized with. UINT mMessage; @@ -364,16 +372,17 @@ class KeyboardLayout { friend class NativeKey; private: KeyboardLayout(); ~KeyboardLayout(); static KeyboardLayout* sInstance; + static nsIIdleServiceInternal* sIdleService; struct DeadKeyTableListEntry { DeadKeyTableListEntry* next; uint8_t data[1]; }; HKL mKeyboardLayout; @@ -416,16 +425,17 @@ private: * them to the aNativeKey. */ void InitNativeKey(NativeKey& aNativeKey, const ModifierKeyState& aModKeyState); public: static KeyboardLayout* GetInstance(); static void Shutdown(); + static void NotifyIdleServiceOfUserActivity(); static bool IsPrintableCharKey(uint8_t aVirtualKey); /** * IsDeadKey() returns true if aVirtualKey is a dead key with aModKeyState. * This method isn't stateful. */ bool IsDeadKey(uint8_t aVirtualKey,
--- a/widget/windows/nsWindow.cpp +++ b/widget/windows/nsWindow.cpp @@ -3610,32 +3610,16 @@ bool nsWindow::DispatchWindowEvent(nsGUI return ConvertStatus(status); } bool nsWindow::DispatchWindowEvent(nsGUIEvent* event, nsEventStatus &aStatus) { DispatchEvent(event, 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<nsIAtom> command; switch (aEventCommand) { case APPCOMMAND_BROWSER_BACKWARD: command = nsGkAtoms::Back; break; case APPCOMMAND_BROWSER_FORWARD: @@ -6453,17 +6437,17 @@ LRESULT nsWindow::OnKeyDown(const MSG &a static bool sRedirectedKeyDownEventPreventedDefault = false; bool noDefault; if (aFakeCharMessage || !IsRedirectedKeyDownMessage(aMsg)) { bool isIMEEnabled = IMEHandler::IsIMEEnabled(mInputContext); 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; } // If IMC wasn't associated to the window but is associated it now (i.e., // focus is moved from a non-editable editor to an editor by keydown // event handler), WM_CHAR and WM_SYSCHAR shouldn't cause first character // inputting if IME is opened. But then, we should redirect the native @@ -6778,24 +6762,24 @@ LRESULT nsWindow::OnKeyDown(const MSG &a } } nsKeyEvent keypressEvent(true, NS_KEY_PRESS, this); keypressEvent.mFlags.Union(extraFlags); 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; } // OnKeyUp LRESULT nsWindow::OnKeyUp(const MSG &aMsg, const ModifierKeyState &aModKeyState, @@ -6813,17 +6797,17 @@ LRESULT nsWindow::OnKeyUp(const MSG &aMs nativeKey.InitKeyEvent(keyupEvent); // Set defaultPrevented of the key event if the VK_MENU is not a system key // release, so that the menu bar does not trigger. This helps avoid // triggering the menu bar for ALT key accelerators used in assistive // technologies such as Window-Eyes and ZoomText or for switching open state // of IME. keyupEvent.mFlags.mDefaultPrevented = (aMsg.wParam == VK_MENU && aMsg.message != WM_SYSKEYUP); - return DispatchKeyEvent(keyupEvent, &aMsg); + return nativeKey.DispatchKeyEvent(keyupEvent, &aMsg); } // OnChar LRESULT nsWindow::OnChar(const MSG &aMsg, const NativeKey& aNativeKey, const ModifierKeyState &aModKeyState, bool *aEventDispatched, const EventFlags *aExtraFlags) @@ -6898,17 +6882,17 @@ LRESULT nsWindow::OnChar(const MSG &aMsg if (aExtraFlags) { keypressEvent.mFlags.Union(*aExtraFlags); } keypressEvent.charCode = uniChar; if (!keypressEvent.charCode) { 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; } void nsWindow::SetupKeyModifiersSequence(nsTArray<KeyPair>* aArray, uint32_t aModifiers) {
--- a/widget/windows/nsWindow.h +++ b/widget/windows/nsWindow.h @@ -190,18 +190,16 @@ public: * Event helpers */ virtual bool DispatchMouseEvent(uint32_t aEventType, WPARAM wParam, LPARAM lParam, bool aIsContextMenuKey = false, 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, LPARAM aLParam, bool aDispatchPendingEvents); void SuppressBlurEvents(bool aSuppress); // Called from nsFilePicker bool BlurEventsSuppressed();