Title: [117307] trunk
Revision
117307
Author
mnaga...@chromium.org
Date
2012-05-16 10:45:32 -0700 (Wed, 16 May 2012)

Log Message

Avoid jumpscroll when entering new text in a multi-line editor.
https://bugs.webkit.org/show_bug.cgi?id=82875

Reviewed by Ryosuke Niwa

Scroll caret to the edge of the viewport in case if a line break or a paragraph
separator is inserted at the end of a multi-line editor.  This avoids
undesirable jumpscroll in cases when there is content under the editor.

Tests: editing/input/scroll-to-edge-if-line-break-at-end-of-document-contenteditable.html
       editing/input/scroll-to-edge-if-line-break-at-end-of-document-textarea.html
       editing/input/scroll-to-edge-if-paragraph-separator-at-end-of-document-contenteditable.html

* editing/Editor.cpp:
(WebCore::Editor::insertLineBreak):
(WebCore::Editor::insertParagraphSeparator):
(WebCore::Editor::revealSelectionAfterEditingOperation):
* editing/Editor.h:
(Editor):

* editing/input/resources/reveal-utilities.js:
(performJumpAtTheEdgeTest):
* editing/input/scroll-to-edge-if-line-break-at-end-of-document-contenteditable-expected.txt: Added.
* editing/input/scroll-to-edge-if-line-break-at-end-of-document-contenteditable.html: Added.
* editing/input/scroll-to-edge-if-line-break-at-end-of-document-textarea-expected.txt: Added.
* editing/input/scroll-to-edge-if-line-break-at-end-of-document-textarea.html: Added.
* editing/input/scroll-to-edge-if-paragraph-separator-at-end-of-document-contenteditable-expected.txt: Added.
* editing/input/scroll-to-edge-if-paragraph-separator-at-end-of-document-contenteditable.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (117306 => 117307)


--- trunk/LayoutTests/ChangeLog	2012-05-16 17:36:23 UTC (rev 117306)
+++ trunk/LayoutTests/ChangeLog	2012-05-16 17:45:32 UTC (rev 117307)
@@ -1,3 +1,23 @@
+2012-05-16  Mikhail Naganov  <mnaga...@chromium.org>
+
+        Avoid jumpscroll when entering new text in a multi-line editor.
+        https://bugs.webkit.org/show_bug.cgi?id=82875
+
+        Reviewed by Ryosuke Niwa.
+
+        Scroll caret to the edge of the viewport in case if a line break or a paragraph
+        separator is inserted at the end of a multi-line editor.  This avoids
+        undesirable jumpscroll in cases when there is content under the editor.
+
+        * editing/input/resources/reveal-utilities.js:
+        (performJumpAtTheEdgeTest):
+        * editing/input/scroll-to-edge-if-line-break-at-end-of-document-contenteditable-expected.txt: Added.
+        * editing/input/scroll-to-edge-if-line-break-at-end-of-document-contenteditable.html: Added.
+        * editing/input/scroll-to-edge-if-line-break-at-end-of-document-textarea-expected.txt: Added.
+        * editing/input/scroll-to-edge-if-line-break-at-end-of-document-textarea.html: Added.
+        * editing/input/scroll-to-edge-if-paragraph-separator-at-end-of-document-contenteditable-expected.txt: Added.
+        * editing/input/scroll-to-edge-if-paragraph-separator-at-end-of-document-contenteditable.html: Added.
+
 2012-05-16  Abhishek Arya  <infe...@chromium.org>
 
         Missing RenderApplet cast check in HTMLAppletElement::renderWidgetForJSBindings.

Modified: trunk/LayoutTests/editing/input/resources/reveal-utilities.js (117306 => 117307)


--- trunk/LayoutTests/editing/input/resources/reveal-utilities.js	2012-05-16 17:36:23 UTC (rev 117306)
+++ trunk/LayoutTests/editing/input/resources/reveal-utilities.js	2012-05-16 17:45:32 UTC (rev 117307)
@@ -64,3 +64,27 @@
         document.execCommand("paste");
     }
 }
