From 068ab34f83001e35579c8bcd0a4d344ebd310347 Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Mon, 22 Nov 2010 03:12:56 -0500 Subject: [PATCH] Bug 611189 - Parchment IF Reader Misbehaves; r=bzbarsky a=blocking-final+ This patch makes sure that we don't try to read the value from the editor if we haven't started to initialize the editor yet. This ensures that the UpdateValueDisplay calls before we start to initialize the editor will always end up reading the value from the content node, and do not rely on the data returned by the editor, which might be stale. --HG-- extra : rebase_source : e31be0ce21585f0f18eca3aa2d8e43d3646348e2 --- .../html/content/src/nsTextEditorState.cpp | 18 +++++++- content/html/content/test/Makefile.in | 1 + content/html/content/test/test_bug611189.html | 46 +++++++++++++++++++ layout/forms/nsTextControlFrame.cpp | 3 ++ 4 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 content/html/content/test/test_bug611189.html diff --git a/content/html/content/src/nsTextEditorState.cpp b/content/html/content/src/nsTextEditorState.cpp index 033da4cd1fd..fa96e2ead6f 100644 --- a/content/html/content/src/nsTextEditorState.cpp +++ b/content/html/content/src/nsTextEditorState.cpp @@ -1636,7 +1636,7 @@ nsTextEditorState::GetMaxLength(PRInt32* aMaxLength) void nsTextEditorState::GetValue(nsAString& aValue, PRBool aIgnoreWrap) const { - if (mEditor && mBoundFrame) { + if (mEditor && mBoundFrame && (mEditorInitialized || !IsSingleLineTextControl())) { PRBool canCache = aIgnoreWrap && !IsSingleLineTextControl(); if (canCache && !mCachedValue.IsEmpty()) { aValue = mCachedValue; @@ -1713,8 +1713,22 @@ nsTextEditorState::SetValue(const nsAString& aValue, PRBool aUserInput) mBoundFrame->SetFireChangeEventState(PR_TRUE); } + NS_ASSERTION(mEditorInitialized || mInitializing, + "We should never try to use the editor if we're not initialized unless we're being initialized"); + nsAutoString currentValue; - mBoundFrame->GetText(currentValue); + if (!mEditorInitialized && IsSingleLineTextControl()) { + // Grab the current value directly from the text node to make sure that we + // deal with stale data correctly. + NS_ASSERTION(mRootNode, "We should have a root node here"); + nsIContent *textContent = mRootNode->GetChildAt(0); + nsCOMPtr textNode = do_QueryInterface(textContent); + if (textNode) { + textNode->GetData(currentValue); + } + } else { + mBoundFrame->GetText(currentValue); + } nsWeakFrame weakFrame(mBoundFrame); diff --git a/content/html/content/test/Makefile.in b/content/html/content/test/Makefile.in index 54d2f54f701..21acfb40e6c 100644 --- a/content/html/content/test/Makefile.in +++ b/content/html/content/test/Makefile.in @@ -242,6 +242,7 @@ _TEST_FILES = \ test_bug601061.html \ test_bug596511.html \ reflect.js \ + test_bug611189.html \ test_bug613113.html \ test_bug605124-1.html \ test_bug605124-2.html \ diff --git a/content/html/content/test/test_bug611189.html b/content/html/content/test/test_bug611189.html new file mode 100644 index 00000000000..deed763155e --- /dev/null +++ b/content/html/content/test/test_bug611189.html @@ -0,0 +1,46 @@ + + + + + Test for Bug 611189 + + + + + + + +Mozilla Bug 611189 +

+
+
+
+
+
+ + diff --git a/layout/forms/nsTextControlFrame.cpp b/layout/forms/nsTextControlFrame.cpp index 2b76971bd82..03e758ec1f9 100644 --- a/layout/forms/nsTextControlFrame.cpp +++ b/layout/forms/nsTextControlFrame.cpp @@ -881,6 +881,9 @@ nsTextControlFrame::SelectAllOrCollapseToEndOfText(PRBool aSelect) nsCOMPtr rootContent = do_QueryInterface(rootElement); nsCOMPtr rootNode(do_QueryInterface(rootElement)); + + NS_ENSURE_TRUE(rootNode && rootContent, NS_ERROR_FAILURE); + PRInt32 numChildren = rootContent->GetChildCount(); if (numChildren > 0) {