Bug 1550561 - Support edit context menu on HTML inputs in chrome documents. r=bgrins
☠☠ backed out by e4eab914f821 ☠ ☠
authorTim Nguyen <ntim.bugs@gmail.com>
Thu, 09 May 2019 19:33:06 +0000
changeset 532111 3315610792f4b94ab15a102fa8119efec42f9a2e
parent 532110 91754861e8d845ea6d84ae52b4ebad339fd89d96
child 532112 d1615ffd338f011c56be6810eda9bd53782c272a
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbgrins
bugs1550561
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1550561 - Support edit context menu on HTML inputs in chrome documents. r=bgrins Differential Revision: https://phabricator.services.mozilla.com/D30552
toolkit/content/editMenuOverlay.js
toolkit/content/tests/chrome/file_edit_contextmenu.xul
toolkit/content/tests/chrome/test_edit_contextmenu.html
--- a/toolkit/content/editMenuOverlay.js
+++ b/toolkit/content/editMenuOverlay.js
@@ -59,17 +59,17 @@ window.addEventListener("DOMContentLoade
 }, { once: true });
 
 // Support context menus on html textareas in the parent process:
 window.addEventListener("contextmenu", (e) => {
   // Note that there's not a risk of e.target being XBL anonymous content for <textbox> (which manages
   // its own context menu), because e.target will be the XBL binding parent in that case.
   let needsContextMenu = e.target.ownerDocument == document &&
                          !e.defaultPrevented &&
-                         e.target.localName == "textarea" &&
+                         ["textarea", "input"].includes(e.target.localName) &&
                          e.target.namespaceURI == "http://www.w3.org/1999/xhtml";
 
   if (!needsContextMenu) {
     return;
   }
 
   let popup = document.getElementById("textbox-contextmenu");
   if (!popup) {
--- a/toolkit/content/tests/chrome/file_edit_contextmenu.xul
+++ b/toolkit/content/tests/chrome/file_edit_contextmenu.xul
@@ -19,10 +19,10 @@
   <command id="cmd_copy" oncommand="goDoCommand('cmd_copy')"/>
   <command id="cmd_paste" oncommand="goDoCommand('cmd_paste')"/>
   <command id="cmd_delete" oncommand="goDoCommand('cmd_delete')"/>
   <command id="cmd_selectAll" oncommand="goDoCommand('cmd_selectAll')"/>
   <command id="cmd_switchTextDirection" oncommand="goDoCommand('cmd_switchTextDirection');"/>
 </commandset>
 
 <html:textarea />
-
+<html:input />
 </window>
--- a/toolkit/content/tests/chrome/test_edit_contextmenu.html
+++ b/toolkit/content/tests/chrome/test_edit_contextmenu.html
@@ -9,56 +9,63 @@ https://bugzilla.mozilla.org/show_bug.cg
   <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
   <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
   <link rel="stylesheet" type="text/css" href="chrome://global/skin"/>
   <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
   <script type="application/javascript">
     const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
     SimpleTest.waitForExplicitFinish();
 
-    async function runTest() {
+    async function testElement(selector) {
       let win = window.open("file_edit_contextmenu.xul", "context-menu", "chrome,width=600,height=600");
       await new Promise(r => win.addEventListener("load", r, { once: true}));
       await SimpleTest.promiseFocus(win);
 
-      let textarea = win.document.querySelector("textarea");
-      ok(textarea, "textarea exists");
+      info("Testing " + selector);
+      let element = win.document.querySelector(selector);
+      ok(element, "element exists");
 
       info("Synthesizing a key so 'Undo' will be enabled");
-      textarea.focus();
+      element.focus();
       synthesizeKey("x", {}, win);
-      is(textarea.value, "x", "initial value");
+      is(element.value, "x", "initial value");
 
-      textarea.select();
+      element.select();
       synthesizeKey("c", { accelKey: true }, win); // copy to clipboard
       synthesizeKey("KEY_ArrowRight", {}, win); // drop selection to disable cut and copy context menu items
 
       win.document.addEventListener("contextmenu", (e) => {
         info("Calling prevent default on the first contextmenu event");
         e.preventDefault();
       }, { once: true });
-      synthesizeMouseAtCenter(textarea, {type: "contextmenu"}, win);
+      synthesizeMouseAtCenter(element, {type: "contextmenu"}, win);
       ok(!win.document.getElementById("textbox-contextmenu"), "contextmenu with preventDefault() doesn't run");
 
       let popupshown = new Promise(r => win.addEventListener("popupshown", r, { once: true }));
-      synthesizeMouseAtCenter(textarea, {type: "contextmenu"}, win);
+      synthesizeMouseAtCenter(element, {type: "contextmenu"}, win);
       let contextmenu = win.document.getElementById("textbox-contextmenu");
       ok(contextmenu, "context menu exists after right click");
       await popupshown;
 
       ok(!contextmenu.querySelector("[command=cmd_undo]").hasAttribute("disabled"), "undo enabled");
       ok(contextmenu.querySelector("[command=cmd_cut]").hasAttribute("disabled"), "cut disabled");
       ok(contextmenu.querySelector("[command=cmd_copy]").hasAttribute("disabled"), "copy disabled");
       ok(!contextmenu.querySelector("[command=cmd_paste]").hasAttribute("disabled"), "paste enabled");
       ok(contextmenu.querySelector("[command=cmd_delete]").hasAttribute("disabled"), "delete disabled");
       ok(!contextmenu.querySelector("[command=cmd_selectAll]").hasAttribute("disabled"), "select all enabled");
 
       contextmenu.querySelector("[command=cmd_undo]").click();
-      is(textarea.value, "", "undo worked");
+      is(element.value, "", "undo worked");
+      win.close();
+    }
 
+    async function runTest() {
+      for (let selector of ["textarea", "input"]) {
+        await testElement(selector);
+      }
       SimpleTest.finish();
     }
 
   </script>
 </head>
 <body onload="runTest()">
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1513343">Mozilla Bug 1513343</a>
 <p id="display"></p>