Commit fb9ee865 authored by Aaron Leventhal's avatar Aaron Leventhal Committed by Commit Bot

Do not block a11y events on trimmed Android text nodes

Do not suppress events on descendants of leaf nodes on Android, otherwise
necessary events are not fired. This is because Android treats a lot more
nodes as leaves.

Bug: 907866
Change-Id: If93d55747249d9084c57a091647f8d4860df6d3c
Reviewed-on: https://chromium-review.googlesource.com/c/1351494Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Commit-Queue: Dominic Mazzoni <dmazzoni@chromium.org>
Commit-Queue: Aaron Leventhal <aleventhal@chromium.org>
Cr-Commit-Position: refs/heads/master@{#611260}
parent 9db27e0d
...@@ -73,6 +73,11 @@ bool BrowserAccessibility::PlatformIsLeaf() const { ...@@ -73,6 +73,11 @@ bool BrowserAccessibility::PlatformIsLeaf() const {
} }
} }
bool BrowserAccessibility::CanFireEvents() const {
// Allow events unless this object would be trimmed away.
return !PlatformIsChildOfLeaf();
}
uint32_t BrowserAccessibility::PlatformChildCount() const { uint32_t BrowserAccessibility::PlatformChildCount() const {
if (HasStringAttribute(ax::mojom::StringAttribute::kChildTreeId)) { if (HasStringAttribute(ax::mojom::StringAttribute::kChildTreeId)) {
AXTreeID child_tree_id = AXTreeID::FromString( AXTreeID child_tree_id = AXTreeID::FromString(
......
...@@ -114,6 +114,9 @@ class CONTENT_EXPORT BrowserAccessibility : public ui::AXPlatformNodeDelegate { ...@@ -114,6 +114,9 @@ class CONTENT_EXPORT BrowserAccessibility : public ui::AXPlatformNodeDelegate {
// that might send notifications. // that might send notifications.
virtual bool PlatformIsLeaf() const; virtual bool PlatformIsLeaf() const;
// Returns true if this object can fire events.
virtual bool CanFireEvents() const;
// Returns the number of children of this object, or 0 if PlatformIsLeaf() // Returns the number of children of this object, or 0 if PlatformIsLeaf()
// returns true. // returns true.
virtual uint32_t PlatformChildCount() const; virtual uint32_t PlatformChildCount() const;
......
...@@ -209,6 +209,10 @@ bool BrowserAccessibilityAndroid::PlatformIsLeaf() const { ...@@ -209,6 +209,10 @@ bool BrowserAccessibilityAndroid::PlatformIsLeaf() const {
return false; return false;
} }
bool BrowserAccessibilityAndroid::CanFireEvents() const {
return true;
}
bool BrowserAccessibilityAndroid::IsCheckable() const { bool BrowserAccessibilityAndroid::IsCheckable() const {
return HasIntAttribute(ax::mojom::IntAttribute::kCheckedState); return HasIntAttribute(ax::mojom::IntAttribute::kCheckedState);
} }
......
...@@ -27,6 +27,8 @@ class CONTENT_EXPORT BrowserAccessibilityAndroid : public BrowserAccessibility { ...@@ -27,6 +27,8 @@ class CONTENT_EXPORT BrowserAccessibilityAndroid : public BrowserAccessibility {
base::string16 GetValue() const override; base::string16 GetValue() const override;
bool PlatformIsLeaf() const override; bool PlatformIsLeaf() const override;
// Android needs events even on objects that are trimmed away.
bool CanFireEvents() const override;
bool IsCheckable() const; bool IsCheckable() const;
bool IsChecked() const; bool IsChecked() const;
......
...@@ -376,7 +376,7 @@ void BrowserAccessibilityManager::OnAccessibilityEvents( ...@@ -376,7 +376,7 @@ void BrowserAccessibilityManager::OnAccessibilityEvents(
// Fire any events related to changes to the tree. // Fire any events related to changes to the tree.
for (auto targeted_event : *this) { for (auto targeted_event : *this) {
BrowserAccessibility* event_target = GetFromAXNode(targeted_event.node); BrowserAccessibility* event_target = GetFromAXNode(targeted_event.node);
if (!event_target || event_target->PlatformIsChildOfLeaf()) if (!event_target || !event_target->CanFireEvents())
continue; continue;
FireGeneratedEvent(targeted_event.event_params.event, event_target); FireGeneratedEvent(targeted_event.event_params.event, event_target);
...@@ -389,7 +389,7 @@ void BrowserAccessibilityManager::OnAccessibilityEvents( ...@@ -389,7 +389,7 @@ void BrowserAccessibilityManager::OnAccessibilityEvents(
// Fire the native event. // Fire the native event.
BrowserAccessibility* event_target = GetFromID(event.id); BrowserAccessibility* event_target = GetFromID(event.id);
if (!event_target || event_target->PlatformIsChildOfLeaf()) if (!event_target || !event_target->CanFireEvents())
return; return;
if (event.event_type == ax::mojom::Event::kHover) if (event.event_type == ax::mojom::Event::kHover)
......
...@@ -191,7 +191,7 @@ void BrowserAccessibilityManagerWin::FireGeneratedEvent( ...@@ -191,7 +191,7 @@ void BrowserAccessibilityManagerWin::FireGeneratedEvent(
void BrowserAccessibilityManagerWin::FireWinAccessibilityEvent( void BrowserAccessibilityManagerWin::FireWinAccessibilityEvent(
LONG win_event_type, LONG win_event_type,
BrowserAccessibility* node) { BrowserAccessibility* node) {
if (node->PlatformIsChildOfLeaf()) if (!node->CanFireEvents())
return; return;
// If there's no root delegate, this may be a new frame that hasn't // If there's no root delegate, this may be a new frame that hasn't
......
// Copyright (c) 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/browser/accessibility/browser_accessibility.h"
#include "build/build_config.h"
#include "content/browser/accessibility/browser_accessibility_manager.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace content {
class BrowserAccessibilityTest : public testing::Test {
public:
BrowserAccessibilityTest();
~BrowserAccessibilityTest() override;
private:
DISALLOW_COPY_AND_ASSIGN(BrowserAccessibilityTest);
};
BrowserAccessibilityTest::BrowserAccessibilityTest() {}
BrowserAccessibilityTest::~BrowserAccessibilityTest() {}
TEST_F(BrowserAccessibilityTest, TestCanFireEvents) {
ui::AXNodeData text1;
text1.id = 111;
text1.role = ax::mojom::Role::kStaticText;
text1.SetName("One two three.");
ui::AXNodeData para1;
para1.id = 11;
para1.role = ax::mojom::Role::kParagraph;
para1.child_ids.push_back(text1.id);
ui::AXNodeData root;
root.id = 1;
root.role = ax::mojom::Role::kRootWebArea;
root.child_ids.push_back(para1.id);
std::unique_ptr<BrowserAccessibilityManager> manager(
BrowserAccessibilityManager::Create(MakeAXTreeUpdate(root, para1, text1),
nullptr,
new BrowserAccessibilityFactory()));
BrowserAccessibility* root_obj = manager->GetRoot();
EXPECT_FALSE(root_obj->PlatformIsLeaf());
EXPECT_TRUE(root_obj->CanFireEvents());
BrowserAccessibility* para_obj = root_obj->PlatformGetChild(0);
EXPECT_TRUE(para_obj->CanFireEvents());
#if defined(OS_ANDROID)
EXPECT_TRUE(para_obj->PlatformIsLeaf());
#else
EXPECT_FALSE(para_obj->PlatformIsLeaf());
#endif
BrowserAccessibility* text_obj = manager->GetFromID(111);
EXPECT_TRUE(text_obj->PlatformIsLeaf());
EXPECT_TRUE(text_obj->CanFireEvents());
manager.reset();
}
} // namespace content
...@@ -1298,6 +1298,7 @@ test("content_unittests") { ...@@ -1298,6 +1298,7 @@ test("content_unittests") {
sources = [ sources = [
"../browser/accessibility/browser_accessibility_mac_unittest.mm", "../browser/accessibility/browser_accessibility_mac_unittest.mm",
"../browser/accessibility/browser_accessibility_manager_unittest.cc", "../browser/accessibility/browser_accessibility_manager_unittest.cc",
"../browser/accessibility/browser_accessibility_unittest.cc",
"../browser/accessibility/browser_accessibility_win_unittest.cc", "../browser/accessibility/browser_accessibility_win_unittest.cc",
"../browser/accessibility/one_shot_accessibility_tree_search_unittest.cc", "../browser/accessibility/one_shot_accessibility_tree_search_unittest.cc",
"../browser/appcache/appcache_database_unittest.cc", "../browser/appcache/appcache_database_unittest.cc",
......
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