diff options
author | dmazzoni@chromium.org <dmazzoni@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-13 22:25:25 +0000 |
---|---|---|
committer | dmazzoni@chromium.org <dmazzoni@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-13 22:25:25 +0000 |
commit | ce3c9bf8016bf2fd11bd41e388764d9f4724e5ef (patch) | |
tree | d0e046745460465d1d06ca28e60fc6cf90ef37f1 /views | |
parent | 69e7ecec96febc8fb52c87206028f2ee2cc2b2e8 (diff) | |
download | chromium_src-ce3c9bf8016bf2fd11bd41e388764d9f4724e5ef.zip chromium_src-ce3c9bf8016bf2fd11bd41e388764d9f4724e5ef.tar.gz chromium_src-ce3c9bf8016bf2fd11bd41e388764d9f4724e5ef.tar.bz2 |
Make the web content accessibility tree a descendant of the main window's
accessibility tree again, which makes it possible to debug Chrome
accessibility on Windows using tools like AccExplorer32 or AccProbe.
This change refactors the code that retrieves the Windows IAccessible
interface from a View that wraps a native HWND. The previous code was
brittle, using ViewProps and hardcoded View classname tests. This
change moves that logic directly to the classes that wrap native
views.
BUG=54220
BUG=85673
TEST=Updated AccessibilityWinBrowserTest.ContainsRendererAccessibilityTree
Review URL: http://codereview.chromium.org/6995126
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@88913 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r-- | views/accessibility/native_view_accessibility_win.cc | 68 | ||||
-rw-r--r-- | views/accessibility/native_view_accessibility_win.h | 14 | ||||
-rw-r--r-- | views/controls/native/native_view_host.cc | 13 | ||||
-rw-r--r-- | views/controls/native/native_view_host.h | 3 | ||||
-rw-r--r-- | views/controls/native/native_view_host_gtk.cc | 4 | ||||
-rw-r--r-- | views/controls/native/native_view_host_gtk.h | 3 | ||||
-rw-r--r-- | views/controls/native/native_view_host_views.cc | 4 | ||||
-rw-r--r-- | views/controls/native/native_view_host_views.h | 3 | ||||
-rw-r--r-- | views/controls/native/native_view_host_win.cc | 18 | ||||
-rw-r--r-- | views/controls/native/native_view_host_win.h | 3 | ||||
-rw-r--r-- | views/controls/native/native_view_host_wrapper.h | 8 | ||||
-rw-r--r-- | views/controls/tabbed_pane/native_tabbed_pane_win.cc | 4 | ||||
-rw-r--r-- | views/controls/tabbed_pane/native_tabbed_pane_win.h | 1 | ||||
-rw-r--r-- | views/view.cc | 6 | ||||
-rw-r--r-- | views/view.h | 13 | ||||
-rw-r--r-- | views/view_gtk.cc | 5 | ||||
-rw-r--r-- | views/view_win.cc | 2 | ||||
-rw-r--r-- | views/widget/native_widget_win.cc | 3 |
18 files changed, 69 insertions, 106 deletions
diff --git a/views/accessibility/native_view_accessibility_win.cc b/views/accessibility/native_view_accessibility_win.cc index 6796afe..e36c406 100644 --- a/views/accessibility/native_view_accessibility_win.cc +++ b/views/accessibility/native_view_accessibility_win.cc @@ -28,33 +28,6 @@ scoped_refptr<NativeViewAccessibilityWin> NativeViewAccessibilityWin::Create( return scoped_refptr<NativeViewAccessibilityWin>(instance); } -// static -IAccessible* NativeViewAccessibilityWin::GetAccessibleForView( - views::View* view) { - IAccessible* accessible = NULL; - - // First, check to see if the view is a native view. - if (view->GetClassName() == views::NativeViewHost::kViewClassName) { - views::NativeViewHost* native_host = - static_cast<views::NativeViewHost*>(view); - if (GetNativeIAccessibleInterface(native_host, &accessible) == S_OK) - return accessible; - } - - // Next, see if the view is a widget container. - if (view->GetChildWidget()) { - views::NativeWidgetWin* native_widget = - reinterpret_cast<views::NativeWidgetWin*>(view->GetChildWidget()); - if (GetNativeIAccessibleInterface( - native_widget->GetNativeView(), &accessible) == S_OK) { - return accessible; - } - } - - // Finally, use our NativeViewAccessibilityWin implementation. - return view->GetNativeViewAccessibilityWin(); -} - NativeViewAccessibilityWin::NativeViewAccessibilityWin() : view_(NULL) { } @@ -86,7 +59,7 @@ STDMETHODIMP NativeViewAccessibilityWin::accHitTest( child->lVal = CHILDID_SELF; } else { child->vt = VT_DISPATCH; - child->pdispVal = GetAccessibleForView(view); + child->pdispVal = view->GetNativeViewAccessible(); child->pdispVal->AddRef(); } return S_OK; @@ -156,7 +129,7 @@ STDMETHODIMP NativeViewAccessibilityWin::accNavigate( views::View* child = view_->GetChildViewAt(child_id); end->vt = VT_DISPATCH; - end->pdispVal = GetAccessibleForView(child); + end->pdispVal = child->GetNativeViewAccessible(); end->pdispVal->AddRef(); return S_OK; } @@ -190,7 +163,7 @@ STDMETHODIMP NativeViewAccessibilityWin::accNavigate( } views::View* child = parent->GetChildViewAt(view_index); - end->pdispVal = GetAccessibleForView(child); + end->pdispVal = child->GetNativeViewAccessible(); end->vt = VT_DISPATCH; end->pdispVal->AddRef(); return S_OK; @@ -270,7 +243,7 @@ STDMETHODIMP NativeViewAccessibilityWin::get_accChild(VARIANT var_child, return E_FAIL; } - *disp_child = GetAccessibleForView(child_view); + *disp_child = child_view->GetNativeViewAccessible(); (*disp_child)->AddRef(); return S_OK; } @@ -344,7 +317,7 @@ STDMETHODIMP NativeViewAccessibilityWin::get_accFocus(VARIANT* focus_child) { focus_child->lVal = CHILDID_SELF; } else if (focus && view_->Contains(focus)) { // Return the child object that has the keyboard focus. - focus_child->pdispVal = GetAccessibleForView(focus); + focus_child->pdispVal = focus->GetNativeViewAccessible(); focus_child->pdispVal->AddRef(); return S_OK; } else { @@ -432,7 +405,7 @@ STDMETHODIMP NativeViewAccessibilityWin::get_accParent( return S_OK; } - *disp_parent = GetAccessibleForView(parent_view); + *disp_parent = parent_view->GetNativeViewAccessible(); (*disp_parent)->AddRef(); return S_OK; } @@ -724,32 +697,3 @@ int32 NativeViewAccessibilityWin::MSAAState(AccessibilityTypes::State state) { msaa_state |= STATE_SYSTEM_UNAVAILABLE; return msaa_state; } - -// static -HRESULT NativeViewAccessibilityWin::GetNativeIAccessibleInterface( - views::NativeViewHost* native_host, IAccessible** accessible) { - if (!native_host || !accessible) - return E_INVALIDARG; - - HWND native_view_window = static_cast<HWND>( - ui::ViewProp::GetValue(native_host->native_view(), - views::kViewsNativeHostPropForAccessibility)); - if (!IsWindow(native_view_window)) { - native_view_window = native_host->native_view(); - } - - return GetNativeIAccessibleInterface(native_view_window, accessible); -} - -// static -HRESULT NativeViewAccessibilityWin::GetNativeIAccessibleInterface( - HWND native_view_window , IAccessible** accessible) { - if (IsWindow(native_view_window)) { - LRESULT ret = SendMessage(native_view_window, WM_GETOBJECT, 0, - OBJID_CLIENT); - return ObjectFromLresult(ret, IID_IDispatch, 0, - reinterpret_cast<void**>(accessible)); - } - - return E_FAIL; -} diff --git a/views/accessibility/native_view_accessibility_win.h b/views/accessibility/native_view_accessibility_win.h index 89708ab..2736160 100644 --- a/views/accessibility/native_view_accessibility_win.h +++ b/views/accessibility/native_view_accessibility_win.h @@ -16,11 +16,8 @@ #include "views/controls/native/native_view_host.h" #include "views/view.h" -namespace views { -extern const char kViewsNativeHostPropForAccessibility[]; // Note: do not put NativeViewAccessibilityWin in the namespace "views"; // Visual Studio 2005 does not allow an ATL::CComObject symbol in a namespace. -} //////////////////////////////////////////////////////////////////////////////// // @@ -43,9 +40,6 @@ class ATL_NO_VTABLE NativeViewAccessibilityWin // Create method for view accessibility. static scoped_refptr<NativeViewAccessibilityWin> Create(views::View* view); - // Returns the IAccessible interface for a view. - static IAccessible* GetAccessibleForView(views::View* view); - virtual ~NativeViewAccessibilityWin(); void set_view(views::View* view) { view_ = view; } @@ -150,14 +144,6 @@ class ATL_NO_VTABLE NativeViewAccessibilityWin // Helper function which sets applicable states of view. void SetState(VARIANT* msaa_state, views::View* view); - // Returns the IAccessible interface for a native view if applicable. - // Returns S_OK on success. - static HRESULT GetNativeIAccessibleInterface( - views::NativeViewHost* native_host, IAccessible** accessible); - - static HRESULT GetNativeIAccessibleInterface( - HWND native_view_window, IAccessible** accessible); - // Give CComObject access to the class constructor. template <class Base> friend class CComObject; diff --git a/views/controls/native/native_view_host.cc b/views/controls/native/native_view_host.cc index 42321e5..1b9d74e 100644 --- a/views/controls/native/native_view_host.cc +++ b/views/controls/native/native_view_host.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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. @@ -200,6 +200,17 @@ bool NativeViewHost::ContainsNativeView(gfx::NativeView native_view) const { return View::ContainsNativeView(native_view); } +gfx::NativeViewAccessible NativeViewHost::GetNativeViewAccessible() { + if (native_wrapper_.get()) { + gfx::NativeViewAccessible accessible_view = + native_wrapper_->GetNativeViewAccessible(); + if (accessible_view) + return accessible_view; + } + + return View::GetNativeViewAccessible(); +} + //////////////////////////////////////////////////////////////////////////////// // NativeViewHost, private: diff --git a/views/controls/native/native_view_host.h b/views/controls/native/native_view_host.h index e19aca2..30e4ddc 100644 --- a/views/controls/native/native_view_host.h +++ b/views/controls/native/native_view_host.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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. @@ -82,6 +82,7 @@ class NativeViewHost : public View { virtual void VisibilityChanged(View* starting_from, bool is_visible); virtual void OnFocus(); virtual bool ContainsNativeView(gfx::NativeView native_view) const; + virtual gfx::NativeViewAccessible GetNativeViewAccessible(); protected: virtual bool NeedsNotificationWhenVisibleBoundsChange() const; diff --git a/views/controls/native/native_view_host_gtk.cc b/views/controls/native/native_view_host_gtk.cc index fedbc416..833e4b4 100644 --- a/views/controls/native/native_view_host_gtk.cc +++ b/views/controls/native/native_view_host_gtk.cc @@ -256,6 +256,10 @@ void NativeViewHostGtk::SetFocus() { gtk_widget_grab_focus(host_->native_view()); } +gfx::NativeViewAccessible NativeViewHostGtk::GetNativeViewAccessible() { + return NULL; +} + //////////////////////////////////////////////////////////////////////////////// // NativeViewHostGtk, private: diff --git a/views/controls/native/native_view_host_gtk.h b/views/controls/native/native_view_host_gtk.h index eb98349..0ecfd99 100644 --- a/views/controls/native/native_view_host_gtk.h +++ b/views/controls/native/native_view_host_gtk.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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. @@ -38,6 +38,7 @@ class NativeViewHostGtk : public NativeViewHostWrapper { virtual void ShowWidget(int x, int y, int w, int h); virtual void HideWidget(); virtual void SetFocus(); + virtual gfx::NativeViewAccessible GetNativeViewAccessible(); private: // Create and Destroy the GtkFixed that performs clipping on our hosted diff --git a/views/controls/native/native_view_host_views.cc b/views/controls/native/native_view_host_views.cc index 7d44818..4b84a05 100644 --- a/views/controls/native/native_view_host_views.cc +++ b/views/controls/native/native_view_host_views.cc @@ -75,4 +75,8 @@ void NativeViewHostViews::SetFocus() { host_->views_view()->RequestFocus(); } +gfx::NativeViewAccessible NativeViewHostViews::GetNativeViewAccessible() { + return NULL; +} + } // namespace views diff --git a/views/controls/native/native_view_host_views.h b/views/controls/native/native_view_host_views.h index 891cf49..cd9f96b 100644 --- a/views/controls/native/native_view_host_views.h +++ b/views/controls/native/native_view_host_views.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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. @@ -30,6 +30,7 @@ class NativeViewHostViews : public NativeViewHostWrapper { virtual void ShowWidget(int x, int y, int w, int h); virtual void HideWidget(); virtual void SetFocus(); + virtual gfx::NativeViewAccessible GetNativeViewAccessible(); private: // Our associated NativeViewHost. diff --git a/views/controls/native/native_view_host_win.cc b/views/controls/native/native_view_host_win.cc index f25e722..b7fa074 100644 --- a/views/controls/native/native_view_host_win.cc +++ b/views/controls/native/native_view_host_win.cc @@ -4,6 +4,8 @@ #include "views/controls/native/native_view_host_win.h" +#include <oleacc.h> + #include "base/logging.h" #include "ui/gfx/canvas.h" #include "views/controls/native/native_view_host.h" @@ -123,6 +125,22 @@ void NativeViewHostWin::SetFocus() { ::SetFocus(host_->native_view()); } +gfx::NativeViewAccessible NativeViewHostWin::GetNativeViewAccessible() { + HWND hwnd = host_->native_view(); + if (!IsWindow(hwnd)) + return NULL; + + LRESULT ret = SendMessage(hwnd, WM_GETOBJECT, 0, OBJID_CLIENT); + IAccessible* accessible = NULL; + HRESULT success = ObjectFromLresult( + ret, IID_IDispatch, 0, reinterpret_cast<void**>(accessible)); + if (success == S_OK) { + return accessible; + } else { + return NULL; + } +} + //////////////////////////////////////////////////////////////////////////////// // NativeViewHostWrapper, public: diff --git a/views/controls/native/native_view_host_win.h b/views/controls/native/native_view_host_win.h index fb8d8be..e885399 100644 --- a/views/controls/native/native_view_host_win.h +++ b/views/controls/native/native_view_host_win.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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. @@ -30,6 +30,7 @@ class NativeViewHostWin : public NativeViewHostWrapper { virtual void ShowWidget(int x, int y, int w, int h); virtual void HideWidget(); virtual void SetFocus(); + virtual gfx::NativeViewAccessible GetNativeViewAccessible(); private: // Our associated NativeViewHost. diff --git a/views/controls/native/native_view_host_wrapper.h b/views/controls/native/native_view_host_wrapper.h index 1b06b3e..8fdd8ad 100644 --- a/views/controls/native/native_view_host_wrapper.h +++ b/views/controls/native/native_view_host_wrapper.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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. @@ -6,6 +6,8 @@ #define VIEWS_CONTROLS_NATIVE_NATIVE_VIEW_HOST_WRAPPER_H_ #pragma once +#include "ui/gfx/native_widget_types.h" + namespace views { class NativeViewHost; @@ -56,6 +58,10 @@ class NativeViewHostWrapper { // Sets focus to the gfx::NativeView. virtual void SetFocus() = 0; + // Return the native view accessible corresponding to the wrapped native + // view. + virtual gfx::NativeViewAccessible GetNativeViewAccessible() = 0; + // Creates a platform-specific instance of an object implementing this // interface. static NativeViewHostWrapper* CreateWrapper(NativeViewHost* host); diff --git a/views/controls/tabbed_pane/native_tabbed_pane_win.cc b/views/controls/tabbed_pane/native_tabbed_pane_win.cc index a585b1b..829d5a3 100644 --- a/views/controls/tabbed_pane/native_tabbed_pane_win.cc +++ b/views/controls/tabbed_pane/native_tabbed_pane_win.cc @@ -364,10 +364,6 @@ void NativeTabbedPaneWin::ViewHierarchyChanged(bool is_add, } } -Widget* NativeTabbedPaneWin::GetChildWidget() { - return content_window_; -} - //////////////////////////////////////////////////////////////////////////////// // NativeTabbedPaneWin, private: diff --git a/views/controls/tabbed_pane/native_tabbed_pane_win.h b/views/controls/tabbed_pane/native_tabbed_pane_win.h index 4fb2a2e..f3e84ea 100644 --- a/views/controls/tabbed_pane/native_tabbed_pane_win.h +++ b/views/controls/tabbed_pane/native_tabbed_pane_win.h @@ -49,7 +49,6 @@ class NativeTabbedPaneWin : public NativeControlWin, virtual void Layout(); virtual FocusTraversable* GetFocusTraversable(); virtual void ViewHierarchyChanged(bool is_add, View *parent, View *child); - virtual Widget* GetChildWidget(); private: // Called upon creation of native control to initialize tabs that are added diff --git a/views/view.cc b/views/view.cc index edc0178..d8e95f1 100644 --- a/views/view.cc +++ b/views/view.cc @@ -89,12 +89,6 @@ bool View::IsHotTracked() const { return false; } -// FATE TBD -------------------------------------------------------------------- - -Widget* View::GetChildWidget() { - return NULL; -} - // Creation and lifetime ------------------------------------------------------- View::View() diff --git a/views/view.h b/views/view.h index 618c53d..cd90af9f 100644 --- a/views/view.h +++ b/views/view.h @@ -172,10 +172,6 @@ class View : public AcceleratorTarget { // Returns whether the view is hot-tracked. virtual bool IsHotTracked() const; - // FATE TBD ------------------------------------------------------------------ - // TODO(beng): Figure out what these methods are for and delete them. - virtual Widget* GetChildWidget(); - // Creation and lifetime ----------------------------------------------------- View(); @@ -872,11 +868,8 @@ class View : public AcceleratorTarget { // Modifies |state| to reflect the current accessible state of this view. virtual void GetAccessibleState(ui::AccessibleViewState* state) { } -#if defined(OS_WIN) - // Returns an instance of the Windows-specific accessibility interface - // for this View. - NativeViewAccessibilityWin* GetNativeViewAccessibilityWin(); -#endif + // Returns an instance of the native accessibility interface for this view. + virtual gfx::NativeViewAccessible GetNativeViewAccessible(); // Scrolling ----------------------------------------------------------------- // TODO(beng): Figure out if this can live somewhere other than View, i.e. @@ -1428,8 +1421,8 @@ class View : public AcceleratorTarget { // Accessibility ------------------------------------------------------------- + // The Windows-specific accessibility implementation for this view. #if defined(OS_WIN) - // The Windows-specific accessibility implementation for this View. scoped_refptr<NativeViewAccessibilityWin> native_view_accessibility_win_; #endif diff --git a/views/view_gtk.cc b/views/view_gtk.cc index 5155099..af62f1e 100644 --- a/views/view_gtk.cc +++ b/views/view_gtk.cc @@ -10,6 +10,11 @@ namespace views { +gfx::NativeViewAccessible View::GetNativeViewAccessible() { + NOTIMPLEMENTED(); + return NULL; +} + int View::GetHorizontalDragThreshold() { static bool determined_threshold = false; static int drag_threshold = 8; diff --git a/views/view_win.cc b/views/view_win.cc index b083dbc..fdfdfb4 100644 --- a/views/view_win.cc +++ b/views/view_win.cc @@ -21,7 +21,7 @@ namespace views { -NativeViewAccessibilityWin* View::GetNativeViewAccessibilityWin() { +gfx::NativeViewAccessible View::GetNativeViewAccessible() { if (!native_view_accessibility_win_.get()) native_view_accessibility_win_ = NativeViewAccessibilityWin::Create(this); diff --git a/views/widget/native_widget_win.cc b/views/widget/native_widget_win.cc index 997d50f..15f03b9 100644 --- a/views/widget/native_widget_win.cc +++ b/views/widget/native_widget_win.cc @@ -1292,8 +1292,7 @@ LRESULT NativeWidgetWin::OnGetObject(UINT uMsg, if (OBJID_CLIENT == l_param) { // Retrieve MSAA dispatch object for the root view. base::win::ScopedComPtr<IAccessible> root( - NativeViewAccessibilityWin::GetAccessibleForView( - GetWidget()->GetRootView())); + GetWidget()->GetRootView()->GetNativeViewAccessible()); // Create a reference that MSAA will marshall to the client. reference_result = LresultFromObject(IID_IAccessible, w_param, |