Title: [103197] trunk
Revision
103197
Author
[email protected]
Date
2011-12-18 17:12:27 -0800 (Sun, 18 Dec 2011)

Log Message

Make AccessibilityObject::lineForPosition return the correct value for cases where the position is not within the current object.
https://bugs.webkit.org/show_bug.cgi?id=71348

Reviewed by Chris Fleizach.

Source/WebCore:

* accessibility/AccessibilityObject.cpp:
(WebCore::AccessibilityObject::lineForPosition):
* accessibility/mac/WebAccessibilityObjectWrapper.mm:
(-[WebAccessibilityObjectWrapper accessibilityAttributeValue:]):

LayoutTests:

* accessibility/textarea-insertion-point-line-number-expected.txt:
* accessibility/textarea-insertion-point-line-number.html:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (103196 => 103197)


--- trunk/LayoutTests/ChangeLog	2011-12-19 00:42:03 UTC (rev 103196)
+++ trunk/LayoutTests/ChangeLog	2011-12-19 01:12:27 UTC (rev 103197)
@@ -1,3 +1,13 @@
+2011-12-18  Alice Boxhall  <[email protected]>
+
+        Make AccessibilityObject::lineForPosition return the correct value for cases where the position is not within the current object.
+        https://bugs.webkit.org/show_bug.cgi?id=71348
+
+        Reviewed by Chris Fleizach.
+
+        * accessibility/textarea-insertion-point-line-number-expected.txt:
+        * accessibility/textarea-insertion-point-line-number.html:
+
 2011-12-18  Adam Barth  <[email protected]>
 
         Adoption agency iteration limits in HTML parser don't match HTML5 spec

Modified: trunk/LayoutTests/accessibility/textarea-insertion-point-line-number-expected.txt (103196 => 103197)


--- trunk/LayoutTests/accessibility/textarea-insertion-point-line-number-expected.txt	2011-12-19 00:42:03 UTC (rev 103196)
+++ trunk/LayoutTests/accessibility/textarea-insertion-point-line-number-expected.txt	2011-12-19 01:12:27 UTC (rev 103197)
@@ -1,5 +1,20 @@
-Test:0) Line Number: Pass [0->0]
-Test:1) Line Number: Pass [7->1]
-Test:2) Line Number: Pass [14->2]
-Not focused on text area line number: -1
+This tests that lineNumberForPosition is reported correctly for textarea and contenteditable elements.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS area1.selectionStart = (0); area1.selectionEnd = (0); area1AXUIElement.insertionPointLineNumber; is currentLine
+PASS area1.selectionStart = (7); area1.selectionEnd = (7); area1AXUIElement.insertionPointLineNumber; is currentLine
+PASS area1.selectionStart = (14); area1.selectionEnd = (14); area1AXUIElement.insertionPointLineNumber; is currentLine
+PASS area2.focus(); area1AXUIElement.insertionPointLineNumber; is -1
+PASS window.getSelection().setBaseAndExtent(contenteditableLine1, 1, contenteditableLine1, 1); contenteditableAXUIElement.insertionPointLineNumber; is 0
+PASS contenteditableLine2.selectionStart = 1; contenteditableLine2.selectionEnd = 1;contenteditableAXUIElement.insertionPointLineNumber; is -1
+PASS window.getSelection().setBaseAndExtent(contenteditableLine3, 1, contenteditableLine3, 1); contenteditableAXUIElement.insertionPointLineNumber; is 2
+PASS textareaAXUIElement.insertionPointLineNumber is 0
+PASS successfullyParsed is true
+
+TEST COMPLETE
   
+Line1
+
+Line3

Modified: trunk/LayoutTests/accessibility/textarea-insertion-point-line-number.html (103196 => 103197)


--- trunk/LayoutTests/accessibility/textarea-insertion-point-line-number.html	2011-12-19 00:42:03 UTC (rev 103196)
+++ trunk/LayoutTests/accessibility/textarea-insertion-point-line-number.html	2011-12-19 01:12:27 UTC (rev 103197)
@@ -1,12 +1,11 @@
 <html>
