Commit 6010f1c3 authored by Akihiro Ota's avatar Akihiro Ota Committed by Commit Bot

Make SVG elements in Chrome clickable by assistive technology.

This change implements the AccessKeyAction method for SVG elements
to make them clickable by assistive technologies.

Bug: 958553
Change-Id: I604379586fe866e666216fe58b703c157457b27f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1691325
Commit-Queue: Akihiro Ota <akihiroota@chromium.org>
Reviewed-by: default avatarNektarios Paisios <nektar@chromium.org>
Reviewed-by: default avatarJochen Eisinger <jochen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#678029}
parent 2c666ad3
......@@ -801,4 +801,34 @@ IN_PROC_BROWSER_TEST_F(AccessibilityActionBrowserTest, ScrollIntoView) {
}
#endif // !defined(OS_ANDROID)
IN_PROC_BROWSER_TEST_F(AccessibilityActionBrowserTest, ClickSVG) {
// Create an svg link element that has the shape of a small, red square.
LoadInitialAccessibilityTreeFromHtml(R"HTML(
<svg aria-label="svg" width="10" height="10" viewBox="0 0 10 10"
onclick="(function() {
let para = document.createElement('p');
para.innerHTML = 'SVG link was clicked!';
document.body.appendChild(para);})()">
<a xlink:href="#">
<path fill-opacity="1" fill="#ff0000"
d="M 0 0 L 10 0 L 10 10 L 0 10 Z"></path>
</a>
</svg>
)HTML");
AccessibilityNotificationWaiter click_waiter(
shell()->web_contents(), ui::kAXModeComplete, ax::mojom::Event::kClicked);
BrowserAccessibility* target_node =
FindNode(ax::mojom::Role::kSvgRoot, "svg");
ASSERT_NE(target_node, nullptr);
GetManager()->DoDefaultAction(*target_node);
click_waiter.WaitForNotification();
#if !defined(OS_ANDROID)
// This waiter times out on some Android try bots.
// TODO(akihiroota): Refactor test to be applicable to all platforms.
WaitForAccessibilityTreeToContainNodeWithName(shell()->web_contents(),
"SVG link was clicked!");
#endif // !defined(OS_ANDROID)
}
} // namespace content
......@@ -1328,4 +1328,9 @@ void SVGElement::Trace(blink::Visitor* visitor) {
Element::Trace(visitor);
}
void SVGElement::AccessKeyAction(bool send_mouse_events) {
DispatchSimulatedClick(
nullptr, send_mouse_events ? kSendMouseUpDownEvents : kSendNoEvents);
}
} // namespace blink
......@@ -264,6 +264,8 @@ class CORE_EXPORT SVGElement : public Element {
void RemovedEventListener(const AtomicString& event_type,
const RegisteredEventListener&) final;
void AccessKeyAction(bool send_mouse_events) override;
private:
bool IsSVGElement() const =
delete; // This will catch anyone doing an unnecessary check.
......
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