1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef VIEWS_ACCESSIBILITY_NATIVE_VIEW_ACCESSIBILITY_WIN_H_
6 #define VIEWS_ACCESSIBILITY_NATIVE_VIEW_ACCESSIBILITY_WIN_H_
14 #include "base/memory/scoped_ptr.h"
15 #include "ui/base/accessibility/accessible_view_state.h"
16 #include "views/controls/native/native_view_host.h"
17 #include "views/view.h"
19 // Note: do not put NativeViewAccessibilityWin in the namespace "views";
20 // Visual Studio 2005 does not allow an ATL::CComObject symbol in a namespace.
22 ////////////////////////////////////////////////////////////////////////////////
24 // NativeViewAccessibilityWin
26 // Class implementing the MSAA IAccessible COM interface for a generic View,
27 // providing accessibility to be used by screen readers and other assistive
30 ////////////////////////////////////////////////////////////////////////////////
31 class ATL_NO_VTABLE NativeViewAccessibilityWin
32 : public CComObjectRootEx
<CComMultiThreadModel
>,
33 public IDispatchImpl
<IAccessible
, &IID_IAccessible
, &LIBID_Accessibility
> {
35 BEGIN_COM_MAP(NativeViewAccessibilityWin
)
36 COM_INTERFACE_ENTRY2(IDispatch
, IAccessible
)
37 COM_INTERFACE_ENTRY(IAccessible
)
40 // Create method for view accessibility.
41 static scoped_refptr
<NativeViewAccessibilityWin
> Create(views::View
* view
);
43 virtual ~NativeViewAccessibilityWin();
45 void set_view(views::View
* view
) { view_
= view
; }
47 // Supported IAccessible methods.
49 // Retrieves the child element or child object at a given point on the screen.
50 STDMETHODIMP
accHitTest(LONG x_left
, LONG y_top
, VARIANT
* child
);
52 // Performs the object's default action.
53 STDMETHODIMP
accDoDefaultAction(VARIANT var_id
);
55 // Retrieves the specified object's current screen location.
56 STDMETHODIMP
accLocation(LONG
* x_left
,
62 // Traverses to another UI element and retrieves the object.
63 STDMETHODIMP
accNavigate(LONG nav_dir
, VARIANT start
, VARIANT
* end
);
65 // Retrieves an IDispatch interface pointer for the specified child.
66 STDMETHODIMP
get_accChild(VARIANT var_child
, IDispatch
** disp_child
);
68 // Retrieves the number of accessible children.
69 STDMETHODIMP
get_accChildCount(LONG
* child_count
);
71 // Retrieves a string that describes the object's default action.
72 STDMETHODIMP
get_accDefaultAction(VARIANT var_id
, BSTR
* default_action
);
74 // Retrieves the tooltip description.
75 STDMETHODIMP
get_accDescription(VARIANT var_id
, BSTR
* desc
);
77 // Retrieves the object that has the keyboard focus.
78 STDMETHODIMP
get_accFocus(VARIANT
* focus_child
);
80 // Retrieves the specified object's shortcut.
81 STDMETHODIMP
get_accKeyboardShortcut(VARIANT var_id
, BSTR
* access_key
);
83 // Retrieves the name of the specified object.
84 STDMETHODIMP
get_accName(VARIANT var_id
, BSTR
* name
);
86 // Retrieves the IDispatch interface of the object's parent.
87 STDMETHODIMP
get_accParent(IDispatch
** disp_parent
);
89 // Retrieves information describing the role of the specified object.
90 STDMETHODIMP
get_accRole(VARIANT var_id
, VARIANT
* role
);
92 // Retrieves the current state of the specified object.
93 STDMETHODIMP
get_accState(VARIANT var_id
, VARIANT
* state
);
95 // Retrieves the current value associated with the specified object.
96 STDMETHODIMP
get_accValue(VARIANT var_id
, BSTR
* value
);
98 // Non-supported IAccessible methods.
100 // Selections not applicable to views.
101 STDMETHODIMP
get_accSelection(VARIANT
* selected
);
102 STDMETHODIMP
accSelect(LONG flags_sel
, VARIANT var_id
);
104 // Help functions not supported.
105 STDMETHODIMP
get_accHelp(VARIANT var_id
, BSTR
* help
);
106 STDMETHODIMP
get_accHelpTopic(BSTR
* help_file
,
110 // Deprecated functions, not implemented here.
111 STDMETHODIMP
put_accName(VARIANT var_id
, BSTR put_name
);
112 STDMETHODIMP
put_accValue(VARIANT var_id
, BSTR put_val
);
114 // Returns a conversion from the event (as defined in accessibility_types.h)
116 static int32
MSAAEvent(ui::AccessibilityTypes::Event event
);
118 // Returns a conversion from the Role (as defined in accessibility_types.h)
120 static int32
MSAARole(ui::AccessibilityTypes::Role role
);
122 // Returns a conversion from the State (as defined in accessibility_types.h)
123 // to MSAA states set.
124 static int32
MSAAState(ui::AccessibilityTypes::State state
);
127 NativeViewAccessibilityWin();
129 // Determines navigation direction for accNavigate, based on left, up and
130 // previous being mapped all to previous and right, down, next being mapped
131 // to next. Returns true if navigation direction is next, false otherwise.
132 bool IsNavDirNext(int nav_dir
) const;
134 // Determines if the navigation target is within the allowed bounds. Returns
135 // true if it is, false otherwise.
136 bool IsValidNav(int nav_dir
,
139 int upper_bound
) const;
141 // Determines if the child id variant is valid.
142 bool IsValidId(const VARIANT
& child
) const;
144 // Helper function which sets applicable states of view.
145 void SetState(VARIANT
* msaa_state
, views::View
* view
);
147 // Give CComObject access to the class constructor.
148 template <class Base
> friend class CComObject
;
150 // Member View needed for view-specific calls.
153 DISALLOW_COPY_AND_ASSIGN(NativeViewAccessibilityWin
);
156 #endif // VIEWS_ACCESSIBILITY_NATIVE_VIEW_ACCESSIBILITY_WIN_H_