Bug 1170531 - Disable clipboard menu commands correctly in non-(X)HTML documents; r=ehsan
☠☠ backed out by 5b3a94511813 ☠ ☠
authorMichael Layzell <michael@thelayzells.com>
Mon, 22 Jun 2015 08:13:26 -0400
changeset 249912 3fca18104696e85d3f90c84802e03479b9c023ee
parent 249911 dbc622672848986638ad7544c6c39b4f15cc9f2c
child 249968 4b47c3f074a36bb16295bf3127268094a64ed7db
push id61392
push usereakhgari@mozilla.com
push dateMon, 22 Jun 2015 12:15:09 +0000
treeherdermozilla-inbound@3fca18104696 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs1170531
milestone41.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 1170531 - Disable clipboard menu commands correctly in non-(X)HTML documents; r=ehsan
dom/base/nsGlobalWindowCommands.cpp
editor/libeditor/nsPlaintextEditor.cpp
toolkit/content/editMenuOverlay.js
toolkit/content/globalOverlay.js
toolkit/content/tests/browser/browser.ini
toolkit/content/tests/browser/browser_bug1170531.js
--- a/dom/base/nsGlobalWindowCommands.cpp
+++ b/dom/base/nsGlobalWindowCommands.cpp
@@ -481,24 +481,33 @@ NS_IMPL_ISUPPORTS(nsClipboardCommand, ns
 
 nsresult
 nsClipboardCommand::IsCommandEnabled(const char* aCommandName, nsISupports *aContext, bool *outCmdEnabled)
 {
   NS_ENSURE_ARG_POINTER(outCmdEnabled);
   *outCmdEnabled = false;
 
   if (strcmp(aCommandName, "cmd_copy") &&
-      strcmp(aCommandName, "cmd_copyAndCollapseToEnd"))
+      strcmp(aCommandName, "cmd_copyAndCollapseToEnd") &&
+      strcmp(aCommandName, "cmd_cut"))
     return NS_OK;
 
   nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aContext);
   NS_ENSURE_TRUE(window, NS_ERROR_FAILURE);
 
   nsCOMPtr<nsIDocument> doc = window->GetExtantDoc();
-  *outCmdEnabled = nsCopySupport::CanCopy(doc);
+  if (doc->IsHTMLOrXHTML()) {
+    // In HTML and XHTML documents, we always want cut and copy commands to be enabled.
+    *outCmdEnabled = true;
+  } else {
+    // Cut isn't enabled in xul documents which use nsClipboardCommand
+    if (strcmp(aCommandName, "cmd_cut")) {
+      *outCmdEnabled = nsCopySupport::CanCopy(doc);
+    }
+  }
   return NS_OK;
 }
 
 nsresult
 nsClipboardCommand::DoCommand(const char *aCommandName, nsISupports *aContext)
 {
   if (strcmp(aCommandName, "cmd_cut") &&
       strcmp(aCommandName, "cmd_copy") &&
--- a/editor/libeditor/nsPlaintextEditor.cpp
+++ b/editor/libeditor/nsPlaintextEditor.cpp
@@ -1150,16 +1150,22 @@ nsPlaintextEditor::Redo(uint32_t aCount)
 
   NotifyEditorObservers(eNotifyEditorObserversOfEnd);
   return result;
 }
 
 bool
 nsPlaintextEditor::CanCutOrCopy(PasswordFieldAllowed aPasswordFieldAllowed)
 {
+  nsCOMPtr<nsIDocument> doc = GetDocument();
+  if (doc && doc->IsHTMLOrXHTML()) {
+    // In HTML and XHTML documents, we always want cut and copy commands to be enabled.
+    return true;
+  }
+
   nsRefPtr<Selection> selection = GetSelection();
   if (!selection) {
     return false;
   }
 
   if (aPasswordFieldAllowed == ePasswordFieldNotAllowed &&
       IsPasswordEditor())
     return false;
--- a/toolkit/content/editMenuOverlay.js
+++ b/toolkit/content/editMenuOverlay.js
@@ -12,17 +12,18 @@ function goUpdateGlobalEditMenuItems()
   // cut, copy, and paste buttons been added to the toolbars) for performance.
   // This only works in applications/on platforms that set the gEditUIVisible
   // flag, so we check to see if that flag is defined before using it.
   if (typeof gEditUIVisible != "undefined" && !gEditUIVisible)
     return;
 
   goUpdateCommand("cmd_undo");
   goUpdateCommand("cmd_redo");
-  // don't update the cmd_cut or cmd_copy items - as we want them to always be enabled
+  goUpdateCommand("cmd_cut");
+  goUpdateCommand("cmd_copy");
   goUpdateCommand("cmd_paste");
   goUpdateCommand("cmd_selectAll");
   goUpdateCommand("cmd_delete");
   goUpdateCommand("cmd_switchTextDirection");
 }
 
 // update menu items that relate to undo/redo
 function goUpdateUndoEditMenuItems()
--- a/toolkit/content/globalOverlay.js
+++ b/toolkit/content/globalOverlay.js
@@ -88,17 +88,17 @@ function goUpdateCommand(aCommand)
   }
 }
 
 function goDoCommand(aCommand)
 {
   try {
     var controller = top.document.commandDispatcher
                         .getControllerForCommand(aCommand);
-    if (controller)
+    if (controller && controller.isCommandEnabled(aCommand))
       controller.doCommand(aCommand);
   }
   catch (e) {
     Components.utils.reportError("An error occurred executing the " +
                                  aCommand + " command: " + e);
   }
 }
 
