Skip to content
Permalink
Browse files
Correctly report selected text range for accessibility APIs for role=…
…textbox

https://bugs.webkit.org/show_bug.cgi?id=65900

Patch by Alice Boxhall <aboxhall@chromium.org> on 2011-08-30
Reviewed by Chris Fleizach.

Source/WebCore:

Test: accessibility/textbox-role-reports-selection.html

* accessibility/AccessibilityRenderObject.cpp:
(WebCore::AccessibilityRenderObject::indexForVisiblePosition):
(WebCore::AccessibilityRenderObject::rootEditableElementForPosition):
(WebCore::AccessibilityRenderObject::nodeIsTextControl):
(WebCore::AccessibilityRenderObject::determineAriaRoleAttribute):
* accessibility/AccessibilityRenderObject.h:

LayoutTests:

* accessibility/textbox-role-reports-selection-expected.txt: Added.
* accessibility/textbox-role-reports-selection.html: Added.

Canonical link: https://commits.webkit.org/83059@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@94134 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
alice authored and webkit-commit-queue committed Aug 31, 2011
1 parent 74e980b commit fd51ae143e7b5863f3cbf8eb76c1340a2eab6844
Showing 6 changed files with 136 additions and 5 deletions.
@@ -1,3 +1,13 @@
2011-08-30 Alice Boxhall <aboxhall@chromium.org>

Correctly report selected text range for accessibility APIs for role=textbox
https://bugs.webkit.org/show_bug.cgi?id=65900

Reviewed by Chris Fleizach.

* accessibility/textbox-role-reports-selection-expected.txt: Added.
* accessibility/textbox-role-reports-selection.html: Added.

2011-08-30 Rachel Blum <groby@chromium.org>

The "port" property of an <a> whose href does not specify a port returns the wrong value
@@ -0,0 +1,12 @@
This tests that the AXSelection property is correctly reported for non-native text boxes.
Some text in a textbox (34 chars).
PASS: axSelection is {0, 0} (Collapsed selection at start)
PASS: axSelection is {34, 0} (Collapsed selection at end)
PASS: axSelection is {15, 0} (Collapsed selection in the middle)
PASS: axSelection is {15, 2} (Non-collapsed selection in the middle)
PASS: axSelection is {0, 15} (Non-collapsed selection at the start)
PASS: axSelection is {15, 19} (Non-collapsed selection at the end)
PASS successfullyParsed is true

TEST COMPLETE

@@ -0,0 +1,60 @@
<!DOCTYPE HTML PUBLIC>
<html>
<head>
<link rel="stylesheet" href="../fast/js/resources/js-test-style.css">
<script>
var successfullyParsed = false;
</script>
<script src="../fast/js/resources/js-test-pre.js"></script>
</head>
<body>
This tests that the AXSelection property is correctly reported for non-native text boxes.<br>
<div role="textbox" id="ariaTextBox" aria-multiline="false" tabindex="0">Some text in a textbox (34 chars).</div>
<div id="console"></div>
<script>
function assertEvaluatesTo(actual, expected, message) {
var actualValue = 0;
try {
actualValue = eval(actual);
} catch (e) {
debug("Evaluating " + actual + ": Threw exception " + e);
return;
}
if (actualValue === expected)
debug("PASS: " + actual + " is " + expected + (message ? " (" + message + ")" : ""));
else
debug("FAIL: " + actual + " should be " + expected + ", got " + actualValue + (message ? " (" + message + ")" : ""));
}

function assertCorrectAXSelection(element, selection, message) {
element.focus();
var selectionValues = /\{(\d+), (\d+)\}/.exec(selection);
var selectionStart = eval(selectionValues[1]);
var selectionLength = eval(selectionValues[2]);
var selectionEnd = selectionStart + selectionLength;

window.getSelection().setBaseAndExtent(element.firstChild, selectionStart, element.firstChild, selectionEnd);
var axElement = accessibilityController.focusedElement;
axSelection = axElement.selectedTextRange;
assertEvaluatesTo("axSelection", selection, message);
}

