WebCore:
authordarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 16 Mar 2009 23:15:32 +0000 (23:15 +0000)
committerdarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 16 Mar 2009 23:15:32 +0000 (23:15 +0000)
2009-03-16  Darin Adler  <darin@apple.com>

        Reviewed by Adele Peterson.

        Bug 24629: moving forward or backward a paragraph fails at edge of document
        https://bugs.webkit.org/show_bug.cgi?id=24629
        rdar://problem/6544413

        Test: editing/selection/move-paragraph-document-edges.html

        * editing/visible_units.cpp:
        (WebCore::previousParagraphPosition): Use the last result from
        previousLinePosition rather than going all the way back to what was originally
        passed in when we hit exception cases like null or not moving. This correctly
        inherits the behavior of previousLinePosition when we are in a paragraph at the
        edge of a document.
        (WebCore::nextParagraphPosition): Ditto.

LayoutTests:

2009-03-16  Darin Adler  <darin@apple.com>

        Reviewed by Adele Peterson.

        Bug 24629: moving forward or backward a paragraph fails at edge of document
        https://bugs.webkit.org/show_bug.cgi?id=24629
        rdar://problem/6544413

        * editing/selection/move-paragraph-document-edges-expected.txt: Added.
        * editing/selection/move-paragraph-document-edges.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/editing/selection/move-paragraph-document-edges-expected.txt [new file with mode: 0644]
LayoutTests/editing/selection/move-paragraph-document-edges.html [new file with mode: 0644]
WebCore/ChangeLog
WebCore/editing/visible_units.cpp

index 3ae4fbd..f0715e2 100644 (file)
@@ -1,3 +1,14 @@
+2009-03-16  Darin Adler  <darin@apple.com>
+
+        Reviewed by Adele Peterson.
+
+        Bug 24629: moving forward or backward a paragraph fails at edge of document
+        https://bugs.webkit.org/show_bug.cgi?id=24629
+        rdar://problem/6544413
+
+        * editing/selection/move-paragraph-document-edges-expected.txt: Added.
+        * editing/selection/move-paragraph-document-edges.html: Added.
+
 2009-03-16  David Hyatt  <hyatt@apple.com>
 
         Reviewed by Eric Seidel
