diff --git a/content/html/document/src/nsHTMLDocument.cpp b/content/html/document/src/nsHTMLDocument.cpp
index 1243a90f29f..c6047b6e73d 100644
--- a/content/html/document/src/nsHTMLDocument.cpp
+++ b/content/html/document/src/nsHTMLDocument.cpp
@@ -3987,25 +3987,27 @@ nsHTMLDocument::EditingStateChanged()
nsCOMPtr 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;
+ 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);
+ rv = editSession->MakeWindowEditable(window, "html", PR_FALSE, PR_FALSE,
+ PR_TRUE);
+ NS_ENSURE_SUCCESS(rv, rv);
- mEditingState = oldState;
+ mEditingState = oldState;
+ }
// XXX Need to call TearDownEditorOnWindow for all failures.
nsCOMPtr editorDocShell =
@@ -4072,20 +4074,22 @@ nsHTMLDocument::EditingStateChanged()
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 (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;
+ 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;
+ return rv;
+ }
}
if (updateState) {