OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/accessibility/browser_accessibility_manager_win.h" | 5 #include "content/browser/accessibility/browser_accessibility_manager_win.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <vector> | 10 #include <vector> |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 } | 130 } |
131 | 131 |
132 void BrowserAccessibilityManagerWin::UserIsReloading() { | 132 void BrowserAccessibilityManagerWin::UserIsReloading() { |
133 if (GetRoot()) | 133 if (GetRoot()) |
134 MaybeCallNotifyWinEvent(IA2_EVENT_DOCUMENT_RELOAD, GetRoot()); | 134 MaybeCallNotifyWinEvent(IA2_EVENT_DOCUMENT_RELOAD, GetRoot()); |
135 } | 135 } |
136 | 136 |
137 void BrowserAccessibilityManagerWin::NotifyAccessibilityEvent( | 137 void BrowserAccessibilityManagerWin::NotifyAccessibilityEvent( |
138 ui::AXEvent event_type, | 138 ui::AXEvent event_type, |
139 BrowserAccessibility* node) { | 139 BrowserAccessibility* node) { |
| 140 if (!node) |
| 141 return; |
| 142 |
140 BrowserAccessibilityDelegate* root_delegate = GetDelegateFromRootManager(); | 143 BrowserAccessibilityDelegate* root_delegate = GetDelegateFromRootManager(); |
141 if (!root_delegate || !root_delegate->AccessibilityGetAcceleratedWidget()) { | 144 if (!root_delegate || !root_delegate->AccessibilityGetAcceleratedWidget()) { |
142 DLOG(WARNING) << "Not firing AX event because of no root_delegate or hwnd"; | 145 DLOG(WARNING) << "Not firing AX event because of no root_delegate or hwnd"; |
143 return; | 146 return; |
144 } | 147 } |
145 | 148 |
146 // Don't fire events when this document might be stale as the user has | 149 // Don't fire events when this document might be stale as the user has |
147 // started navigating to a new document. | 150 // started navigating to a new document. |
148 if (user_is_navigating_away_) | 151 if (user_is_navigating_away_) |
149 return; | 152 return; |
150 | 153 |
151 // Inline text boxes are an internal implementation detail, we don't | 154 // Inline text boxes are an internal implementation detail, we don't |
152 // expose them to Windows. | 155 // expose them to Windows. |
153 if (node->GetRole() == ui::AX_ROLE_INLINE_TEXT_BOX) | 156 if (node->GetRole() == ui::AX_ROLE_INLINE_TEXT_BOX) |
154 return; | 157 return; |
155 | 158 |
156 // Don't fire focus, blur, or load complete notifications if the | 159 // Don't fire focus, blur, or load complete notifications if the |
157 // window isn't focused, because that can confuse screen readers into | 160 // window isn't focused, because that can confuse screen readers into |
158 // entering their "browse" mode. | 161 // entering their "browse" mode. |
159 if ((event_type == ui::AX_EVENT_FOCUS || | 162 if ((event_type == ui::AX_EVENT_FOCUS || |
160 event_type == ui::AX_EVENT_BLUR || | 163 event_type == ui::AX_EVENT_BLUR || |
161 event_type == ui::AX_EVENT_LOAD_COMPLETE) && | 164 event_type == ui::AX_EVENT_LOAD_COMPLETE) && |
162 !NativeViewHasFocus()) { | 165 !NativeViewHasFocus()) { |
163 return; | 166 return; |
164 } | 167 } |
165 | 168 |
166 LONG event_id = EVENT_MIN; | 169 LONG event_id = EVENT_MIN; |
167 switch (event_type) { | 170 switch (event_type) { |
168 case ui::AX_EVENT_ACTIVEDESCENDANTCHANGED: | 171 case ui::AX_EVENT_ACTIVEDESCENDANTCHANGED: { |
169 event_id = IA2_EVENT_ACTIVE_DESCENDANT_CHANGED; | 172 event_id = IA2_EVENT_ACTIVE_DESCENDANT_CHANGED; |
| 173 BrowserAccessibility* active_descendant = GetActiveDescendantFocus(node); |
| 174 if (active_descendant != node) |
| 175 FireFocusEvent(active_descendant); |
170 break; | 176 break; |
| 177 } |
171 case ui::AX_EVENT_ALERT: | 178 case ui::AX_EVENT_ALERT: |
172 event_id = EVENT_SYSTEM_ALERT; | 179 event_id = EVENT_SYSTEM_ALERT; |
173 break; | 180 break; |
174 case ui::AX_EVENT_AUTOCORRECTION_OCCURED: | 181 case ui::AX_EVENT_AUTOCORRECTION_OCCURED: |
175 event_id = IA2_EVENT_OBJECT_ATTRIBUTE_CHANGED; | 182 event_id = IA2_EVENT_OBJECT_ATTRIBUTE_CHANGED; |
176 break; | 183 break; |
177 case ui::AX_EVENT_BLUR: | 184 case ui::AX_EVENT_BLUR: |
178 // Equivalent to focus on the root. | 185 // Equivalent to focus on the root. |
179 event_id = EVENT_OBJECT_FOCUS; | 186 event_id = EVENT_OBJECT_FOCUS; |
180 node = GetRoot(); | 187 node = GetRoot(); |
(...skipping 29 matching lines...) Expand all Loading... |
210 node = focus_object; | 217 node = focus_object; |
211 event_id = IA2_EVENT_TEXT_CARET_MOVED; | 218 event_id = IA2_EVENT_TEXT_CARET_MOVED; |
212 break; | 219 break; |
213 } | 220 } |
214 default: | 221 default: |
215 // Not all WebKit accessibility events result in a Windows | 222 // Not all WebKit accessibility events result in a Windows |
216 // accessibility notification. | 223 // accessibility notification. |
217 break; | 224 break; |
218 } | 225 } |
219 | 226 |
220 if (!node) | |
221 return; | |
222 | |
223 if (event_id != EVENT_MIN) | 227 if (event_id != EVENT_MIN) |
224 MaybeCallNotifyWinEvent(event_id, node); | 228 MaybeCallNotifyWinEvent(event_id, node); |
225 | 229 |
226 // If this is a layout complete notification (sent when a container scrolls) | 230 // If this is a layout complete notification (sent when a container scrolls) |
227 // and there is a descendant tracked object, send a notification on it. | 231 // and there is a descendant tracked object, send a notification on it. |
228 // TODO(dmazzoni): remove once http://crbug.com/113483 is fixed. | 232 // TODO(dmazzoni): remove once http://crbug.com/113483 is fixed. |
229 if (event_type == ui::AX_EVENT_LAYOUT_COMPLETE && | 233 if (event_type == ui::AX_EVENT_LAYOUT_COMPLETE && |
230 tracked_scroll_object_ && | 234 tracked_scroll_object_ && |
231 tracked_scroll_object_->IsDescendantOf(node)) { | 235 tracked_scroll_object_->IsDescendantOf(node)) { |
232 MaybeCallNotifyWinEvent( | 236 MaybeCallNotifyWinEvent( |
233 IA2_EVENT_VISIBLE_DATA_CHANGED, tracked_scroll_object_); | 237 IA2_EVENT_VISIBLE_DATA_CHANGED, tracked_scroll_object_); |
234 tracked_scroll_object_->Release(); | 238 tracked_scroll_object_->Release(); |
235 tracked_scroll_object_ = NULL; | 239 tracked_scroll_object_ = NULL; |
236 } | 240 } |
237 } | 241 } |
238 | 242 |
239 bool BrowserAccessibilityManagerWin::CanFireEvents() { | 243 bool BrowserAccessibilityManagerWin::CanFireEvents() { |
240 BrowserAccessibilityDelegate* root_delegate = GetDelegateFromRootManager(); | 244 BrowserAccessibilityDelegate* root_delegate = GetDelegateFromRootManager(); |
241 if (!root_delegate) | 245 if (!root_delegate) |
242 return false; | 246 return false; |
243 HWND hwnd = root_delegate->AccessibilityGetAcceleratedWidget(); | 247 HWND hwnd = root_delegate->AccessibilityGetAcceleratedWidget(); |
244 return hwnd != nullptr; | 248 return hwnd != nullptr; |
245 } | 249 } |
246 | 250 |
247 void BrowserAccessibilityManagerWin::FireFocusEvent( | 251 void BrowserAccessibilityManagerWin::FireFocusEvent( |
248 BrowserAccessibility* node) { | 252 BrowserAccessibility* node) { |
| 253 DCHECK(node); |
249 // On Windows, we always fire a FOCUS event on the root of a frame before | 254 // On Windows, we always fire a FOCUS event on the root of a frame before |
250 // firing a focus event within that frame. | 255 // firing a focus event within that frame. |
251 if (node->manager() != last_focused_manager_ && | 256 if (node->manager() != last_focused_manager_ && |
252 node != node->manager()->GetRoot()) { | 257 node != node->manager()->GetRoot()) { |
253 NotifyAccessibilityEvent(ui::AX_EVENT_FOCUS, node->manager()->GetRoot()); | 258 NotifyAccessibilityEvent(ui::AX_EVENT_FOCUS, node->manager()->GetRoot()); |
254 } | 259 } |
255 | 260 |
256 BrowserAccessibilityManager::FireFocusEvent(node); | 261 BrowserAccessibilityManager::FireFocusEvent(node); |
257 } | 262 } |
258 | 263 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 | 345 |
341 void BrowserAccessibilityManagerWin::TrackScrollingObject( | 346 void BrowserAccessibilityManagerWin::TrackScrollingObject( |
342 BrowserAccessibilityWin* node) { | 347 BrowserAccessibilityWin* node) { |
343 if (tracked_scroll_object_) | 348 if (tracked_scroll_object_) |
344 tracked_scroll_object_->Release(); | 349 tracked_scroll_object_->Release(); |
345 tracked_scroll_object_ = node; | 350 tracked_scroll_object_ = node; |
346 tracked_scroll_object_->AddRef(); | 351 tracked_scroll_object_->AddRef(); |
347 } | 352 } |
348 | 353 |
349 } // namespace content | 354 } // namespace content |
OLD | NEW |