Skip to content

Commit efc9001

Browse files
author
wutao
committed
M66 merge: Make TabbedPane a11y work properly in CrOS.
This patch makes the a11y work properly in Chrome OS. 1. "search + space" can select a tab. 2. "search + left arrow" navigating tabs can get correct label text. 3. Use up/down arrows to navigate tabs in vertical mode. [email protected],[email protected],[email protected] Bug: 817709, 768932 Test: tested on device and passed TabbedPaneTest. Change-Id: I052e60428bf123f3346fae9bbb3255c172e42fd8 Reviewed-on: https://chromium-review.googlesource.com/942693 Commit-Queue: Tao Wu <[email protected]> Reviewed-by: Trent Apted <[email protected]> Reviewed-by: Michael Wasserman <[email protected]> Reviewed-by: Dominic Mazzoni <[email protected]> Cr-Original-Commit-Position: refs/heads/master@{#540449}(cherry picked from commit a3ca0ea) Reviewed-on: https://chromium-review.googlesource.com/952872 Reviewed-by: Tao Wu <[email protected]> Cr-Commit-Position: refs/branch-heads/3359@{#65} Cr-Branched-From: 66afc5e-refs/heads/master@{#540276}
1 parent 1e83273 commit efc9001

File tree

1 file changed

+27
-31
lines changed

1 file changed

+27
-31
lines changed

ui/views/controls/tabbed_pane/tabbed_pane.cc

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "ui/gfx/font_list.h"
2222
#include "ui/gfx/geometry/insets.h"
2323
#include "ui/native_theme/native_theme.h"
24+
#include "ui/views/accessibility/view_accessibility.h"
2425
#include "ui/views/border.h"
2526
#include "ui/views/controls/label.h"
2627
#include "ui/views/controls/tabbed_pane/tabbed_pane_listener.h"
@@ -61,24 +62,6 @@ constexpr int kLabelFontSizeDeltaHighlight = 1;
6162
const int kHarmonyTabStripTabHeight = 32;
6263
constexpr int kBorderThickness = 2;
6364

64-
// The View containing the text for each tab in the tab strip.
65-
class TabLabel : public Label {
66-
public:
67-
explicit TabLabel(const base::string16& tab_title)
68-
: Label(tab_title, style::CONTEXT_LABEL, style::STYLE_TAB_ACTIVE) {}
69-
70-
// Label:
71-
void GetAccessibleNodeData(ui::AXNodeData* data) override {
72-
// views::Tab shouldn't expose any of its children in the a11y tree.
73-
// Instead, it should provide the a11y information itself. Normally,
74-
// non-keyboard-focusable children of keyboard-focusable parents are
75-
// ignored, but Tabs only mark the currently selected tab as
76-
// keyboard-focusable. This means all unselected Tabs expose their children
77-
// to the a11y tree. To fix, manually ignore the children.
78-
data->role = ax::mojom::Role::kIgnored;
79-
}
80-
};
81-
8265
} // namespace
8366

8467
// static
@@ -141,7 +124,7 @@ const char Tab::kViewClassName[] = "Tab";
141124

142125
Tab::Tab(TabbedPane* tabbed_pane, const base::string16& title, View* contents)
143126
: tabbed_pane_(tabbed_pane),
144-
title_(new TabLabel(title)),
127+
title_(new Label(title, style::CONTEXT_LABEL, style::STYLE_TAB_ACTIVE)),
145128
tab_state_(TAB_ACTIVE),
146129
contents_(contents) {
147130
// Calculate the size while the font list is bold.
@@ -172,6 +155,10 @@ Tab::Tab(TabbedPane* tabbed_pane, const base::string16& title, View* contents)
172155
// Calculate the size while the font list is normal and set the max size.
173156
preferred_title_size_.SetToMax(title_->GetPreferredSize());
174157
AddChildView(title_);
158+
159+
// Use leaf so that name is spoken by screen reader without exposing the
160+
// children.
161+
GetViewAccessibility().OverrideIsLeaf();
175162
}
176163

177164
Tab::~Tab() {}
@@ -195,6 +182,10 @@ void Tab::OnStateChanged() {
195182
: ui::kLabelFontSizeDelta;
196183
switch (tab_state_) {
197184
case TAB_INACTIVE:
185+
// Notify assistive tools to update this tab's selected status.
186+
// The way Chrome OS accessibility is implemented right now, firing almost
187+
// any event will work, we just need to trigger its state to be refreshed.
188+
NotifyAccessibilityEvent(ax::mojom::Event::kCheckedStateChanged, true);
198189
title_->SetEnabledColor(is_highlight_mode
199190
? kTabTitleColor_InactiveHighlight
200191
: kTabTitleColor_InactiveBorder);
@@ -219,8 +210,7 @@ void Tab::OnStateChanged() {
219210
}
220211

221212
bool Tab::OnMousePressed(const ui::MouseEvent& event) {
222-
if (event.IsOnlyLeftMouseButton() &&
223-
GetLocalBounds().Contains(event.location()))
213+
if (enabled() && event.IsOnlyLeftMouseButton())
224214
tabbed_pane_->SelectTab(this);
225215
return true;
226216
}
@@ -302,13 +292,12 @@ void Tab::GetAccessibleNodeData(ui::AXNodeData* data) {
302292
}
303293

304294
bool Tab::HandleAccessibleAction(const ui::AXActionData& action_data) {
305-
if (action_data.action != ax::mojom::Action::kSetSelection || !enabled())
306-
return false;
307-
308-
// It's not clear what should happen if a tab is 'deselected', so the
309-
// ax::mojom::Action::kSetSelection action will always select the tab.
310-
tabbed_pane_->SelectTab(this);
311-
return true;
295+
// If the assistive tool sends kSetSelection, handle it like kDoDefault.
296+
// These generate a click event handled in Tab::OnMousePressed.
297+
ui::AXActionData action_data_copy(action_data);
298+
if (action_data.action == ax::mojom::Action::kSetSelection)
299+
action_data_copy.action = ax::mojom::Action::kDoDefault;
300+
return View::HandleAccessibleAction(action_data_copy);
312301
}
313302

314303
void Tab::OnFocus() {
@@ -329,9 +318,16 @@ void Tab::OnBlur() {
329318

330319
bool Tab::OnKeyPressed(const ui::KeyEvent& event) {
331320
ui::KeyboardCode key = event.key_code();
332-
if (key != ui::VKEY_LEFT && key != ui::VKEY_RIGHT)
333-
return false;
334-
return tabbed_pane_->MoveSelectionBy(key == ui::VKEY_RIGHT ? 1 : -1);
321+
const bool is_horizontal =
322+
tabbed_pane_->GetOrientation() == TabbedPane::Orientation::kHorizontal;
323+
// Use left and right arrows to navigate tabs in horizontal orientation.
324+
if (is_horizontal) {
325+
return (key == ui::VKEY_LEFT || key == ui::VKEY_RIGHT) &&
326+
tabbed_pane_->MoveSelectionBy(key == ui::VKEY_RIGHT ? 1 : -1);
327+
}
328+
// Use up and down arrows to navigate tabs in vertical orientation.
329+
return (key == ui::VKEY_UP || key == ui::VKEY_DOWN) &&
330+
tabbed_pane_->MoveSelectionBy(key == ui::VKEY_DOWN ? 1 : -1);
335331
}
336332

337333
MdTab::MdTab(TabbedPane* tabbed_pane,

0 commit comments

Comments
 (0)