Bug 1119609 part.2 Don't dispatch keyboard events from TextEventDispatcher if there is a composition r=smaug

This commit is contained in:
Masayuki Nakano 2015-02-19 15:50:18 +09:00
parent fd631dd6f0
commit 7921d21dce
3 changed files with 34 additions and 0 deletions

View File

@ -161,6 +161,11 @@ pref("dom.gamepad.non_standard_events.enabled", true);
// Whether the KeyboardEvent.code is enabled
pref("dom.keyboardevent.code.enabled", true);
// If this is true, TextEventDispatcher dispatches keydown and keyup events
// even during composition (keypress events are never fired during composition
// even if this is true).
pref("dom.keyboardevent.dispatch_during_composition", false);
// Whether the WebCrypto API is enabled
pref("dom.webcrypto.enabled", true);

View File

@ -3,6 +3,7 @@
* 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 "mozilla/Preferences.h"
#include "mozilla/TextEvents.h"
#include "mozilla/TextEventDispatcher.h"
#include "nsIDocShell.h"
@ -19,12 +20,23 @@ namespace widget {
* TextEventDispatcher
*****************************************************************************/
bool TextEventDispatcher::sDispatchKeyEventsDuringComposition = false;
TextEventDispatcher::TextEventDispatcher(nsIWidget* aWidget)
: mWidget(aWidget)
, mForTests(false)
, mIsComposing(false)
{
MOZ_RELEASE_ASSERT(mWidget, "aWidget must not be nullptr");
static bool sInitialized = false;
if (!sInitialized) {
Preferences::AddBoolVarCache(
&sDispatchKeyEventsDuringComposition,
"dom.keyboardevent.dispatch_during_composition",
false);
sInitialized = true;
}
}
nsresult
@ -253,6 +265,19 @@ TextEventDispatcher::DispatchKeyboardEventInternal(
return false;
}
// Basically, key events shouldn't be dispatched during composition.
if (IsComposing()) {
// However, if we need to behave like other browsers, we need the keydown
// and keyup events. Note that this behavior is also allowed by D3E spec.
// FYI: keypress events must not be fired during composition.
if (!sDispatchKeyEventsDuringComposition || aMessage == NS_KEY_PRESS) {
return false;
}
// XXX If there was mOnlyContentDispatch for this case, it might be useful
// because our chrome doesn't assume that key events are fired during
// composition.
}
nsCOMPtr<nsIWidget> widget(mWidget);
WidgetKeyboardEvent keyEvent(true, aMessage, widget);

View File

@ -235,6 +235,10 @@ private:
// See IsComposing().
bool mIsComposing;
// If this is true, keydown and keyup events are dispatched even when there
// is a composition.
static bool sDispatchKeyEventsDuringComposition;
nsresult BeginInputTransactionInternal(
TextEventDispatcherListener* aListener,
bool aForTests);