Bug 672709 - Update the intrinsic state for elements in designMode documents correctly; r=bzbarsky a=johnath
authorEhsan Akhgari <ehsan@mozilla.com>
Wed, 20 Jul 2011 15:58:25 -0400
changeset 72700 8d1b66d7fb5b
parent 72699 1b4168e307fb
child 72701 e3b5c473098e
push id246
push usereakhgari@mozilla.com
push dateThu, 21 Jul 2011 22:09:07 +0000
treeherdermozilla-aurora@8d1b66d7fb5b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbzbarsky, johnath
bugs672709
milestone7.0a2
Bug 672709 - Update the intrinsic state for elements in designMode documents correctly; r=bzbarsky a=johnath This patch fixes two things: * The intrinsic state on elements inserted in a contenteditable section when the document is in designMode (the nsGenericElement::UpdateEditableState change). * The intrinsic state on elements existing in the document when the document first enters designMode (the nsHTMLDocument::EditingStateChanged change). The reftest included tests both cases.
content/base/src/nsGenericElement.cpp
content/html/document/src/nsHTMLDocument.cpp
layout/reftests/editor/672709-ref.html
layout/reftests/editor/672709.html
layout/reftests/editor/reftest.list
--- a/content/base/src/nsGenericElement.cpp
+++ b/content/base/src/nsGenericElement.cpp
@@ -1220,34 +1220,30 @@ nsIContent::UpdateEditableState(PRBool a
   SetEditableFlag(parent && parent->HasFlag(NODE_IS_EDITABLE));
 }
 
 void
 nsGenericElement::UpdateEditableState(PRBool aNotify)
 {
   nsIContent *parent = GetParent();
 
-  PRBool oldEditable = IsEditable();
   SetEditableFlag(parent && parent->HasFlag(NODE_IS_EDITABLE));
-  PRBool newEditable = IsEditable();
-  if (oldEditable != newEditable) {
-    if (aNotify) {
-      UpdateState(aNotify);
+  if (aNotify) {
+    UpdateState(aNotify);
+  } else {
+    // Avoid calling UpdateState in this very common case, because
+    // this gets called for pretty much every single element on
+    // insertion into the document and UpdateState can be slow for
+    // some kinds of elements even when not notifying.
+    if (IsEditable()) {
+      RemoveStatesSilently(NS_EVENT_STATE_MOZ_READONLY);
+      AddStatesSilently(NS_EVENT_STATE_MOZ_READWRITE);
     } else {
-      // Avoid calling UpdateState in this very common case, because
-      // this gets called for pretty much every single element on
-      // insertion into the document and UpdateState can be slow for
-      // some kinds of elements even when not notifying.
-      if (oldEditable) {
-        RemoveStatesSilently(NS_EVENT_STATE_MOZ_READWRITE);
-        AddStatesSilently(NS_EVENT_STATE_MOZ_READONLY);
-      } else {
-        RemoveStatesSilently(NS_EVENT_STATE_MOZ_READONLY);
-        AddStatesSilently(NS_EVENT_STATE_MOZ_READWRITE);
-      }
+      RemoveStatesSilently(NS_EVENT_STATE_MOZ_READWRITE);
+      AddStatesSilently(NS_EVENT_STATE_MOZ_READONLY);
     }
   }
 }
 
 nsIContent*
 nsIContent::FindFirstNonNativeAnonymous() const
 {
   // This handles also nested native anonymous content.
--- a/content/html/document/src/nsHTMLDocument.cpp
+++ b/content/html/document/src/nsHTMLDocument.cpp
@@ -2953,17 +2953,17 @@ nsHTMLDocument::EditingStateChanged()
       mEditingState = eOff;
 
       return rv;
     }
   }
 
   if (updateState) {
     nsAutoScriptBlocker scriptBlocker;
-    NotifyEditableStateChange(this, this, !designMode);
+    NotifyEditableStateChange(this, this, designMode);
   }
 
   // Resync the editor's spellcheck state.
   if (spellRecheckAll) {
     nsCOMPtr<nsISelectionController> selcon;
     nsresult rv = editor->GetSelectionController(getter_AddRefs(selcon));
     NS_ENSURE_SUCCESS(rv, rv); 
 
new file mode 100644
--- /dev/null
+++ b/layout/reftests/editor/672709-ref.html
@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<html class="reftest-wait">
+  <body>
+    <style>
+      :-moz-read-only { color: red; }
+      :-moz-read-write { color: green; }
+    </style>
+    <script>
+      onload = function() {
+        document.designMode = "on";
+        var p = document.createElement("p");
+        p.textContent = "test";
+        document.getElementById("x").appendChild(p);
+        getSelection().removeAllRanges(); // don't need a caret
+        document.documentElement.removeAttribute("class");
+      };
+    </script>
+    <div contenteditable id="x">
+    </div>
+    more test
+  </body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/editor/672709.html
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html>
+  <body>
+    <style>
+      body { color: green; }
+    </style>
+    <div>
+      <p>test</p>
+    </div>
+    more test
+  </body>
+</html>
--- a/layout/reftests/editor/reftest.list
+++ b/layout/reftests/editor/reftest.list
@@ -57,8 +57,9 @@ fails-if(Android) != spellcheck-hyphen-i
 fails-if(Android) != spellcheck-hyphen-multiple-invalid.html spellcheck-hyphen-multiple-invalid-ref.html
 == spellcheck-dotafterquote-valid.html spellcheck-dotafterquote-valid-ref.html
 == unneeded_scroll.html unneeded_scroll-ref.html
 == caret_on_presshell_reinit.html caret_on_presshell_reinit-ref.html
 == caret_on_presshell_reinit-2.html caret_on_presshell_reinit-ref.html
 == 642800.html 642800-ref.html
 == selection_visibility_after_reframe.html selection_visibility_after_reframe-ref.html
 != selection_visibility_after_reframe-2.html selection_visibility_after_reframe-ref.html
+== 672709.html 672709-ref.html