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
This commit is contained in:
Ehsan Akhgari 2010-11-22 03:12:56 -05:00
Родитель 4009005faf
Коммит 068ab34f83
4 изменённых файлов: 66 добавлений и 2 удалений

Просмотреть файл

@ -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<nsIDOMCharacterData> textNode = do_QueryInterface(textContent);
if (textNode) {
textNode->GetData(currentValue);
}
} else {
mBoundFrame->GetText(currentValue);
}
nsWeakFrame weakFrame(mBoundFrame);

Просмотреть файл

@ -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 \

Просмотреть файл

@ -0,0 +1,46 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=611189
-->
<head>
<title>Test for Bug 611189</title>
<script type="application/javascript" src="/MochiKit/packed.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/WindowSnapshot.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=611189">Mozilla Bug 611189</a>
<p id="display"></p>
<div id="content">
</div>
<pre id="test">
<script type="application/javascript">
/** Test for Bug 611189 **/
SimpleTest.waitForExplicitFinish();
addLoadEvent(function() {
var i = document.createElement("input");
var b = document.getElementById("content");
b.appendChild(i);
b.clientWidth; // bind to frame
i.focus(); // initialize editor
var before = snapshotWindow(window, true);
i.value = "L"; // set the value
i.style.display = "none";
b.clientWidth; // unbind from frame
i.value = ""; // set the value without a frame
i.style.display = "";
b.clientWidth; // rebind to frame
is(i.value, "", "Input's value should be correctly updated");
var after = snapshotWindow(window, true);
ok(compareSnapshots(before, after, true), "The correct value should be rendered inside the control");
SimpleTest.finish();
});
</script>
</pre>
</body>
</html>

Просмотреть файл

@ -881,6 +881,9 @@ nsTextControlFrame::SelectAllOrCollapseToEndOfText(PRBool aSelect)
nsCOMPtr<nsIContent> rootContent = do_QueryInterface(rootElement);
nsCOMPtr<nsIDOMNode> rootNode(do_QueryInterface(rootElement));
NS_ENSURE_TRUE(rootNode && rootContent, NS_ERROR_FAILURE);
PRInt32 numChildren = rootContent->GetChildCount();
if (numChildren > 0) {