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 | |
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')
29 files changed, 194 insertions, 157 deletions
diff --git a/chrome/browser/views/frame/opaque_browser_frame_view.cc b/chrome/browser/views/frame/opaque_browser_frame_view.cc index a93449f..567b615 100644 --- a/chrome/browser/views/frame/opaque_browser_frame_view.cc +++ b/chrome/browser/views/frame/opaque_browser_frame_view.cc @@ -613,12 +613,11 @@ void OpaqueBrowserFrameView::ViewHierarchyChanged(bool is_add, } } -bool OpaqueBrowserFrameView::GetAccessibleRole(VARIANT* role) { +bool OpaqueBrowserFrameView::GetAccessibleRole(AccessibilityTypes::Role* role) { DCHECK(role); // We aren't actually the client area of the window, but we act like it as - // far as MSAA and the UI tests are concerned. - role->vt = VT_I4; - role->lVal = ROLE_SYSTEM_CLIENT; + // far as accessibility and the UI tests are concerned. + *role = AccessibilityTypes::ROLE_CLIENT; return true; } diff --git a/chrome/browser/views/frame/opaque_browser_frame_view.h b/chrome/browser/views/frame/opaque_browser_frame_view.h index ecbab36..88d44e4 100644 --- a/chrome/browser/views/frame/opaque_browser_frame_view.h +++ b/chrome/browser/views/frame/opaque_browser_frame_view.h @@ -52,7 +52,7 @@ class OpaqueBrowserFrameView : public BrowserNonClientFrameView, virtual void ViewHierarchyChanged(bool is_add, views::View* parent, views::View* child); - virtual bool GetAccessibleRole(VARIANT* role); + virtual bool GetAccessibleRole(AccessibilityTypes::Role* role); virtual bool GetAccessibleName(std::wstring* name); virtual void SetAccessibleName(const std::wstring& name); diff --git a/chrome/browser/views/location_bar_view.cc b/chrome/browser/views/location_bar_view.cc index 19db7b2..3499c6d 100644 --- a/chrome/browser/views/location_bar_view.cc +++ b/chrome/browser/views/location_bar_view.cc @@ -566,11 +566,10 @@ void LocationBarView::OnMouseEvent(const views::MouseEvent& event, UINT msg) { location_entry_->HandleExternalMsg(msg, flags, screen_point.ToPOINT()); } -bool LocationBarView::GetAccessibleRole(VARIANT* role) { +bool LocationBarView::GetAccessibleRole(AccessibilityTypes::Role* role) { DCHECK(role); - role->vt = VT_I4; - role->lVal = ROLE_SYSTEM_GROUPING; + *role = AccessibilityTypes::ROLE_GROUPING; return true; } diff --git a/chrome/browser/views/location_bar_view.h b/chrome/browser/views/location_bar_view.h index 93df32e..7251a85 100644 --- a/chrome/browser/views/location_bar_view.h +++ b/chrome/browser/views/location_bar_view.h @@ -104,8 +104,8 @@ class LocationBarView : public LocationBar, virtual SkBitmap GetFavIcon() const; virtual std::wstring GetTitle() const; - // Returns the MSAA role - bool GetAccessibleRole(VARIANT* role); + // Returns the accessibility role. + bool GetAccessibleRole(AccessibilityTypes::Role* role); AutocompleteEditView* location_entry() { return location_entry_.get(); diff --git a/chrome/browser/views/tab_contents_container_view.cc b/chrome/browser/views/tab_contents_container_view.cc index c0089a7..b31f6b6 100644 --- a/chrome/browser/views/tab_contents_container_view.cc +++ b/chrome/browser/views/tab_contents_container_view.cc @@ -138,11 +138,11 @@ void TabContentsContainerView::RequestFocus() { View::RequestFocus(); } -bool TabContentsContainerView::GetAccessibleRole(VARIANT* role) { +bool TabContentsContainerView::GetAccessibleRole( + AccessibilityTypes::Role* role) { DCHECK(role); - role->vt = VT_I4; - role->lVal = ROLE_SYSTEM_GROUPING; + *role = AccessibilityTypes::ROLE_GROUPING; return true; } diff --git a/chrome/browser/views/tab_contents_container_view.h b/chrome/browser/views/tab_contents_container_view.h index 8bda8bb..6840460 100644 --- a/chrome/browser/views/tab_contents_container_view.h +++ b/chrome/browser/views/tab_contents_container_view.h @@ -36,6 +36,7 @@ class TabContentsContainerView : public views::HWNDView, virtual void RequestFocus(); virtual void AboutToRequestFocusFromTabTraversal(bool reverse); virtual bool CanProcessTabKeyEvents(); + virtual bool GetAccessibleRole(AccessibilityTypes::Role* role); // Overridden from HWNDView. virtual views::FocusTraversable* GetFocusTraversableParent(); @@ -46,11 +47,6 @@ class TabContentsContainerView : public views::HWNDView, const NotificationSource& source, const NotificationDetails& details); - // 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); - protected: // Web content should be given first crack at accelerators. This function // returns false if the current tab is a webcontents. diff --git a/chrome/browser/views/tabs/tab.cc b/chrome/browser/views/tabs/tab.cc index e553cf0..5fa6d8d 100644 --- a/chrome/browser/views/tabs/tab.cc +++ b/chrome/browser/views/tabs/tab.cc @@ -215,11 +215,10 @@ bool Tab::GetTooltipTextOrigin(int x, int y, CPoint* origin) { return true; } -bool Tab::GetAccessibleRole(VARIANT* role) { +bool Tab::GetAccessibleRole(AccessibilityTypes::Role* role) { DCHECK(role); - role->vt = VT_I4; - role->lVal = ROLE_SYSTEM_PAGETAB; + *role = AccessibilityTypes::ROLE_PAGETAB; return true; } diff --git a/chrome/browser/views/tabs/tab.h b/chrome/browser/views/tabs/tab.h index 9230dd0..ec295ed 100644 --- a/chrome/browser/views/tabs/tab.h +++ b/chrome/browser/views/tabs/tab.h @@ -103,7 +103,7 @@ class Tab : public TabRenderer, virtual bool GetTooltipText(int x, int y, std::wstring* tooltip); virtual bool GetTooltipTextOrigin(int x, int y, CPoint* origin); virtual std::string GetClassName() const { return kTabClassName; } - virtual bool GetAccessibleRole(VARIANT* role); + virtual bool GetAccessibleRole(AccessibilityTypes::Role* role); virtual bool GetAccessibleName(std::wstring* name); // views::ContextMenuController overrides: diff --git a/chrome/browser/views/tabs/tab_strip.cc b/chrome/browser/views/tabs/tab_strip.cc index 37e1a94..60c6268 100644 --- a/chrome/browser/views/tabs/tab_strip.cc +++ b/chrome/browser/views/tabs/tab_strip.cc @@ -711,11 +711,10 @@ int TabStrip::OnPerformDrop(const DropTargetEvent& event) { return GetDropEffect(event); } -bool TabStrip::GetAccessibleRole(VARIANT* role) { +bool TabStrip::GetAccessibleRole(AccessibilityTypes::Role* role) { DCHECK(role); - role->vt = VT_I4; - role->lVal = ROLE_SYSTEM_GROUPING; + *role = AccessibilityTypes::ROLE_GROUPING; return true; } diff --git a/chrome/browser/views/tabs/tab_strip.h b/chrome/browser/views/tabs/tab_strip.h index ea819a8..8e10b5e 100644 --- a/chrome/browser/views/tabs/tab_strip.h +++ b/chrome/browser/views/tabs/tab_strip.h @@ -100,7 +100,7 @@ class TabStrip : public views::View, virtual int OnDragUpdated(const views::DropTargetEvent& event); virtual void OnDragExited(); virtual int OnPerformDrop(const views::DropTargetEvent& event); - virtual bool GetAccessibleRole(VARIANT* role); + virtual bool GetAccessibleRole(AccessibilityTypes::Role* role); virtual bool GetAccessibleName(std::wstring* name); virtual void SetAccessibleName(const std::wstring& name); virtual views::View* GetViewForPoint(const gfx::Point& point); diff --git a/chrome/browser/views/toolbar_view.cc b/chrome/browser/views/toolbar_view.cc index 860385f..4757920 100644 --- a/chrome/browser/views/toolbar_view.cc +++ b/chrome/browser/views/toolbar_view.cc @@ -748,11 +748,10 @@ bool BrowserToolbarView::GetAccessibleName(std::wstring* name) { return false; } -bool BrowserToolbarView::GetAccessibleRole(VARIANT* role) { +bool BrowserToolbarView::GetAccessibleRole(AccessibilityTypes::Role* role) { DCHECK(role); - role->vt = VT_I4; - role->lVal = ROLE_SYSTEM_TOOLBAR; + *role = AccessibilityTypes::ROLE_TOOLBAR; return true; } diff --git a/chrome/browser/views/toolbar_view.h b/chrome/browser/views/toolbar_view.h index 9cb14fc..ca2502a 100644 --- a/chrome/browser/views/toolbar_view.h +++ b/chrome/browser/views/toolbar_view.h @@ -60,6 +60,9 @@ class BrowserToolbarView : public views::View, virtual bool OnKeyPressed(const views::KeyEvent& e); virtual bool OnKeyReleased(const views::KeyEvent& e); virtual gfx::Size GetPreferredSize(); + virtual bool GetAccessibleName(std::wstring* name); + virtual bool GetAccessibleRole(AccessibilityTypes::Role* role); + virtual void SetAccessibleName(const std::wstring& name); // Overridden from EncodingMenuControllerDelegate: virtual bool IsItemChecked(int id) const; @@ -91,17 +94,6 @@ class BrowserToolbarView : public views::View, virtual void OnInputInProgress(bool in_progress); - // Returns a brief, identifying string, containing a unique, readable name. - virtual bool GetAccessibleName(std::wstring* name); - - // 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. - virtual bool GetAccessibleRole(VARIANT* role); - - // Assigns an accessible string name. - virtual void SetAccessibleName(const std::wstring& name); - virtual View* GetAccFocusedChildView() { return acc_focused_view_; } // Returns the index of the next view of the toolbar, starting from the given diff --git a/chrome/common/accessibility_types.h b/chrome/common/accessibility_types.h new file mode 100644 index 0000000..b1e6e2e --- /dev/null +++ b/chrome/common/accessibility_types.h @@ -0,0 +1,48 @@ +// Copyright (c) 2006-2009 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. + +#ifndef CHROME_COMMON_ACCESSIBILITY_TYPES_H_ +#define CHROME_COMMON_ACCESSIBILITY_TYPES_H_ + +//////////////////////////////////////////////////////////////////////////////// +// +// AccessibilityTypes +// +// Provides enumerations used to preserve platform-independence in accessibility +// functions used in various Views, both in Browser\Views and Views. +// +//////////////////////////////////////////////////////////////////////////////// +class AccessibilityTypes { + public: + // 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. + // ViewAccessibility::get_accRole and ViewAccessibility::MSAARole). + enum Role { + ROLE_APPLICATION, + ROLE_BUTTONDROPDOWN, + ROLE_CLIENT, + ROLE_GROUPING, + ROLE_PAGETAB, + ROLE_PUSHBUTTON, + ROLE_TEXT, + ROLE_TOOLBAR + }; + + // 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() {} + ~AccessibilityTypes() {} +}; + +#endif // CHROME_COMMON_ACCESSIBILITY_TYPES_H_ diff --git a/chrome/common/common.vcproj b/chrome/common/common.vcproj index 5a26a5e..7bf3fed 100644 --- a/chrome/common/common.vcproj +++ b/chrome/common/common.vcproj @@ -358,6 +358,10 @@ </File> </Filter> <File + RelativePath=".\accessibility_types.h" + > + </File> + <File RelativePath=".\animation.cc" > </File> 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, |