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 @@ -3309,16 +3309,52 @@ static PRBool HasPresShell(nsPIDOMWindow docShell->GetPresShell(getter_AddRefs(presShell)); return presShell != nsnull; } nsresult nsHTMLDocument::SetEditingState(EditingState aState) { mEditingState = aState; + return NS_OK; +} + +nsresult +nsHTMLDocument::ReinitEditor() +{ + if (mRemovedFromDocShell) { + return NS_OK; + } + + if (mEditingState == eSettingUp || mEditingState == eTearingDown) { + return NS_OK; + } + + nsresult rv; + + nsPIDOMWindow *window = GetWindow(); + if (!window) + return NS_ERROR_FAILURE; + + nsIDocShell *docshell = window->GetDocShell(); + if (!docshell) + return NS_ERROR_FAILURE; + + nsCOMPtr editorDocShell = + do_QueryInterface(docshell, &rv); + NS_ENSURE_SUCCESS(rv, rv); + + PRBool isEditable = PR_FALSE; + editorDocShell->GetEditable(&isEditable); + + if ((HasFlag(NODE_IS_EDITABLE) || mContentEditableCount > 0) || isEditable) { + if (IsEditingOn()) + TurnEditingOff(); + return EditingStateChanged(); + } return NS_OK; } nsresult nsHTMLDocument::EditingStateChanged() { if (mRemovedFromDocShell) { return NS_OK; 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 @@ -225,16 +225,18 @@ public: NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_NO_UNLINK(nsHTMLDocument, nsDocument) 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; virtual NS_HIDDEN_(void) RemovedFromDocShell(); protected: 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 @@ -159,16 +159,23 @@ public: GetEditingState() == eContentEditable; } /** * Returns the editing state of the document (not editable, contentEditable or * designMode). */ virtual EditingState GetEditingState() = 0; + + /** + * Reinits the editor after something (partially) destroyed it + * Called by nsFrameFrame when frame comes alive, required because of the + * way the editor works. + */ + virtual nsresult ReinitEditor() = 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; 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 @@ -66,16 +66,17 @@ _TEST_FILES = test_bug1682.html \ 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_bug468353.html \ test_form-parsing.html \ test_viewport.html \ test_documentAll.html \ test_bug445004.html \ bug445004-inner.js \ bug445004-outer-rel.html \ bug445004-outer-abs.html \ 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,167 @@ + + + + + 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 @@ -938,27 +938,21 @@ nsSubDocumentFrame::ShowDocShell() } // 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 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")); - } + doc->ReinitEditor(); } } return NS_OK; } nsresult nsSubDocumentFrame::CreateViewAndWidget(nsContentType aContentType)