Commit 5f0d4d4d authored by Joel Riley's avatar Joel Riley Committed by Commit Bot

Include SVG g element in AX tree on Chrome OS.

Do not ignore SVG grouping elements in the accessibility tree on ChromeOS, so Select-to-speak can properly order SVG elements when reading them aloud.

AX-Relnotes: SVG grouping elements will now appear in the accessibility tree on ChromeOS.

Bug: 892822
Change-Id: I50226cef7d5d19f4c9326a10bb48c8828c16cabf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2375989Reviewed-by: default avatarNate Chapin <japhet@chromium.org>
Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Commit-Queue: Joel Riley <joelriley@google.com>
Cr-Commit-Position: refs/heads/master@{#803908}
parent 06242552
...@@ -2276,8 +2276,14 @@ IN_PROC_BROWSER_TEST_P(DumpAccessibilityTreeTest, AccessibilitySvg) { ...@@ -2276,8 +2276,14 @@ IN_PROC_BROWSER_TEST_P(DumpAccessibilityTreeTest, AccessibilitySvg) {
RunHtmlTest(FILE_PATH_LITERAL("svg.html")); RunHtmlTest(FILE_PATH_LITERAL("svg.html"));
} }
// On ChromeOS, SVG <g> elements are included.
#if defined(OS_CHROMEOS)
#define AccessibilitySvgG_TestFile FILE_PATH_LITERAL("svg-g-for-cros.html")
#else
#define AccessibilitySvgG_TestFile FILE_PATH_LITERAL("svg-g.html")
#endif
IN_PROC_BROWSER_TEST_P(DumpAccessibilityTreeTest, AccessibilitySvgG) { IN_PROC_BROWSER_TEST_P(DumpAccessibilityTreeTest, AccessibilitySvgG) {
RunHtmlTest(FILE_PATH_LITERAL("svg-g.html")); RunHtmlTest(AccessibilitySvgG_TestFile);
} }
IN_PROC_BROWSER_TEST_P(DumpAccessibilityTreeTest, AccessibilityTableSimple) { IN_PROC_BROWSER_TEST_P(DumpAccessibilityTreeTest, AccessibilityTableSimple) {
......
...@@ -222,6 +222,12 @@ RenderAccessibilityImpl::RenderAccessibilityImpl( ...@@ -222,6 +222,12 @@ RenderAccessibilityImpl::RenderAccessibilityImpl(
settings->SetAriaModalPrunesAXTree(true); settings->SetAriaModalPrunesAXTree(true);
#endif #endif
#if defined(OS_CHROMEOS)
// Do not ignore SVG grouping (<g>) elements on ChromeOS, which is needed so
// Select-to-Speak can read SVG text nodes in natural reading order.
settings->SetAccessibilityIncludeSvgGElement(true);
#endif
if (render_frame_->IsMainFrame()) if (render_frame_->IsMainFrame())
event_schedule_mode_ = EventScheduleMode::kDeferEvents; event_schedule_mode_ = EventScheduleMode::kDeferEvents;
else else
......
...@@ -12,4 +12,4 @@ rootWebArea ...@@ -12,4 +12,4 @@ rootWebArea
++++++++genericContainer ignored htmlTag='g' ++++++++genericContainer ignored htmlTag='g'
++++++++++genericContainer ++++++++++genericContainer
++++++++++++staticText name='Group 2 Text 1' ++++++++++++staticText name='Group 2 Text 1'
++++++++++++++inlineTextBox name='Group 2 Text 1' ++++++++++++++inlineTextBox name='Group 2 Text 1'
\ No newline at end of file
rootWebArea
++genericContainer ignored
++++genericContainer
++++++svgRoot name='svg'
++++++++genericContainer htmlTag='g'
++++++++++genericContainer
++++++++++++staticText name='Group 1 Text 1'
++++++++++++++inlineTextBox name='Group 1 Text 1'
++++++++++genericContainer
++++++++++++staticText name='Group 1 Text 2'
++++++++++++++inlineTextBox name='Group 1 Text 2'
++++++++genericContainer htmlTag='g'
++++++++++genericContainer
++++++++++++staticText name='Group 2 Text 1'
++++++++++++++inlineTextBox name='Group 2 Text 1'
\ No newline at end of file
<!--
@BLINK-ALLOW:htmlTag='g'
-->
<!DOCTYPE html>
<html>
<body>
<svg aria-label="svg">
<g>
<text x="10" y="10" fill="red">Group 1 Text 1</text>
<text x="10" y="100" fill="red">Group 1 Text 2</text>
</g>
<g>
<text x="200" y="10" fill="red">Group 2 Text 1</text>
</g>
</svg>
</body>
</html>
...@@ -17,4 +17,3 @@ ...@@ -17,4 +17,3 @@
</body> </body>
</html> </html>
...@@ -298,6 +298,7 @@ class WebSettings { ...@@ -298,6 +298,7 @@ class WebSettings {
virtual void SetAriaModalPrunesAXTree(bool) = 0; virtual void SetAriaModalPrunesAXTree(bool) = 0;
virtual void SetUseAXMenuList(bool) = 0; virtual void SetUseAXMenuList(bool) = 0;
virtual void SetSelectionClipboardBufferAvailable(bool) = 0; virtual void SetSelectionClipboardBufferAvailable(bool) = 0;
virtual void SetAccessibilityIncludeSvgGElement(bool) = 0;
protected: protected:
~WebSettings() = default; ~WebSettings() = default;
......
...@@ -788,6 +788,10 @@ void WebSettingsImpl::SetSelectionClipboardBufferAvailable(bool available) { ...@@ -788,6 +788,10 @@ void WebSettingsImpl::SetSelectionClipboardBufferAvailable(bool available) {
settings_->SetSelectionClipboardBufferAvailable(available); settings_->SetSelectionClipboardBufferAvailable(available);
} }
void WebSettingsImpl::SetAccessibilityIncludeSvgGElement(bool include) {
settings_->SetAccessibilityIncludeSvgGElement(include);
}
STATIC_ASSERT_ENUM(WebSettings::ImageAnimationPolicy::kAllowed, STATIC_ASSERT_ENUM(WebSettings::ImageAnimationPolicy::kAllowed,
kImageAnimationPolicyAllowed); kImageAnimationPolicyAllowed);
STATIC_ASSERT_ENUM(WebSettings::ImageAnimationPolicy::kAnimateOnce, STATIC_ASSERT_ENUM(WebSettings::ImageAnimationPolicy::kAnimateOnce,
......
...@@ -225,6 +225,7 @@ class CORE_EXPORT WebSettingsImpl final : public WebSettings { ...@@ -225,6 +225,7 @@ class CORE_EXPORT WebSettingsImpl final : public WebSettings {
void SetAriaModalPrunesAXTree(bool) override; void SetAriaModalPrunesAXTree(bool) override;
void SetUseAXMenuList(bool) override; void SetUseAXMenuList(bool) override;
void SetSelectionClipboardBufferAvailable(bool) override; void SetSelectionClipboardBufferAvailable(bool) override;
void SetAccessibilityIncludeSvgGElement(bool) override;
bool RenderVSyncNotificationEnabled() const { bool RenderVSyncNotificationEnabled() const {
return render_v_sync_notification_enabled_; return render_v_sync_notification_enabled_;
......
...@@ -1091,5 +1091,10 @@ ...@@ -1091,5 +1091,10 @@
initial: false, initial: false,
type: "bool", type: "bool",
}, },
{
name: "accessibilityIncludeSvgGElement",
initial: false,
type: "bool",
},
], ],
} }
...@@ -85,6 +85,7 @@ ...@@ -85,6 +85,7 @@
#include "third_party/blink/renderer/core/style/computed_style_constants.h" #include "third_party/blink/renderer/core/style/computed_style_constants.h"
#include "third_party/blink/renderer/core/svg/graphics/svg_image.h" #include "third_party/blink/renderer/core/svg/graphics/svg_image.h"
#include "third_party/blink/renderer/core/svg/svg_document_extensions.h" #include "third_party/blink/renderer/core/svg/svg_document_extensions.h"
#include "third_party/blink/renderer/core/svg/svg_g_element.h"
#include "third_party/blink/renderer/core/svg/svg_svg_element.h" #include "third_party/blink/renderer/core/svg/svg_svg_element.h"
#include "third_party/blink/renderer/modules/accessibility/ax_image_map_link.h" #include "third_party/blink/renderer/modules/accessibility/ax_image_map_link.h"
#include "third_party/blink/renderer/modules/accessibility/ax_inline_text_box.h" #include "third_party/blink/renderer/modules/accessibility/ax_inline_text_box.h"
...@@ -746,6 +747,14 @@ bool AXLayoutObject::ComputeAccessibilityIsIgnored( ...@@ -746,6 +747,14 @@ bool AXLayoutObject::ComputeAccessibilityIsIgnored(
return true; return true;
} }
// If setting enabled, do not ignore SVG grouping (<g>) elements.
if (IsA<SVGGElement>(GetNode())) {
Settings* settings = GetDocument()->GetSettings();
if (settings->GetAccessibilityIncludeSvgGElement()) {
return false;
}
}
// By default, objects should be ignored so that the AX hierarchy is not // By default, objects should be ignored so that the AX hierarchy is not
// filled with unnecessary items. // filled with unnecessary items.
if (ignored_reasons) if (ignored_reasons)
......
<!DOCTYPE HTML>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script>
if (window.internals)
internals.settings.setAccessibilityIncludeSvgGElement(false);
</script>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="g1">
<text>Group 1 Text 1</text>
<text>Group 1 Text 2</text>
</g>
<g id="g2">
<text>Group 2 Text 1</text>
</g>
</svg>
<script>
test(function(t) {
var axGroup1 = accessibilityController.accessibleElementById('g1');
assert_equals(axGroup1.role, 'AXRole: AXGenericContainer');
assert_equals(axGroup1.childAtIndex(0).role, 'AXRole: AXGenericContainer');
assert_true(axGroup1.isIgnored);
var axGroup2 = accessibilityController.accessibleElementById('g2');
assert_equals(axGroup2.role, 'AXRole: AXGenericContainer');
assert_equals(axGroup2.childAtIndex(0).role, 'AXRole: AXGenericContainer');
assert_true(axGroup2.isIgnored);
}, 'When AccessibilityIncludeSvgGElement disabled, SVG groups are ignored');
</script>
\ No newline at end of file
<!DOCTYPE HTML>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script>
if (window.internals)
internals.settings.setAccessibilityIncludeSvgGElement(true);
</script>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="g1">
<text>Group 1 Text 1</text>
<text>Group 1 Text 2</text>
</g>
<g id="g2">
<text>Group 2 Text 1</text>
</g>
</svg>
<script>
test(function(t) {
var axGroup1 = accessibilityController.accessibleElementById('g1');
assert_equals(axGroup1.role, 'AXRole: AXGenericContainer');
assert_equals(axGroup1.childAtIndex(0).role, 'AXRole: AXGenericContainer');
assert_false(axGroup1.isIgnored);
var axGroup2 = accessibilityController.accessibleElementById('g2');
assert_equals(axGroup2.role, 'AXRole: AXGenericContainer');
assert_equals(axGroup2.childAtIndex(0).role, 'AXRole: AXGenericContainer');
assert_false(axGroup2.isIgnored);
}, 'When AccessibilityIncludeSvgGElement enabled, SVG groups are preserved and not ignored');
</script>
\ No newline at end of file
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