diff --git a/widget/windows/KeyboardLayout.cpp b/widget/windows/KeyboardLayout.cpp index 3d912c96eede..bdb8b532980b 100644 --- a/widget/windows/KeyboardLayout.cpp +++ b/widget/windows/KeyboardLayout.cpp @@ -1847,14 +1847,14 @@ NativeKey::HandleKeyDownMessage(bool* aEventDispatched) const } if (defaultPrevented) { - DispatchPluginEventsAndDiscardsCharMessages(); + MaybeDispatchPluginEventsForRemovedCharMessages(); return true; } // If we won't be getting a WM_CHAR, WM_SYSCHAR or WM_DEADCHAR, synthesize a // keypress for almost all keys if (NeedsToHandleWithoutFollowingCharMessages()) { - return (DispatchPluginEventsAndDiscardsCharMessages() || + return (MaybeDispatchPluginEventsForRemovedCharMessages() || DispatchKeyPressEventsWithoutCharMessage()); } @@ -2386,14 +2386,15 @@ NativeKey::GetFollowingCharMessage(MSG& aCharMsg) const return false; } -// TODO: Rename this method later. bool -NativeKey::DispatchPluginEventsAndDiscardsCharMessages() const +NativeKey::MaybeDispatchPluginEventsForRemovedCharMessages() const { MOZ_ASSERT(IsKeyDownMessage()); MOZ_ASSERT(!IsKeyMessageOnPlugin()); - for (size_t i = 0; i < mFollowingCharMsgs.Length(); ++i) { + for (size_t i = 0; + i < mFollowingCharMsgs.Length() && mWidget->ShouldDispatchPluginEvent(); + ++i) { MOZ_RELEASE_ASSERT(!mWidget->Destroyed(), "NativeKey tries to dispatch a plugin event on destroyed widget"); mWidget->DispatchPluginEvent(mFollowingCharMsgs[i]); @@ -2404,7 +2405,9 @@ NativeKey::DispatchPluginEventsAndDiscardsCharMessages() const // Dispatch odd char messages which are caused by ATOK or WXG (both of them // are Japanese IME) and removed by RemoveFollowingOddCharMessages(). - for (size_t i = 0; i < mRemovedOddCharMsgs.Length(); ++i) { + for (size_t i = 0; + i < mRemovedOddCharMsgs.Length() && mWidget->ShouldDispatchPluginEvent(); + ++i) { MOZ_RELEASE_ASSERT(!mWidget->Destroyed(), "NativeKey tries to dispatch a plugin event on destroyed widget"); mWidget->DispatchPluginEvent(mRemovedOddCharMsgs[i]); diff --git a/widget/windows/KeyboardLayout.h b/widget/windows/KeyboardLayout.h index 8a9c1d0e0c1d..a27319aa8b49 100644 --- a/widget/windows/KeyboardLayout.h +++ b/widget/windows/KeyboardLayout.h @@ -504,12 +504,12 @@ private: bool DispatchKeyPressEventsWithoutCharMessage() const; /** - * Remove all following WM_CHAR, WM_SYSCHAR and WM_DEADCHAR messages for the - * WM_KEYDOWN or WM_SYSKEYDOWN message. Additionally, dispatches plugin - * events if it's necessary. - * Returns true if the widget is destroyed. Otherwise, false. + * MaybeDispatchPluginEventsForRemovedCharMessages() dispatches plugin events + * for removed char messages when a windowless plugin has focus. + * Returns true if the widget is destroyed or blurred during dispatching a + * plugin event. */ - bool DispatchPluginEventsAndDiscardsCharMessages() const; + bool MaybeDispatchPluginEventsForRemovedCharMessages() const; /** * DispatchKeyPressEventForFollowingCharMessage() dispatches keypress event diff --git a/widget/windows/nsWindowBase.cpp b/widget/windows/nsWindowBase.cpp index da4c6c2c2edb..4c2edac6e527 100644 --- a/widget/windows/nsWindowBase.cpp +++ b/widget/windows/nsWindowBase.cpp @@ -21,7 +21,7 @@ InjectTouchInputPtr nsWindowBase::sInjectTouchFuncPtr; bool nsWindowBase::DispatchPluginEvent(const MSG& aMsg) { - if (!PluginHasFocus()) { + if (!ShouldDispatchPluginEvent()) { return false; } WidgetPluginEvent pluginEvent(true, ePluginInputEvent, this); @@ -36,6 +36,12 @@ nsWindowBase::DispatchPluginEvent(const MSG& aMsg) return DispatchWindowEvent(&pluginEvent); } +bool +nsWindowBase::ShouldDispatchPluginEvent() +{ + return PluginHasFocus(); +} + // static bool nsWindowBase::InitTouchInjection() diff --git a/widget/windows/nsWindowBase.h b/widget/windows/nsWindowBase.h index 46b237f4a1a5..405f5b359ea2 100644 --- a/widget/windows/nsWindowBase.h +++ b/widget/windows/nsWindowBase.h @@ -85,6 +85,11 @@ public: */ virtual bool DispatchPluginEvent(const MSG& aMsg); + /* + * Returns true if this should dispatch a plugin event. + */ + bool ShouldDispatchPluginEvent(); + /* * Touch input injection apis */