Bug 672709 - Update the intrinsic state for elements in designMode documents correctly; r=bzbarsky
authorEhsan Akhgari <ehsan@mozilla.com>
Wed, 20 Jul 2011 15:58:25 -0400
changeset 73128 579944e7e8f7
parent 73127 f46c32f62931
child 73129 47c7c675129f
push id20819
push usermak77@bonardo.net
push dateThu, 21 Jul 2011 12:32:52 +0000
treeherdermozilla-central@036c28e4e0f2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbzbarsky
bugs672709
milestone8.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 672709 - Update the intrinsic state for elements in designMode documents correctly; r=bzbarsky 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
@@ -1221,34 +1221,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
@@ -2941,17 +2941,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