+
+function performJumpAtTheEdgeTest(useCtrlKeyModifier)
+{
+    var textArea = document.getElementById("input");
+    textArea.focus();
+    if (window.eventSender) {
+        var previousScrollTop = 0, currentScrollTop = 0;
+        var jumpDetected = false;
+        for (var i = 0; i < 120; ++i) {
+            previousScrollTop = document.body.scrollTop;
+            eventSender.keyDown("\r", useCtrlKeyModifier ? ["ctrlKey"] : []);
+            currentScrollTop = document.body.scrollTop;
+            // Smooth scrolls are allowed.
+            if (Math.abs(previousScrollTop - currentScrollTop) > 24) {
+                jumpDetected = true;
+                break;
+            }
+        }
+        if (!jumpDetected)
+            document.write("PASS");
+        else
+            document.write("FAIL<br>Jump scroll from " + previousScrollTop + " to " + currentScrollTop);
+    }
+}

Added: trunk/LayoutTests/editing/input/scroll-to-edge-if-line-break-at-end-of-document-contenteditable-expected.txt (0 => 117307)


--- trunk/LayoutTests/editing/input/scroll-to-edge-if-line-break-at-end-of-document-contenteditable-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/editing/input/scroll-to-edge-if-line-break-at-end-of-document-contenteditable-expected.txt	2012-05-16 17:45:32 UTC (rev 117307)
@@ -0,0 +1,123 @@
+When the caret is scrolled out and resides at the end of the contenteditable, on pressing "Ctrl+Return" it must be scrolled to the bottom of the view, not to the center to avoid undesirable content view jumping.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+PASS
Property changes on: trunk/LayoutTests/editing/input/scroll-to-edge-if-line-break-at-end-of-document-contenteditable-expected.txt
___________________________________________________________________

Added: svn:eol-style

Added: trunk/LayoutTests/editing/input/scroll-to-edge-if-line-break-at-end-of-document-contenteditable.html (0 => 117307)


--- trunk/LayoutTests/editing/input/scroll-to-edge-if-line-break-at-end-of-document-contenteditable.html	                        (rev 0)
+++ trunk/LayoutTests/editing/input/scroll-to-edge-if-line-break-at-end-of-document-contenteditable.html	2012-05-16 17:45:32 UTC (rev 117307)
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<head>
+<script type="text/_javascript_" src=""
+</head>
+<body>
+<div>When the caret is scrolled out and resides at the end of the contenteditable,
+on pressing &quot;Ctrl+Return&quot; it must be scrolled to the bottom of the view,
+not to the center to avoid undesirable content view jumping.</div>
+<div style="height:1000px;">
+  <div style="overflow:visible; height:100px;" contenteditable="true" id="input"></div>
+</div>
+<script>
+if (window.layoutTestController)
+   layoutTestController.dumpAsText();
+
+performJumpAtTheEdgeTest(true);
+
+</script>
+</body>
Property changes on: trunk/LayoutTests/editing/input/scroll-to-edge-if-line-break-at-end-of-document-contenteditable.html
___________________________________________________________________

Added: svn:eol-style

Added: trunk/LayoutTests/editing/input/scroll-to-edge-if-line-break-at-end-of-document-textarea-expected.txt (0 => 117307)


--- trunk/LayoutTests/editing/input/scroll-to-edge-if-line-break-at-end-of-document-textarea-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/editing/input/scroll-to-edge-if-line-break-at-end-of-document-textarea-expected.txt	2012-05-16 17:45:32 UTC (rev 117307)
@@ -0,0 +1,3 @@
+When the caret is scrolled out and resides at the end of the textarea, on pressing "Return" it must be scrolled to the bottom of the view, not to the center to avoid undesirable content view jumping.
+
+PASS
Property changes on: trunk/LayoutTests/editing/input/scroll-to-edge-if-line-break-at-end-of-document-textarea-expected.txt
___________________________________________________________________

Added: svn:eol-style

Added: trunk/LayoutTests/editing/input/scroll-to-edge-if-line-break-at-end-of-document-textarea.html (0 => 117307)


