Bug 692153 Make Copy and Select All always work even when contenteditable areas are present r=ehsan
authorNeil Rashbrook <neil@parkwaycc.co.uk>
Fri, 30 Dec 2011 17:42:04 +0000
changeset 84796 4dd80e8ee29e8539d0d81aea2b4229919bd7ea5d
parent 84795 9fdaea5d67e2f1f97045700e7fe92b4eb277f12b
child 84797 f268da52217d333b76c02e8219cb6d983a900207
push id805
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 18:17:35 +0000
treeherdermozilla-aurora@6fb3bf232436 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs692153
milestone12.0a1
Bug 692153 Make Copy and Select All always work even when contenteditable areas are present r=ehsan
editor/libeditor/base/nsEditorCommands.cpp
editor/libeditor/html/tests/test_bug676401.html
--- a/editor/libeditor/base/nsEditorCommands.cpp
+++ b/editor/libeditor/base/nsEditorCommands.cpp
@@ -315,23 +315,17 @@ nsCutOrDeleteCommand::GetCommandStatePar
 NS_IMETHODIMP
 nsCopyCommand::IsCommandEnabled(const char * aCommandName,
                                 nsISupports *aCommandRefCon,
                                 bool *outCmdEnabled)
 {
   NS_ENSURE_ARG_POINTER(outCmdEnabled);
   nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
   if (editor)
-  {
-    bool isEditable = false;
-    nsresult rv = editor->GetIsSelectionEditable(&isEditable);
-    NS_ENSURE_SUCCESS(rv, rv);
-    if (isEditable)
-      return editor->CanCopy(outCmdEnabled);
-  }
+    return editor->CanCopy(outCmdEnabled);
 
   *outCmdEnabled = false;
   return NS_OK;
 }
 
 
 NS_IMETHODIMP
 nsCopyCommand::DoCommand(const char *aCommandName, nsISupports *aCommandRefCon)
@@ -658,29 +652,24 @@ NS_IMETHODIMP
 nsSelectAllCommand::IsCommandEnabled(const char * aCommandName,
                                      nsISupports *aCommandRefCon,
                                      bool *outCmdEnabled)
 {
   NS_ENSURE_ARG_POINTER(outCmdEnabled);
 
   nsresult rv = NS_OK;
   *outCmdEnabled = false;
-  bool docIsEmpty, selectionIsEditable;
+  bool docIsEmpty;
  
   // you can select all if there is an editor which is non-empty
   nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
   if (editor) {
-    rv = editor->GetIsSelectionEditable(&selectionIsEditable);
+    rv = editor->GetDocumentIsEmpty(&docIsEmpty);
     NS_ENSURE_SUCCESS(rv, rv);
-
-    if (selectionIsEditable) {
-      rv = editor->GetDocumentIsEmpty(&docIsEmpty);
-      NS_ENSURE_SUCCESS(rv, rv);
-      *outCmdEnabled = !docIsEmpty;
-    }
+    *outCmdEnabled = !docIsEmpty;
   } 
 
   return rv;
 }
 
 
 NS_IMETHODIMP
 nsSelectAllCommand::DoCommand(const char *aCommandName,
--- a/editor/libeditor/html/tests/test_bug676401.html
+++ b/editor/libeditor/html/tests/test_bug676401.html
@@ -27,23 +27,23 @@ https://bugzilla.mozilla.org/show_bug.cg
 <script type="application/javascript">
 
 /** Test for Bug 676401 **/
 SimpleTest.waitForExplicitFinish();
 SimpleTest.waitForFocus(runTests);
 
 var gBlock1, gBlock2;
 
-function IsCommandEnabled(command) {
+function IsCommandEnabled(command, alwaysEnabled) {
   var enabled;
 
-  // non-editable div: should return false
+  // non-editable div: should return false unless alwaysEnabled
   window.getSelection().selectAllChildren(gBlock1);
   enabled = document.queryCommandEnabled(command);
-  is(enabled, false, "'" + command + "' should not be enabled on a non-editable block.");
+  is(enabled, alwaysEnabled, "'" + command + "' should not be enabled on a non-editable block.");
 
   // editable div: should return true
   window.getSelection().selectAllChildren(gBlock2);
   enabled = document.queryCommandEnabled(command);
   is(enabled, true, "'" + command + "' should be enabled on an editable block.");
 }
 
 function runTests() {
@@ -62,47 +62,47 @@ function runTests() {
     "heading", "formatBlock",
     "contentReadOnly", "createLink",
     "decreaseFontSize", "increaseFontSize",
     "insertHTML", "insertHorizontalRule", "insertImage",
     "removeFormat", "selectAll", "styleWithCSS"
   ];
   document.execCommand("styleWithCSS", false, false);
   for (i = 0; i < commands.length; i++)
-    IsCommandEnabled(commands[i]);
+    IsCommandEnabled(commands[i], commands[i] == "selectAll");
   document.execCommand("styleWithCSS", false, true);
   for (i = 0; i < commands.length; i++)
-    IsCommandEnabled(commands[i]);
+    IsCommandEnabled(commands[i], commands[i] == "selectAll");
 
   // Mozilla-specific stuff
   commands = ["enableInlineTableEditing", "enableObjectResizing", "insertBrOnReturn"];
   for (i = 0; i < commands.length; i++)
-    IsCommandEnabled(commands[i]);
+    IsCommandEnabled(commands[i], false);
 
   // cut/copy/paste -- SpecialPowers required
   SpecialPowers.setCharPref("capability.policy.policynames",                      "allowclipboard");
   SpecialPowers.setCharPref("capability.policy.allowclipboard.sites",             "http://mochi.test:8888");
   SpecialPowers.setCharPref("capability.policy.allowclipboard.Clipboard.cutcopy", "allAccess");
   SpecialPowers.setCharPref("capability.policy.allowclipboard.Clipboard.paste",   "allAccess");
   commands = ["cut", "paste", "copy"];
   for (i = 0; i < commands.length; i++) {
-    IsCommandEnabled(commands[i]);
+    IsCommandEnabled(commands[i], commands[i] == "copy");
     document.execCommand(commands[i], false, false);
   }
   SpecialPowers.clearUserPref("capability.policy.policynames");
   SpecialPowers.clearUserPref("capability.policy.allowclipboard.sites");
   SpecialPowers.clearUserPref("capability.policy.allowclipboard.Clipboard.cutcopy");
   SpecialPowers.clearUserPref("capability.policy.allowclipboard.Clipboard.paste");
 
   // delete/undo/redo -- we have to execute this commands because:
   //  * there's nothing to undo if we haven't modified the selection first
   //  * there's nothing to redo if we haven't undone something first
   commands = ["delete", "undo", "redo"];
   for (i = 0; i < commands.length; i++) {
-    IsCommandEnabled(commands[i]);
+    IsCommandEnabled(commands[i], false);
     document.execCommand(commands[i], false, false);
   }
 
   // done
   SimpleTest.finish();
 }
 
 </script>