OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "chrome/browser/autocomplete/autocomplete_accessibility.h" | |
6 | |
7 #include "chrome/browser/autocomplete/autocomplete_edit.h" | |
8 #include "chrome/browser/ui/views/omnibox/omnibox_view_win.h" | |
9 #include "grit/generated_resources.h" | |
10 #include "ui/base/l10n/l10n_util.h" | |
11 #include "views/accessibility/native_view_accessibility_win.h" | |
12 #include "views/view.h" | |
13 | |
14 HRESULT AutocompleteAccessibility::Initialize( | |
15 const OmniboxViewWin* omnibox_view) { | |
16 if (omnibox_view == NULL) { | |
17 return E_INVALIDARG; | |
18 } | |
19 | |
20 omnibox_view_ = omnibox_view; | |
21 | |
22 // Create a default accessible object for this instance. | |
23 return CreateStdAccessibleObject(omnibox_view_->m_hWnd, OBJID_CLIENT, | |
24 IID_IAccessible, | |
25 reinterpret_cast<void **>(default_accessibility_server_.Receive())); | |
26 } | |
27 | |
28 STDMETHODIMP AutocompleteAccessibility::get_accChildCount(LONG* child_count) { | |
29 if (!child_count) { | |
30 return E_INVALIDARG; | |
31 } | |
32 | |
33 DCHECK(default_accessibility_server_); | |
34 return default_accessibility_server_->get_accChildCount(child_count); | |
35 } | |
36 | |
37 STDMETHODIMP AutocompleteAccessibility::get_accChild(VARIANT var_child, | |
38 IDispatch** disp_child) { | |
39 if (var_child.vt != VT_I4 || !disp_child) { | |
40 return E_INVALIDARG; | |
41 } | |
42 | |
43 // If var_child is the parent, remain with the same IDispatch | |
44 if (var_child.lVal == CHILDID_SELF) | |
45 return S_OK; | |
46 | |
47 *disp_child = NULL; | |
48 return S_FALSE; | |
49 } | |
50 | |
51 STDMETHODIMP AutocompleteAccessibility::get_accParent(IDispatch** disp_parent) { | |
52 if (!disp_parent) { | |
53 return E_INVALIDARG; | |
54 } | |
55 | |
56 if (omnibox_view_->parent_view() == NULL) { | |
57 *disp_parent = NULL; | |
58 return S_FALSE; | |
59 } | |
60 | |
61 // Retrieve the IDispatch interface for the parent view. | |
62 *disp_parent = omnibox_view_->parent_view()->GetNativeViewAccessible(); | |
63 // Increment the reference count for the retrieved interface. | |
64 (*disp_parent)->AddRef(); | |
65 return S_OK; | |
66 } | |
67 | |
68 STDMETHODIMP AutocompleteAccessibility::accNavigate(LONG nav_dir, VARIANT start, | |
69 VARIANT* end) { | |
70 if (start.vt != VT_I4 || !end) { | |
71 return E_INVALIDARG; | |
72 } | |
73 | |
74 DCHECK(default_accessibility_server_); | |
75 return default_accessibility_server_->accNavigate(nav_dir, start, end); | |
76 } | |
77 | |
78 STDMETHODIMP AutocompleteAccessibility::get_accFocus(VARIANT* focus_child) { | |
79 if (!focus_child) { | |
80 return E_INVALIDARG; | |
81 } | |
82 | |
83 DCHECK(default_accessibility_server_); | |
84 return default_accessibility_server_->get_accFocus(focus_child); | |
85 } | |
86 | |
87 STDMETHODIMP AutocompleteAccessibility::get_accName(VARIANT var_id, | |
88 BSTR* name) { | |
89 if (var_id.vt != VT_I4 || !name) { | |
90 return E_INVALIDARG; | |
91 } | |
92 | |
93 string16 temp_name = l10n_util::GetStringUTF16(IDS_ACCNAME_LOCATION); | |
94 | |
95 if (!temp_name.empty()) { | |
96 // Return name retrieved. | |
97 *name = SysAllocString(temp_name.c_str()); | |
98 } else { | |
99 // If no name is found, return S_FALSE. | |
100 return S_FALSE; | |
101 } | |
102 DCHECK(*name); | |
103 | |
104 return S_OK; | |
105 } | |
106 | |
107 STDMETHODIMP AutocompleteAccessibility::get_accDescription(VARIANT var_id, | |
108 BSTR* desc) { | |
109 if (var_id.vt != VT_I4 || !desc) { | |
110 return E_INVALIDARG; | |
111 } | |
112 | |
113 return S_FALSE; | |
114 } | |
115 | |
116 STDMETHODIMP AutocompleteAccessibility::get_accValue(VARIANT var_id, | |
117 BSTR* value) { | |
118 if (var_id.vt != VT_I4 || !value) { | |
119 return E_INVALIDARG; | |
120 } | |
121 | |
122 string16 temp_value; | |
123 | |
124 if (var_id.lVal != CHILDID_SELF) | |
125 return E_INVALIDARG; | |
126 | |
127 // Edit box has no children, only handle self. | |
128 temp_value = omnibox_view_->GetText(); | |
129 if (temp_value.empty()) | |
130 return S_FALSE; | |
131 | |
132 // Return value retrieved. | |
133 *value = SysAllocString(temp_value.c_str()); | |
134 | |
135 DCHECK(*value); | |
136 | |
137 return S_OK; | |
138 } | |
139 | |
140 STDMETHODIMP AutocompleteAccessibility::get_accState(VARIANT var_id, | |
141 VARIANT* state) { | |
142 if (var_id.vt != VT_I4 || !state) { | |
143 return E_INVALIDARG; | |
144 } | |
145 | |
146 DCHECK(default_accessibility_server_); | |
147 HRESULT hr = default_accessibility_server_->get_accState(var_id, state); | |
148 | |
149 if (hr != S_OK) | |
150 return hr; | |
151 | |
152 // Adding on state to convey the fact that there is a dropdown. | |
153 state->lVal |= STATE_SYSTEM_HASPOPUP; | |
154 return S_OK; | |
155 } | |
156 | |
157 STDMETHODIMP AutocompleteAccessibility::get_accRole(VARIANT var_id, | |
158 VARIANT* role) { | |
159 if (var_id.vt != VT_I4 || !role) { | |
160 return E_INVALIDARG; | |
161 } | |
162 | |
163 role->vt = VT_I4; | |
164 | |
165 // Need to override the default role, which is ROLE_SYSTEM_CLIENT. | |
166 if (var_id.lVal == CHILDID_SELF) { | |
167 role->lVal = ROLE_SYSTEM_TEXT; | |
168 } else { | |
169 return S_FALSE; | |
170 } | |
171 | |
172 return S_OK; | |
173 } | |
174 | |
175 STDMETHODIMP AutocompleteAccessibility::get_accDefaultAction(VARIANT var_id, | |
176 BSTR* def_action) { | |
177 if (var_id.vt != VT_I4 || !def_action) { | |
178 return E_INVALIDARG; | |
179 } | |
180 | |
181 return S_FALSE; | |
182 } | |
183 | |
184 STDMETHODIMP AutocompleteAccessibility::accLocation(LONG* x_left, LONG* y_top, | |
185 LONG* width, LONG* height, | |
186 VARIANT var_id) { | |
187 if (var_id.vt != VT_I4 || !x_left || !y_top || !width || !height) { | |
188 return E_INVALIDARG; | |
189 } | |
190 | |
191 DCHECK(default_accessibility_server_); | |
192 return default_accessibility_server_->accLocation(x_left, y_top, width, | |
193 height, var_id); | |
194 } | |
195 | |
196 STDMETHODIMP AutocompleteAccessibility::accHitTest(LONG x_left, LONG y_top, | |
197 VARIANT* child) { | |
198 if (!child) { | |
199 return E_INVALIDARG; | |
200 } | |
201 | |
202 DCHECK(default_accessibility_server_); | |
203 return default_accessibility_server_->accHitTest(x_left, y_top, child); | |
204 } | |
205 | |
206 STDMETHODIMP AutocompleteAccessibility::get_accKeyboardShortcut(VARIANT var_id, | |
207 BSTR* acc_key) { | |
208 if (var_id.vt != VT_I4 || !acc_key) { | |
209 return E_INVALIDARG; | |
210 } | |
211 | |
212 return S_FALSE; | |
213 } | |
214 | |
215 // IAccessible functions not supported. | |
216 | |
217 HRESULT AutocompleteAccessibility::accDoDefaultAction(VARIANT var_id) { | |
218 return DISP_E_MEMBERNOTFOUND; | |
219 } | |
220 | |
221 STDMETHODIMP AutocompleteAccessibility::get_accSelection(VARIANT* selected) { | |
222 if (selected) | |
223 selected->vt = VT_EMPTY; | |
224 return DISP_E_MEMBERNOTFOUND; | |
225 } | |
226 | |
227 STDMETHODIMP AutocompleteAccessibility::accSelect(LONG flagsSelect, | |
228 VARIANT var_id) { | |
229 return DISP_E_MEMBERNOTFOUND; | |
230 } | |
231 | |
232 STDMETHODIMP AutocompleteAccessibility::get_accHelp(VARIANT var_id, | |
233 BSTR* help) { | |
234 if (help) | |
235 *help = NULL; | |
236 return DISP_E_MEMBERNOTFOUND; | |
237 } | |
238 | |
239 STDMETHODIMP AutocompleteAccessibility::get_accHelpTopic(BSTR* help_file, | |
240 VARIANT var_id, | |
241 LONG* topic_id) { | |
242 if (help_file) { | |
243 *help_file = NULL; | |
244 } | |
245 if (topic_id) { | |
246 *topic_id = static_cast<LONG>(-1); | |
247 } | |
248 return DISP_E_MEMBERNOTFOUND; | |
249 } | |
250 | |
251 STDMETHODIMP AutocompleteAccessibility::put_accName(VARIANT var_id, | |
252 BSTR put_name) { | |
253 // Deprecated. | |
254 return DISP_E_MEMBERNOTFOUND; | |
255 } | |
256 | |
257 STDMETHODIMP AutocompleteAccessibility::put_accValue(VARIANT var_id, | |
258 BSTR put_val) { | |
259 // Deprecated. | |
260 return DISP_E_MEMBERNOTFOUND; | |
261 } | |
OLD | NEW |