WebCore:
authorjustin.garcia@apple.com <justin.garcia@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 23 Apr 2008 18:25:10 +0000 (18:25 +0000)
committerjustin.garcia@apple.com <justin.garcia@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 23 Apr 2008 18:25:10 +0000 (18:25 +0000)
2008-04-23  Justin Garcia  <justin.garcia@apple.com>

        Reviewed by Darin Adler.

        <rdar://problem/5825350> OWA: Caret disappears when navigating with arrows keys in contenteditable div

        * editing/htmlediting.cpp:
        (WebCore::firstEditablePositionAfterPositionInRoot): Return a null VisiblePosition if
        this function moves out of highestRoot.  Re-wrote so as to not duplicate code inside
        and outside of the while loop.
        (WebCore::lastEditablePositionBeforePositionInRoot): Ditto.

LayoutTests:

2008-04-23  Justin Garcia  <justin.garcia@apple.com>

        Reviewed by Darin Adler.

        <rdar://problem/5825350> OWA: Caret disappears when navigating with arrows keys in contenteditable div

        * editing/selection/5825350-1-expected.txt: Added.
        * editing/selection/5825350-1.html: Added.
        * editing/selection/5825350-2-expected.txt: Added.
        * editing/selection/5825350-2.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/editing/selection/5825350-1-expected.txt [new file with mode: 0644]
LayoutTests/editing/selection/5825350-1.html [new file with mode: 0644]
LayoutTests/editing/selection/5825350-2-expected.txt [new file with mode: 0644]
LayoutTests/editing/selection/5825350-2.html [new file with mode: 0644]
WebCore/ChangeLog
WebCore/editing/htmlediting.cpp

index e105dfa..a2f7375 100644 (file)
@@ -1,3 +1,14 @@
+2008-04-23  Justin Garcia  <justin.garcia@apple.com>
+
+        Reviewed by Darin Adler.
+
+        <rdar://problem/5825350> OWA: Caret disappears when navigating with arrows keys in contenteditable div
+
+        * editing/selection/5825350-1-expected.txt: Added.
+        * editing/selection/5825350-1.html: Added.
+        * editing/selection/5825350-2-expected.txt: Added.
+        * editing/selection/5825350-2.html: Added.
+
 2008-04-23  Darin Adler  <darin@apple.com>
 
         - updated a test affected by the addition of mask-composite
diff --git a/LayoutTests/editing/selection/5825350-1-expected.txt b/LayoutTests/editing/selection/5825350-1-expected.txt
new file mode 100644 (file)
index 0000000..0f3673f
--- /dev/null
@@ -0,0 +1,3 @@
+This tests for a bug where moving the caret left towards a non-editable pocket of an editable region would make the caret disappear. The caret should be just after the 'b' in "Bob".
+
+Caret One: (" ; ", 0)
diff --git a/LayoutTests/editing/selection/5825350-1.html b/LayoutTests/editing/selection/5825350-1.html
new file mode 100644 (file)
index 0000000..743d3ed
--- /dev/null
@@ -0,0 +1,15 @@
+<div id="description">This tests for a bug where moving the caret left towards a non-editable pocket of an editable region would make the caret disappear. The caret should be just after the 'b' in "Bob".</div>
+<div id="edit" contenteditable="true"><span contenteditable="false">Bob</span> ; <span contenteditable="false">Sally</span></div>
+
+<script>
+if (window.layoutTestController)
+    window.layoutTestController.dumpAsText();
+
+edit = document.getElementById("edit");
+text = edit.childNodes[1];
+s = window.getSelection();
+s.setPosition(text, 0);
+s.modify("move", "left", "character");
+if (window.layoutTestController)
+    document.body.innerText = document.getElementById("description").innerText + "\n\nCaret One: (\"" + s.anchorNode.data + "\", " + s.anchorOffset + ")";
+</script>
diff --git a/LayoutTests/editing/selection/5825350-2-expected.txt b/LayoutTests/editing/selection/5825350-2-expected.txt
new file mode 100644 (file)
index 0000000..9707516
--- /dev/null
@@ -0,0 +1,3 @@
+This tests for a bug where moving the caret right towards a non-editable pocket of an editable region would make the caret disappear. The caret should be just before the 'S' in "Sally".
+
+Caret One: (" ; ", 3)
diff --git a/LayoutTests/editing/selection/5825350-2.html b/LayoutTests/editing/selection/5825350-2.html
new file mode 100644 (file)
index 0000000..6e7ef57
--- /dev/null
@@ -0,0 +1,15 @@
+<div id="description">This tests for a bug where moving the caret right towards a non-editable pocket of an editable region would make the caret disappear. The caret should be just before the 'S' in "Sally".</div>
+<div id="edit" contenteditable="true"><span contenteditable="false">Bob</span> ; <span contenteditable="false">Sally</span></div>
+
+<script>
+if (window.layoutTestController)
+    window.layoutTestController.dumpAsText();
+
+edit = document.getElementById("edit");
+text = edit.childNodes[1];
+s = window.getSelection();
+s.setPosition(text, text.length);
+s.modify("move", "right", "character");
+if (window.layoutTestController)
+    document.body.innerText = document.getElementById("description").innerText + "\n\nCaret One: (\"" + s.anchorNode.data + "\", " + s.anchorOffset + ")";
+</script>
index 8004e36..dcf133c 100644 (file)
@@ -1,3 +1,15 @@
+2008-04-23  Justin Garcia  <justin.garcia@apple.com>
+
+        Reviewed by Darin Adler.
+
+        <rdar://problem/5825350> OWA: Caret disappears when navigating with arrows keys in contenteditable div
+
+        * editing/htmlediting.cpp:
+        (WebCore::firstEditablePositionAfterPositionInRoot): Return a null VisiblePosition if
+        this function moves out of highestRoot.  Re-wrote so as to not duplicate code inside
+        and outside of the while loop.
+        (WebCore::lastEditablePositionBeforePositionInRoot): Ditto.
+
 2008-04-23  Daniel Zucker  <zucker@wake3.com>
 
         Reviewed by Adam Roben.
