mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-18 07:45:30 +00:00
Bug 1649278 - Don't do PreventDefault for escape key if <select> dropdown is not shown r=smaug
We always use PreventDefault for <select> element, which is problematic if modal dialog is on as it prevents cancelling the dialog. We fix it by not blocking the default action if <select> is not shown. Differential Revision: https://phabricator.services.mozilla.com/D82590
This commit is contained in:
parent
da46069826
commit
7ba74df412
@ -2,6 +2,7 @@
|
|||||||
prefs =
|
prefs =
|
||||||
dom.dialog_element.enabled=true
|
dom.dialog_element.enabled=true
|
||||||
[test_cancelDialogByEscape.html]
|
[test_cancelDialogByEscape.html]
|
||||||
|
[test_dialog_cancel_with_select.html]
|
||||||
[test_dialog_cancel_events.html]
|
[test_dialog_cancel_events.html]
|
||||||
[test_dialog_cancel_preventDefault.html]
|
[test_dialog_cancel_preventDefault.html]
|
||||||
[test_dialog_keydown_preventDefault.html]
|
[test_dialog_keydown_preventDefault.html]
|
||||||
|
48
dom/html/test/dialog/test_dialog_cancel_with_select.html
Normal file
48
dom/html/test/dialog/test_dialog_cancel_with_select.html
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
<!DOCTYPE HTML>
|
||||||
|
<html>
|
||||||
|
<!--
|
||||||
|
https://bugzilla.mozilla.org/show_bug.cgi?id=1322947
|
||||||
|
-->
|
||||||
|
<head>
|
||||||
|
<title>Test for Bug 1322947</title>
|
||||||
|
<script src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||||
|
<script src="/tests/SimpleTest/EventUtils.js"></script>
|
||||||
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||||
|
</head>
|
||||||
|
<body onload="SimpleTest.waitForFocus(runTest)">
|
||||||
|
<a target="_blank"
|
||||||
|
href="https://bugzilla.mozilla.org/show_bug.cgi?id=1322947"> Test dialog modal is closed by escape key</a>
|
||||||
|
<p id="display"></p>
|
||||||
|
<dialog id="dialog">
|
||||||
|
<select>
|
||||||
|
<option value="one">one</option>
|
||||||
|
<option value="two">two</option>
|
||||||
|
</select>
|
||||||
|
</dialog>
|
||||||
|
|
||||||
|
<pre id="test">
|
||||||
|
<script type="application/javascript">
|
||||||
|
SimpleTest.waitForExplicitFinish();
|
||||||
|
|
||||||
|
function runTest() {
|
||||||
|
const dialog = document.getElementById("dialog");
|
||||||
|
const select = document.querySelector("select");
|
||||||
|
|
||||||
|
dialog.addEventListener("close", function() {
|
||||||
|
ok(dialog.close, "dialog with select is closed");
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
dialog.showModal();
|
||||||
|
ok(select == document.activeElement, "select element should be focused");
|
||||||
|
|
||||||
|
synthesizeKey("VK_ESCAPE", {}, window);
|
||||||
|
}
|
||||||
|
|
||||||
|
function done() {
|
||||||
|
SimpleTest.finish();
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</pre>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
@ -2061,11 +2061,20 @@ nsresult nsListControlFrame::KeyDown(dom::Event* aKeyEvent) {
|
|||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We don't want to preventDefault for escape key if the dropdown
|
||||||
|
// popup is not shown.
|
||||||
|
// Need to do the check before AboutToRollup because AboutToRollup
|
||||||
|
// may update the dropdown flags.
|
||||||
|
bool doPreventDefault =
|
||||||
|
!mComboboxFrame || mComboboxFrame->IsDroppedDownOrHasParentPopup();
|
||||||
|
|
||||||
AboutToRollup();
|
AboutToRollup();
|
||||||
// If the select element is a dropdown style, Enter key should be
|
// If the select element is a dropdown style, Escape key should be
|
||||||
// consumed everytime since Escape key may be pressed accidentally after
|
// consumed everytime since Escape key may be pressed accidentally after
|
||||||
// the dropdown is closed by Escepe key.
|
// the dropdown is closed by Escepe key.
|
||||||
aKeyEvent->PreventDefault();
|
if (doPreventDefault) {
|
||||||
|
aKeyEvent->PreventDefault();
|
||||||
|
}
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
case NS_VK_PAGE_UP: {
|
case NS_VK_PAGE_UP: {
|
||||||
|
@ -343,7 +343,7 @@ function runTests()
|
|||||||
|
|
||||||
reset()
|
reset()
|
||||||
synthesizeKey("KEY_Escape");
|
synthesizeKey("KEY_Escape");
|
||||||
check(true, false, "'Escape' key on combobox");
|
check(false, false, "'Escape' key on combobox");
|
||||||
|
|
||||||
if (!kIsWin) {
|
if (!kIsWin) {
|
||||||
reset()
|
reset()
|
||||||
|
Loading…
Reference in New Issue
Block a user