Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(272)

Unified Diff: ui/views/controls/tabbed_pane/tabbed_pane.cc

Issue 2578303003: a11y: Add a11y information to views::Tab and manually ignore its a11y children. (Closed)
Patch Set: Add tests. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/views/controls/tabbed_pane/tabbed_pane.cc
diff --git a/ui/views/controls/tabbed_pane/tabbed_pane.cc b/ui/views/controls/tabbed_pane/tabbed_pane.cc
index f36f68083227ffe0517ac13fcd8a703def3e8bff..bd4564bcd66512c29966f79b85672e81d2c6e2fa 100644
--- a/ui/views/controls/tabbed_pane/tabbed_pane.cc
+++ b/ui/views/controls/tabbed_pane/tabbed_pane.cc
@@ -8,6 +8,7 @@
#include "base/macros.h"
#include "third_party/skia/include/core/SkPaint.h"
#include "third_party/skia/include/core/SkPath.h"
+#include "ui/accessibility/ax_action_data.h"
#include "ui/accessibility/ax_node_data.h"
#include "ui/base/default_style.h"
#include "ui/base/material_design/material_design_controller.h"
@@ -27,6 +28,8 @@
#include "ui/views/layout/layout_manager.h"
#include "ui/views/widget/widget.h"
+namespace views {
+
namespace {
// TODO(markusheintz|msw): Use NativeTheme colors.
@@ -42,9 +45,29 @@ const gfx::Font::Weight kInactiveWeight = gfx::Font::Weight::NORMAL;
const int kHarmonyTabStripTabHeight = 40;
-} // namespace
+// The View containing the text for each tab in the tab strip.
+class TabLabel : public Label {
+ public:
+ explicit TabLabel(const base::string16& tab_title)
+ : Label(tab_title,
+ ui::ResourceBundle::GetSharedInstance().GetFontListWithDelta(
+ ui::kLabelFontSizeDelta,
+ gfx::Font::NORMAL,
+ kActiveWeight)) {}
+
+ // Label:
+ void GetAccessibleNodeData(ui::AXNodeData* data) override {
+ // views::Tab shouldn't expose any of its children in the a11y tree.
+ // Instead, it should provide the a11y information itself. Normally,
+ // non-keyboard-focusable children of keyboard-focusable parents are
+ // ignored, but Tabs only mark the currently selected tab as
+ // keyboard-focusable. This means all unselected Tabs expose their children
+ // to the a11y tree. To fix, manually ignore the children.
+ data->role = ui::AX_ROLE_IGNORED;
+ }
+};
-namespace views {
+} // namespace
// static
const char TabbedPane::kViewClassName[] = "TabbedPane";
@@ -132,12 +155,7 @@ const char Tab::kViewClassName[] = "Tab";
Tab::Tab(TabbedPane* tabbed_pane, const base::string16& title, View* contents)
: tabbed_pane_(tabbed_pane),
- title_(new Label(
- title,
- ui::ResourceBundle::GetSharedInstance().GetFontListWithDelta(
- ui::kLabelFontSizeDelta,
- gfx::Font::NORMAL,
- kActiveWeight))),
+ title_(new TabLabel(title)),
tab_state_(TAB_ACTIVE),
contents_(contents) {
// Calculate this now while the font list is guaranteed to be bold.
@@ -238,6 +256,23 @@ void Tab::SetState(TabState tab_state) {
SchedulePaint();
}
+void Tab::GetAccessibleNodeData(ui::AXNodeData* data) {
+ data->role = ui::AX_ROLE_TAB;
+ data->SetName(title()->text());
+ data->AddStateFlag(ui::AX_STATE_SELECTABLE);
+ if (selected())
+ data->AddStateFlag(ui::AX_STATE_SELECTED);
+}
+
+bool Tab::HandleAccessibleAction(const ui::AXActionData& action_data) {
+ if (action_data.action != ui::AX_ACTION_SET_SELECTION || !enabled())
+ return false;
+ // It's not clear what should happen if a tab is 'deselected', so having the
+ // AX_ACTION_SET_SELECTION action always selects the tab.
+ tabbed_pane_->SelectTab(this);
+ return true;
+}
+
void Tab::OnFocus() {
OnStateChanged();
// When the tab gains focus, send an accessibility event indicating that the

Powered by Google App Engine
This is Rietveld 408576698