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

Side by Side 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: Rebase back onto origin/master. Created 4 years 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 unified diff | Download patch
« no previous file with comments | « ui/views/controls/tabbed_pane/tabbed_pane.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/views/controls/tabbed_pane/tabbed_pane.h" 5 #include "ui/views/controls/tabbed_pane/tabbed_pane.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "third_party/skia/include/core/SkPaint.h" 9 #include "third_party/skia/include/core/SkPaint.h"
10 #include "third_party/skia/include/core/SkPath.h" 10 #include "third_party/skia/include/core/SkPath.h"
11 #include "ui/accessibility/ax_node_data.h" 11 #include "ui/accessibility/ax_node_data.h"
12 #include "ui/base/default_style.h" 12 #include "ui/base/default_style.h"
13 #include "ui/base/material_design/material_design_controller.h" 13 #include "ui/base/material_design/material_design_controller.h"
14 #include "ui/base/resource/resource_bundle.h" 14 #include "ui/base/resource/resource_bundle.h"
15 #include "ui/events/keycodes/keyboard_codes.h" 15 #include "ui/events/keycodes/keyboard_codes.h"
16 #include "ui/gfx/animation/animation_delegate.h" 16 #include "ui/gfx/animation/animation_delegate.h"
17 #include "ui/gfx/animation/linear_animation.h" 17 #include "ui/gfx/animation/linear_animation.h"
18 #include "ui/gfx/animation/tween.h" 18 #include "ui/gfx/animation/tween.h"
19 #include "ui/gfx/canvas.h" 19 #include "ui/gfx/canvas.h"
20 #include "ui/gfx/font_list.h" 20 #include "ui/gfx/font_list.h"
21 #include "ui/native_theme/native_theme.h" 21 #include "ui/native_theme/native_theme.h"
22 #include "ui/views/border.h" 22 #include "ui/views/border.h"
23 #include "ui/views/controls/label.h" 23 #include "ui/views/controls/label.h"
24 #include "ui/views/controls/tabbed_pane/tabbed_pane_listener.h" 24 #include "ui/views/controls/tabbed_pane/tabbed_pane_listener.h"
25 #include "ui/views/layout/box_layout.h" 25 #include "ui/views/layout/box_layout.h"
26 #include "ui/views/layout/fill_layout.h" 26 #include "ui/views/layout/fill_layout.h"
27 #include "ui/views/layout/layout_manager.h" 27 #include "ui/views/layout/layout_manager.h"
28 #include "ui/views/widget/widget.h" 28 #include "ui/views/widget/widget.h"
29 29
30 namespace views {
31
30 namespace { 32 namespace {
31 33
32 // TODO(markusheintz|msw): Use NativeTheme colors. 34 // TODO(markusheintz|msw): Use NativeTheme colors.
33 const SkColor kTabTitleColor_Inactive = SkColorSetRGB(0x64, 0x64, 0x64); 35 const SkColor kTabTitleColor_Inactive = SkColorSetRGB(0x64, 0x64, 0x64);
34 const SkColor kTabTitleColor_Active = SK_ColorBLACK; 36 const SkColor kTabTitleColor_Active = SK_ColorBLACK;
35 const SkColor kTabTitleColor_Hovered = SK_ColorBLACK; 37 const SkColor kTabTitleColor_Hovered = SK_ColorBLACK;
36 const SkColor kTabBorderColor = SkColorSetRGB(0xC8, 0xC8, 0xC8); 38 const SkColor kTabBorderColor = SkColorSetRGB(0xC8, 0xC8, 0xC8);
37 const SkScalar kTabBorderThickness = 1.0f; 39 const SkScalar kTabBorderThickness = 1.0f;
38 40
39 const gfx::Font::Weight kHoverWeight = gfx::Font::Weight::NORMAL; 41 const gfx::Font::Weight kHoverWeight = gfx::Font::Weight::NORMAL;
40 const gfx::Font::Weight kActiveWeight = gfx::Font::Weight::BOLD; 42 const gfx::Font::Weight kActiveWeight = gfx::Font::Weight::BOLD;
41 const gfx::Font::Weight kInactiveWeight = gfx::Font::Weight::NORMAL; 43 const gfx::Font::Weight kInactiveWeight = gfx::Font::Weight::NORMAL;
42 44
43 const int kHarmonyTabStripTabHeight = 40; 45 const int kHarmonyTabStripTabHeight = 40;
44 46
47 // views::Tab shouldn't expose any of its children in the a11y tree. Instead, it
48 // should provide the a11y information itself. Normally, non-keyboard-focusable
49 // children of keyboard-focusable parents are ignored, but Tabs only mark the
50 // currently selected tab as keyboard-focusable. This means all unselected Tabs
51 // expose their children to the a11y tree. To fix, manually ignore the children.
52 class IgnoredLabel : public Label {
Patti Lor 2016/12/22 00:20:30 Alternatively, we could add a method onto NativeVi
tapted 2016/12/22 00:50:09 This looks good.
Patti Lor 2016/12/30 00:35:02 Ok, thanks! :)
53 public:
54 IgnoredLabel(const base::string16& text, const gfx::FontList& font_list)
tapted 2016/12/22 00:50:08 Can we call this TabLabel? And move the font_list
Patti Lor 2016/12/30 00:35:02 Done.
55 : Label(text, font_list) {}
56
57 void GetAccessibleNodeData(ui::AXNodeData* data) override {
58 data->role = ui::AX_ROLE_IGNORED;
59 }
60 };
61
45 } // namespace 62 } // namespace
46 63
47 namespace views {
48
49 // static 64 // static
50 const char TabbedPane::kViewClassName[] = "TabbedPane"; 65 const char TabbedPane::kViewClassName[] = "TabbedPane";
51 66
52 // A subclass of Tab that implements the Harmony visual styling. 67 // A subclass of Tab that implements the Harmony visual styling.
53 class MdTab : public Tab { 68 class MdTab : public Tab {
54 public: 69 public:
55 MdTab(TabbedPane* tabbed_pane, const base::string16& title, View* contents); 70 MdTab(TabbedPane* tabbed_pane, const base::string16& title, View* contents);
56 ~MdTab() override; 71 ~MdTab() override;
57 72
58 // Overridden from Tab: 73 // Overridden from Tab:
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 gfx::Range animating_to_; 140 gfx::Range animating_to_;
126 141
127 DISALLOW_COPY_AND_ASSIGN(MdTabStrip); 142 DISALLOW_COPY_AND_ASSIGN(MdTabStrip);
128 }; 143 };
129 144
130 // static 145 // static
131 const char Tab::kViewClassName[] = "Tab"; 146 const char Tab::kViewClassName[] = "Tab";
132 147
133 Tab::Tab(TabbedPane* tabbed_pane, const base::string16& title, View* contents) 148 Tab::Tab(TabbedPane* tabbed_pane, const base::string16& title, View* contents)
134 : tabbed_pane_(tabbed_pane), 149 : tabbed_pane_(tabbed_pane),
135 title_(new Label( 150 title_(new IgnoredLabel(
136 title, 151 title,
137 ui::ResourceBundle::GetSharedInstance().GetFontListWithDelta( 152 ui::ResourceBundle::GetSharedInstance().GetFontListWithDelta(
138 ui::kLabelFontSizeDelta, 153 ui::kLabelFontSizeDelta,
139 gfx::Font::NORMAL, 154 gfx::Font::NORMAL,
140 kActiveWeight))), 155 kActiveWeight))),
141 tab_state_(TAB_ACTIVE), 156 tab_state_(TAB_ACTIVE),
142 contents_(contents) { 157 contents_(contents) {
143 // Calculate this now while the font list is guaranteed to be bold. 158 // Calculate this now while the font list is guaranteed to be bold.
144 preferred_title_size_ = title_->GetPreferredSize(); 159 preferred_title_size_ = title_->GetPreferredSize();
145 160
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 } 246 }
232 247
233 void Tab::SetState(TabState tab_state) { 248 void Tab::SetState(TabState tab_state) {
234 if (tab_state == tab_state_) 249 if (tab_state == tab_state_)
235 return; 250 return;
236 tab_state_ = tab_state; 251 tab_state_ = tab_state;
237 OnStateChanged(); 252 OnStateChanged();
238 SchedulePaint(); 253 SchedulePaint();
239 } 254 }
240 255
256 void Tab::GetAccessibleNodeData(ui::AXNodeData* data) {
257 data->role = ui::AX_ROLE_TAB;
258 data->SetName(title()->text());
259 data->AddStateFlag(ui::AX_STATE_SELECTABLE);
260 }
tapted 2016/12/22 00:50:08 Are there more things we should add that NSSegment
Patti Lor 2016/12/30 00:35:02 Good point - I've added ui::AX_STATE_SELECTED => A
261
241 void Tab::OnFocus() { 262 void Tab::OnFocus() {
242 OnStateChanged(); 263 OnStateChanged();
243 // When the tab gains focus, send an accessibility event indicating that the 264 // When the tab gains focus, send an accessibility event indicating that the
244 // contents are focused. When the tab loses focus, whichever new View ends up 265 // contents are focused. When the tab loses focus, whichever new View ends up
245 // with focus will send an AX_EVENT_FOCUS of its own, so there's no need to 266 // with focus will send an AX_EVENT_FOCUS of its own, so there's no need to
246 // send one in OnBlur(). 267 // send one in OnBlur().
247 if (contents()) 268 if (contents())
248 contents()->NotifyAccessibilityEvent(ui::AX_EVENT_FOCUS, true); 269 contents()->NotifyAccessibilityEvent(ui::AX_EVENT_FOCUS, true);
249 SchedulePaint(); 270 SchedulePaint();
250 } 271 }
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 640
620 View* TabbedPane::GetSelectedTabContentView() { 641 View* TabbedPane::GetSelectedTabContentView() {
621 return GetSelectedTab() ? GetSelectedTab()->contents() : nullptr; 642 return GetSelectedTab() ? GetSelectedTab()->contents() : nullptr;
622 } 643 }
623 644
624 void TabbedPane::GetAccessibleNodeData(ui::AXNodeData* node_data) { 645 void TabbedPane::GetAccessibleNodeData(ui::AXNodeData* node_data) {
625 node_data->role = ui::AX_ROLE_TAB_LIST; 646 node_data->role = ui::AX_ROLE_TAB_LIST;
626 } 647 }
627 648
628 } // namespace views 649 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/tabbed_pane/tabbed_pane.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698