Bug 230474 - Bug 829606 - No longer scroll to the beginning of the editor when the value is changed in a text field. r=bz
authorMounir Lamouri <mounir.lamouri@gmail.com>
Wed, 27 Feb 2013 14:08:49 +0000
changeset 134365 ebbcf3fc9240804d10da3164cad6e2612e5db3ef
parent 134364 6c59b73c8c4b908e2defbafce28b75636563da75
child 134366 ef0c622197dde770537e329973c67714d8c04dbb
push id336
push userakeybl@mozilla.com
push dateMon, 17 Jun 2013 22:53:19 +0000
treeherdermozilla-release@574a39cdf657 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs230474, 829606
milestone22.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 230474 - Bug 829606 - No longer scroll to the beginning of the editor when the value is changed in a text field. r=bz
content/html/content/src/nsTextEditorState.cpp
content/html/content/test/forms/Makefile.in
content/html/content/test/forms/test_input_textarea_set_value_no_scroll.html
--- a/content/html/content/src/nsTextEditorState.cpp
+++ b/content/html/content/src/nsTextEditorState.cpp
@@ -1894,29 +1894,16 @@ nsTextEditorState::SetValue(const nsAStr
         }
 
         plaintextEditor->SetMaxTextLength(savedMaxLength);
         mEditor->SetFlags(savedFlags);
         if (selPriv)
           selPriv->EndBatchChanges();
       }
     }
-
-    // This second check _shouldn't_ be necessary, but let's be safe.
-    if (!weakFrame.IsAlive()) {
-      return;
-    }
-    nsIScrollableFrame* scrollableFrame = do_QueryFrame(mBoundFrame->GetFirstPrincipalChild());
-    if (scrollableFrame)
-    {
-      // Scroll the upper left corner of the text control's
-      // content area back into view.
-      scrollableFrame->ScrollTo(nsPoint(0, 0), nsIScrollableFrame::INSTANT);
-    }
-
   } else {
     if (!mValue) {
       mValue = new nsCString;
     }
     nsString value(aValue);
     nsContentUtils::PlatformToDOMLineBreaks(value);
     CopyUTF16toUTF8(value, *mValue);
 
--- a/content/html/content/test/forms/Makefile.in
+++ b/content/html/content/test/forms/Makefile.in
@@ -47,12 +47,13 @@ MOCHITEST_FILES = \
 		test_step_attribute.html \
 		test_stepup_stepdown.html \
 		test_valueasnumber_attribute.html \
 		test_experimental_forms_pref.html \
 		test_input_typing_sanitization.html \
 		test_input_sanitization.html \
 		test_valueasdate_attribute.html \
 		test_input_file_b2g_disabled.html \
+		test_input_textarea_set_value_no_scroll.html \
 		$(NULL)
 
 include $(topsrcdir)/config/rules.mk
 
new file mode 100644
--- /dev/null
+++ b/content/html/content/test/forms/test_input_textarea_set_value_no_scroll.html
@@ -0,0 +1,122 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=829606
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Test for Bug 829606</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
+  <script type="application/javascript" src="/tests/SimpleTest/WindowSnapshot.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+  <script type="application/javascript;version=1.7">
+
+  /** Test for Bug 829606 **/
+  /*
+   * This test checks that setting .value on an text field (input or textarea)
+   * doesn't scroll the field to its beginning.
+   */
+
+  SimpleTest.waitForExplicitFinish();
+
+  var gTestRunner = null;
+
+  function test(aElementName)
+  {
+    var element = document.getElementsByTagName(aElementName)[0];
+    element.focus();
+
+    var baseSnapshot = snapshotWindow(window);
+
+    // This is a sanity check.
+    var s2 = snapshotWindow(window);
+    var results = compareSnapshots(baseSnapshot, snapshotWindow(window), true);
+    ok(results[0], "sanity check: screenshots should be the same");
+
+    element.selectionStart = element.selectionEnd = element.value.length;
+
+    setTimeout(function() {
+      synthesizeKey('f', {});
+
+      var selectionAtTheEndSnapshot = snapshotWindow(window);
+      results = compareSnapshots(baseSnapshot, selectionAtTheEndSnapshot, false);
+      ok(results[0], "after appending a character, string should have changed");
+
+      element.value = element.value;
+      var tmpSnapshot = snapshotWindow(window);
+
+      results = compareSnapshots(baseSnapshot, tmpSnapshot, false);
+      ok(results[0], "re-settig the value should change nothing");
+
+      results = compareSnapshots(selectionAtTheEndSnapshot, tmpSnapshot, true);
+      ok(results[0], "re-settig the value should change nothing");
+
+      element.selectionStart = element.selectionEnd = 0;
+      element.blur();
+
+      gTestRunner.next();
+    }, 0);
+  }
+
+  // This test checks that when a textarea has a long list of values and the
+  // textarea's value is then changed, the values are shown correctly.
+  function testCorrectUpdateOnScroll()
+  {
+    var textarea = document.createElement('textarea');
+    textarea.rows = 5;
+    textarea.cols = 10;
+    textarea.value = 'a\nb\nc\nd';
+    document.getElementById('content').appendChild(textarea);
+
+    var baseSnapshot = snapshotWindow(window);
+
+    textarea.value = '1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n';
+    textarea.selectionStart = textarea.selectionEnd = textarea.value.length;
+
+    var fullSnapshot = snapshotWindow(window);
+    var results = compareSnapshots(baseSnapshot, fullSnapshot, false);
+    ok(results[0], "sanity check: screenshots should not be the same");
+
+    textarea.value = 'a\nb\nc\nd';
+
+    var tmpSnapshot = snapshotWindow(window);
+    results = compareSnapshots(baseSnapshot, tmpSnapshot, true);
+    ok(results[0], "textarea view should look like the beginning");
+
+    setTimeout(function() {
+      gTestRunner.next();
+    }, 0);
+  }
+
+  function runTest()
+  {
+    test('input');
+    yield;
+    test('textarea');
+    yield;
+    testCorrectUpdateOnScroll();
+    yield;
+    SimpleTest.finish();
+    yield;
+  }
+
+  gTestRunner = runTest();
+
+  SimpleTest.waitForFocus(function() {
+    gTestRunner.next();
+  });;
+
+  </script>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=829606">Mozilla Bug 829606</a>
+<p id="display"></p>
+<div id="content">
+  <textarea rows='1' cols='5'>this is a \n long text</textarea>
+  <input size='5' value="this is a very long text">
+</div>
+<pre id="test">
+</pre>
+</body>
+</html>