<https://webkit.org/b/119882> Speed up moving cursor/selection up or down past non...
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 19 Aug 2013 11:12:41 +0000 (11:12 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 19 Aug 2013 11:12:41 +0000 (11:12 +0000)
Patch by Mario Sanchez Prada <mario.prada@samsung.com> on 2013-08-19
Reviewed by Darin Adler.

This is a port from Blink originally written by Dominic Mazzoni:
https://src.chromium.org/viewvc/blink?revision=154977&view=revision

Source/WebCore:

From the original commit:

Skips calling firstPositionInOrBeforeNode when a node doesn't have a
renderer, since there couldn't possibly be a visible position there.
This was particularly wasteful when trying to move the cursor up when at
the beginning of a document, as it did a O(n^2) scan through the document head.

Test: editing/execCommand/move-up-down-should-skip-hidden-elements.html

* editing/VisibleUnits.cpp:
(WebCore::previousRootInlineBoxCandidatePosition): Updated.
(WebCore::nextRootInlineBoxCandidatePosition): Updates.

LayoutTests:

* editing/execCommand/move-up-down-should-skip-hidden-elements-expected.txt: Added.
* editing/execCommand/move-up-down-should-skip-hidden-elements.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@154274 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/editing/execCommand/move-up-down-should-skip-hidden-elements-expected.txt [new file with mode: 0644]
LayoutTests/editing/execCommand/move-up-down-should-skip-hidden-elements.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/editing/VisibleUnits.cpp

index 15c699cdafbf98aa43f71a3b73b5b716e92cd1fd..a43d8bf6c80a58c9c6579fb3d28deb59230a242e 100644 (file)
@@ -1,3 +1,15 @@
+2013-08-19  Mario Sanchez Prada  <mario.prada@samsung.com>
+
+        <https://webkit.org/b/119882> Speed up moving cursor/selection up or down past non-rendered elements.
+
+        Reviewed by Darin Adler.
+
+        This is a port from Blink originally written by Dominic Mazzoni:
+        https://src.chromium.org/viewvc/blink?revision=154977&view=revision
+
+        * editing/execCommand/move-up-down-should-skip-hidden-elements-expected.txt: Added.
+        * editing/execCommand/move-up-down-should-skip-hidden-elements.html: Added.
+
 2013-08-18  Seokju Kwon  <seokju@webkit.org>
 
         Unreviewed gardening after r154135
diff --git a/LayoutTests/editing/execCommand/move-up-down-should-skip-hidden-elements-expected.txt b/LayoutTests/editing/execCommand/move-up-down-should-skip-hidden-elements-expected.txt
new file mode 100644 (file)
index 0000000..c8dc67d
--- /dev/null
@@ -0,0 +1,11 @@
+First line of rendered text
+
+Test moving up and down through non-rendered elements. This test should execute quickly if it's working correctly; a timeout is a failure.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/editing/execCommand/move-up-down-should-skip-hidden-elements.html b/LayoutTests/editing/execCommand/move-up-down-should-skip-hidden-elements.html
new file mode 100644 (file)
index 0000000..2d46bb9
--- /dev/null
@@ -0,0 +1,49 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../fast/js/resources/js-test-pre.js"></script>
+<title>Test moving up and down through non-rendered elements.</title>
+</head>
+<body>
+<div id="before" hidden></div>
+<h1 id="first_line">First line of rendered text</h1>
+<div id="after" hidden></div>
+
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test moving up and down through non-rendered elements. This test should execute quickly if it's working correctly; a timeout is a failure.");
+
+var before = document.getElementById("before");
+var after = document.getElementById("after");
+for (var i = 0; i < 1000; i++) {
+    before.appendChild(document.createElement("meta"));
+    after.appendChild(document.createElement("meta"));
+}
+
+function selectFirstLine() {
+    var selection = document.getSelection();
+    selection.removeAllRanges();
+    var range = document.createRange();
+    range.selectNode(document.getElementById("first_line"));
+   selection.addRange(range);
+}
+
+for (var i = 0; i < 100; i++) {
+    selectFirstLine();
+    if (window.testRunner)
+        testRunner.execCommand("MoveUpAndModifySelection");
+
+    selectFirstLine();
+   if (window.testRunner)
+        testRunner.execCommand("MoveDownAndModifySelection");
+}
+
+before.textContent = "";
+after.textContent = "";
+
+</script>
+<script src="../../fast/js/resources/js-test-post.js"></script>
+</body>
+</html>
\ No newline at end of file
index d2a3275bad858f531af74078416d298a4c12d2c7..5a3a2d8217fc9118b31b6a1326c03b8917b85d98 100644 (file)
@@ -1,3 +1,25 @@
+2013-08-19  Mario Sanchez Prada  <mario.prada@samsung.com>
+
+        <https://webkit.org/b/119882> Speed up moving cursor/selection up or down past non-rendered elements.
+
+        Reviewed by Darin Adler.
+
+        This is a port from Blink originally written by Dominic Mazzoni:
+        https://src.chromium.org/viewvc/blink?revision=154977&view=revision
+
+        From the original commit:
+
+        Skips calling firstPositionInOrBeforeNode when a node doesn't have a
+        renderer, since there couldn't possibly be a visible position there.
+        This was particularly wasteful when trying to move the cursor up when at
+        the beginning of a document, as it did a O(n^2) scan through the document head.
+
+        Test: editing/execCommand/move-up-down-should-skip-hidden-elements.html
+
+        * editing/VisibleUnits.cpp:
+        (WebCore::previousRootInlineBoxCandidatePosition): Updated.
+        (WebCore::nextRootInlineBoxCandidatePosition): Updates.
+
 2013-08-19  Andreas Kling  <akling@apple.com>
 
         <https://webkit.org/b/120000> Chrome::client() should return a reference.
index b629bdcc66edf75132677b6542cfd881815f9267..05a2e5598d8079d455cb2b374d57b5142375fe64 100644 (file)
@@ -80,7 +80,7 @@ static Position previousRootInlineBoxCandidatePosition(Node* node, const Visible
     Node* highestRoot = highestEditableRoot(visiblePosition.deepEquivalent(), editableType);
     Node* previousNode = previousLeafWithSameEditability(node, editableType);
 
-    while (previousNode && inSameLine(firstPositionInOrBeforeNode(previousNode), visiblePosition))
+    while (previousNode && (!previousNode->renderer() || inSameLine(firstPositionInOrBeforeNode(previousNode), visiblePosition)))
         previousNode = previousLeafWithSameEditability(previousNode, editableType);
 
     while (previousNode && !previousNode->isShadowRoot()) {
@@ -102,7 +102,7 @@ static Position nextRootInlineBoxCandidatePosition(Node* node, const VisiblePosi
 {
     Node* highestRoot = highestEditableRoot(visiblePosition.deepEquivalent(), editableType);
     Node* nextNode = nextLeafWithSameEditability(node, editableType);
-    while (nextNode && inSameLine(firstPositionInOrBeforeNode(nextNode), visiblePosition))
+    while (nextNode && (!nextNode->renderer() || inSameLine(firstPositionInOrBeforeNode(nextNode), visiblePosition)))
         nextNode = nextLeafWithSameEditability(nextNode, ContentIsEditable);
 
     while (nextNode && !nextNode->isShadowRoot()) {