зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1310565 TextInputHandler shouldn't dispatch a composition events when a key press causes 2 or more characters r=m_kato
TextInputHandler::InsertText() dispatches a set of composition events when a key press causes 2 or more characters (Note that InsertText() is typically called only when IME is available because it's called via [NSResponder interpretKeyEvents]). However, this is different from the behavior of Windows. On Windows, NativeKey dispatches two ore more eKeyPress events in this case. So, for consistency between platforms, TextInputHandler should dispatch eKeyPress events in such case. MozReview-Commit-ID: EMvaL7sklKf --HG-- extra : rebase_source : 0309d32d692a2394f53cd59216c6e774068e452b
This commit is contained in:
Родитель
b815cfe432
Коммит
bd146a2e1e
|
@ -2188,16 +2188,10 @@ TextInputHandler::InsertText(NSAttributedString* aAttrString,
|
|||
return;
|
||||
}
|
||||
|
||||
if (str.Length() != 1 || IsIMEComposing()) {
|
||||
// If this is not caused by pressing a key or there is a composition, let's
|
||||
// insert the text as committing a composition.
|
||||
if (!currentKeyEvent || IsIMEComposing()) {
|
||||
InsertTextAsCommittingComposition(aAttrString, aReplacementRange);
|
||||
// For now, consume keypress events when we dispatch the string with a
|
||||
// composition for preventing to dispatch keypress events later.
|
||||
// TODO: When there is a currentKeyEvent, we should dispatch keypress
|
||||
// events even if the length of the string is over 1.
|
||||
if (currentKeyEvent) {
|
||||
currentKeyEvent->mKeyPressHandled = true;
|
||||
currentKeyEvent->mKeyPressDispatched = true;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -1906,6 +1906,21 @@ function* runKeyEventTests()
|
|||
yield testKey({layout:KEYBOARD_LAYOUT_DVORAK_QWERTY, keyCode:MAC_VK_ANSI_I,
|
||||
modifiers:{metaKey:1, altKey:1, shiftKey:1}, chars:"\u02C6", unmodifiedChars:"C"},
|
||||
"\u02C6", "KeyI", nsIDOMKeyEvent.DOM_VK_I, "\u02C6", SHOULD_DELIVER_KEYDOWN_KEYPRESS, KeyboardEvent.DOM_KEY_LOCATION_STANDARD);
|
||||
|
||||
// Arabic - PC keyboard layout inputs 2 or more characters with some key.
|
||||
yield testKey({layout:KEYBOARD_LAYOUT_ARABIC_PC, keyCode:MAC_VK_ANSI_G,
|
||||
modifiers:{shiftKey:1}, chars:"\u0644\u0623", unmodifiedChars:"\u0644\u0623"},
|
||||
["\u0644\u0623", "\u0644", "\u0623", "\u0644\u0623"], "KeyG", nsIDOMKeyEvent.DOM_VK_G, "\u0644\u0623", SHOULD_DELIVER_ALL, KeyboardEvent.DOM_KEY_LOCATION_STANDARD);
|
||||
yield testKey({layout:KEYBOARD_LAYOUT_ARABIC_PC, keyCode:MAC_VK_ANSI_T,
|
||||
modifiers:{shiftKey:1}, chars:"\u0644\u0625", unmodifiedChars:"\u0644\u0625"},
|
||||
["\u0644\u0625", "\u0644", "\u0625", "\u0644\u0625"], "KeyT", nsIDOMKeyEvent.DOM_VK_T, "\u0644\u0625", SHOULD_DELIVER_ALL, KeyboardEvent.DOM_KEY_LOCATION_STANDARD);
|
||||
yield testKey({layout:KEYBOARD_LAYOUT_ARABIC_PC, keyCode:MAC_VK_ANSI_B,
|
||||
modifiers:{shiftKey:1}, chars:"\u0644\u0622", unmodifiedChars:"\u0644\u0622"},
|
||||
["\u0644\u0622", "\u0644", "\u0622", "\u0644\u0622"], "KeyB", nsIDOMKeyEvent.DOM_VK_B, "\u0644\u0622", SHOULD_DELIVER_ALL, KeyboardEvent.DOM_KEY_LOCATION_STANDARD);
|
||||
yield testKey({layout:KEYBOARD_LAYOUT_ARABIC_PC, keyCode:MAC_VK_ANSI_B,
|
||||
modifiers:{}, chars:"\u0644\u0627", unmodifiedChars:"\u0644\u0627"},
|
||||
["\u0644\u0627", "\u0644", "\u0627", "\u0644\u0627"], "KeyB", nsIDOMKeyEvent.DOM_VK_B, "\u0644\u0627", SHOULD_DELIVER_ALL, KeyboardEvent.DOM_KEY_LOCATION_STANDARD);
|
||||
|
||||
cleanup();
|
||||
}
|
||||
|
||||
|
@ -4197,11 +4212,37 @@ function* runTextInputTests()
|
|||
textbox.value = "";
|
||||
textbox.focus();
|
||||
|
||||
var name = eventToString(aEvent);
|
||||
|
||||
// Check if the text comes with keypress events rather than composition events.
|
||||
var keypress = 0;
|
||||
function onKeypress(aEvent) {
|
||||
keypress++;
|
||||
if (keypress == 1 && aExpectText == "") {
|
||||
if (!aEvent.ctrlKey && !aEvent.altKey) {
|
||||
is(aEvent.charCode, 0, name + ", the charCode value should be 0 when it shouldn't cause inputting text");
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (keypress > aExpectText.length) {
|
||||
ok(false, name + " causes too many keypress events");
|
||||
return;
|
||||
}
|
||||
is(aEvent.key, aExpectText[keypress - 1],
|
||||
name + ", " + keypress + "th keypress event's key value should be '" + aExpectText[keypress - 1] + "'");
|
||||
is(aEvent.charCode, aExpectText.charCodeAt(keypress - 1),
|
||||
name + ", " + keypress + "th keypress event's charCode value should be 0x" + parseInt(aExpectText.charCodeAt(keypress - 1), 16));
|
||||
}
|
||||
textbox.addEventListener("keypress", onKeypress, true);
|
||||
|
||||
return synthesizeKey(aEvent, "textbox", function() {
|
||||
|
||||
var name = eventToString(aEvent);
|
||||
|
||||
is(textbox.value, aExpectText, name + " does not input correct text.");
|
||||
textbox.removeEventListener("keypress", onKeypress, true);
|
||||
if (aExpectText == "") {
|
||||
is(keypress, 1, name + " should cause one keypress event because it doesn't cause inputting text");
|
||||
} else {
|
||||
is(keypress, aExpectText.length, name + " should cause " + aExpectText.length + " keypress events");
|
||||
is(textbox.value, aExpectText, name + " does not input correct text.");
|
||||
}
|
||||
|
||||
continueTest();
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче