diff options
author | ctguil@chromium.org <ctguil@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-27 23:00:03 +0000 |
---|---|---|
committer | ctguil@chromium.org <ctguil@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-27 23:00:03 +0000 |
commit | b82a049e6ffc65c14daf1c2c8bee6390cb7fe1fa (patch) | |
tree | 21f95e3df23460ae77342f865a24178d0cadba89 | |
parent | 6f496b2703a7ccb7bba1dbb14a2b9c00f02a853e (diff) | |
download | chromium_src-b82a049e6ffc65c14daf1c2c8bee6390cb7fe1fa.zip chromium_src-b82a049e6ffc65c14daf1c2c8bee6390cb7fe1fa.tar.gz chromium_src-b82a049e6ffc65c14daf1c2c8bee6390cb7fe1fa.tar.bz2 |
Initial work to fix the IAccessible tree in circumstances where there is a widget not at the root of the UI heirarchy. Also contains misc fixes for setting correct name/role for controls found in the Options dialog.
BUG=9621
TEST=none
Review URL: http://codereview.chromium.org/2174002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@48444 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/views/options/options_group_view.cc | 11 | ||||
-rw-r--r-- | chrome/browser/views/options/options_group_view.h | 5 | ||||
-rw-r--r-- | chrome/browser/views/options/options_page_view.cc | 8 | ||||
-rw-r--r-- | chrome/browser/views/options/options_page_view.h | 6 | ||||
-rw-r--r-- | chrome/browser/views/options/options_window_view.cc | 8 | ||||
-rw-r--r-- | views/accessibility/view_accessibility.cc | 59 | ||||
-rw-r--r-- | views/accessibility/view_accessibility.h | 3 | ||||
-rw-r--r-- | views/controls/tabbed_pane/native_tabbed_pane_win.h | 6 | ||||
-rw-r--r-- | views/controls/tabbed_pane/tabbed_pane.cc | 1 | ||||
-rw-r--r-- | views/view.cc | 12 | ||||
-rw-r--r-- | views/view.h | 11 | ||||
-rw-r--r-- | views/window/client_view.cc | 7 | ||||
-rw-r--r-- | views/window/client_view.h | 3 | ||||
-rw-r--r-- | views/window/non_client_view.cc | 5 | ||||
-rw-r--r-- | views/window/non_client_view.h | 2 |
15 files changed, 110 insertions, 37 deletions
diff --git a/chrome/browser/views/options/options_group_view.cc b/chrome/browser/views/options/options_group_view.cc index 3426d22..39cb18e2 100644 --- a/chrome/browser/views/options/options_group_view.cc +++ b/chrome/browser/views/options/options_group_view.cc @@ -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. @@ -48,6 +48,10 @@ OptionsGroupView::OptionsGroupView(views::View* contents, description_label_->SetMultiLine(true); description_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); + + SetAccessibleName(title); + contents->SetAccessibleName(title); + contents->SetAccessibleRole(AccessibilityTypes::ROLE_GROUPING); } void OptionsGroupView::SetHighlighted(bool highlighted) { @@ -62,6 +66,11 @@ int OptionsGroupView::GetContentsWidth() const { /////////////////////////////////////////////////////////////////////////////// // OptionsGroupView, views::View overrides: +bool OptionsGroupView::GetAccessibleRole(AccessibilityTypes::Role* role) { + *role = AccessibilityTypes::ROLE_GROUPING; + return true; +} + void OptionsGroupView::Paint(gfx::Canvas* canvas) { if (highlighted_) { COLORREF infocolor = GetSysColor(COLOR_INFOBK); diff --git a/chrome/browser/views/options/options_group_view.h b/chrome/browser/views/options/options_group_view.h index de39226..83a638f 100644 --- a/chrome/browser/views/options/options_group_view.h +++ b/chrome/browser/views/options/options_group_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. @@ -34,6 +34,7 @@ class OptionsGroupView : public views::View { protected: // views::View overrides: + virtual bool GetAccessibleRole(AccessibilityTypes::Role* role); virtual void Paint(gfx::Canvas* canvas); virtual void ViewHierarchyChanged(bool is_add, views::View* parent, @@ -55,7 +56,7 @@ class OptionsGroupView : public views::View { // user's attention. bool highlighted_; - DISALLOW_EVIL_CONSTRUCTORS(OptionsGroupView); + DISALLOW_COPY_AND_ASSIGN(OptionsGroupView); }; #endif // CHROME_BROWSER_VIEWS_OPTIONS_OPTIONS_GROUP_VIEW_H__ diff --git a/chrome/browser/views/options/options_page_view.cc b/chrome/browser/views/options/options_page_view.cc index c0d5efb..933ee9a 100644 --- a/chrome/browser/views/options/options_page_view.cc +++ b/chrome/browser/views/options/options_page_view.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. @@ -35,3 +35,9 @@ void OptionsPageView::ViewHierarchyChanged(bool is_add, NotifyPrefChanged(NULL); } } + +bool OptionsPageView::GetAccessibleRole(AccessibilityTypes::Role* role) { + *role = AccessibilityTypes::ROLE_PAGETAB; + return true; +} + diff --git a/chrome/browser/views/options/options_page_view.h b/chrome/browser/views/options/options_page_view.h index 3c29acf..289b00a 100644 --- a/chrome/browser/views/options/options_page_view.h +++ b/chrome/browser/views/options/options_page_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. @@ -40,11 +40,13 @@ class OptionsPageView : public views::View, views::View* parent, views::View* child); + virtual bool GetAccessibleRole(AccessibilityTypes::Role* role); + private: // Whether or not the control layout has been initialized for this page. bool initialized_; - DISALLOW_EVIL_CONSTRUCTORS(OptionsPageView); + DISALLOW_COPY_AND_ASSIGN(OptionsPageView); }; #endif // CHROME_BROWSER_VIEWS_OPTIONS_OPTIONS_PAGE_VIEW_H__ diff --git a/chrome/browser/views/options/options_window_view.cc b/chrome/browser/views/options/options_window_view.cc index 86933b65..a01cebe 100644 --- a/chrome/browser/views/options/options_window_view.cc +++ b/chrome/browser/views/options/options_window_view.cc @@ -53,6 +53,7 @@ class OptionsWindowView : public views::View, virtual void TabSelectedAt(int index); // views::View overrides: + virtual bool GetAccessibleRole(AccessibilityTypes::Role* role); virtual void Layout(); virtual gfx::Size GetPreferredSize(); @@ -170,6 +171,11 @@ void OptionsWindowView::TabSelectedAt(int index) { /////////////////////////////////////////////////////////////////////////////// // OptionsWindowView, views::View overrides: +bool OptionsWindowView::GetAccessibleRole(AccessibilityTypes::Role* role) { + *role = AccessibilityTypes::ROLE_CLIENT; + return true; +} + void OptionsWindowView::Layout() { tabs_->SetBounds(kDialogPadding, kDialogPadding, width() - (2 * kDialogPadding), @@ -196,6 +202,8 @@ void OptionsWindowView::ViewHierarchyChanged(bool is_add, void OptionsWindowView::Init() { tabs_ = new views::TabbedPane; + tabs_->SetAccessibleName(l10n_util::GetStringF(IDS_OPTIONS_DIALOG_TITLE, + l10n_util::GetString(IDS_PRODUCT_NAME))); tabs_->SetListener(this); AddChildView(tabs_); diff --git a/views/accessibility/view_accessibility.cc b/views/accessibility/view_accessibility.cc index c440e53..67aaaf2 100644 --- a/views/accessibility/view_accessibility.cc +++ b/views/accessibility/view_accessibility.cc @@ -6,6 +6,7 @@ #include "views/accessibility/view_accessibility_wrapper.h" #include "views/widget/widget.h" +#include "views/widget/widget_win.h" const wchar_t kViewsUninitializeAccessibilityInstance[] = L"Views_Uninitialize_AccessibilityInstance"; @@ -285,7 +286,6 @@ STDMETHODIMP ViewAccessibility::get_accChild(VARIANT var_child, } views::View* child_view = NULL; - bool get_iaccessible = false; // Check to see if child is out-of-bounds. if (IsValidChild((var_child.lVal - 1), view_)) { @@ -293,7 +293,6 @@ STDMETHODIMP ViewAccessibility::get_accChild(VARIANT var_child, } else { // Child is located elsewhere in the hierarchy, get ID and adjust for MSAA. child_view = view_->GetViewByID(static_cast<int>(var_child.lVal)); - get_iaccessible = true; } if (!child_view) { @@ -302,29 +301,35 @@ STDMETHODIMP ViewAccessibility::get_accChild(VARIANT var_child, return E_FAIL; } - if (get_iaccessible || child_view->GetChildViewCount() != 0) { - // Retrieve the IUnknown interface for the requested child view, and - // assign the IDispatch returned. - if ((GetViewAccessibilityWrapper(child_view))-> - GetInstance(IID_IAccessible, - reinterpret_cast<void**>(disp_child)) == S_OK) { - // Increment the reference count for the retrieved interface. - (*disp_child)->AddRef(); + // First, check to see if the child is a native view. + if (child_view->GetClassName() == views::NativeViewHost::kViewClassName) { + views::NativeViewHost* native_host = + static_cast<views::NativeViewHost*>(child_view); + if (GetNativeIAccessibleInterface(native_host, disp_child) == S_OK) + return S_OK; + } + + // Next, see if the child view is a widget container. + if (child_view->child_widget()) { + views::WidgetWin* native_widget = + reinterpret_cast<views::WidgetWin*>(child_view->child_widget()); + if (GetNativeIAccessibleInterface( + native_widget->GetNativeView(), disp_child) == S_OK) { return S_OK; - } else { - // No interface, return failure. - return E_NOINTERFACE; } + } + + // Finally, try our ViewAccessibility implementation. + // Retrieve the IUnknown interface for the requested child view, and + // assign the IDispatch returned. + HRESULT hr = GetViewAccessibilityWrapper(child_view)-> + GetInstance(IID_IAccessible, reinterpret_cast<void**>(disp_child)); + if (hr == S_OK) { + // Increment the reference count for the retrieved interface. + (*disp_child)->AddRef(); + return S_OK; } else { - if (child_view->GetClassName() == views::NativeViewHost::kViewClassName) { - views::NativeViewHost* native_host = - static_cast<views::NativeViewHost*>(child_view); - if (GetNativeIAccessibleInterface(native_host, disp_child) == S_OK) - return S_OK; - } - // When at a leaf, children are handled by the parent object. - *disp_child = NULL; - return S_FALSE; + return E_NOINTERFACE; } } @@ -697,9 +702,8 @@ void ViewAccessibility::SetState(VARIANT* msaa_state, views::View* view) { // Add on any view-specific states. AccessibilityTypes::State state; - view->GetAccessibleState(&state); - - msaa_state->lVal |= MSAAState(state); + if (view->GetAccessibleState(&state)) + msaa_state->lVal |= MSAAState(state); } // IAccessible functions not supported. @@ -839,6 +843,11 @@ HRESULT ViewAccessibility::GetNativeIAccessibleInterface( native_view_window = native_host->native_view(); } + return GetNativeIAccessibleInterface(native_view_window, disp_child); +} + +HRESULT ViewAccessibility::GetNativeIAccessibleInterface( + HWND native_view_window , IDispatch** disp_child) { if (IsWindow(native_view_window)) { LRESULT ret = SendMessage(native_view_window, WM_GETOBJECT, 0, OBJID_CLIENT); diff --git a/views/accessibility/view_accessibility.h b/views/accessibility/view_accessibility.h index 0224dfa07..d2472fb 100644 --- a/views/accessibility/view_accessibility.h +++ b/views/accessibility/view_accessibility.h @@ -141,6 +141,9 @@ class ATL_NO_VTABLE ViewAccessibility HRESULT GetNativeIAccessibleInterface(views::NativeViewHost* native_host, IDispatch** disp_child); + HRESULT GetNativeIAccessibleInterface(HWND native_view_window, + IDispatch** disp_child); + // Member View needed for view-specific calls. views::View* view_; diff --git a/views/controls/tabbed_pane/native_tabbed_pane_win.h b/views/controls/tabbed_pane/native_tabbed_pane_win.h index a7423f5..c3dcaed 100644 --- a/views/controls/tabbed_pane/native_tabbed_pane_win.h +++ b/views/controls/tabbed_pane/native_tabbed_pane_win.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. @@ -47,6 +47,10 @@ class NativeTabbedPaneWin : public NativeControlWin, virtual FocusTraversable* GetFocusTraversable(); virtual void ViewHierarchyChanged(bool is_add, View *parent, View *child); + virtual Widget* child_widget() { + return reinterpret_cast<Widget*>(content_window_); + } + private: // Called upon creation of native control to initialize tabs that are added // before the native control is created. diff --git a/views/controls/tabbed_pane/tabbed_pane.cc b/views/controls/tabbed_pane/tabbed_pane.cc index ec324d4..5cb570a 100644 --- a/views/controls/tabbed_pane/tabbed_pane.cc +++ b/views/controls/tabbed_pane/tabbed_pane.cc @@ -35,6 +35,7 @@ void TabbedPane::AddTabAtIndex(int index, bool select_if_first_tab) { native_tabbed_pane_->AddTabAtIndex(index, title, contents, select_if_first_tab); + contents->SetAccessibleName(title); } int TabbedPane::GetSelectedTabIndex() { diff --git a/views/view.cc b/views/view.cc index 5cb4f0e..012240a 100644 --- a/views/view.cc +++ b/views/view.cc @@ -1127,10 +1127,22 @@ bool View::GetAccessibleName(std::wstring* name) { return true; } +bool View::GetAccessibleRole(AccessibilityTypes::Role* role) { + if (accessible_role_) { + *role = accessible_role_; + return true; + } + return false; +} + void View::SetAccessibleName(const std::wstring& name) { accessible_name_ = name; } +void View::SetAccessibleRole(const AccessibilityTypes::Role role) { + accessible_role_ = role; +} + // static void View::ConvertPointToView(const View* src, const View* dst, diff --git a/views/view.h b/views/view.h index 83247e6..c0f6f07 100644 --- a/views/view.h +++ b/views/view.h @@ -265,6 +265,8 @@ class View : public AcceleratorTarget { // Returns whether the view is hot-tracked. virtual bool IsHotTracked() const { return false; } + virtual Widget* child_widget() { return NULL; } + // Returns whether the view is pushed. virtual bool IsPushed() const { return false; } @@ -562,9 +564,7 @@ class View : public AcceleratorTarget { // 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(AccessibilityTypes::Role* role) { - return false; - } + virtual bool GetAccessibleRole(AccessibilityTypes::Role* role); // Returns the accessibility state of the current view. Sets the input State // appropriately, and returns true if successful. @@ -581,6 +581,8 @@ class View : public AcceleratorTarget { // certain type. void SetAccessibleName(const std::wstring& name); + void SetAccessibleRole(const AccessibilityTypes::Role role); + // Returns an instance of a wrapper class implementing the (platform-specific) // accessibility interface for a given View. If one exists, it will be // re-used, otherwise a new instance will be created. @@ -1245,6 +1247,9 @@ class View : public AcceleratorTarget { // Name for this view, which can be retrieved by accessibility APIs. std::wstring accessible_name_; + // Role for this view, which can be retrieved by accessibility APIs. + AccessibilityTypes::Role accessible_role_; + // Next view to be focused when the Tab key is pressed. View* next_focusable_view_; diff --git a/views/window/client_view.cc b/views/window/client_view.cc index 57046c1..1594386 100644 --- a/views/window/client_view.cc +++ b/views/window/client_view.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. @@ -61,4 +61,9 @@ void ClientView::DidChangeBounds(const gfx::Rect& previous, // NonClientView::Layout. } +bool ClientView::GetAccessibleRole(AccessibilityTypes::Role* role) { + *role = AccessibilityTypes::ROLE_CLIENT; + return true; +} + } // namespace views diff --git a/views/window/client_view.h b/views/window/client_view.h index b56fcfd..f6088e3 100644 --- a/views/window/client_view.h +++ b/views/window/client_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. @@ -62,6 +62,7 @@ class ClientView : public View { virtual void ViewHierarchyChanged(bool is_add, View* parent, View* child); virtual void DidChangeBounds(const gfx::Rect& previous, const gfx::Rect& current); + virtual bool GetAccessibleRole(AccessibilityTypes::Role* role); // Accessors for private data members. Window* window() const { return window_; } diff --git a/views/window/non_client_view.cc b/views/window/non_client_view.cc index e2d1a5c..8fe3346 100644 --- a/views/window/non_client_view.cc +++ b/views/window/non_client_view.cc @@ -253,4 +253,9 @@ bool NonClientFrameView::ShouldPaintAsActive() const { return GetWindow()->IsActive() || paint_as_active_; } +bool NonClientFrameView::GetAccessibleRole(AccessibilityTypes::Role* role) { + *role = AccessibilityTypes::ROLE_WINDOW; + return true; +} + } // namespace views diff --git a/views/window/non_client_view.h b/views/window/non_client_view.h index 0e736df..4377505 100644 --- a/views/window/non_client_view.h +++ b/views/window/non_client_view.h @@ -70,6 +70,8 @@ class NonClientFrameView : public View { // Overridden from View: virtual bool HitTest(const gfx::Point& l) const; + virtual bool GetAccessibleRole(AccessibilityTypes::Role* role); + protected: virtual void DidChangeBounds(const gfx::Rect& previous, const gfx::Rect& current); |