if (window.layoutTestController && window.accessibilityController) {
window.layoutTestController.dumpAsText();
var ariaTextBox = document.getElementById("ariaTextBox");
var textLength = ariaTextBox.textContent.length;

assertCorrectAXSelection(ariaTextBox, "{0, 0}", "Collapsed selection at start");
assertCorrectAXSelection(ariaTextBox, "{" + textLength + ", 0}", "Collapsed selection at end");
assertCorrectAXSelection(ariaTextBox, "{15, 0}", "Collapsed selection in the middle");
assertCorrectAXSelection(ariaTextBox, "{15, 2}", "Non-collapsed selection in the middle");
assertCorrectAXSelection(ariaTextBox, "{0, 15}", "Non-collapsed selection at the start");
assertCorrectAXSelection(ariaTextBox, "{15, "+ (textLength - 15) + "}", "Non-collapsed selection at the end");
}

successfullyParsed = true;
</script>

<script src="../fast/js/resources/js-test-post.js"></script>
</body>
</html>
@@ -1,3 +1,19 @@
2011-08-30 Alice Boxhall <aboxhall@chromium.org>

Correctly report selected text range for accessibility APIs for role=textbox
https://bugs.webkit.org/show_bug.cgi?id=65900

Reviewed by Chris Fleizach.

Test: accessibility/textbox-role-reports-selection.html

* accessibility/AccessibilityRenderObject.cpp:
(WebCore::AccessibilityRenderObject::indexForVisiblePosition):
(WebCore::AccessibilityRenderObject::rootEditableElementForPosition):
(WebCore::AccessibilityRenderObject::nodeIsTextControl):
(WebCore::AccessibilityRenderObject::determineAriaRoleAttribute):
* accessibility/AccessibilityRenderObject.h:

2011-08-30 Rachel Blum <groby@chromium.org>

The "port" property of an <a> whose href does not specify a port returns the wrong value
@@ -2518,7 +2518,7 @@ int AccessibilityRenderObject::indexForVisiblePosition(const VisiblePosition& po
return 0;

Position indexPosition = pos.deepEquivalent();
if (indexPosition.isNull() || pos.rootEditableElement() != node)
if (indexPosition.isNull() || rootEditableElementForPosition(indexPosition) != node)
return 0;

ExceptionCode ec = 0;
@@ -2535,6 +2535,38 @@ int AccessibilityRenderObject::indexForVisiblePosition(const VisiblePosition& po
#endif
}

Element* AccessibilityRenderObject::rootEditableElementForPosition(const Position& position) const
{
// Find the root editable or pseudo-editable (i.e. having an editable ARIA role) element.
Element* result = 0;

Element* rootEditableElement = position.rootEditableElement();

for (Element* e = position.element(); e && e != rootEditableElement; e = e->parentElement()) {
if (nodeIsTextControl(e))
result = e;
if (e->hasTagName(bodyTag))
break;
}

if (result)
return result;

return rootEditableElement;
}

bool AccessibilityRenderObject::nodeIsTextControl(const Node* node) const
{
if (!node)
return false;

const AccessibilityObject* axObjectForNode = axObjectCache()->getOrCreate(node->renderer());
if (!axObjectForNode)
return false;

return axObjectForNode->isTextControl();
}

LayoutRect AccessibilityRenderObject::boundsForVisiblePositionRange(const VisiblePositionRange& visiblePositionRange) const
{
if (visiblePositionRange.isNull())
@@ -3026,7 +3058,7 @@ AccessibilityRole AccessibilityRenderObject::determineAriaRoleAttribute() const

if (role)
return role;

return UnknownRole;
}

@@ -1,4 +1,3 @@

/*
* Copyright (C) 2008 Apple Inc. All rights reserved.
*
@@ -247,7 +246,7 @@ class AccessibilityRenderObject : public AccessibilityObject {

virtual VisiblePosition visiblePositionForIndex(int) const;
virtual int indexForVisiblePosition(const VisiblePosition&) const;

virtual PlainTextRange doAXRangeForLine(unsigned) const;
virtual PlainTextRange doAXRangeForIndex(unsigned) const;

@@ -280,13 +279,15 @@ class AccessibilityRenderObject : public AccessibilityObject {
bool hasTextAlternative() const;
String positionalDescriptionForMSAA() const;
PlainTextRange ariaSelectedTextRange() const;
Element* rootEditableElementForPosition(const Position&) const;
bool nodeIsTextControl(const Node*) const;

Element* menuElementForMenuButton() const;
Element* menuItemElementForMenu() const;
AccessibilityRole determineAccessibilityRole();
AccessibilityRole determineAriaRoleAttribute() const;
AccessibilityRole remapAriaRoleDueToParent(AccessibilityRole) const;

bool isTabItemSelected() const;
void alterSliderValue(bool increase);
void changeValueByStep(bool increase);

0 comments on commit fd51ae1

Please sign in to comment.