Bug 751749 part.3 Editor should handle Win key as a modifier key r=ehsan

This commit is contained in:
Masayuki Nakano 2012-07-19 10:28:17 +09:00
parent 4c95259d7e
commit 8191cad1be
5 changed files with 117 additions and 8 deletions

View File

@ -5005,6 +5005,7 @@ nsEditor::HandleKeyPressEvent(nsIDOMKeyEvent* aKeyEvent)
switch (nativeKeyEvent->keyCode) {
case nsIDOMKeyEvent::DOM_VK_META:
case nsIDOMKeyEvent::DOM_VK_WIN:
case nsIDOMKeyEvent::DOM_VK_SHIFT:
case nsIDOMKeyEvent::DOM_VK_CONTROL:
case nsIDOMKeyEvent::DOM_VK_ALT:
@ -5012,7 +5013,7 @@ nsEditor::HandleKeyPressEvent(nsIDOMKeyEvent* aKeyEvent)
return NS_OK;
case nsIDOMKeyEvent::DOM_VK_BACK_SPACE:
if (nativeKeyEvent->IsControl() || nativeKeyEvent->IsAlt() ||
nativeKeyEvent->IsMeta()) {
nativeKeyEvent->IsMeta() || nativeKeyEvent->IsOS()) {
return NS_OK;
}
DeleteSelection(nsIEditor::ePrevious, nsIEditor::eStrip);
@ -5023,7 +5024,8 @@ nsEditor::HandleKeyPressEvent(nsIDOMKeyEvent* aKeyEvent)
// modifies what delete does (cmd_cut in this case).
// bailing here to allow the keybindings to do the cut.
if (nativeKeyEvent->IsShift() || nativeKeyEvent->IsControl() ||
nativeKeyEvent->IsAlt() || nativeKeyEvent->IsMeta()) {
nativeKeyEvent->IsAlt() || nativeKeyEvent->IsMeta() ||
nativeKeyEvent->IsOS()) {
return NS_OK;
}
DeleteSelection(nsIEditor::eNext, nsIEditor::eStrip);

View File

@ -599,6 +599,7 @@ nsHTMLEditor::HandleKeyPressEvent(nsIDOMKeyEvent* aKeyEvent)
switch (nativeKeyEvent->keyCode) {
case nsIDOMKeyEvent::DOM_VK_META:
case nsIDOMKeyEvent::DOM_VK_WIN:
case nsIDOMKeyEvent::DOM_VK_SHIFT:
case nsIDOMKeyEvent::DOM_VK_CONTROL:
case nsIDOMKeyEvent::DOM_VK_ALT:
@ -619,7 +620,7 @@ nsHTMLEditor::HandleKeyPressEvent(nsIDOMKeyEvent* aKeyEvent)
}
if (nativeKeyEvent->IsControl() || nativeKeyEvent->IsAlt() ||
nativeKeyEvent->IsMeta()) {
nativeKeyEvent->IsMeta() || nativeKeyEvent->IsOS()) {
return NS_OK;
}
@ -669,7 +670,7 @@ nsHTMLEditor::HandleKeyPressEvent(nsIDOMKeyEvent* aKeyEvent)
case nsIDOMKeyEvent::DOM_VK_RETURN:
case nsIDOMKeyEvent::DOM_VK_ENTER:
if (nativeKeyEvent->IsControl() || nativeKeyEvent->IsAlt() ||
nativeKeyEvent->IsMeta()) {
nativeKeyEvent->IsMeta() || nativeKeyEvent->IsOS()) {
return NS_OK;
}
aKeyEvent->PreventDefault(); // consumed
@ -684,7 +685,8 @@ nsHTMLEditor::HandleKeyPressEvent(nsIDOMKeyEvent* aKeyEvent)
// NOTE: On some keyboard layout, some characters are inputted with Control
// key or Alt key, but at that time, widget sets FALSE to these keys.
if (nativeKeyEvent->charCode == 0 || nativeKeyEvent->IsControl() ||
nativeKeyEvent->IsAlt() || nativeKeyEvent->IsMeta()) {
nativeKeyEvent->IsAlt() || nativeKeyEvent->IsMeta() ||
nativeKeyEvent->IsOS()) {
// we don't PreventDefault() here or keybindings like control-x won't work
return NS_OK;
}

View File

@ -136,6 +136,10 @@ function runTests()
synthesizeKey("VK_META", { type: "keypress" });
check(aDescription + "Meta", true, true, !aIsReadonly);
reset("");
synthesizeKey("VK_WIN", { type: "keypress" });
check(aDescription + "OS", true, true, !aIsReadonly);
reset("");
synthesizeKey("VK_SHIFT", { type: "keypress" });
check(aDescription + "Shift", true, true, !aIsReadonly);
@ -176,6 +180,10 @@ function runTests()
synthesizeKey("VK_BACK_SPACE", { metaKey: true });
check(aDescription + "Meta+Backspace", true, true, aIsReadonly);
reset("");
synthesizeKey("VK_BACK_SPACE", { osKey: true });
check(aDescription + "OS+Backspace", true, true, aIsReadonly);
// Delete key:
// If editor is readonly, it doesn't consume.
// If editor is editable, delete is consumed.
@ -200,6 +208,10 @@ function runTests()
synthesizeKey("VK_DELETE", { metaKey: true });
check(aDescription + "Meta+Delete", true, true, false);
reset("");
synthesizeKey("VK_DELETE", { osKey: true });
check(aDescription + "OS+Delete", true, true, false);
// Return key:
// If editor is readonly, it doesn't consume.
// If editor is editable and not single line editor, it consumes Return
@ -234,6 +246,11 @@ function runTests()
check(aDescription + "Meta+Return", true, true, false);
is(aElement.innerHTML, "a", aDescription + "Meta+Return");
reset("a");
synthesizeKey("VK_RETURN", { osKey: true });
check(aDescription + "OS+Return", true, true, false);
is(aElement.innerHTML, "a", aDescription + "OS+Return");
// Enter key (same as Return key):
// If editor is readonly, it doesn't consume.
// If editor is editable and not single line editor, it consumes Return
@ -268,6 +285,11 @@ function runTests()
check(aDescription + "Meta+Enter", true, true, false);
is(aElement.innerHTML, "a", aDescription + "Meta+Enter");
reset("a");
synthesizeKey("VK_ENTER", { osKey: true });
check(aDescription + "OS+Enter", true, true, false);
is(aElement.innerHTML, "a", aDescription + "OS+Enter");
// Tab key:
// If editor is tabbable, editor doesn't consume all tab key events.
// Otherwise, editor consumes tab key event without any modifier keys.
@ -311,6 +333,13 @@ function runTests()
is(fm.focusedElement, aElement,
aDescription + "focus moved unexpectedly (Meta+Tab)");
reset("a");
synthesizeKey("VK_TAB", { osKey: true });
check(aDescription + "OS+Tab", true, true, false);
is(aElement.innerHTML, "a", aDescription + "OS+Tab");
is(fm.focusedElement, aElement,
aDescription + "focus moved unexpectedly (OS+Tab)");
// Indent/Outdent tests:
// UL
resetForIndent("<ul><li id=\"target\">ul list item</li></ul>");
@ -372,6 +401,14 @@ function runTests()
is(fm.focusedElement, aElement,
aDescription + "focus moved unexpectedly (Meta+Tab on UL)");
resetForIndent("<ul><li id=\"target\">ul list item</li></ul>");
synthesizeKey("VK_TAB", { osKey: true });
check(aDescription + "OS+Tab on UL", true, true, false);
is(aElement.innerHTML, "<ul><li id=\"target\">ul list item</li></ul>",
aDescription + "OS+Tab on UL");
is(fm.focusedElement, aElement,
aDescription + "focus moved unexpectedly (OS+Tab on UL)");
// OL
resetForIndent("<ol><li id=\"target\">ol list item</li></ol>");
synthesizeKey("VK_TAB", { });
@ -432,6 +469,14 @@ function runTests()
is(fm.focusedElement, aElement,
aDescription + "focus moved unexpectedly (Meta+Tab on OL)");
resetForIndent("<ol><li id=\"target\">ol list item</li></ol>");
synthesizeKey("VK_TAB", { osKey: true });
check(aDescription + "OS+Tab on OL", true, true, false);
is(aElement.innerHTML, "<ol><li id=\"target\">ol list item</li></ol>",
aDescription + "OS+Tab on OL");
is(fm.focusedElement, aElement,
aDescription + "focus moved unexpectedly (OS+Tab on OL)");
// TD
resetForIndent("<table><tr><td id=\"target\">td</td></tr></table>");
synthesizeKey("VK_TAB", { });
@ -494,6 +539,15 @@ function runTests()
is(fm.focusedElement, aElement,
aDescription + "focus moved unexpectedly (Meta+Tab on TD)");
resetForIndent("<table><tr><td id=\"target\">td</td></tr></table>");
synthesizeKey("VK_TAB", { osKey: true });
check(aDescription + "OS+Tab on TD", true, true, false);
is(aElement.innerHTML,
"<table><tbody><tr><td id=\"target\">td</td></tr></tbody></table>",
aDescription + "OS+Tab on TD");
is(fm.focusedElement, aElement,
aDescription + "focus moved unexpectedly (OS+Tab on TD)");
// TH
resetForIndent("<table><tr><th id=\"target\">th</th></tr></table>");
synthesizeKey("VK_TAB", { });
@ -556,6 +610,15 @@ function runTests()
is(fm.focusedElement, aElement,
aDescription + "focus moved unexpectedly (Meta+Tab on TH)");
resetForIndent("<table><tr><th id=\"target\">th</th></tr></table>");
synthesizeKey("VK_TAB", { osKey: true });
check(aDescription + "OS+Tab on TH", true, true, false);
is(aElement.innerHTML,
"<table><tbody><tr><th id=\"target\">th</th></tr></tbody></table>",
aDescription + "OS+Tab on TH");
is(fm.focusedElement, aElement,
aDescription + "focus moved unexpectedly (OS+Tab on TH)");
// Esc key:
// In all cases, esc key events are not consumed
reset("abc");
@ -578,6 +641,10 @@ function runTests()
synthesizeKey("VK_ESCAPE", { metaKey: true });
check(aDescription + "Meta+Esc", true, true, false);
reset("abc");
synthesizeKey("VK_ESCAPE", { osKey: true });
check(aDescription + "OS+Esc", true, true, false);
// typical typing tests:
reset("");
synthesizeKey("M", { shiftKey: true });

View File

@ -358,6 +358,7 @@ nsPlaintextEditor::HandleKeyPressEvent(nsIDOMKeyEvent* aKeyEvent)
switch (nativeKeyEvent->keyCode) {
case nsIDOMKeyEvent::DOM_VK_META:
case nsIDOMKeyEvent::DOM_VK_WIN:
case nsIDOMKeyEvent::DOM_VK_SHIFT:
case nsIDOMKeyEvent::DOM_VK_CONTROL:
case nsIDOMKeyEvent::DOM_VK_ALT:
@ -371,7 +372,8 @@ nsPlaintextEditor::HandleKeyPressEvent(nsIDOMKeyEvent* aKeyEvent)
}
if (nativeKeyEvent->IsShift() || nativeKeyEvent->IsControl() ||
nativeKeyEvent->IsAlt() || nativeKeyEvent->IsMeta()) {
nativeKeyEvent->IsAlt() || nativeKeyEvent->IsMeta() ||
nativeKeyEvent->IsOS()) {
return NS_OK;
}
@ -382,7 +384,8 @@ nsPlaintextEditor::HandleKeyPressEvent(nsIDOMKeyEvent* aKeyEvent)
case nsIDOMKeyEvent::DOM_VK_RETURN:
case nsIDOMKeyEvent::DOM_VK_ENTER:
if (IsSingleLineEditor() || nativeKeyEvent->IsControl() ||
nativeKeyEvent->IsAlt() || nativeKeyEvent->IsMeta()) {
nativeKeyEvent->IsAlt() || nativeKeyEvent->IsMeta() ||
nativeKeyEvent->IsOS()) {
return NS_OK;
}
aKeyEvent->PreventDefault();
@ -392,7 +395,8 @@ nsPlaintextEditor::HandleKeyPressEvent(nsIDOMKeyEvent* aKeyEvent)
// NOTE: On some keyboard layout, some characters are inputted with Control
// key or Alt key, but at that time, widget sets FALSE to these keys.
if (nativeKeyEvent->charCode == 0 || nativeKeyEvent->IsControl() ||
nativeKeyEvent->IsAlt() || nativeKeyEvent->IsMeta()) {
nativeKeyEvent->IsAlt() || nativeKeyEvent->IsMeta() ||
nativeKeyEvent->IsOS()) {
// we don't PreventDefault() here or keybindings like control-x won't work
return NS_OK;
}

View File

@ -123,6 +123,10 @@ function runTests()
synthesizeKey("VK_META", { type: "keypress" });
check(aDescription + "Meta", true, true, !aIsReadonly);
reset("");
synthesizeKey("VK_WIN", { type: "keypress" });
check(aDescription + "OS", true, true, !aIsReadonly);
reset("");
synthesizeKey("VK_SHIFT", { type: "keypress" });
check(aDescription + "Shift", true, true, !aIsReadonly);
@ -169,6 +173,10 @@ function runTests()
synthesizeKey("VK_BACK_SPACE", { metaKey: true });
check(aDescription + "Meta+Backspace", true, true, aIsReadonly);
reset("");
synthesizeKey("VK_BACK_SPACE", { osKey: true });
check(aDescription + "OS+Backspace", true, true, aIsReadonly);
// Delete key:
// If editor is readonly, it doesn't consume.
// If editor is editable, delete is consumed.
@ -206,6 +214,11 @@ function runTests()
check(aDescription + "Meta+Delete",
true, true, kIsLinux);
reset("");
synthesizeKey("VK_DELETE", { osKey: true });
check(aDescription + "OS+Delete",
true, true, false);
// XXX input.value returns "\n" when it's empty, so, we should use dummy
// value ("a") for the following tests.
@ -243,6 +256,11 @@ function runTests()
check(aDescription + "Meta+Return", true, true, false);
is(aElement.value, "a", aDescription + "Meta+Return");
reset("a");
synthesizeKey("VK_RETURN", { osKey: true });
check(aDescription + "OS+Return", true, true, false);
is(aElement.value, "a", aDescription + "OS+Return");
// Enter key (same as Return key):
// If editor is readonly, it doesn't consume.
// If editor is editable and not single line editor, it consumes Return
@ -277,6 +295,11 @@ function runTests()
check(aDescription + "Meta+Enter", true, true, false);
is(aElement.value, "a", aDescription + "Meta+Enter");
reset("a");
synthesizeKey("VK_ENTER", { osKey: true });
check(aDescription + "OS+Enter", true, true, false);
is(aElement.value, "a", aDescription + "OS+Enter");
// Tab key:
// If editor is tabbable, editor doesn't consume all tab key events.
// Otherwise, editor consumes tab key event without any modifier keys.
@ -330,6 +353,13 @@ function runTests()
is(fm.focusedElement, aElement,
aDescription + "focus moved unexpectedly (Meta+Tab)");
reset("a");
synthesizeKey("VK_TAB", { osKey: true });
check(aDescription + "OS+Tab", true, true, false);
is(aElement.value, "a", aDescription + "OS+Tab");
is(fm.focusedElement, aElement,
aDescription + "focus moved unexpectedly (OS+Tab)");
// Esc key:
// In all cases, esc key events are not consumed
reset("abc");
@ -352,6 +382,10 @@ function runTests()
synthesizeKey("VK_ESCAPE", { metaKey: true });
check(aDescription + "Meta+Esc", true, true, false);
reset("abc");
synthesizeKey("VK_ESCAPE", { osKey: true });
check(aDescription + "OS+Esc", true, true, false);
// typical typing tests:
reset("");
synthesizeKey("M", { shiftKey: true });