index 105a3bd..6ef8f8f 100644 (file)
@@ -242,45 +242,43 @@ Position previousVisuallyDistinctCandidate(const Position& position)
 
 VisiblePosition firstEditablePositionAfterPositionInRoot(const Position& position, Node* highestRoot)
 {
+    // position falls before highestRoot.
     if (comparePositions(position, Position(highestRoot, 0)) == -1 && highestRoot->isContentEditable())
         return VisiblePosition(Position(highestRoot, 0));
-    
-    Position p = nextVisuallyDistinctCandidate(position);
-    Node* root = editableRootForPosition(position);
-    Node* shadowAncestor = root ? root->shadowAncestorNode() : 0;
-    if (p.isNull() && root && (shadowAncestor != root))
-        p = Position(shadowAncestor, maxDeepOffset(shadowAncestor));
-    while (p.isNotNull() && !isEditablePosition(p) && p.node()->isDescendantOf(highestRoot)) {
-        p = isAtomicNode(p.node()) ? positionAfterNode(p.node()) : nextVisuallyDistinctCandidate(p);
         
-        root = editableRootForPosition(position);
-        shadowAncestor = root ? root->shadowAncestorNode() : 0;
-        if (p.isNull() && root && (shadowAncestor != root))
+    Position p = position;
+    
+    if (Node* shadowAncestor = p.node()->shadowAncestorNode())
+        if (shadowAncestor != p.node())
             p = Position(shadowAncestor, maxDeepOffset(shadowAncestor));
-    }
-
+    
+    while (p.node() && !isEditablePosition(p) && p.node()->isDescendantOf(highestRoot))
+        p = isAtomicNode(p.node()) ? positionAfterNode(p.node()) : nextVisuallyDistinctCandidate(p);
+    
+    if (p.node() && !p.node()->isDescendantOf(highestRoot))
+        return VisiblePosition();
+    
     return VisiblePosition(p);
 }
 
 VisiblePosition lastEditablePositionBeforePositionInRoot(const Position& position, Node* highestRoot)
 {
+    // When position falls after highestRoot, the result is easy to compute.
     if (comparePositions(position, Position(highestRoot, maxDeepOffset(highestRoot))) == 1)
         return VisiblePosition(Position(highestRoot, maxDeepOffset(highestRoot)));
-    
-    Position p = previousVisuallyDistinctCandidate(position);
-    Node* root = editableRootForPosition(position);
-    Node* shadowAncestor = root ? root->shadowAncestorNode() : 0;
-    if (p.isNull() && root && (shadowAncestor != root))
-        p = Position(shadowAncestor, 0);
-    while (p.isNotNull() && !isEditablePosition(p) && p.node()->isDescendantOf(highestRoot)) {
-        p = isAtomicNode(p.node()) ? positionBeforeNode(p.node()) : previousVisuallyDistinctCandidate(p);
         
-        root = editableRootForPosition(position);
-        shadowAncestor = root ? root->shadowAncestorNode() : 0;
-        if (p.isNull() && root && (shadowAncestor != root))
+    Position p = position;
+    
+    if (Node* shadowAncestor = p.node()->shadowAncestorNode())
+        if (shadowAncestor != p.node())
             p = Position(shadowAncestor, 0);
-    }
-
+    
+    while (p.node() && !isEditablePosition(p) && p.node()->isDescendantOf(highestRoot))
+        p = isAtomicNode(p.node()) ? positionBeforeNode(p.node()) : previousVisuallyDistinctCandidate(p);
+    
+    if (p.node() && !p.node()->isDescendantOf(highestRoot))
+        return VisiblePosition();
+    
     return VisiblePosition(p);
 }