diff options
author | klink@chromium.org <klink@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-28 00:12:01 +0000 |
---|---|---|
committer | klink@chromium.org <klink@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-28 00:12:01 +0000 |
commit | e92070ac9982489502180c006fe7911889c8fbee (patch) | |
tree | 577f25e7a8b61fd5b497886f57d89770f19f60cb /chrome/views | |
parent | ec7690fc03aef949ea4eece3c17b3f78b265006e (diff) | |
download | chromium_src-e92070ac9982489502180c006fe7911889c8fbee.zip chromium_src-e92070ac9982489502180c006fe7911889c8fbee.tar.gz chromium_src-e92070ac9982489502180c006fe7911889c8fbee.tar.bz2 |
Removes the use of Windows-specific types for accessibility roles and states in Views and Browser\Views. Helps with the porting effort, and makes for a cleaner implementation.
Review URL: http://codereview.chromium.org/93085
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14689 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/views')
-rw-r--r-- | chrome/views/accessibility/view_accessibility.cc | 67 | ||||
-rw-r--r-- | chrome/views/accessibility/view_accessibility.h | 10 | ||||
-rw-r--r-- | chrome/views/controls/button/button.cc | 5 | ||||
-rw-r--r-- | chrome/views/controls/button/button.h | 1 | ||||
-rw-r--r-- | chrome/views/controls/button/button_dropdown.cc | 9 | ||||
-rw-r--r-- | chrome/views/controls/button/button_dropdown.h | 18 | ||||
-rw-r--r-- | chrome/views/controls/button/menu_button.cc | 9 | ||||
-rw-r--r-- | chrome/views/controls/button/menu_button.h | 18 | ||||
-rw-r--r-- | chrome/views/controls/label.cc | 11 | ||||
-rw-r--r-- | chrome/views/controls/label.h | 20 | ||||
-rw-r--r-- | chrome/views/controls/label_unittest.cc | 14 | ||||
-rw-r--r-- | chrome/views/view.h | 23 | ||||
-rw-r--r-- | chrome/views/widget/root_view.cc | 7 | ||||
-rw-r--r-- | chrome/views/widget/root_view.h | 16 | ||||
-rw-r--r-- | chrome/views/widget/root_view_win.cc | 8 |
15 files changed, 119 insertions, 117 deletions
diff --git a/chrome/views/accessibility/view_accessibility.cc b/chrome/views/accessibility/view_accessibility.cc index 4ba7d54..be91849 100644 --- a/chrome/views/accessibility/view_accessibility.cc +++ b/chrome/views/accessibility/view_accessibility.cc @@ -498,9 +498,11 @@ STDMETHODIMP ViewAccessibility::get_accRole(VARIANT var_id, VARIANT* role) { return E_INVALIDARG; } + AccessibilityTypes::Role acc_role; + if (var_id.lVal == CHILDID_SELF) { // Retrieve parent role. - if (!view_->GetAccessibleRole(role)) { + if (!view_->GetAccessibleRole(&acc_role)) { return E_FAIL; } } else { @@ -508,15 +510,14 @@ STDMETHODIMP ViewAccessibility::get_accRole(VARIANT var_id, VARIANT* role) { return E_INVALIDARG; } // Retrieve child role. - if (!view_->GetChildViewAt(var_id.lVal - 1)->GetAccessibleRole(role)) { + if (!view_->GetChildViewAt(var_id.lVal - 1)->GetAccessibleRole(&acc_role)) { + role->vt = VT_EMPTY; return E_FAIL; } } - // Make sure that role is not empty, and has the proper type. - if (role->vt == VT_EMPTY) - return E_FAIL; - + role->vt = VT_I4; + role->lVal = MSAARole(acc_role); return S_OK; } @@ -577,35 +578,73 @@ bool ViewAccessibility::IsValidNav(int nav_dir, int start_id, int lower_bound, return true; } -void ViewAccessibility::SetState(VARIANT* state, views::View* view) { +void ViewAccessibility::SetState(VARIANT* msaa_state, views::View* view) { // Default state; all views can have accessibility focus. - state->lVal |= STATE_SYSTEM_FOCUSABLE; + msaa_state->lVal |= STATE_SYSTEM_FOCUSABLE; if (!view) return; if (!view->IsEnabled()) { - state->lVal |= STATE_SYSTEM_UNAVAILABLE; + msaa_state->lVal |= STATE_SYSTEM_UNAVAILABLE; } if (!view->IsVisible()) { - state->lVal |= STATE_SYSTEM_INVISIBLE; + msaa_state->lVal |= STATE_SYSTEM_INVISIBLE; } if (view->IsHotTracked()) { - state->lVal |= STATE_SYSTEM_HOTTRACKED; + msaa_state->lVal |= STATE_SYSTEM_HOTTRACKED; } if (view->IsPushed()) { - state->lVal |= STATE_SYSTEM_PRESSED; + msaa_state->lVal |= STATE_SYSTEM_PRESSED; } // Check both for actual View focus, as well as accessibility focus. views::View* parent = view->GetParent(); if (view->HasFocus() || (parent && parent->GetAccFocusedChildView() == view)) { - state->lVal |= STATE_SYSTEM_FOCUSED; + msaa_state->lVal |= STATE_SYSTEM_FOCUSED; } // Add on any view-specific states. - view->GetAccessibleState(state); + AccessibilityTypes::State state; + view->GetAccessibleState(&state); + + msaa_state->lVal |= MSAAState(state); +} + +long ViewAccessibility::MSAARole(AccessibilityTypes::Role role) { + switch (role) { + case AccessibilityTypes::ROLE_APPLICATION : + return ROLE_SYSTEM_APPLICATION; + case AccessibilityTypes::ROLE_BUTTONDROPDOWN : + return ROLE_SYSTEM_BUTTONDROPDOWN; + case AccessibilityTypes::ROLE_GROUPING : + return ROLE_SYSTEM_GROUPING; + case AccessibilityTypes::ROLE_PAGETAB : + return ROLE_SYSTEM_PAGETAB; + case AccessibilityTypes::ROLE_PUSHBUTTON : + return ROLE_SYSTEM_PUSHBUTTON; + case AccessibilityTypes::ROLE_TEXT : + return ROLE_SYSTEM_TEXT; + case AccessibilityTypes::ROLE_TOOLBAR : + return ROLE_SYSTEM_TOOLBAR; + case AccessibilityTypes::ROLE_CLIENT : + default: + // This is the default role for MSAA. + return ROLE_SYSTEM_CLIENT; + } +} + +long 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; + } } // IAccessible functions not supported. diff --git a/chrome/views/accessibility/view_accessibility.h b/chrome/views/accessibility/view_accessibility.h index c541a04..ba3d995 100644 --- a/chrome/views/accessibility/view_accessibility.h +++ b/chrome/views/accessibility/view_accessibility.h @@ -125,7 +125,15 @@ class ATL_NO_VTABLE ViewAccessibility } // Helper function which sets applicable states of view. - void SetState(VARIANT* state, views::View* view); + void SetState(VARIANT* msaa_state, views::View* view); + + // Returns a conversion from the Role (as defined in + // chrome/common/accessibility_types.h) to an MSAA role. + long MSAARole(AccessibilityTypes::Role role); + + // Returns a conversion from the State (as defined in + // chrome/common/accessibility_types.h) to MSAA states set. + long MSAAState(AccessibilityTypes::State state); // Member View needed for view-specific calls. views::View* view_; diff --git a/chrome/views/controls/button/button.cc b/chrome/views/controls/button/button.cc index 29b5da8..605b409 100644 --- a/chrome/views/controls/button/button.cc +++ b/chrome/views/controls/button/button.cc @@ -44,6 +44,11 @@ bool Button::GetAccessibleName(std::wstring* name) { return false; } +bool Button::GetAccessibleRole(AccessibilityTypes::Role* role) { + *role = AccessibilityTypes::ROLE_PUSHBUTTON; + return true; +} + void Button::SetAccessibleKeyboardShortcut(const std::wstring& shortcut) { accessible_shortcut_.assign(shortcut); } diff --git a/chrome/views/controls/button/button.h b/chrome/views/controls/button/button.h index f00f8a1..40ee98155 100644 --- a/chrome/views/controls/button/button.h +++ b/chrome/views/controls/button/button.h @@ -35,6 +35,7 @@ class Button : public View { virtual bool GetTooltipText(int x, int y, std::wstring* tooltip); virtual bool GetAccessibleKeyboardShortcut(std::wstring* shortcut); virtual bool GetAccessibleName(std::wstring* name); + virtual bool GetAccessibleRole(AccessibilityTypes::Role* role); virtual void SetAccessibleKeyboardShortcut(const std::wstring& shortcut); virtual void SetAccessibleName(const std::wstring& name); diff --git a/chrome/views/controls/button/button_dropdown.cc b/chrome/views/controls/button/button_dropdown.cc index c2ea7cc..89abf85 100644 --- a/chrome/views/controls/button/button_dropdown.cc +++ b/chrome/views/controls/button/button_dropdown.cc @@ -175,18 +175,17 @@ bool ButtonDropDown::GetAccessibleDefaultAction(std::wstring* action) { return true; } -bool ButtonDropDown::GetAccessibleRole(VARIANT* role) { +bool ButtonDropDown::GetAccessibleRole(AccessibilityTypes::Role* role) { DCHECK(role); - role->vt = VT_I4; - role->lVal = ROLE_SYSTEM_BUTTONDROPDOWN; + *role = AccessibilityTypes::ROLE_BUTTONDROPDOWN; return true; } -bool ButtonDropDown::GetAccessibleState(VARIANT* state) { +bool ButtonDropDown::GetAccessibleState(AccessibilityTypes::State* state) { DCHECK(state); - state->lVal |= STATE_SYSTEM_HASPOPUP; + *state = AccessibilityTypes::STATE_HASPOPUP; return true; } diff --git a/chrome/views/controls/button/button_dropdown.h b/chrome/views/controls/button/button_dropdown.h index b46158b..3e43df5 100644 --- a/chrome/views/controls/button/button_dropdown.h +++ b/chrome/views/controls/button/button_dropdown.h @@ -24,20 +24,10 @@ class ButtonDropDown : public ImageButton { ButtonDropDown(ButtonListener* listener, Menu::Delegate* menu_delegate); virtual ~ButtonDropDown(); - // Returns the MSAA default action of the current view. The string returned - // describes the default action that will occur when executing - // IAccessible::DoDefaultAction. - bool GetAccessibleDefaultAction(std::wstring* action); - - // Returns the MSAA role of the current view. The role is what assistive - // technologies (ATs) use to determine what behavior to expect from a given - // control. - bool GetAccessibleRole(VARIANT* role); - - // Returns the MSAA state of the current view. Sets the input VARIANT - // appropriately, and returns true if a change was performed successfully. - // Overriden from View. - virtual bool GetAccessibleState(VARIANT* state); + // Accessibility accessors, overridden from View. + virtual bool GetAccessibleDefaultAction(std::wstring* action); + virtual bool GetAccessibleRole(AccessibilityTypes::Role* role); + virtual bool GetAccessibleState(AccessibilityTypes::State* state); private: // Overridden from Button diff --git a/chrome/views/controls/button/menu_button.cc b/chrome/views/controls/button/menu_button.cc index 0bcd2ae..4687132 100644 --- a/chrome/views/controls/button/menu_button.cc +++ b/chrome/views/controls/button/menu_button.cc @@ -236,18 +236,17 @@ bool MenuButton::GetAccessibleDefaultAction(std::wstring* action) { return true; } -bool MenuButton::GetAccessibleRole(VARIANT* role) { +bool MenuButton::GetAccessibleRole(AccessibilityTypes::Role* role) { DCHECK(role); - role->vt = VT_I4; - role->lVal = ROLE_SYSTEM_BUTTONDROPDOWN; + *role = AccessibilityTypes::ROLE_BUTTONDROPDOWN; return true; } -bool MenuButton::GetAccessibleState(VARIANT* state) { +bool MenuButton::GetAccessibleState(AccessibilityTypes::State* state) { DCHECK(state); - state->lVal |= STATE_SYSTEM_HASPOPUP; + *state = AccessibilityTypes::STATE_HASPOPUP; return true; } diff --git a/chrome/views/controls/button/menu_button.h b/chrome/views/controls/button/menu_button.h index 438d191..119abb2 100644 --- a/chrome/views/controls/button/menu_button.h +++ b/chrome/views/controls/button/menu_button.h @@ -53,20 +53,10 @@ class MenuButton : public TextButton { virtual bool OnKeyReleased(const KeyEvent& e); virtual void OnMouseExited(const MouseEvent& event); - // Returns the MSAA default action of the current view. The string returned - // describes the default action that will occur when executing - // IAccessible::DoDefaultAction. - bool GetAccessibleDefaultAction(std::wstring* action); - - // Returns the MSAA role of the current view. The role is what assistive - // technologies (ATs) use to determine what behavior to expect from a given - // control. - bool GetAccessibleRole(VARIANT* role); - - // Returns the MSAA state of the current view. Sets the input VARIANT - // appropriately, and returns true if a change was performed successfully. - // Overriden from View. - virtual bool GetAccessibleState(VARIANT* state); + // Accessibility accessors, overridden from View. + virtual bool GetAccessibleDefaultAction(std::wstring* action); + virtual bool GetAccessibleRole(AccessibilityTypes::Role* role); + virtual bool GetAccessibleState(AccessibilityTypes::State* state); protected: // true if the menu is currently visible. diff --git a/chrome/views/controls/label.cc b/chrome/views/controls/label.cc index 22c11d7..7f1a886 100644 --- a/chrome/views/controls/label.cc +++ b/chrome/views/controls/label.cc @@ -412,12 +412,10 @@ void Label::SizeToFit(int max_width) { SizeToPreferredSize(); } -#if defined(OS_WIN) -bool Label::GetAccessibleRole(VARIANT* role) { +bool Label::GetAccessibleRole(AccessibilityTypes::Role* role) { DCHECK(role); - role->vt = VT_I4; - role->lVal = ROLE_SYSTEM_TEXT; + *role = AccessibilityTypes::ROLE_TEXT; return true; } @@ -426,12 +424,11 @@ bool Label::GetAccessibleName(std::wstring* name) { return true; } -bool Label::GetAccessibleState(VARIANT* state) { +bool Label::GetAccessibleState(AccessibilityTypes::State* state) { DCHECK(state); - state->lVal |= STATE_SYSTEM_READONLY; + *state = AccessibilityTypes::STATE_READONLY; return true; } -#endif // defined(OS_WIN) } // namespace views diff --git a/chrome/views/controls/label.h b/chrome/views/controls/label.h index 15e90ae..fc4f897 100644 --- a/chrome/views/controls/label.h +++ b/chrome/views/controls/label.h @@ -164,22 +164,10 @@ class Label : public View { // wrapped). If 0, no maximum width is enforced. void SizeToFit(int max_width); -#if defined(OS_WIN) - // TODO(port): Make portable equivalents of accessibility-related functions. - - // Returns the MSAA role of the current view. The role is what assistive - // technologies (ATs) use to determine what behavior to expect from a given - // control. - bool GetAccessibleRole(VARIANT* role); - - // Returns a brief, identifying string, containing a unique, readable name. - bool GetAccessibleName(std::wstring* name); - - // Returns the MSAA state of the current view. Sets the input VARIANT - // appropriately, and returns true if a change was performed successfully. - // Overriden from View. - virtual bool GetAccessibleState(VARIANT* state); -#endif // defined(OS_WIN) + // Accessibility accessors, overridden from View. + virtual bool GetAccessibleRole(AccessibilityTypes::Role* role); + virtual bool GetAccessibleName(std::wstring* name); + virtual bool GetAccessibleState(AccessibilityTypes::State* state); // Gets/sets the flag to determine whether the label should be collapsed when // it's hidden (not visible). If this flag is true, the label will return a diff --git a/chrome/views/controls/label_unittest.cc b/chrome/views/controls/label_unittest.cc index 58d6655..fb1d057 100644 --- a/chrome/views/controls/label_unittest.cc +++ b/chrome/views/controls/label_unittest.cc @@ -146,23 +146,17 @@ TEST(LabelTest, Accessibility) { std::wstring test_text(L"My special text."); label.SetText(test_text); - VARIANT role; - ::VariantInit(&role); + AccessibilityTypes::Role role; EXPECT_TRUE(label.GetAccessibleRole(&role)); - EXPECT_EQ(VT_I4, role.vt); - EXPECT_EQ(ROLE_SYSTEM_TEXT, role.lVal); + EXPECT_EQ(AccessibilityTypes::ROLE_TEXT, role); std::wstring name; EXPECT_TRUE(label.GetAccessibleName(&name)); EXPECT_STREQ(test_text.c_str(), name.c_str()); - VARIANT state; - ::VariantInit(&state); - state.vt = VT_I4; - state.lVal = 0; + AccessibilityTypes::State state; EXPECT_TRUE(label.GetAccessibleState(&state)); - EXPECT_EQ(VT_I4, state.vt); - EXPECT_EQ(STATE_SYSTEM_READONLY, state.lVal); + EXPECT_EQ(AccessibilityTypes::STATE_READONLY, state); } TEST(LabelTest, SingleLineSizing) { diff --git a/chrome/views/view.h b/chrome/views/view.h index f88ad7e..b502842 100644 --- a/chrome/views/view.h +++ b/chrome/views/view.h @@ -20,6 +20,7 @@ #include "base/gfx/rect.h" #include "base/scoped_ptr.h" +#include "chrome/common/accessibility_types.h" #include "chrome/views/accelerator.h" #include "chrome/views/background.h" #include "chrome/views/border.h" @@ -559,19 +560,19 @@ class View : public AcceleratorTarget { // successful. virtual bool GetAccessibleName(std::wstring* name) { return false; } -#if defined(OS_WIN) - // TODO(port): Make these functions using VARIANT portable. - - // Returns the MSAA role of the current view. The role is what assistive - // technologies (ATs) use to determine what behavior to expect from a given - // control. Sets the input VARIANT appropriately, and returns true if + // Returns the accessibility role of the current view. The role is what + // assistive technologies (ATs) use to determine what behavior to expect from + // a given control. Sets the input Role appropriately, and returns true if // successful. - virtual bool GetAccessibleRole(VARIANT* role) { return false; } + virtual bool GetAccessibleRole(AccessibilityTypes::Role* role) { + return false; + } - // Returns the MSAA state of the current view. Sets the input VARIANT - // appropriately, and returns true if a change was performed successfully. - virtual bool GetAccessibleState(VARIANT* state) { return false; } -#endif // defined(OS_WIN) + // Returns the accessibility state of the current view. Sets the input State + // appropriately, and returns true if successful. + virtual bool GetAccessibleState(AccessibilityTypes::State* state) { + return false; + } // Assigns a keyboard shortcut string description to the given control. Needed // as a View does not know which shortcut will be associated with it until it diff --git a/chrome/views/widget/root_view.cc b/chrome/views/widget/root_view.cc index 6158a10..f8135bb 100644 --- a/chrome/views/widget/root_view.cc +++ b/chrome/views/widget/root_view.cc @@ -960,6 +960,13 @@ void RootView::ClearPaintRect() { // ///////////////////////////////////////////////////////////////////////////// +bool RootView::GetAccessibleRole(AccessibilityTypes::Role* role) { + DCHECK(role); + + *role = AccessibilityTypes::ROLE_APPLICATION; + return true; +} + bool RootView::GetAccessibleName(std::wstring* name) { if (!accessible_name_.empty()) { *name = accessible_name_; diff --git a/chrome/views/widget/root_view.h b/chrome/views/widget/root_view.h index 0eaaa1d..1232af5 100644 --- a/chrome/views/widget/root_view.h +++ b/chrome/views/widget/root_view.h @@ -188,18 +188,10 @@ class RootView : public View, void OnPaint(GdkEventExpose* event); #endif -#if defined(OS_WIN) - // Returns the MSAA role of the current view. The role is what assistive - // technologies (ATs) use to determine what behavior to expect from a given - // control. - bool GetAccessibleRole(VARIANT* role); -#endif - - // Returns a brief, identifying string, containing a unique, readable name. - bool GetAccessibleName(std::wstring* name); - - // Assigns an accessible string name. - void SetAccessibleName(const std::wstring& name); + // Accessibility accessors/mutators, overridden from View. + virtual bool GetAccessibleRole(AccessibilityTypes::Role* role); + virtual bool GetAccessibleName(std::wstring* name); + virtual void SetAccessibleName(const std::wstring& name); protected: diff --git a/chrome/views/widget/root_view_win.cc b/chrome/views/widget/root_view_win.cc index 89f198e..1beff61 100644 --- a/chrome/views/widget/root_view_win.cc +++ b/chrome/views/widget/root_view_win.cc @@ -49,14 +49,6 @@ void RootView::OnPaint(HWND hwnd) { } } -bool RootView::GetAccessibleRole(VARIANT* role) { - DCHECK(role); - - role->vt = VT_I4; - role->lVal = ROLE_SYSTEM_APPLICATION; - return true; -} - void RootView::StartDragForViewFromMouseEvent( View* view, IDataObject* data, |