Bug 1300003 part.6 NativeKey shouldn't try to dispatch plugin events for removed char messages when mWidget won't dispatch plugin events r=m_kato

Currently, NativeKey::DispatchPluginEventsAndDiscardsCharMessages() calls nsWindowBase::DispatchPluginEvent() and nsWindowBase::DispatchPluginEvent() does nothing when windowless plugin doesn't have focus.  However, this is unclear when other developers read the code of DispatchPluginEventsAndDiscardsCharMessages() and it causes unnecessary virtual calls.  So, it should try to dispatch plugin events only when a windowless plugin has focus.

For making the check safer, nsWindowBase should expose the method to check it as ShouldDispatchPluginEvent().  Unfortunately, we cannot mark this method as const due to PluginHasFocus() needs to be not const method, though.  Then, for loops in DispatchPluginEventsAndDiscardsCharMessages() should check it at each try.

This change helps to log the behavior (working on bug 1297013) without noise.

Additionally, this patch renames the method to MaybeDispatchPluginEventsForRemovedCharMessages() because it doesn't remove any char messages anymore.

MozReview-Commit-ID: F14Lcx47M6U

--HG--
extra : rebase_source : 64b6da75590c99299f75358023844762198136d6
This commit is contained in:
Masayuki Nakano 2016-09-15 00:16:18 +09:00
parent 050c1b4088
commit eac959a338
4 changed files with 26 additions and 12 deletions

View File

@ -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]);

View File

@ -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

View File

@ -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()

View File

@ -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
*/