Bug 1857303 - Fire copy event when pressing Ctrl+C on contenteditable without selection. r=sefeng,masayuki

Differential Revision: https://phabricator.services.mozilla.com/D190402
This commit is contained in:
Divyanshu Agrawal 2023-10-27 18:36:02 +00:00
parent e4533f2062
commit 13347e51bb
3 changed files with 40 additions and 1 deletions

View File

@ -1560,7 +1560,11 @@ bool EditorBase::CheckForClipboardCommandListener(
return false;
}
RefPtr<EventTarget> et = GetDOMEventTarget();
RefPtr<EventTarget> et = IsHTMLEditor()
? AsHTMLEditor()->ComputeEditingHost(
HTMLEditor::LimitInBodyElement::No)
: GetDOMEventTarget();
while (et) {
EventListenerManager* elm = et->GetExistingListenerManager();
if (elm && elm->HasListenersFor(aCommand)) {

View File

@ -420,6 +420,8 @@ skip-if = ["os == 'android'"] #Bug 1575739
["test_composition_with_highlight_in_texteditor.html"]
["test_contenteditable_copy_empty_selection.html"]
["test_contenteditable_focus.html"]
["test_cut_copy_delete_command_enabled.html"]

View File

@ -0,0 +1,33 @@
<!DOCTYPE html>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1857303
-->
<head>
<meta charset="utf-8">
<title>Test for contenteditable copy event fired even when selection is empty</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>
<div contenteditable=true id="elem">Copy</div>
<script>
SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(() => {
let copyEventFired = false;
const editableDiv = document.getElementById("elem");
editableDiv.addEventListener("copy", function () {
copyEventFired = true;
});
editableDiv.focus();
synthesizeKey("c", { accelKey: true });
ok(copyEventFired, "Copy event should be fired");
SimpleTest.finish();
});
</script>
</body>
</html>