Skip to content

Commit

Permalink
Stand Up IsOffscreen in AXPlatformNodeWin::GetPropertyValue
Browse files Browse the repository at this point in the history
- Enabled/implemented IsOffscreen property for UIA in
AXPlatformNodeWin::GetPropertyValue and assoicated browser tests.
GetPropertyValue calculates isOffscreen status by utilizing
AXTree::RelativeToTreeBounds, which looks at the bounds of the
node relative to its ancestor and rootWebArea bounds to determine
the isOffscreen status.

- Modified AccessibilityWinBrowserTests::FindNodeInSubtree to take
into account of StringAttribute::kValue when finding the node.

Bug: 844149
Change-Id: Ied62e00814957a6ca97b1849935ec692f1acf03a
Reviewed-on: https://chromium-review.googlesource.com/c/1481800
Commit-Queue: Victor Fei <vicfei@microsoft.com>
Reviewed-by: Dominic Mazzoni <dmazzoni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#636934}
  • Loading branch information
vicfei-ms authored and Commit Bot committed Mar 1, 2019
1 parent cebbbd2 commit 7996d08
Show file tree
Hide file tree
Showing 11 changed files with 114 additions and 8 deletions.
26 changes: 19 additions & 7 deletions content/browser/accessibility/accessibility_win_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ class AccessibilityWinBrowserTest : public ContentBrowserTest {
void SetUpSampleParagraphInScrollableEditable(
Microsoft::WRL::ComPtr<IAccessibleText>* accessible_text,
ui::AXMode accessibility_mode = ui::kAXModeComplete);
BrowserAccessibility* FindNode(ax::mojom::Role role, const std::string& name);
BrowserAccessibility* FindNode(ax::mojom::Role role,
const std::string& name_or_value);
BrowserAccessibilityManager* GetManager();
static Microsoft::WRL::ComPtr<IAccessible> GetAccessibleFromVariant(
IAccessible* parent,
Expand Down Expand Up @@ -126,7 +127,7 @@ class AccessibilityWinBrowserTest : public ContentBrowserTest {
Microsoft::WRL::ComPtr<IAccessibleText>* accessible_text);
BrowserAccessibility* FindNodeInSubtree(BrowserAccessibility& node,
ax::mojom::Role role,
const std::string& name);
const std::string& name_or_value);
DISALLOW_COPY_AND_ASSIGN(AccessibilityWinBrowserTest);
};

Expand Down Expand Up @@ -477,30 +478,41 @@ void AccessibilityWinBrowserTest::SetUpSampleParagraphHelper(
ASSERT_HRESULT_SUCCEEDED(paragraph.CopyTo(accessible_text->GetAddressOf()));
}

// Retrieve the accessibility node, starting from the root node, that matches
// the accessibility role, name or value.
BrowserAccessibility* AccessibilityWinBrowserTest::FindNode(
ax::mojom::Role role,
const std::string& name) {
const std::string& name_or_value) {
BrowserAccessibility* root = GetManager()->GetRoot();
CHECK(root);
return FindNodeInSubtree(*root, role, name);
return FindNodeInSubtree(*root, role, name_or_value);
}

// Retrieve the browser accessibility manager object for the current web
// contents.
BrowserAccessibilityManager* AccessibilityWinBrowserTest::GetManager() {
WebContentsImpl* web_contents =
static_cast<WebContentsImpl*>(shell()->web_contents());
return web_contents->GetRootBrowserAccessibilityManager();
}

// Retrieve the accessibility node in the subtree that matches the accessibility
// role, name or value.
BrowserAccessibility* AccessibilityWinBrowserTest::FindNodeInSubtree(
BrowserAccessibility& node,
ax::mojom::Role role,
const std::string& name) {
const std::string& name_or_value) {
const auto& name = node.GetStringAttribute(ax::mojom::StringAttribute::kName);
const auto& value =
node.GetStringAttribute(ax::mojom::StringAttribute::kValue);
if (node.GetRole() == role &&
node.GetStringAttribute(ax::mojom::StringAttribute::kName) == name)
(name == name_or_value || value == name_or_value)) {
return &node;
}

for (unsigned int i = 0; i < node.PlatformChildCount(); ++i) {
BrowserAccessibility* result =
FindNodeInSubtree(*node.PlatformGetChild(i), role, name);
FindNodeInSubtree(*node.PlatformGetChild(i), role, name_or_value);
if (result)
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1750,11 +1750,21 @@ IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest, AccessibilityOffscreen) {
RunHtmlTest(FILE_PATH_LITERAL("offscreen.html"));
}

IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest,
AccessibilityOffscreenIframe) {
RunHtmlTest(FILE_PATH_LITERAL("offscreen-iframe.html"));
}

IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest,
AccessibilityOffscreenScroll) {
RunHtmlTest(FILE_PATH_LITERAL("offscreen-scroll.html"));
}

IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest,
AccessibilityOffscreenSelect) {
RunHtmlTest(FILE_PATH_LITERAL("offscreen-select.html"));
}

IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest, AccessibilityOptgroup) {
RunHtmlTest(FILE_PATH_LITERAL("optgroup.html"));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!doctype html>
<html>
<body>
<div aria-label="iframe_onscreen" style="height:300px; background-color: red;"></div>
<div aria-label="iframe_offscreen" style="height:200px; background-color: green"></div>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
rootWebArea
++genericContainer
++++iframe
++++++rootWebArea
++++++++genericContainer name='iframe_onscreen'
++++++++genericContainer offscreen name='iframe_offscreen'
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ROLE_SYSTEM_DOCUMENT READONLY FOCUSABLE
++IA2_ROLE_SECTION
++++IA2_ROLE_INTERNAL_FRAME
++++++ROLE_SYSTEM_DOCUMENT READONLY FOCUSABLE
++++++++IA2_ROLE_SECTION name='iframe_onscreen'
++++++++IA2_ROLE_SECTION name='iframe_offscreen' OFFSCREEN
10 changes: 10 additions & 0 deletions content/test/data/accessibility/html/offscreen-iframe.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!--
@WIN-ALLOW:OFFSCREEN
@BLINK-ALLOW:offscreen
-->

<html>
<body>
<iframe height="300px" width="200px" src="offscreen-iframe-content.html"></iframe>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
rootWebArea
++popUpButton collapsed value='Onscreen 1'
++++menuListPopup invisible
++++++menuListOption name='Onscreen 1' selected=true
++++++menuListOption invisible name='Onscreen 2' selected=false
++++++menuListOption invisible name='Onscreen 3' selected=false
++popUpButton collapsed offscreen value='Offscreen 1'
++++menuListPopup invisible
++++++menuListOption offscreen name='Offscreen 1' selected=true
++++++menuListOption invisible offscreen name='Offscreen 2' selected=false
++++++menuListOption invisible offscreen name='Offscreen 3' selected=false
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
ROLE_SYSTEM_DOCUMENT READONLY FOCUSABLE
++ROLE_SYSTEM_COMBOBOX value='Onscreen 1' COLLAPSED FOCUSABLE HASPOPUP
++++ROLE_SYSTEM_LIST INVISIBLE
++++++ROLE_SYSTEM_LISTITEM name='Onscreen 1' SELECTED FOCUSABLE
++++++ROLE_SYSTEM_LISTITEM name='Onscreen 2' INVISIBLE FOCUSABLE
++++++ROLE_SYSTEM_LISTITEM name='Onscreen 3' INVISIBLE FOCUSABLE
++ROLE_SYSTEM_COMBOBOX value='Offscreen 1' COLLAPSED OFFSCREEN FOCUSABLE HASPOPUP
++++ROLE_SYSTEM_LIST INVISIBLE
++++++ROLE_SYSTEM_LISTITEM name='Offscreen 1' SELECTED OFFSCREEN FOCUSABLE
++++++ROLE_SYSTEM_LISTITEM name='Offscreen 2' INVISIBLE OFFSCREEN FOCUSABLE
++++++ROLE_SYSTEM_LISTITEM name='Offscreen 3' INVISIBLE OFFSCREEN FOCUSABLE
27 changes: 27 additions & 0 deletions content/test/data/accessibility/html/offscreen-select.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!--
@WIN-ALLOW:OFFSCREEN
@BLINK-ALLOW:offscreen
-->

<html>
<body>
<!-- Test when list box items are onscreen
Currently collapsed <option> elements are treated as onscreen, but this
probably isn't the most correct behavior, we should fix it.
http://crbug.com/937386 -->
<select name="Select onscreen">
<option value="1">Onscreen 1</option>
<option value="2">Onscreen 2</option>
<option value="3">Onscreen 3</option>
</select>

<div style="height:650px"></div>

<!-- Test when list box items are offscreen -->
<select name="Select offscreen">
<option value="1">Offscreen 1</option>
<option value="2">Offscreen 2</option>
<option value="3">Offscreen 3</option>
</select>
</body>
</html>
7 changes: 6 additions & 1 deletion ui/accessibility/platform/ax_platform_node_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3695,6 +3695,12 @@ IFACEMETHODIMP AXPlatformNodeWin::GetPropertyValue(PROPERTYID property_id,
: VARIANT_FALSE;
break;

case UIA_IsOffscreenPropertyId:
result->vt = VT_BOOL;
result->boolVal =
GetDelegate()->IsOffscreen() ? VARIANT_TRUE : VARIANT_FALSE;
break;

case UIA_IsRequiredForFormPropertyId:
result->vt = VT_BOOL;
if (data.HasState(ax::mojom::State::kRequired)) {
Expand Down Expand Up @@ -3847,7 +3853,6 @@ IFACEMETHODIMP AXPlatformNodeWin::GetPropertyValue(PROPERTYID property_id,
// Covered by MSAA.
case UIA_BoundingRectanglePropertyId:
case UIA_HelpTextPropertyId:
case UIA_IsOffscreenPropertyId:
case UIA_NativeWindowHandlePropertyId:
case UIA_ProcessIdPropertyId:
break;
Expand Down
1 change: 1 addition & 0 deletions ui/accessibility/platform/ax_platform_node_win_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3219,6 +3219,7 @@ TEST_F(AXPlatformNodeWinTest, TestUIAGetPropertySimple) {
EXPECT_UIA_BOOL_EQ(root_node, UIA_IsRequiredForFormPropertyId, false);
EXPECT_UIA_BOOL_EQ(root_node, UIA_IsDataValidForFormPropertyId, true);
EXPECT_UIA_BOOL_EQ(root_node, UIA_IsKeyboardFocusablePropertyId, false);
EXPECT_UIA_BOOL_EQ(root_node, UIA_IsOffscreenPropertyId, false);
ComPtr<IRawElementProviderSimple> child_node1 =
QueryInterfaceFromNode<IRawElementProviderSimple>(
GetRootNode()->children()[0]);
Expand Down

0 comments on commit 7996d08

Please sign in to comment.