diff --git a/LayoutTests/editing/selection/move-paragraph-document-edges-expected.txt b/LayoutTests/editing/selection/move-paragraph-document-edges-expected.txt
new file mode 100644 (file)
index 0000000..3422923
--- /dev/null
@@ -0,0 +1,7 @@
+This is the first paragraph, used for the moving-backward test.
+
+This tests for a problem with selections at document edges.
+
+SUCCESS
+
+This is the last paragraph, used for the moving-forward test.
diff --git a/LayoutTests/editing/selection/move-paragraph-document-edges.html b/LayoutTests/editing/selection/move-paragraph-document-edges.html
new file mode 100644 (file)
index 0000000..7b2e267
--- /dev/null
@@ -0,0 +1,67 @@
+<html>
+<head>
+<script>
+    function nodeAsString(node)
+    {
+        if (node && node.nodeType == Node.TEXT_NODE)
+            return "text in " + nodeAsString(node.parentNode);
+        if (node && node.nodeType == Node.ELEMENT_NODE) {
+            var id;
+            if (id = node.getAttribute("id"))
+                return id;
+        }
+        return node;
+    }
+    function selectionAsString()
+    {
+        return "(" + nodeAsString(getSelection().anchorNode)
+            + ", " + getSelection().anchorOffset
+            + "), (" + nodeAsString(getSelection().focusNode)
+            + ", " + getSelection().focusOffset + ")";        
+    }
+    function checkSelection(step, expected)
+    {
+        if (selectionAsString() !== expected) {
+            document.getElementById("result").innerHTML = "FAIL: After step " + step + " selection was " + selectionAsString();
+            return true;
+        }
+        return false;
+    }
+    function runTest()
+    {
+        if (window.layoutTestController)
+            layoutTestController.dumpAsText();
+        getSelection().setPosition(document.getElementById("first").firstChild, 4);
+        if (checkSelection(1, "(text in first, 4), (text in first, 4)"))
+            return;
+        getSelection().modify("extend", "backward", "line");
+        if (checkSelection(2, "(text in first, 4), (text in first, 0)"))
+            return;
+        getSelection().setPosition(document.getElementById("last").firstChild, 4);
+        if (checkSelection(3, "(text in last, 4), (text in last, 4)"))
+            return;
+        getSelection().modify("extend", "forward", "line");
+        if (checkSelection(4, "(text in last, 4), (text in last, 61)"))
+            return;
+        getSelection().setPosition(document.getElementById("first").firstChild, 4);
+        if (checkSelection(5, "(text in first, 4), (text in first, 4)"))
+            return;
+        getSelection().modify("extend", "backward", "paragraph");
+        if (checkSelection(6, "(text in first, 4), (text in first, 0)"))
+            return;
+        getSelection().setPosition(document.getElementById("last").firstChild, 4);
+        if (checkSelection(7, "(text in last, 4), (text in last, 4)"))
+            return;
+        getSelection().modify("extend", "forward", "paragraph");
+        if (checkSelection(8, "(text in last, 4), (text in last, 61)"))
+            return;
+        document.getElementById("result").innerHTML = "SUCCESS";
+    }
+</script>
+</head>
+<body onload="runTest()"><p id="first">This is the first paragraph, used for the moving-backward test.</p>
+<p>This tests for a problem with selections at document edges.</p>
+<p id="result">TEST HAS NOT YET RUN.</p>
+<p id="last">This is the last paragraph, used for the moving-forward test.</p>
+</body>
+</html>
index 7898c71..726d0fc 100644 (file)
@@ -2,6 +2,24 @@
 
         Reviewed by Adele Peterson.
 
+        Bug 24629: moving forward or backward a paragraph fails at edge of document
+        https://bugs.webkit.org/show_bug.cgi?id=24629
+        rdar://problem/6544413
+
+        Test: editing/selection/move-paragraph-document-edges.html
+
+        * editing/visible_units.cpp:
+        (WebCore::previousParagraphPosition): Use the last result from
+        previousLinePosition rather than going all the way back to what was originally
+        passed in when we hit exception cases like null or not moving. This correctly
+        inherits the behavior of previousLinePosition when we are in a paragraph at the
+        edge of a document.
+        (WebCore::nextParagraphPosition): Ditto.
+
+2009-03-16  Darin Adler  <darin@apple.com>
+
+        Reviewed by Adele Peterson.
+
         Bug 24619: RenderObject::selectionStartEnd does not need to be a virtual function
         https://bugs.webkit.org/show_bug.cgi?id=24619
 
index 3b9aeef..32a2078 100644 (file)
@@ -886,25 +886,25 @@ bool isEndOfParagraph(const VisiblePosition &pos)
     return pos.isNotNull() && pos == endOfParagraph(pos);
 }
 
-VisiblePosition previousParagraphPosition(const VisiblePosition &p, int x)
+VisiblePosition previousParagraphPosition(const VisiblePositionp, int x)
 {
     VisiblePosition pos = p;
     do {
         VisiblePosition n = previousLinePosition(pos, x);
         if (n.isNull() || n == pos)
-            return p;
+            break;
         pos = n;
     } while (inSameParagraph(p, pos));
     return pos;
 }
 
-VisiblePosition nextParagraphPosition(const VisiblePosition &p, int x)
+VisiblePosition nextParagraphPosition(const VisiblePositionp, int x)
 {
     VisiblePosition pos = p;
     do {
         VisiblePosition n = nextLinePosition(pos, x);
         if (n.isNull() || n == pos)
-            return p;
+            break;
         pos = n;
     } while (inSameParagraph(p, pos));
     return pos;