Bug 738440 - Support queryCommandState("stylewithcss"); r=ehsan
authorAryeh Gregor <ayg@aryeh.name>
Fri, 23 Mar 2012 15:03:42 -0400
changeset 90912 cfcdf9a80f363c126687af797c0182c7f8c4c74a
parent 90911 aaba08c212963d155ae99e58c78a48c84eebcd61
child 90913 4f3fb04bd5e074996832605eedeafece40087010
push id22401
push usermak77@bonardo.net
push dateWed, 04 Apr 2012 11:37:12 +0000
treeherdermozilla-central@638769f8ec54 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs738440
milestone14.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 738440 - Support queryCommandState("stylewithcss"); r=ehsan
content/html/content/test/test_bug408231.html
content/html/document/src/nsHTMLDocument.cpp
editor/composer/src/nsComposerDocumentCommands.cpp
editor/composer/test/Makefile.in
editor/composer/test/test_bug738440.html
--- a/content/html/content/test/test_bug408231.html
+++ b/content/html/content/test/test_bug408231.html
@@ -85,17 +85,17 @@ https://bugzilla.mozilla.org/show_bug.cg
       ["justifyleft", "true"],
       ["justifyright", "false"],
       ["outdent", "exception"],
       //["paste", "exception"],
       ["redo", "exception"],
       ["removeformat", "exception"],
       ["selectall", "exception"],
       ["strikethrough", "false"],
-      ["styleWithCSS", "exception"],
+      ["styleWithCSS", "false"],
       ["subscript", "false"],
       ["superscript", "false"],
       ["underline", "false"],
       ["undo", "exception"],
       ["unlink", "false"],
       ["not-a-command", "exception"]
     ];
     
@@ -125,17 +125,17 @@ https://bugzilla.mozilla.org/show_bug.cg
       ["justifyleft", "left"],
       ["justifyright", "left"],
       ["outdent", ""],
       //["paste", ""],
       ["redo", ""],
       ["removeformat", ""],
       ["selectall", ""],
       ["strikethrough", ""],
-      ["styleWithCSS", "exception"],
+      ["styleWithCSS", ""],
       ["subscript", ""],
       ["superscript", ""],
       ["underline", ""],
       ["undo", ""],
       ["unlink", ""],
       ["not-a-command", "exception"],
     ];
     
--- a/content/html/document/src/nsHTMLDocument.cpp
+++ b/content/html/document/src/nsHTMLDocument.cpp
@@ -3228,16 +3228,23 @@ nsHTMLDocument::QueryCommandState(const 
   GetMidasCommandManager(getter_AddRefs(cmdMgr));
   if (!cmdMgr)
     return NS_ERROR_FAILURE;
 
   nsIDOMWindow *window = GetWindow();
   if (!window)
     return NS_ERROR_FAILURE;
 
+  if (commandID.LowerCaseEqualsLiteral("usecss")) {
+    // Per spec, state is supported for styleWithCSS but not useCSS, so we just
+    // return false always.
+    *_retval = false;
+    return NS_OK;
+  }
+
   nsCAutoString cmdToDispatch, paramToCheck;
   bool dummy, dummy2;
   if (!ConvertToMidasInternalCommand(commandID, commandID,
                                      cmdToDispatch, paramToCheck, dummy, dummy2))
     return NS_ERROR_NOT_IMPLEMENTED;
 
   nsresult rv;
   nsCOMPtr<nsICommandParams> cmdParams = do_CreateInstance(
--- a/editor/composer/src/nsComposerDocumentCommands.cpp
+++ b/editor/composer/src/nsComposerDocumentCommands.cpp
@@ -58,16 +58,17 @@
 #include "nsCOMPtr.h"
 
 #include "nsComposerCommands.h"
 #include "nsICommandParams.h"
 #include "nsCRT.h"
 
 //defines
 #define STATE_ENABLED  "state_enabled"
+#define STATE_ALL "state_all"
 #define STATE_ATTRIBUTE "state_attribute"
 #define STATE_DATA "state_data"
 
 static
 nsresult
 GetPresContextFromEditor(nsIEditor *aEditor, nsPresContext **aResult)
 {
   NS_ENSURE_ARG_POINTER(aResult);
@@ -373,17 +374,17 @@ nsSetDocumentStateCommand::GetCommandSta
   if (!nsCRT::strcmp(aCommandName, "cmd_setDocumentUseCSS"))
   {
     NS_ENSURE_ARG_POINTER(aParams);
     nsCOMPtr<nsIHTMLEditor> htmleditor = do_QueryInterface(refCon);
     NS_ENSURE_TRUE(htmleditor, NS_ERROR_INVALID_ARG);
 
     bool isCSS;
     htmleditor->GetIsCSSEnabled(&isCSS);
-    return aParams->SetBooleanValue(STATE_ATTRIBUTE, isCSS);
+    return aParams->SetBooleanValue(STATE_ALL, isCSS);
   }
 
   if (!nsCRT::strcmp(aCommandName, "cmd_insertBrOnReturn"))
   {
     NS_ENSURE_ARG_POINTER(aParams);
     nsCOMPtr<nsIHTMLEditor> htmleditor = do_QueryInterface(refCon);
     NS_ENSURE_TRUE(htmleditor, NS_ERROR_INVALID_ARG);
 
--- a/editor/composer/test/Makefile.in
+++ b/editor/composer/test/Makefile.in
@@ -45,16 +45,17 @@ include $(DEPTH)/config/autoconf.mk
 include $(topsrcdir)/config/rules.mk
 
 _TEST_FILES = \
 		test_bug348497.html \
 		test_bug384147.html \
 		test_bug389350.html \
 		test_bug519928.html \
 		bug678842_subframe.html \
+		test_bug738440.html \
 		$(NULL)
 
 _CHROME_TEST_FILES = \
 		test_bug434998.xul \
 		test_bug338427.html \
 		test_bug678842.html \
 		$(NULL)
 
new file mode 100644
--- /dev/null
+++ b/editor/composer/test/test_bug738440.html
@@ -0,0 +1,37 @@
+<!doctype html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=738440
+-->
+<title>Test for Bug 738440</title>
+<script src="/tests/SimpleTest/SimpleTest.js"></script>
+<link rel="stylesheet" href="/tests/SimpleTest/test.css" />
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=738440">Mozilla Bug 738440</a>
+<div contenteditable></div>
+<script>
+
+/** Test for Bug 738440 **/
+document.execCommand("stylewithcss", false, "true");
+is(document.queryCommandState("stylewithcss"), true,
+   "setting stylewithcss to true should cause its state to be true");
+is(document.queryCommandState("usecss"), false,
+   "usecss state should always be false");
+
+document.execCommand("stylewithcss", false, "false");
+is(document.queryCommandState("stylewithcss"), false,
+   "setting stylewithcss to false should cause its state to be false");
+is(document.queryCommandState("usecss"), false,
+   "usecss state should always be false");
+
+document.execCommand("usecss", false, "true");
+is(document.queryCommandState("stylewithcss"), false,
+   "setting usecss to true should cause stylewithcss state to be false");
+is(document.queryCommandState("usecss"), false,
+   "usecss state should always be false");
+
+document.execCommand("usecss", false, "false");
+is(document.queryCommandState("stylewithcss"), true,
+   "setting usecss to false should cause stylewithcss state to be true");
+is(document.queryCommandState("usecss"), false,
+   "usecss state should always be false");
+
+</script>