diff --git a/content/html/content/src/nsTextEditorState.cpp b/content/html/content/src/nsTextEditorState.cpp
index 6e34c4f51083..6ac7549fdecc 100644
--- a/content/html/content/src/nsTextEditorState.cpp
+++ b/content/html/content/src/nsTextEditorState.cpp
@@ -1234,6 +1234,16 @@ nsTextEditorState::PrepareEditor(const nsAString *aValue)
newEditor = mEditor; // just pretend that we have a new editor!
}
+ // Get the current value of the textfield from the content.
+ // Note that if we've created a new editor, mEditor is null at this stage,
+ // so we will get the real value from the content.
+ nsAutoString defaultValue;
+ if (aValue) {
+ defaultValue = *aValue;
+ } else {
+ GetValue(defaultValue, true);
+ }
+
if (!mEditorInitialized) {
// Now initialize the editor.
//
@@ -1254,7 +1264,8 @@ nsTextEditorState::PrepareEditor(const nsAString *aValue)
// already does the relevant security checks.
AutoNoJSAPI nojsapi;
- rv = newEditor->Init(domdoc, GetRootNode(), mSelCon, editorFlags);
+ rv = newEditor->Init(domdoc, GetRootNode(), mSelCon, editorFlags,
+ defaultValue);
NS_ENSURE_SUCCESS(rv, rv);
}
@@ -1335,16 +1346,6 @@ nsTextEditorState::PrepareEditor(const nsAString *aValue)
newEditor->SetFlags(editorFlags);
}
- // Get the current value of the textfield from the content.
- // Note that if we've created a new editor, mEditor is null at this stage,
- // so we will get the real value from the content.
- nsAutoString defaultValue;
- if (aValue) {
- defaultValue = *aValue;
- } else {
- GetValue(defaultValue, true);
- }
-
if (shouldInitializeEditor) {
// Hold on to the newly created editor
preDestroyer.Swap(mEditor);
@@ -1780,18 +1781,7 @@ nsTextEditorState::SetValue(const nsAString& aValue, bool aUserInput,
#endif
nsAutoString 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->GetFirstChild();
- nsCOMPtr textNode = do_QueryInterface(textContent);
- if (textNode) {
- textNode->GetData(currentValue);
- }
- } else {
- mBoundFrame->GetText(currentValue);
- }
+ mBoundFrame->GetText(currentValue);
nsWeakFrame weakFrame(mBoundFrame);
diff --git a/content/html/content/test/mochitest.ini b/content/html/content/test/mochitest.ini
index c0f589642fde..8f0fc8952166 100644
--- a/content/html/content/test/mochitest.ini
+++ b/content/html/content/test/mochitest.ini
@@ -393,6 +393,7 @@ skip-if = (buildapp == 'b2g' && toolkit != 'gonk') #Bug 931116, b2g desktop spec
[test_bug787134.html]
[test_bug797113.html]
[test_bug803677.html]
+[test_bug821307.html]
[test_bug827126.html]
[test_bug827426.html]
[test_bug838582.html]
diff --git a/content/html/content/test/test_bug821307.html b/content/html/content/test/test_bug821307.html
new file mode 100644
index 000000000000..46721fccaeeb
--- /dev/null
+++ b/content/html/content/test/test_bug821307.html
@@ -0,0 +1,41 @@
+
+
+
+
+ Test for Bug 821307
+
+
+
+
+
+Mozilla Bug 821307
+
+