Commit a8671260 authored by Katie Dektar's avatar Katie Dektar Committed by Commit Bot

Elements with no size are offscreen only if outside the screen.

Children of elements with no size are offscreen still by virtue
of being clipped.

This fixes <br> tags (lineBreak) being labeled 'offscreen',
as well as any size (0, 0) element that is on the screen.

Bug: 773851
Change-Id: I3e2ed49d3b66b3eb3280f44fcf86315273cce485
Reviewed-on: https://chromium-review.googlesource.com/772900Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Commit-Queue: Katie D <katie@chromium.org>
Cr-Commit-Position: refs/heads/master@{#517558}
parent 59b5d989
...@@ -948,7 +948,7 @@ IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest, AccessibiltyBoundsClips) { ...@@ -948,7 +948,7 @@ IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest, AccessibiltyBoundsClips) {
RunHtmlTest(FILE_PATH_LITERAL("bounds-clips.html")); RunHtmlTest(FILE_PATH_LITERAL("bounds-clips.html"));
} }
IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest, DISABLED_AccessibilityBR) { IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest, AccessibilityBR) {
RunHtmlTest(FILE_PATH_LITERAL("br.html")); RunHtmlTest(FILE_PATH_LITERAL("br.html"));
} }
......
...@@ -9,11 +9,11 @@ rootWebArea ...@@ -9,11 +9,11 @@ rootWebArea
++++staticText name='Also visible' ++++staticText name='Also visible'
++++++inlineTextBox name='Also ' ++++++inlineTextBox name='Also '
++++++inlineTextBox name='visible' ++++++inlineTextBox name='visible'
++genericContainer offscreen ++genericContainer
++++staticText offscreen name='Hidden' ++++staticText offscreen name='Hidden'
++++++inlineTextBox offscreen name='Hidden' ++++++inlineTextBox offscreen name='Hidden'
++genericContainer size=(10, 10) ++genericContainer size=(10, 10)
++++genericContainer offscreen ++++genericContainer
++++++staticText offscreen name='Also hidden' ++++++staticText offscreen name='Also hidden'
++++++++inlineTextBox offscreen name='Also ' ++++++++inlineTextBox offscreen name='Also '
++++++++inlineTextBox offscreen name='hidden' ++++++++inlineTextBox offscreen name='hidden'
......
rootWebArea rootWebArea
++genericContainer size=(200, 200) ++genericContainer size=(200, 200)
++++genericContainer offscreen size=(0, 0) ++++genericContainer size=(0, 0)
++++++genericContainer offscreen size=(0, 0) ++++++genericContainer offscreen size=(0, 0)
<-- End-of-file --> <-- End-of-file -->
\ No newline at end of file
android.webkit.WebView focusable focused scrollable android.webkit.WebView focusable focused scrollable
++android.view.View ++android.view.View name='<newline>'
++++android.view.View clickable name='Text line 1 ' ++android.view.View name='Text line 1'
++++android.view.View ++android.view.View name='Text line 2<newline>Text line 3'
++++android.view.View clickable name='Text line 2' ++android.view.View name='<newline>'
<-- End-of-file -->
rootWebArea
++lineBreak size=(0, 0) name='<newline>'
++++inlineTextBox name='<newline>'
++staticText name='Text line 1'
++++inlineTextBox name='Text line 1'
++paragraph
++++staticText name='Text line 2'
++++++inlineTextBox name='Text line 2'
++++lineBreak size=(0, 0) name='<newline>'
++++++inlineTextBox offscreen size=(0, 0) name='<newline>'
++++staticText name='Text line 3'
++++++inlineTextBox name='Text line 3'
++lineBreak size=(0, 0) name='<newline>'
++++inlineTextBox name='<newline>'
<-- End-of-file -->
\ No newline at end of file
ROLE_SYSTEM_DOCUMENT READONLY FOCUSABLE ROLE_SYSTEM_DOCUMENT READONLY FOCUSABLE
++IA2_ROLE_SECTION ++ROLE_SYSTEM_WHITESPACE name='<newline>'
++++ROLE_SYSTEM_STATICTEXT name='Text line 1 ' ++ROLE_SYSTEM_STATICTEXT name='Text line 1'
++++ROLE_SYSTEM_WHITESPACE ++IA2_ROLE_PARAGRAPH
++++ROLE_SYSTEM_STATICTEXT name='Text line 2' ++++ROLE_SYSTEM_STATICTEXT name='Text line 2'
++++ROLE_SYSTEM_WHITESPACE name='<newline>'
++++ROLE_SYSTEM_STATICTEXT name='Text line 3'
++ROLE_SYSTEM_WHITESPACE name='<newline>'
<-- End-of-file -->
<!--
@BLINK-ALLOW:offscreen
@BLINK-ALLOW:size=(0, 0)
@WIN-ALLOW:OFFSCREEN
@WIN-ALLOW:size=(0, 0)
-->
<html> <html>
<body> <body>
<br>
Text line 1 Text line 1
<p>Text line 2<br>Text line 3</p>
<br> <br>
Text line 2
</body> </body>
</html> </html>
...@@ -176,19 +176,11 @@ gfx::RectF AXTree::RelativeToTreeBounds(const AXNode* node, ...@@ -176,19 +176,11 @@ gfx::RectF AXTree::RelativeToTreeBounds(const AXNode* node,
// If the node bounds is empty (either width or height is zero), // If the node bounds is empty (either width or height is zero),
// try to compute good bounds from the children. // try to compute good bounds from the children.
if (bounds.IsEmpty()) { if (bounds.IsEmpty()) {
bool all_children_offscreen = true;
for (size_t i = 0; i < node->children().size(); i++) { for (size_t i = 0; i < node->children().size(); i++) {
ui::AXNode* child = node->children()[i]; ui::AXNode* child = node->children()[i];
bool temp_offscreen = false; bounds.Union(GetTreeBounds(child));
bounds.Union(GetTreeBounds(child, &temp_offscreen));
if (!temp_offscreen)
// At least one child is on screen.
all_children_offscreen = false;
} }
if (bounds.width() > 0 && bounds.height() > 0) { if (bounds.width() > 0 && bounds.height() > 0) {
// If all the children are offscreen, the node itself is offscreen.
if (offscreen != nullptr && all_children_offscreen)
*offscreen |= true;
return bounds; return bounds;
} }
} }
...@@ -226,7 +218,7 @@ gfx::RectF AXTree::RelativeToTreeBounds(const AXNode* node, ...@@ -226,7 +218,7 @@ gfx::RectF AXTree::RelativeToTreeBounds(const AXNode* node,
if (bounds.width() == 0 && bounds.height() == 0) { if (bounds.width() == 0 && bounds.height() == 0) {
bounds.set_size(container_bounds.size()); bounds.set_size(container_bounds.size());
if (offscreen != nullptr) if (offscreen != nullptr)
*offscreen = true; *offscreen |= true;
} }
int scroll_x = 0; int scroll_x = 0;
...@@ -238,17 +230,6 @@ gfx::RectF AXTree::RelativeToTreeBounds(const AXNode* node, ...@@ -238,17 +230,6 @@ gfx::RectF AXTree::RelativeToTreeBounds(const AXNode* node,
gfx::RectF clipped = bounds; gfx::RectF clipped = bounds;
clipped.Intersect(container_bounds); clipped.Intersect(container_bounds);
if (container->data().role != ui::AX_ROLE_DESKTOP && clipped.IsEmpty()) {
// If it is offscreen with respect to its parent, label it offscreen.
// Here we are extending the definition of offscreen to include elements
// that are clipped by their parents in addition to those clipped by
// the rootWebArea.
// No need to update |offscreen| if |clipped| is not empty, because it
// should be false by default.
if (offscreen != nullptr)
*offscreen |= true;
}
// If this is the root web area, make sure we clip the node to fit. // If this is the root web area, make sure we clip the node to fit.
if (container->data().role == ui::AX_ROLE_ROOT_WEB_AREA) { if (container->data().role == ui::AX_ROLE_ROOT_WEB_AREA) {
if (!clipped.IsEmpty()) { if (!clipped.IsEmpty()) {
...@@ -274,6 +255,19 @@ gfx::RectF AXTree::RelativeToTreeBounds(const AXNode* node, ...@@ -274,6 +255,19 @@ gfx::RectF AXTree::RelativeToTreeBounds(const AXNode* node,
} }
} }
if (container->data().role != ui::AX_ROLE_DESKTOP && clipped.IsEmpty() &&
!bounds.IsEmpty()) {
// If it is offscreen with respect to its parent, and the node itself is
// not empty, label it offscreen.
// Here we are extending the definition of offscreen to include elements
// that are clipped by their parents in addition to those clipped by
// the rootWebArea.
// No need to update |offscreen| if |clipped| is not empty, because it
// should be false by default.
if (offscreen != nullptr)
*offscreen |= true;
}
node = container; node = container;
} }
......
...@@ -836,7 +836,7 @@ TEST(AXTreeTest, EmptyNodeBoundsIsUnionOfChildren) { ...@@ -836,7 +836,7 @@ TEST(AXTreeTest, EmptyNodeBoundsIsUnionOfChildren) {
// If a node doesn't specify its location but at least one child does have // If a node doesn't specify its location but at least one child does have
// a location, it will be offscreen if all of its children are offscreen. // a location, it will be offscreen if all of its children are offscreen.
TEST(AXTreeTest, EmptyNodeOffscreenWhenAllChildrenOffscreen) { TEST(AXTreeTest, EmptyNodeNotOffscreenEvenIfAllChildrenOffscreen) {
AXTreeUpdate tree_update; AXTreeUpdate tree_update;
tree_update.root_id = 1; tree_update.root_id = 1;
tree_update.nodes.resize(4); tree_update.nodes.resize(4);
...@@ -855,7 +855,9 @@ TEST(AXTreeTest, EmptyNodeOffscreenWhenAllChildrenOffscreen) { ...@@ -855,7 +855,9 @@ TEST(AXTreeTest, EmptyNodeOffscreenWhenAllChildrenOffscreen) {
tree_update.nodes[3].location = gfx::RectF(1000, 30, 400, 20); tree_update.nodes[3].location = gfx::RectF(1000, 30, 400, 20);
AXTree tree(tree_update); AXTree tree(tree_update);
EXPECT_TRUE(IsNodeOffscreen(tree, 2)); EXPECT_FALSE(IsNodeOffscreen(tree, 2));
EXPECT_TRUE(IsNodeOffscreen(tree, 3));
EXPECT_TRUE(IsNodeOffscreen(tree, 4));
} }
// Test that getting the bounds of a node works when there's a transform. // Test that getting the bounds of a node works when there's a transform.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment