Bug 1606018 - Make sure edit context menu also appears on inputs inside shadow trees. r=bgrins

Differential Revision: https://phabricator.services.mozilla.com/D61847

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Tim Nguyen 2020-02-06 19:15:17 +00:00
parent df16bc9e25
commit f6a013abd2
3 changed files with 16 additions and 6 deletions

View File

@ -96,12 +96,12 @@ window.addEventListener(
window.addEventListener("contextmenu", e => {
const HTML_NS = "http://www.w3.org/1999/xhtml";
let needsContextMenu =
e.target.ownerDocument == document &&
e.composedTarget.ownerDocument == document &&
!e.defaultPrevented &&
e.target.parentNode.nodeName != "moz-input-box" &&
((["textarea", "input"].includes(e.target.localName) &&
e.target.namespaceURI == HTML_NS) ||
e.target.closest("search-textbox"));
e.composedTarget.parentNode.nodeName != "moz-input-box" &&
((["textarea", "input"].includes(e.composedTarget.localName) &&
e.composedTarget.namespaceURI == HTML_NS) ||
e.composedTarget.closest("search-textbox"));
if (!needsContextMenu) {
return;

View File

@ -2,7 +2,15 @@
<?xml-stylesheet href="chrome://global/skin/global.css"?>
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
xmlns:html="http://www.w3.org/1999/xhtml">
<script>
customElements.define("shadow-input", class extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: "open" });
this.shadowRoot.appendChild(document.createElement("input"));
}
});
</script>
<script type="application/javascript" src="chrome://global/content/globalOverlay.js"/>
<!-- Copied from toolkit/content/editMenuCommands.inc.xul -->
<script type="application/javascript" src="chrome://global/content/editMenuOverlay.js"/>
@ -32,6 +40,7 @@
<html:textarea />
<html:input />
<search-textbox />
<html:shadow-input />
</hbox>
</window>

View File

@ -23,6 +23,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1513343
win.document.querySelector("textarea"),
win.document.querySelector("input"),
win.document.querySelector("search-textbox"),
win.document.querySelector("shadow-input").shadowRoot.querySelector("input"),
];
for (const element of elements) {
await testElement(element, win);