--- trunk/LayoutTests/editing/input/scroll-to-edge-if-line-break-at-end-of-document-textarea.html	                        (rev 0)
+++ trunk/LayoutTests/editing/input/scroll-to-edge-if-line-break-at-end-of-document-textarea.html	2012-05-16 17:45:32 UTC (rev 117307)
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<head>
+<script type="text/_javascript_" src=""
+</head>
+<body>
+<div>When the caret is scrolled out and resides at the end of the textarea,
+on pressing &quot;Return&quot; it must be scrolled to the bottom of the view,
+not to the center to avoid undesirable content view jumping.</div>
+<div style="overflow:auto;height:1000px;">
+  <textarea rows="50" cols="20" id="input"></textarea>
+</div>
+<script>
+if (window.layoutTestController)
+   layoutTestController.dumpAsText();
+
+performJumpAtTheEdgeTest(false);
+
+</script>
+</body>
Property changes on: trunk/LayoutTests/editing/input/scroll-to-edge-if-line-break-at-end-of-document-textarea.html
___________________________________________________________________

Added: svn:eol-style

Added: trunk/LayoutTests/editing/input/scroll-to-edge-if-paragraph-separator-at-end-of-document-contenteditable-expected.txt (0 => 117307)


--- trunk/LayoutTests/editing/input/scroll-to-edge-if-paragraph-separator-at-end-of-document-contenteditable-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/editing/input/scroll-to-edge-if-paragraph-separator-at-end-of-document-contenteditable-expected.txt	2012-05-16 17:45:32 UTC (rev 117307)
@@ -0,0 +1,123 @@
+When the caret is scrolled out and resides at the end of the contenteditable, on pressing "Return" it must be scrolled to the bottom of the view, not to the center to avoid undesirable content view jumping.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+PASS
Property changes on: trunk/LayoutTests/editing/input/scroll-to-edge-if-paragraph-separator-at-end-of-document-contenteditable-expected.txt
___________________________________________________________________

Added: svn:eol-style

Added: trunk/LayoutTests/editing/input/scroll-to-edge-if-paragraph-separator-at-end-of-document-contenteditable.html (0 => 117307)


--- trunk/LayoutTests/editing/input/scroll-to-edge-if-paragraph-separator-at-end-of-document-contenteditable.html	                        (rev 0)
+++ trunk/LayoutTests/editing/input/scroll-to-edge-if-paragraph-separator-at-end-of-document-contenteditable.html	2012-05-16 17:45:32 UTC (rev 117307)
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<head>
+<script type="text/_javascript_" src=""
+</head>
+<body>
+<div>When the caret is scrolled out and resides at the end of the contenteditable,
+on pressing &quot;Return&quot; it must be scrolled to the bottom of the view,
+not to the center to avoid undesirable content view jumping.</div>
+<div style="height:1000px;">
+  <div style="overflow:visible; height:100px;" contenteditable="true" id="input"></div>
+</div>
+<script>
+if (window.layoutTestController)
+   layoutTestController.dumpAsText();
+
+performJumpAtTheEdgeTest(false);
+
+</script>
+</body>
Property changes on: trunk/LayoutTests/editing/input/scroll-to-edge-if-paragraph-separator-at-end-of-document-contenteditable.html
___________________________________________________________________

Added: svn:eol-style

Modified: trunk/Source/WebCore/ChangeLog (117306 => 117307)


--- trunk/Source/WebCore/ChangeLog	2012-05-16 17:36:23 UTC (rev 117306)
+++ trunk/Source/WebCore/ChangeLog	2012-05-16 17:45:32 UTC (rev 117307)
@@ -1,3 +1,25 @@
+2012-05-16  Mikhail Naganov  <mnaga...@chromium.org>
+
+        Avoid jumpscroll when entering new text in a multi-line editor.
+        https://bugs.webkit.org/show_bug.cgi?id=82875
+
+        Reviewed by Ryosuke Niwa.
+
+        Scroll caret to the edge of the viewport in case if a line break or a paragraph
+        separator is inserted at the end of a multi-line editor.  This avoids
+        undesirable jumpscroll in cases when there is content under the editor.
+
+        Tests: editing/input/scroll-to-edge-if-line-break-at-end-of-document-contenteditable.html
+               editing/input/scroll-to-edge-if-line-break-at-end-of-document-textarea.html
+               editing/input/scroll-to-edge-if-paragraph-separator-at-end-of-document-contenteditable.html
+
+        * editing/Editor.cpp:
+        (WebCore::Editor::insertLineBreak):
+        (WebCore::Editor::insertParagraphSeparator):
+        (WebCore::Editor::revealSelectionAfterEditingOperation):
+        * editing/Editor.h:
+        (Editor):
+
 2012-05-16  Vsevolod Vlasov  <vse...@chromium.org>
 
         Web Inspector: Pressing esc after requesting snippet creation should remove snippet.