+<script src=""
 <script>
     if (window.layoutTestController)
         layoutTestController.dumpAsText();
 </script>
 <body>
-    
-    <div id="result"></div>
-    
+    <div id="console"></div>
     <textarea name="area1" id="area1" rows="5" cols="40">
 line 1
 line 2
@@ -14,31 +13,54 @@
     </textarea>
 
     <textarea name="area2" id="area2" rows="5" cols="40"></textarea>
-     
+
+
+    <div id="contenteditable-div" role="textbox" contenteditable="true" tabindex="0">
+      <div id="contenteditable-line1">Line1</div>
+      <textarea id="contenteditable-line2" rows="1" cols="40">Line2</textarea>
+      <div id="contenteditable-line3">Line3</div>
+    </div>
     <script>
+        description("This tests that lineNumberForPosition is reported correctly for textarea and contenteditable elements.");
+
         if (window.accessibilityController) {
-            var result = document.getElementById("result");
+            var console = document.getElementById("console");
 
             var area1 = document.getElementById("area1");
             area1.focus();
+            var area1AXUIElement = accessibilityController.focusedElement;
+            var lineNumber = -2;
 
-            for (var k = 0; k < 3; k++) {
-                area1.selectionStart = (k*7);
-                area1.selectionEnd = (k*7);
-                var lineNumber = accessibilityController.focusedElement.insertionPointLineNumber;            
-                if (lineNumber == k) {
-                    result.innerText += "Test:" + k + ") Line Number: Pass [" + area1.selectionStart + "->" + lineNumber + "]\n";       
-                }
-                else {
-                    result.innerText += "Test:" + k + ") Line Number: Fail [" + area1.selectionStart + "->" + lineNumber + "]\n";       
-                }
+            for (var currentLine = 0; currentLine < 3; currentLine++ ) {
+                shouldBe("area1.selectionStart = (" + (currentLine * 7) + "); " +
+                         "area1.selectionEnd = (" + (currentLine * 7) +"); " +
+                         "area1AXUIElement.insertionPointLineNumber;", "currentLine");
             }
 
             var area2 = document.getElementById("area2");
-            area2.focus();
-            var lineNumber = accessibilityController.focusedElement.insertionPointLineNumber
-            result.innerText += "Not focused on text area line number: " + lineNumber + "\n";
+            shouldBe("area2.focus(); area1AXUIElement.insertionPointLineNumber;", "-1");
+
+            var contenteditableDiv = document.getElementById("contenteditable-div");
+            contenteditableDiv.focus();
+            var contenteditableAXUIElement = accessibilityController.focusedElement;
+
+            var contenteditableLine1 = document.getElementById("contenteditable-line1");
+            shouldBe("window.getSelection().setBaseAndExtent(contenteditableLine1, 1, contenteditableLine1, 1); " +
+                     "contenteditableAXUIElement.insertionPointLineNumber;", "0");
+
+            var contenteditableLine2 = document.getElementById("contenteditable-line2");
+            shouldBe("contenteditableLine2.selectionStart = 1; contenteditableLine2.selectionEnd = 1;" +
+                     "contenteditableAXUIElement.insertionPointLineNumber;", "-1");
+
+            var contenteditableLine3 = document.getElementById("contenteditable-line3");
+            shouldBe("window.getSelection().setBaseAndExtent(contenteditableLine3, 1, contenteditableLine3, 1); " +
+                     "contenteditableAXUIElement.insertionPointLineNumber;", "2");
+
+            contenteditableLine2.focus();
+            var textareaAXUIElement = accessibilityController.focusedElement;
+            shouldBe("textareaAXUIElement.insertionPointLineNumber", "0");
         }
     </script>
+<script src=""
 </body>
 </html>

Modified: trunk/Source/WebCore/ChangeLog (103196 => 103197)


--- trunk/Source/WebCore/ChangeLog	2011-12-19 00:42:03 UTC (rev 103196)
+++ trunk/Source/WebCore/ChangeLog	2011-12-19 01:12:27 UTC (rev 103197)
@@ -1,3 +1,15 @@
+2011-12-18  Alice Boxhall  <[email protected]>
+
+        Make AccessibilityObject::lineForPosition return the correct value for cases where the position is not within the current object.
+        https://bugs.webkit.org/show_bug.cgi?id=71348
+
+        Reviewed by Chris Fleizach.
+
+        * accessibility/AccessibilityObject.cpp:
+        (WebCore::AccessibilityObject::lineForPosition):
+        * accessibility/mac/WebAccessibilityObjectWrapper.mm:
+        (-[WebAccessibilityObjectWrapper accessibilityAttributeValue:]):
+
 2011-12-18  Sam Weinig  <[email protected]>
 
         Make EventHandler::handleWheelEvent take const PlatformWheelEvent&

Modified: trunk/Source/WebCore/accessibility/AccessibilityObject.cpp (103196 => 103197)


--- trunk/Source/WebCore/accessibility/AccessibilityObject.cpp	2011-12-19 00:42:03 UTC (rev 103196)
+++ trunk/Source/WebCore/accessibility/AccessibilityObject.cpp	2011-12-19 01:12:27 UTC (rev 103197)
@@ -1023,24 +1023,29 @@
 
 int AccessibilityObject::lineForPosition(const VisiblePosition& visiblePos) const
 {
-    if (visiblePos.isNull())
-        return 0;
+    if (visiblePos.isNull() || !node())
+        return -1;
 
-    unsigned lineCount = 0;
+    // If the position is not in the same editable region as this AX object, return -1.
+    Node* containerNode = visiblePos.deepEquivalent().containerNode();
+    if (!containerNode->containsIncludingShadowDOM(node()) && !node()->containsIncludingShadowDOM(containerNode))
+        return -1;
+
+    int lineCount = -1;
     VisiblePosition currentVisiblePos = visiblePos;
     VisiblePosition savedVisiblePos;
 
     // move up until we get to the top
     // FIXME: This only takes us to the top of the rootEditableElement, not the top of the
     // top document.
-    while (currentVisiblePos.isNotNull() && !(inSameLine(currentVisiblePos, savedVisiblePos))) {
-        ++lineCount;
+    do {
         savedVisiblePos = currentVisiblePos;
         VisiblePosition prevVisiblePos = previousLinePosition(currentVisiblePos, 0);
         currentVisiblePos = prevVisiblePos;
-    }
+        ++lineCount;
+    }  while (currentVisiblePos.isNotNull() && !(inSameLine(currentVisiblePos, savedVisiblePos)));
 
-    return lineCount - 1;
+    return lineCount;
 }
 
 // NOTE: Consider providing this utility method as AX API

Modified: trunk/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapper.mm (103196 => 103197)


--- trunk/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapper.mm	2011-12-19 00:42:03 UTC (rev 103196)
+++ trunk/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapper.mm	2011-12-19 01:12:27 UTC (rev 103197)
@@ -1889,9 +1889,16 @@
             // if selectionEnd > 0, then there is selected text and this question should not be answered
             if (m_object->isPasswordField() || m_object->selectionEnd() > 0)
                 return nil;
-            int lineNumber = m_object->lineForPosition(m_object->visiblePositionForIndex(m_object->selectionStart(), true));
+
+            AccessibilityObject* focusedObject = m_object->focusedUIElement();
+            if (focusedObject != m_object)
+                return nil;
+
+            VisiblePosition focusedPosition = focusedObject->visiblePositionForIndex(focusedObject->selectionStart(), true);
+            int lineNumber = m_object->lineForPosition(focusedPosition);
             if (lineNumber < 0)
                 return nil;
+
             return [NSNumber numberWithInt:lineNumber];
         }
     }
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to