summaryrefslogtreecommitdiffstats
path: root/chrome/browser/browser_accessibility.h
blob: 8833d881f5f5fc45452d145a966c0b1fc61a037e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
// Copyright (c) 2006-2008 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_BROWSER_BROWSER_ACCESSIBILITY_H_
#define CHROME_BROWSER_BROWSER_ACCESSIBILITY_H_

#include <atlbase.h>
#include <atlcom.h>

#include <oleacc.h>

#include "webkit/glue/webaccessibility.h"

using webkit_glue::WebAccessibility;

////////////////////////////////////////////////////////////////////////////////
//
// BrowserAccessibility
//
// Class implementing the MSAA IAccessible COM interface for the
// Browser-Renderer communication of MSAA information, providing accessibility
// to be used by screen readers and other assistive technology (AT).
//
////////////////////////////////////////////////////////////////////////////////
class ATL_NO_VTABLE BrowserAccessibility
  : public CComObjectRootEx<CComMultiThreadModel>,
    public IDispatchImpl<IAccessible, &IID_IAccessible, &LIBID_Accessibility> {
 public:
  BEGIN_COM_MAP(BrowserAccessibility)
    COM_INTERFACE_ENTRY2(IDispatch, IAccessible)
    COM_INTERFACE_ENTRY(IAccessible)
  END_COM_MAP()

  BrowserAccessibility()
      : iaccessible_id_(-1),
        routing_id_(-1),
        process_id_(-1),
        parent_hwnd_(NULL),
        instance_active_(false) {
  }

  ~BrowserAccessibility() {}

  HRESULT Initialize(int iaccessible_id,
                     int routing_id,
                     int process_id,
                     HWND parent_hwnd);

  // Supported IAccessible methods.

  // Performs the default action on a given object.
  STDMETHODIMP accDoDefaultAction(VARIANT var_id);

  // Retrieves the child element or child object at a given point on the screen.
  STDMETHODIMP accHitTest(LONG x_left, LONG y_top, VARIANT* child);

  // Retrieves the specified object's current screen location.
  STDMETHODIMP accLocation(LONG* x_left,
                           LONG* y_top,
                           LONG* width,
                           LONG* height,
                           VARIANT var_id);

  // Traverses to another UI element and retrieves the object.
  STDMETHODIMP accNavigate(LONG nav_dir, VARIANT start, VARIANT* end);

  // Retrieves an IDispatch interface pointer for the specified child.
  STDMETHODIMP get_accChild(VARIANT var_child, IDispatch** disp_child);

  // Retrieves the number of accessible children.
  STDMETHODIMP get_accChildCount(LONG* child_count);

  // Retrieves a string that describes the object's default action.
  STDMETHODIMP get_accDefaultAction(VARIANT var_id, BSTR* default_action);

  // Retrieves the object's description.
  STDMETHODIMP get_accDescription(VARIANT var_id, BSTR* desc);

  // Retrieves the object that has the keyboard focus.
  STDMETHODIMP get_accFocus(VARIANT* focus_child);

  // Retrieves the help information associated with the object.
  STDMETHODIMP get_accHelp(VARIANT var_id, BSTR* help);

  // Retrieves the specified object's shortcut.
  STDMETHODIMP get_accKeyboardShortcut(VARIANT var_id, BSTR* access_key);

  // Retrieves the name of the specified object.
  STDMETHODIMP get_accName(VARIANT var_id, BSTR* name);

  // Retrieves the IDispatch interface of the object's parent.
  STDMETHODIMP get_accParent(IDispatch** disp_parent);

  // Retrieves information describing the role of the specified object.
  STDMETHODIMP get_accRole(VARIANT var_id, VARIANT* role);

  // Retrieves the current state of the specified object.
  STDMETHODIMP get_accState(VARIANT var_id, VARIANT* state);

  // Returns the value associated with the object.
  STDMETHODIMP get_accValue(VARIANT var_id, BSTR* value);

  // Non-supported (by WebKit) IAccessible methods.
  STDMETHODIMP accSelect(LONG flags_sel, VARIANT var_id) { return E_NOTIMPL; }

  STDMETHODIMP get_accHelpTopic(BSTR* help_file,
                                VARIANT var_id,
                                LONG* topic_id);

  STDMETHODIMP get_accSelection(VARIANT* selected);

  // Deprecated functions, not implemented here.
  STDMETHODIMP put_accName(VARIANT var_id, BSTR put_name) { return E_NOTIMPL; }
  STDMETHODIMP put_accValue(VARIANT var_id, BSTR put_val) { return E_NOTIMPL; }

  // Accessors/mutators.
  HWND parent_hwnd() const { return parent_hwnd_;}

  // Modify/retrieve the state (active/inactive) of this instance.
  void set_instance_active(bool instance_active) {
    instance_active_ = instance_active;
  }
  int instance_active() const { return instance_active_; }

  int routing_id() const { return routing_id_; }

 private:
  // Creates an empty VARIANT. Used as the equivalent of a NULL (unused) input
  // parameter.
  VARIANT EmptyVariant() const {
    VARIANT empty;
    empty.vt = VT_EMPTY;
    return empty;
  }

  // Wrapper functions, calling through to singleton instance of
  // BrowserAccessibilityManager.

  // Creates an instance of BrowserAccessibility, initializes it and sets the
  // [iaccessible_id] and [parent_id].
  STDMETHODIMP CreateInstance(REFIID iid,
                              int iaccessible_id,
                              void** interface_ptr);

  // Composes and sends a message for requesting needed accessibility
  // information. Unused LONG input parameters should be NULL, and the VARIANT
  // an empty, valid instance.
  bool RequestAccessibilityInfo(int iaccessible_func_id,
                                VARIANT var_id,
                                LONG input1, LONG input2);

  // Accessors.
  const WebAccessibility::OutParams& response();

  // Returns a conversion from the BrowserAccessibilityRole (as defined in
  // webkit/glue/webaccessibility.h) to an MSAA role.
  long MSAARole(long browser_accessibility_role);

  // Returns a conversion from the BrowserAccessibilityState (as defined in
  // webkit/glue/webaccessibility.h) to MSAA states set.
  long MSAAState(long browser_accessibility_state);

  // Id to uniquely distinguish this instance in the render-side caching,
  // mapping it to the correct IAccessible on that side. Initialized to -1.
  int iaccessible_id_;

  // The unique ids of this IAccessible instance. Used to help
  // BrowserAccessibilityManager instance retrieve the correct member
  // variables for this process.
  int routing_id_;
  int process_id_;

  HWND parent_hwnd_;

  // The instance should only be active if there is a non-terminated
  // RenderProcessHost associated with it. The BrowserAccessibilityManager keeps
  // track of this state, and sets it to false to disable all calls into the
  // renderer from this instance of BroweserAccessibility, and have all
  // IAccessible functions return E_FAIL.
  bool instance_active_;

  DISALLOW_COPY_AND_ASSIGN(BrowserAccessibility);
};
#endif  // CHROME_BROWSER_BROWSER_ACCESSIBILITY_H_