diff --git a/content/html/document/src/nsHTMLDocument.cpp b/content/html/document/src/nsHTMLDocument.cpp --- a/content/html/document/src/nsHTMLDocument.cpp +++ b/content/html/document/src/nsHTMLDocument.cpp @@ -3258,22 +3258,23 @@ NotifyEditableStateChange(child, aDocument, aEditable); } } void nsHTMLDocument::TearingDownEditor(nsIEditor *aEditor) { if (IsEditingOn()) { + EditingState oldState = mEditingState; mEditingState = eTearingDown; nsCOMPtr editorss = do_QueryInterface(aEditor); if (editorss) { editorss->RemoveOverrideStyleSheet(NS_LITERAL_STRING("resource://gre/res/contenteditable.css")); - if (mEditingState == eDesignMode) + if (oldState == eDesignMode) editorss->RemoveOverrideStyleSheet(NS_LITERAL_STRING("resource://gre/res/designmode.css")); } } } nsresult nsHTMLDocument::TurnEditingOff() { @@ -3293,16 +3294,25 @@ // turn editing off rv = editSession->TearDownEditorOnWindow(window); NS_ENSURE_SUCCESS(rv, rv); mEditingState = eOff; return NS_OK; +} + +nsresult +nsHTMLDocument::ReinitEditor() +{ + NS_ASSERTION(mEditingState != eOff, "Editor not inited."); + + TurnEditingOff(); + return EditingStateChanged(); } static PRBool HasPresShell(nsPIDOMWindow *aWindow) { nsIDocShell *docShell = aWindow->GetDocShell(); if (!docShell) return PR_FALSE; nsCOMPtr presShell; diff --git a/content/html/document/src/nsHTMLDocument.h b/content/html/document/src/nsHTMLDocument.h --- a/content/html/document/src/nsHTMLDocument.h +++ b/content/html/document/src/nsHTMLDocument.h @@ -226,16 +226,18 @@ virtual already_AddRefed GetFragmentParser() { return mFragmentParser.forget(); } virtual void SetFragmentParser(nsIParser* aParser) { mFragmentParser = aParser; } + virtual nsresult ReinitEditor(); + virtual nsresult SetEditingState(EditingState aState); virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const; protected: nsresult GetBodySize(PRInt32* aWidth, PRInt32* aHeight); diff --git a/content/html/document/src/nsIHTMLDocument.h b/content/html/document/src/nsIHTMLDocument.h --- a/content/html/document/src/nsIHTMLDocument.h +++ b/content/html/document/src/nsIHTMLDocument.h @@ -166,16 +166,22 @@ virtual EditingState GetEditingState() = 0; /** * Set the editing state of the document. Don't use this if you want * to enable/disable editing, call EditingStateChanged() or * SetDesignMode(). */ virtual nsresult SetEditingState(EditingState aState) = 0; + + /** + * Re-inits the editor (if midas is on). + * Required because of the way the editor works. (bug 440614) + */ + virtual nsresult ReinitEditor() = 0; /** * Returns the result of document.all[aID] which can either be a node * or a nodelist depending on if there are multiple nodes with the same * id. */ virtual nsresult GetDocumentAllResult(const nsAString& aID, nsISupports** aResult) = 0; diff --git a/content/html/document/test/Makefile.in b/content/html/document/test/Makefile.in --- a/content/html/document/test/Makefile.in +++ b/content/html/document/test/Makefile.in @@ -65,15 +65,16 @@ bug369370-popup.png \ test_bug380383.html \ test_bug386495.html \ test_bug391777.html \ test_bug402680.html \ test_bug403868.html \ test_bug403868.xhtml \ test_bug404320.html \ + test_bug440614.html \ test_form-parsing.html \ test_viewport.html \ test_documentAll.html \ $(NULL) libs:: $(_TEST_FILES) $(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir) diff --git a/content/html/document/test/test_bug440614.html b/content/html/document/test/test_bug440614.html new file mode 100644 --- /dev/null +++ b/content/html/document/test/test_bug440614.html @@ -0,0 +1,103 @@ + + + + + Test for Bug 440614 + + + + + +Mozilla Bug 440614 +

+
+ +
+
+
+
+ + diff --git a/layout/generic/nsFrameFrame.cpp b/layout/generic/nsFrameFrame.cpp --- a/layout/generic/nsFrameFrame.cpp +++ b/layout/generic/nsFrameFrame.cpp @@ -81,17 +81,17 @@ #include "nsINameSpaceManager.h" #include "nsIWidget.h" #include "nsWeakReference.h" #include "nsIDOMWindow.h" #include "nsIDOMDocument.h" #include "nsIRenderingContext.h" #include "nsIFrameFrame.h" #include "nsAutoPtr.h" -#include "nsIDOMNSHTMLDocument.h" +#include "nsIHTMLDocument.h" #include "nsDisplayList.h" #include "nsUnicharUtils.h" #include "nsIReflowCallback.h" #include "nsIScrollableFrame.h" #include "nsIObjectLoadingContent.h" #include "nsLayoutUtils.h" #ifdef MOZ_XUL @@ -968,31 +968,25 @@ baseWindow->Create(); baseWindow->SetVisibility(PR_TRUE); } // Trigger editor re-initialization if midas is turned on in the // sub-document. This shouldn't be necessary, but given the way our // editor works, it is. See - // https://bugzilla.mozilla.org/show_bug.cgi?id=284245 + // https://bugzilla.mozilla.org/show_bug.cgi?id=284245 && 440614 docShell->GetPresShell(getter_AddRefs(presShell)); if (presShell) { - nsCOMPtr doc = + nsCOMPtr doc = do_QueryInterface(presShell->GetDocument()); - if (doc) { - nsAutoString designMode; - doc->GetDesignMode(designMode); - - if (designMode.EqualsLiteral("on")) { - doc->SetDesignMode(NS_LITERAL_STRING("off")); - doc->SetDesignMode(NS_LITERAL_STRING("on")); - } - } + // Re-init the editor, if necessary + if (doc && doc->IsEditingOn()) + doc->ReinitEditor(); } return NS_OK; } nsresult nsSubDocumentFrame::CreateViewAndWidget(nsContentType aContentType) {