Bug 1455479 - Show paste context menu item when there are paste event listeners. r=Gijs

Differential Revision: https://phabricator.services.mozilla.com/D97751
This commit is contained in:
Emilio Cobos Álvarez 2020-11-21 16:22:42 +00:00
Родитель 5c7fde1b72
Коммит e69e249773
4 изменённых файлов: 70 добавлений и 2 удалений

Просмотреть файл

@ -924,6 +924,17 @@ class ContextMenuChild extends JSWindowActorChild {
context.shouldInitInlineSpellCheckerUINoChildren = false;
context.shouldInitInlineSpellCheckerUIWithChildren = false;
context.hasPasteEventListeners = (function() {
let els = Services.els;
const composed = false; // Paste event listener is not composed.
for (let item of els.getEventTargetChainFor(context.target, composed)) {
if (els.hasListenersFor(item, "paste")) {
return true;
}
}
return false;
})();
this._setContextForNodesNoChildren(editFlags);
this._setContextForNodesWithChildren(editFlags);

Просмотреть файл

@ -228,6 +228,7 @@ class nsContextMenu {
this.onSpellcheckable = context.onSpellcheckable;
this.onTextInput = context.onTextInput;
this.onVideo = context.onVideo;
this.hasPasteEventListeners = context.hasPasteEventListeners;
this.target = context.target;
this.targetIdentifier = context.targetIdentifier;
@ -445,6 +446,7 @@ class nsContextMenu {
this.onTextInput ||
this.onLink ||
this.isContentSelected ||
this.hasPasteEventListeners ||
this.onImage ||
this.onCanvas ||
this.onVideo ||
@ -756,9 +758,15 @@ class nsContextMenu {
this.showItem("context-sep-undo", this.onTextInput);
this.showItem("context-cut", this.onTextInput);
this.showItem("context-copy", this.isContentSelected || this.onTextInput);
this.showItem("context-paste", this.onTextInput);
this.showItem(
"context-paste",
this.hasPasteEventListeners || this.onTextInput
);
this.showItem("context-delete", this.onTextInput);
this.showItem("context-sep-paste", this.onTextInput);
this.showItem(
"context-sep-paste",
this.hasPasteEventListeners || this.onTextInput
);
this.showItem(
"context-selectall",
!(

Просмотреть файл

@ -271,6 +271,51 @@ add_task(async function test_mailto() {
]);
});
add_task(async function test_paste_event_listener() {
const expected = [
"context-navigation",
null,
[
"context-back",
false,
"context-forward",
false,
"context-reload",
true,
"context-bookmarkpage",
true,
],
null,
"---",
null,
...(hasPocket ? ["context-pocket", true] : []),
"---",
null,
"context-sendpagetodevice",
true,
[],
null,
"---",
null,
"context-viewbgimage",
false,
"context-paste",
null,
"---",
null,
"context-selectall",
true,
"---",
null,
"context-viewsource",
true,
"context-viewinfo",
true,
];
await test_contextmenu("#test-paste-listener", expected);
await test_contextmenu("#test-paste-listener-child", expected);
});
add_task(async function test_image() {
for (let selector of ["#test-image", "#test-svg-image"]) {
await test_contextmenu(

Просмотреть файл

@ -17,6 +17,10 @@ if ("ShadowRoot" in this) {
}
</script>
<a id="test-mailto" href="mailto:codemonkey@mozilla.com">Mail the monkey!</a><br>
<div id="test-paste-listener" onpaste="doSomething()">
ABCD
<p id="test-paste-listener-child">EFGH</p>
</div>
<input id="test-input"><br>
<img id="test-image" src="ctxmenu-image.png">
<svg>