diff options
author | mhm@chromium.org <mhm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-09 04:00:49 +0000 |
---|---|---|
committer | mhm@chromium.org <mhm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-09 04:00:49 +0000 |
commit | 70d38b09d6f504b6a47b4d0e8f0a9b2f5d615373 (patch) | |
tree | efcc27929e40b9e71d0284d8094dab970945214d /views | |
parent | 7f265f9db6a502cb8909636d350afd0dbf6c5539 (diff) | |
download | chromium_src-70d38b09d6f504b6a47b4d0e8f0a9b2f5d615373.zip chromium_src-70d38b09d6f504b6a47b4d0e8f0a9b2f5d615373.tar.gz chromium_src-70d38b09d6f504b6a47b4d0e8f0a9b2f5d615373.tar.bz2 |
[accessibility] Allow views to have multiple accessibility states and add correct roles.
Allow views to contain multiple accessibility states since states are not mutually exclusive, we treat them as an uint32. Add missing roles to couple of views.
BUG=None
TEST=Run unit tests, and check accessibility tree.
Review URL: http://codereview.chromium.org/1527019
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@44054 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
21 files changed, 141 insertions, 45 deletions
diff --git a/views/accessibility/accessibility_types.h b/views/accessibility/accessibility_types.h index 79b9e03..83c7aa7 100644 --- a/views/accessibility/accessibility_types.h +++ b/views/accessibility/accessibility_types.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -15,6 +15,21 @@ //////////////////////////////////////////////////////////////////////////////// class AccessibilityTypes { public: + + + // This defines states of the supported accessibility roles in our + // Views (e.g. used in View::GetAccessibleState). Any interface using roles + // must provide a conversion to its own roles (see e.g. + // ViewAccessibility::get_accState and ViewAccessibility::MSAAState). + typedef uint32 State; + enum StateFlag { + STATE_CHECKED = 1 << 0, + STATE_HASPOPUP = 1 << 1, + STATE_LINKED = 1 << 2, + STATE_PROTECTED = 1 << 3, + STATE_READONLY = 1 << 4 + }; + // This defines an enumeration of the supported accessibility roles in our // Views (e.g. used in View::GetAccessibleRole). Any interface using roles // must provide a conversion to its own roles (see e.g. @@ -29,26 +44,24 @@ class AccessibilityTypes { ROLE_GRAPHIC, ROLE_GROUPING, ROLE_LINK, + ROLE_MENUITEM, + ROLE_MENUPOPUP, + ROLE_OUTLINE, + ROLE_OUTLINEITEM, ROLE_PAGETAB, ROLE_PAGETABLIST, ROLE_PANE, + ROLE_PROGRESSBAR, ROLE_PUSHBUTTON, + ROLE_SCROLLBAR, ROLE_SEPARATOR, + ROLE_STATICTEXT, ROLE_TEXT, ROLE_TITLEBAR, ROLE_TOOLBAR, ROLE_WINDOW }; - // This defines an enumeration of the supported accessibility roles in our - // Views (e.g. used in View::GetAccessibleState). Any interface using roles - // must provide a conversion to its own roles (see e.g. - // ViewAccessibility::get_accState and ViewAccessibility::MSAAState). - enum State { - STATE_HASPOPUP, - STATE_READONLY - }; - private: // Do not instantiate this class. AccessibilityTypes() {} diff --git a/views/accessibility/view_accessibility.cc b/views/accessibility/view_accessibility.cc index 9d8861a..f9dc5c6 100644 --- a/views/accessibility/view_accessibility.cc +++ b/views/accessibility/view_accessibility.cc @@ -717,16 +717,30 @@ int32 ViewAccessibility::MSAARole(AccessibilityTypes::Role role) { return ROLE_SYSTEM_GROUPING; case AccessibilityTypes::ROLE_LINK: return ROLE_SYSTEM_LINK; + case AccessibilityTypes::ROLE_MENUITEM: + return ROLE_SYSTEM_MENUITEM; + case AccessibilityTypes::ROLE_MENUPOPUP: + return ROLE_SYSTEM_MENUPOPUP; + case AccessibilityTypes::ROLE_OUTLINE: + return ROLE_SYSTEM_OUTLINE; + case AccessibilityTypes::ROLE_OUTLINEITEM: + return ROLE_SYSTEM_OUTLINEITEM; case AccessibilityTypes::ROLE_PAGETAB: return ROLE_SYSTEM_PAGETAB; case AccessibilityTypes::ROLE_PAGETABLIST: return ROLE_SYSTEM_PAGETABLIST; case AccessibilityTypes::ROLE_PANE: return ROLE_SYSTEM_PANE; + case AccessibilityTypes::ROLE_PROGRESSBAR: + return ROLE_SYSTEM_PROGRESSBAR; case AccessibilityTypes::ROLE_PUSHBUTTON: return ROLE_SYSTEM_PUSHBUTTON; + case AccessibilityTypes::ROLE_SCROLLBAR: + return ROLE_SYSTEM_SCROLLBAR; case AccessibilityTypes::ROLE_SEPARATOR: return ROLE_SYSTEM_SEPARATOR; + case AccessibilityTypes::ROLE_STATICTEXT: + return ROLE_SYSTEM_STATICTEXT; case AccessibilityTypes::ROLE_TEXT: return ROLE_SYSTEM_TEXT; case AccessibilityTypes::ROLE_TITLEBAR: @@ -743,15 +757,18 @@ int32 ViewAccessibility::MSAARole(AccessibilityTypes::Role role) { } int32 ViewAccessibility::MSAAState(AccessibilityTypes::State state) { - switch (state) { - case AccessibilityTypes::STATE_HASPOPUP : - return STATE_SYSTEM_HASPOPUP; - case AccessibilityTypes::STATE_READONLY : - return STATE_SYSTEM_READONLY; - default : - // No default state in MSAA. - return 0; - } + int32 msaa_state = 0; + if (state & AccessibilityTypes::STATE_CHECKED) + msaa_state |= STATE_SYSTEM_CHECKED; + if (state & AccessibilityTypes::STATE_HASPOPUP) + msaa_state |= STATE_SYSTEM_HASPOPUP; + if (state & AccessibilityTypes::STATE_LINKED) + msaa_state |= STATE_SYSTEM_LINKED; + if (state & AccessibilityTypes::STATE_PROTECTED) + msaa_state |= STATE_SYSTEM_PROTECTED; + if (state & AccessibilityTypes::STATE_READONLY) + msaa_state |= STATE_SYSTEM_READONLY; + return msaa_state; } // IAccessible functions not supported. diff --git a/views/controls/button/checkbox.cc b/views/controls/button/checkbox.cc index 3b0b804..1fcbea3 100644 --- a/views/controls/button/checkbox.cc +++ b/views/controls/button/checkbox.cc @@ -160,6 +160,13 @@ bool Checkbox::GetAccessibleRole(AccessibilityTypes::Role* role) { return true; } +bool Checkbox::GetAccessibleState(AccessibilityTypes::State* state) { + DCHECK(state); + + *state = checked() ? AccessibilityTypes::STATE_CHECKED : 0; + return true; +} + std::string Checkbox::GetClassName() const { return kViewClassName; } diff --git a/views/controls/button/checkbox.h b/views/controls/button/checkbox.h index a579628..bea240a 100644 --- a/views/controls/button/checkbox.h +++ b/views/controls/button/checkbox.h @@ -59,6 +59,7 @@ class Checkbox : public NativeButton { // Accessibility accessors, overridden from View. virtual bool GetAccessibleRole(AccessibilityTypes::Role* role); + virtual bool GetAccessibleState(AccessibilityTypes::State* state); // Overridden from NativeButton: virtual void SetLabel(const std::wstring& label); diff --git a/views/controls/label.cc b/views/controls/label.cc index 19060f6..89e9a572 100644 --- a/views/controls/label.cc +++ b/views/controls/label.cc @@ -248,7 +248,7 @@ void Label::SizeToFit(int max_width) { bool Label::GetAccessibleRole(AccessibilityTypes::Role* role) { DCHECK(role); - *role = AccessibilityTypes::ROLE_TEXT; + *role = AccessibilityTypes::ROLE_STATICTEXT; return true; } diff --git a/views/controls/label_unittest.cc b/views/controls/label_unittest.cc index 5ea20b3..2766643 100644 --- a/views/controls/label_unittest.cc +++ b/views/controls/label_unittest.cc @@ -161,7 +161,7 @@ TEST(LabelTest, Accessibility) { AccessibilityTypes::Role role; EXPECT_TRUE(label.GetAccessibleRole(&role)); - EXPECT_EQ(AccessibilityTypes::ROLE_TEXT, role); + EXPECT_EQ(AccessibilityTypes::ROLE_STATICTEXT, role); std::wstring name; EXPECT_TRUE(label.GetAccessibleName(&name)); @@ -169,7 +169,7 @@ TEST(LabelTest, Accessibility) { AccessibilityTypes::State state; EXPECT_TRUE(label.GetAccessibleState(&state)); - EXPECT_EQ(AccessibilityTypes::STATE_READONLY, state); + EXPECT_TRUE(AccessibilityTypes::STATE_READONLY & state); } TEST(LabelTest, SingleLineSizing) { diff --git a/views/controls/menu/menu_item_view.cc b/views/controls/menu/menu_item_view.cc index 62243e7..79f4306 100644 --- a/views/controls/menu/menu_item_view.cc +++ b/views/controls/menu/menu_item_view.cc @@ -78,6 +78,12 @@ bool MenuItemView::GetTooltipText(const gfx::Point& p, std::wstring* tooltip) { return !tooltip_.empty(); } +bool MenuItemView::GetAccessibleRole(AccessibilityTypes::Role* role) { + DCHECK(role); + *role = AccessibilityTypes::ROLE_MENUITEM; + return true; +} + void MenuItemView::RunMenuAt(gfx::NativeWindow parent, MenuButton* button, const gfx::Rect& bounds, diff --git a/views/controls/menu/menu_item_view.h b/views/controls/menu/menu_item_view.h index b342356..db06bf1 100644 --- a/views/controls/menu/menu_item_view.h +++ b/views/controls/menu/menu_item_view.h @@ -73,6 +73,7 @@ class MenuItemView : public View { // Overridden from View: virtual bool GetTooltipText(const gfx::Point& p, std::wstring* tooltip); + virtual bool GetAccessibleRole(AccessibilityTypes::Role* role); // Returns the preferred height of menu items. This is only valid when the // menu is about to be shown. diff --git a/views/controls/menu/menu_scroll_view_container.cc b/views/controls/menu/menu_scroll_view_container.cc index efd47ca..a80424e 100644 --- a/views/controls/menu/menu_scroll_view_container.cc +++ b/views/controls/menu/menu_scroll_view_container.cc @@ -231,4 +231,11 @@ gfx::Size MenuScrollViewContainer::GetPreferredSize() { return prefsize; } +bool MenuScrollViewContainer::GetAccessibleRole( + AccessibilityTypes::Role* role) { + DCHECK(role); + *role = AccessibilityTypes::ROLE_MENUPOPUP; + return true; +} + } // namespace views diff --git a/views/controls/menu/menu_scroll_view_container.h b/views/controls/menu/menu_scroll_view_container.h index a13805a..41c7540 100644 --- a/views/controls/menu/menu_scroll_view_container.h +++ b/views/controls/menu/menu_scroll_view_container.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -28,6 +28,7 @@ class MenuScrollViewContainer : public View { virtual void DidChangeBounds(const gfx::Rect& previous, const gfx::Rect& current); virtual gfx::Size GetPreferredSize(); + virtual bool GetAccessibleRole(AccessibilityTypes::Role* role); private: class MenuScrollView; diff --git a/views/controls/progress_bar.cc b/views/controls/progress_bar.cc index de9cd59..19f10c5 100644 --- a/views/controls/progress_bar.cc +++ b/views/controls/progress_bar.cc @@ -187,16 +187,12 @@ void ProgressBar::SetEnabled(bool enabled) { bool ProgressBar::GetAccessibleRole(AccessibilityTypes::Role* role) { DCHECK(role); - if (role == NULL) - return false; - *role = AccessibilityTypes::ROLE_TEXT; + *role = AccessibilityTypes::ROLE_PROGRESSBAR; return true; } bool ProgressBar::GetAccessibleState(AccessibilityTypes::State* state) { DCHECK(state); - if (state == NULL) - return false; *state = AccessibilityTypes::STATE_READONLY; return true; } diff --git a/views/controls/progress_bar_unittest.cc b/views/controls/progress_bar_unittest.cc index 2966d56..2912744 100644 --- a/views/controls/progress_bar_unittest.cc +++ b/views/controls/progress_bar_unittest.cc @@ -50,7 +50,7 @@ TEST(ProgressBarTest, Accessibility) { AccessibilityTypes::Role role; EXPECT_TRUE(bar.GetAccessibleRole(&role)); - EXPECT_EQ(AccessibilityTypes::ROLE_TEXT, role); + EXPECT_EQ(AccessibilityTypes::ROLE_PROGRESSBAR, role); std::wstring name; EXPECT_FALSE(bar.GetAccessibleName(&name)); @@ -63,7 +63,7 @@ TEST(ProgressBarTest, Accessibility) { AccessibilityTypes::State state; EXPECT_TRUE(bar.GetAccessibleState(&state)); - EXPECT_EQ(AccessibilityTypes::STATE_READONLY, state); + EXPECT_TRUE(AccessibilityTypes::STATE_READONLY & state); } } // namespace views diff --git a/views/controls/scrollbar/scroll_bar.cc b/views/controls/scrollbar/scroll_bar.cc index a475c44..9a7a9e3 100644 --- a/views/controls/scrollbar/scroll_bar.cc +++ b/views/controls/scrollbar/scroll_bar.cc @@ -1,9 +1,11 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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 "views/controls/scrollbar/scroll_bar.h" +#include "base/logging.h" + namespace views { ///////////////////////////////////////////////////////////////////////////// @@ -20,6 +22,13 @@ ScrollBar::ScrollBar(bool is_horiz) : is_horiz_(is_horiz), ScrollBar::~ScrollBar() { } +bool ScrollBar::GetAccessibleRole(AccessibilityTypes::Role* role) { + DCHECK(role); + + *role = AccessibilityTypes::ROLE_SCROLLBAR; + return true; +} + bool ScrollBar::IsHorizontal() const { return is_horiz_; } diff --git a/views/controls/scrollbar/scroll_bar.h b/views/controls/scrollbar/scroll_bar.h index 9354fcb..a4203d4 100644 --- a/views/controls/scrollbar/scroll_bar.h +++ b/views/controls/scrollbar/scroll_bar.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -58,6 +58,9 @@ class ScrollBar : public View { public: virtual ~ScrollBar(); + // Overridden from View: + virtual bool GetAccessibleRole(AccessibilityTypes::Role* role); + // Return whether this scrollbar is horizontal bool IsHorizontal() const; @@ -99,5 +102,5 @@ class ScrollBar : public View { } // namespace views -#endif // #ifndef VIEWS_CONTROLS_SCROLLBAR_SCROLLBAR_H_ +#endif // VIEWS_CONTROLS_SCROLLBAR_SCROLLBAR_H_ diff --git a/views/controls/separator.cc b/views/controls/separator.cc index dad3578..cd1deeb 100644 --- a/views/controls/separator.cc +++ b/views/controls/separator.cc @@ -1,9 +1,10 @@ -// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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 "views/controls/separator.h" +#include "base/logging.h" #if defined(OS_LINUX) #include "views/controls/native_control_gtk.h" #elif defined(OS_WIN) @@ -91,6 +92,13 @@ std::string Separator::GetClassName() const { return kViewClassName; } +bool Separator::GetAccessibleRole(AccessibilityTypes::Role* role) { + DCHECK(role); + + *role = AccessibilityTypes::ROLE_SEPARATOR; + return true; +} + //////////////////////////////////////////////////////////////////////////////// // Separator, private: diff --git a/views/controls/separator.h b/views/controls/separator.h index 0988d62..823ebb3 100644 --- a/views/controls/separator.h +++ b/views/controls/separator.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -25,6 +25,8 @@ class Separator : public View { // Overridden from View: virtual void Layout(); virtual gfx::Size GetPreferredSize(); + virtual bool GetAccessibleRole(AccessibilityTypes::Role* role); + protected: virtual void ViewHierarchyChanged(bool is_add, View* parent, View* child); diff --git a/views/controls/tabbed_pane/tabbed_pane.cc b/views/controls/tabbed_pane/tabbed_pane.cc index 6e649ee..ec324d4 100644 --- a/views/controls/tabbed_pane/tabbed_pane.cc +++ b/views/controls/tabbed_pane/tabbed_pane.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -121,4 +121,11 @@ void TabbedPane::PaintFocusBorder(gfx::Canvas* canvas) { View::PaintFocusBorder(canvas); } +bool TabbedPane::GetAccessibleRole(AccessibilityTypes::Role* role) { + DCHECK(role); + + *role = AccessibilityTypes::ROLE_PAGETABLIST; + return true; +} + } // namespace views diff --git a/views/controls/tabbed_pane/tabbed_pane.h b/views/controls/tabbed_pane/tabbed_pane.h index e5793be..abbb9fa 100644 --- a/views/controls/tabbed_pane/tabbed_pane.h +++ b/views/controls/tabbed_pane/tabbed_pane.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -71,6 +71,7 @@ class TabbedPane : public View { virtual void Layout(); virtual void Focus(); virtual void PaintFocusBorder(gfx::Canvas* canvas); + virtual bool GetAccessibleRole(AccessibilityTypes::Role* role); protected: // The object that actually implements the tabbed-pane. diff --git a/views/controls/textfield/textfield.cc b/views/controls/textfield/textfield.cc index 54e34dd..11dceba 100644 --- a/views/controls/textfield/textfield.cc +++ b/views/controls/textfield/textfield.cc @@ -253,8 +253,6 @@ void Textfield::PaintFocusBorder(gfx::Canvas* canvas) { bool Textfield::GetAccessibleRole(AccessibilityTypes::Role* role) { DCHECK(role); - if (!role) - return false; *role = AccessibilityTypes::ROLE_TEXT; return true; @@ -262,17 +260,18 @@ bool Textfield::GetAccessibleRole(AccessibilityTypes::Role* role) { bool Textfield::GetAccessibleState(AccessibilityTypes::State* state) { DCHECK(state); - if (!state) - return false; + + *state = 0; - *state = AccessibilityTypes::STATE_READONLY; + if (read_only()) + *state |= AccessibilityTypes::STATE_READONLY; + if (IsPassword()) + *state |= AccessibilityTypes::STATE_PROTECTED; return true; } bool Textfield::GetAccessibleValue(std::wstring* value) { DCHECK(value); - if (!value) - return false; if (!text_.empty()) { *value = UTF16ToWide(text_); diff --git a/views/controls/tree/tree_view.cc b/views/controls/tree/tree_view.cc index f5afcce..e5587b9 100644 --- a/views/controls/tree/tree_view.cc +++ b/views/controls/tree/tree_view.cc @@ -55,6 +55,20 @@ TreeView::~TreeView() { ImageList_Destroy(image_list_); } +bool TreeView::GetAccessibleRole(AccessibilityTypes::Role* role) { + DCHECK(role); + + *role = AccessibilityTypes::ROLE_OUTLINE; + return true; +} + +bool TreeView::GetAccessibleState(AccessibilityTypes::State* state) { + DCHECK(state); + + *state = AccessibilityTypes::STATE_READONLY; + return true; +} + void TreeView::SetModel(TreeModel* model) { if (model == model_) return; diff --git a/views/controls/tree/tree_view.h b/views/controls/tree/tree_view.h index cc2c8a1..177fc40 100644 --- a/views/controls/tree/tree_view.h +++ b/views/controls/tree/tree_view.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -78,6 +78,10 @@ class TreeView : public NativeControl, TreeModelObserver { lines_at_root_ = lines_at_root; } + // Overridden from View: + virtual bool GetAccessibleRole(AccessibilityTypes::Role* role); + virtual bool GetAccessibleState(AccessibilityTypes::State* state); + // Edits the specified node. This cancels the current edit and expands // all parents of node. void StartEditing(TreeModelNode* node); |