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) {