From b51abf4b071544860fa3298839c38a1617b6eca3 Mon Sep 17 00:00:00 2001 From: Mike Kaplinskiy Date: Fri, 5 Dec 2008 17:27:02 +0100 Subject: [PATCH] Bug 440614 - text entry field unable to take focus; r=(bzbarsky + jst + peterv) sr=peterv --- content/html/document/src/nsHTMLDocument.cpp | 12 +- content/html/document/src/nsHTMLDocument.h | 2 + content/html/document/src/nsIHTMLDocument.h | 7 ++ content/html/document/test/Makefile.in | 1 + .../html/document/test/test_bug440614.html | 103 ++++++++++++++++++ layout/generic/nsFrameFrame.cpp | 18 +-- 6 files changed, 130 insertions(+), 13 deletions(-) create mode 100644 content/html/document/test/test_bug440614.html diff --git a/content/html/document/src/nsHTMLDocument.cpp b/content/html/document/src/nsHTMLDocument.cpp index a12283586ac..626cd142578 100644 --- a/content/html/document/src/nsHTMLDocument.cpp +++ b/content/html/document/src/nsHTMLDocument.cpp @@ -3260,12 +3260,13 @@ 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")); } } @@ -3297,6 +3298,15 @@ nsHTMLDocument::TurnEditingOff() 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(); diff --git a/content/html/document/src/nsHTMLDocument.h b/content/html/document/src/nsHTMLDocument.h index 2db280b9441..01581d8d2e8 100644 --- a/content/html/document/src/nsHTMLDocument.h +++ b/content/html/document/src/nsHTMLDocument.h @@ -231,6 +231,8 @@ public: mFragmentParser = aParser; } + virtual nsresult ReinitEditor(); + virtual nsresult SetEditingState(EditingState aState); virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const; diff --git a/content/html/document/src/nsIHTMLDocument.h b/content/html/document/src/nsIHTMLDocument.h index 0f8b1843435..41f669711fd 100644 --- a/content/html/document/src/nsIHTMLDocument.h +++ b/content/html/document/src/nsIHTMLDocument.h @@ -171,6 +171,13 @@ public: * SetDesignMode(). */ virtual nsresult SetEditingState(EditingState aState) = 0; + + /** + * Re-inits the editor. Editing must be on from contentEditable or designMode + * when calling this. + * 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 diff --git a/content/html/document/test/Makefile.in b/content/html/document/test/Makefile.in index 6ba8cb473ec..abeba718402 100644 --- a/content/html/document/test/Makefile.in +++ b/content/html/document/test/Makefile.in @@ -71,6 +71,7 @@ _TEST_FILES = test_bug1682.html \ test_bug403868.html \ test_bug403868.xhtml \ test_bug404320.html \ + test_bug440614.html \ test_form-parsing.html \ test_viewport.html \ test_documentAll.html \ diff --git a/content/html/document/test/test_bug440614.html b/content/html/document/test/test_bug440614.html new file mode 100644 index 00000000000..c30cccf78ba --- /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 index 1c371252070..8b1a88942e2 100644 --- a/layout/generic/nsFrameFrame.cpp +++ b/layout/generic/nsFrameFrame.cpp @@ -86,7 +86,7 @@ #include "nsIRenderingContext.h" #include "nsIFrameFrame.h" #include "nsAutoPtr.h" -#include "nsIDOMNSHTMLDocument.h" +#include "nsIHTMLDocument.h" #include "nsDisplayList.h" #include "nsUnicharUtils.h" #include "nsIReflowCallback.h" @@ -975,21 +975,15 @@ 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 + // 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;