--- a/toolkit/content/tests/browser/browser.ini
+++ b/toolkit/content/tests/browser/browser.ini
@@ -31,8 +31,9 @@ support-files =
   data/post_form_inner.sjs
   data/post_form_outer.sjs
 skip-if = e10s # Bug ?????? - test directly manipulates content (gBrowser.contentDocument.getElementById("postForm").submit();)
 [browser_content_url_annotation.js]
 skip-if = !e10s || !crashreporter
 support-files =
   file_redirect.html
   file_redirect_to.html
+[browser_bug1170531.js]
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/toolkit/content/tests/browser/browser_bug1170531.js
@@ -0,0 +1,36 @@
+// Test for bug 1170531
+// https://bugzilla.mozilla.org/show_bug.cgi?id=1170531
+
+add_task(function* () {
+  yield BrowserTestUtils.withNewTab({ gBrowser: gBrowser, url: "about:blank" }, function* (browser) {
+    let menu_EditPopup = document.getElementById("menu_EditPopup");
+    let menu_cut_disabled, menu_copy_disabled;
+
+    yield BrowserTestUtils.loadURI(browser, "data:text/html,<div>hello!</div>");
+    browser.focus();
+    yield new Promise(resolve => waitForFocus(resolve, window));
+    goUpdateGlobalEditMenuItems();
+    menu_cut_disabled = menu_EditPopup.querySelector("#menu_cut").getAttribute('disabled') == "true";
+    is(menu_cut_disabled, false, "menu_cut should be enabled");
+    menu_copy_disabled = menu_EditPopup.querySelector("#menu_copy").getAttribute('disabled') == "true";
+    is(menu_copy_disabled, false, "menu_copy should be enabled");
+
+    yield BrowserTestUtils.loadURI(browser, "data:text/html,<div contentEditable='true'>hello!</div>");
+    browser.focus();
+    yield new Promise(resolve => waitForFocus(resolve, window));
+    goUpdateGlobalEditMenuItems();
+    menu_cut_disabled = menu_EditPopup.querySelector("#menu_cut").getAttribute('disabled') == "true";
+    is(menu_cut_disabled, false, "menu_cut should be enabled");
+    menu_copy_disabled = menu_EditPopup.querySelector("#menu_copy").getAttribute('disabled') == "true";
+    is(menu_copy_disabled, false, "menu_copy should be enabled");
+
+    yield BrowserTestUtils.loadURI(browser, "about:preferences");
+    browser.focus();
+    yield new Promise(resolve => waitForFocus(resolve, window));
+    goUpdateGlobalEditMenuItems();
+    menu_cut_disabled = menu_EditPopup.querySelector("#menu_cut").getAttribute('disabled') == "true";
+    is(menu_cut_disabled, true, "menu_cut should be disabled");
+    menu_copy_disabled = menu_EditPopup.querySelector("#menu_copy").getAttribute('disabled') == "true";
+    is(menu_copy_disabled, true, "menu_copy should be disabled");
+  });
+});