Fix for bug 402284 (Switching between designMode and contentEditable broken). r=cpearce, sr=roc, a=beltzner.
authorpeterv@propagandism.org
Mon, 05 Nov 2007 13:19:52 -0800
changeset 7350 850822d92b6666918dc1659256ea20ed99e73d73
parent 7349 70b42a1fbfa1aa7a52002c6b7fc6efa05014b240
child 7351 0dd3bf0a19225942fb0082ce386bb2f7262086b7
push idunknown
push userunknown
push dateunknown
reviewerscpearce, roc, beltzner
bugs402284
milestone1.9a9pre
Fix for bug 402284 (Switching between designMode and contentEditable broken). r=cpearce, sr=roc, a=beltzner.
content/html/document/src/nsHTMLDocument.cpp
--- a/content/html/document/src/nsHTMLDocument.cpp
+++ b/content/html/document/src/nsHTMLDocument.cpp
@@ -3982,35 +3982,37 @@ nsHTMLDocument::EditingStateChanged()
   nsIDocShell *docshell = window->GetDocShell();
   if (!docshell)
     return NS_ERROR_FAILURE;
 
   nsresult rv;
   nsCOMPtr<nsIEditingSession> editSession = do_GetInterface(docshell, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  PRBool makeWindowEditable = (mEditingState == eOff) && HasPresShell(window);
-  if (!makeWindowEditable) {
+  if (!HasPresShell(window)) {
     // We should not make the window editable or setup its editor.
     // It's probably style=display:none.
     return NS_OK;
   }
 
-  // Editing is being turned on (through designMode or contentEditable)
-  // Turn on editor.
-  // XXX This can cause flushing which can change the editing state, so make
-  //     sure to avoid recursing.
-  EditingState oldState = mEditingState;
-  mEditingState = eSettingUp;
-
-  rv = editSession->MakeWindowEditable(window, "html", PR_FALSE, PR_FALSE,
-                                       PR_TRUE);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  mEditingState = oldState;
+  PRBool makeWindowEditable = mEditingState == eOff;
+  if (makeWindowEditable) {
+    // Editing is being turned on (through designMode or contentEditable)
+    // Turn on editor.
+    // XXX This can cause flushing which can change the editing state, so make
+    //     sure to avoid recursing.
+    EditingState oldState = mEditingState;
+    mEditingState = eSettingUp;
+
+    rv = editSession->MakeWindowEditable(window, "html", PR_FALSE, PR_FALSE,
+                                         PR_TRUE);
+    NS_ENSURE_SUCCESS(rv, rv);
+
+    mEditingState = oldState;
+  }
 
   // XXX Need to call TearDownEditorOnWindow for all failures.
   nsCOMPtr<nsIEditorDocShell> editorDocShell =
     do_QueryInterface(docshell, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIEditor> editor;
   editorDocShell->GetEditor(getter_AddRefs(editor));
@@ -4067,30 +4069,32 @@ nsHTMLDocument::EditingStateChanged()
   }
   else {
     // contentEditable is being turned on (and designMode is off).
     updateState = PR_FALSE;
   }
 
   mEditingState = newState;
 
-  // Set the editor to not insert br's on return when in p
-  // elements by default.
-  // XXX Do we only want to do this for designMode?
-  PRBool unused;
-  rv = ExecCommand(NS_LITERAL_STRING("insertBrOnReturn"), PR_FALSE,
-                   NS_LITERAL_STRING("false"), &unused);
-
-  if (NS_FAILED(rv)) {
-    // Editor setup failed. Editing is not on after all.
-    // XXX Should we reset the editable flag on nodes?
-    editSession->TearDownEditorOnWindow(window, PR_TRUE);
-    mEditingState = eOff;
-
-    return rv;
+  if (makeWindowEditable) {
+    // Set the editor to not insert br's on return when in p
+    // elements by default.
+    // XXX Do we only want to do this for designMode?
+    PRBool unused;
+    rv = ExecCommand(NS_LITERAL_STRING("insertBrOnReturn"), PR_FALSE,
+                     NS_LITERAL_STRING("false"), &unused);
+
+    if (NS_FAILED(rv)) {
+      // Editor setup failed. Editing is not on after all.
+      // XXX Should we reset the editable flag on nodes?
+      editSession->TearDownEditorOnWindow(window, PR_TRUE);
+      mEditingState = eOff;
+
+      return rv;
+    }
   }
 
   if (updateState) {
     mozAutoDocUpdate upd(this, UPDATE_CONTENT_STATE, PR_TRUE);
     NotifyEditableStateChange(this, this, !designMode);
   }
 
   // Resync the editor's spellcheck state.