Modified: trunk/Source/WebCore/editing/Editor.cpp (117306 => 117307)


--- trunk/Source/WebCore/editing/Editor.cpp	2012-05-16 17:36:23 UTC (rev 117306)
+++ trunk/Source/WebCore/editing/Editor.cpp	2012-05-16 17:45:32 UTC (rev 117307)
@@ -945,9 +945,11 @@
     if (!shouldInsertText("\n", m_frame->selection()->toNormalizedRange().get(), EditorInsertActionTyped))
         return true;
 
+    VisiblePosition caret = m_frame->selection()->selection().visibleStart();
+    bool alignToEdge = isEndOfDocument(caret);
     bool autocorrectionIsApplied = m_alternativeTextController->applyAutocorrectionBeforeTypingIfAppropriate();
     TypingCommand::insertLineBreak(m_frame->document(), autocorrectionIsApplied ? TypingCommand::RetainAutocorrectionIndicator : 0);
-    revealSelectionAfterEditingOperation();
+    revealSelectionAfterEditingOperation(alignToEdge ? ScrollAlignment::alignToEdgeIfNeeded : ScrollAlignment::alignCenterIfNeeded);
 
     return true;
 }
@@ -963,9 +965,11 @@
     if (!shouldInsertText("\n", m_frame->selection()->toNormalizedRange().get(), EditorInsertActionTyped))
         return true;
 
+    VisiblePosition caret = m_frame->selection()->selection().visibleStart();
+    bool alignToEdge = isEndOfDocument(caret);
     bool autocorrectionIsApplied = m_alternativeTextController->applyAutocorrectionBeforeTypingIfAppropriate();
     TypingCommand::insertParagraphSeparator(m_frame->document(), autocorrectionIsApplied ? TypingCommand::RetainAutocorrectionIndicator : 0);
-    revealSelectionAfterEditingOperation();
+    revealSelectionAfterEditingOperation(alignToEdge ? ScrollAlignment::alignToEdgeIfNeeded : ScrollAlignment::alignCenterIfNeeded);
 
     return true;
 }
@@ -2283,12 +2287,12 @@
     return avoidIntersectionWithNode(selection.toNormalizedRange().get(), m_deleteButtonController->containerElement());
 }
 
-void Editor::revealSelectionAfterEditingOperation()
+void Editor::revealSelectionAfterEditingOperation(const ScrollAlignment& alignment)
 {
     if (m_ignoreCompositionSelectionChange)
         return;
 
-    m_frame->selection()->revealSelection(ScrollAlignment::alignCenterIfNeeded);
+    m_frame->selection()->revealSelection(alignment);
 }
 
 void Editor::setIgnoreCompositionSelectionChange(bool ignore)

Modified: trunk/Source/WebCore/editing/Editor.h (117306 => 117307)


--- trunk/Source/WebCore/editing/Editor.h	2012-05-16 17:36:23 UTC (rev 117306)
+++ trunk/Source/WebCore/editing/Editor.h	2012-05-16 17:45:32 UTC (rev 117307)
@@ -421,7 +421,7 @@
     PassRefPtr<Clipboard> newGeneralClipboard(ClipboardAccessPolicy, Frame*);
     void pasteAsPlainTextWithPasteboard(Pasteboard*);
     void pasteWithPasteboard(Pasteboard*, bool allowPlainText);
-    void revealSelectionAfterEditingOperation();
+    void revealSelectionAfterEditingOperation(const ScrollAlignment& = ScrollAlignment::alignCenterIfNeeded);
     void markMisspellingsOrBadGrammar(const VisibleSelection&, bool checkSpelling, RefPtr<Range>& firstMisspellingRange);
     TextCheckingTypeMask resolveTextCheckingTypeMask(TextCheckingTypeMask);
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to