Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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.h" | 5 #include "content/browser/accessibility/browser_accessibility_manager.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "content/browser/accessibility/browser_accessibility.h" | 8 #include "content/browser/accessibility/browser_accessibility.h" |
| 9 #include "content/common/view_messages.h" | 9 #include "content/common/view_messages.h" |
| 10 | 10 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 BrowserAccessibilityManager* BrowserAccessibilityManager::Create( | 28 BrowserAccessibilityManager* BrowserAccessibilityManager::Create( |
| 29 gfx::NativeView parent_view, | 29 gfx::NativeView parent_view, |
| 30 const WebAccessibility& src, | 30 const WebAccessibility& src, |
| 31 BrowserAccessibilityDelegate* delegate, | 31 BrowserAccessibilityDelegate* delegate, |
| 32 BrowserAccessibilityFactory* factory) { | 32 BrowserAccessibilityFactory* factory) { |
| 33 return new BrowserAccessibilityManager( | 33 return new BrowserAccessibilityManager( |
| 34 parent_view, src, delegate, factory); | 34 parent_view, src, delegate, factory); |
| 35 } | 35 } |
| 36 #endif | 36 #endif |
| 37 | 37 |
| 38 // static | |
| 39 BrowserAccessibilityManager* BrowserAccessibilityManager::CreateEmptyDocument( | |
| 40 gfx::NativeView parent_view, | |
| 41 WebAccessibility::State state, | |
| 42 BrowserAccessibilityDelegate* delegate, | |
| 43 BrowserAccessibilityFactory* factory) { | |
| 44 // Use empty document to process notifications | |
| 45 webkit_glue::WebAccessibility empty_document; | |
| 46 // Renderer id's always start at 1000 as determined by webkit. Boot strap | |
| 47 // our ability to reuse BrowserAccessibility instances. | |
| 48 empty_document.id = 1000; | |
| 49 empty_document.role = WebAccessibility::ROLE_WEB_AREA; | |
| 50 empty_document.state = state; | |
| 51 return BrowserAccessibilityManager::Create( | |
| 52 parent_view, empty_document, delegate, factory); | |
| 53 } | |
| 54 | |
| 38 BrowserAccessibilityManager::BrowserAccessibilityManager( | 55 BrowserAccessibilityManager::BrowserAccessibilityManager( |
| 39 gfx::NativeView parent_view, | 56 gfx::NativeView parent_view, |
| 40 const WebAccessibility& src, | 57 const WebAccessibility& src, |
| 41 BrowserAccessibilityDelegate* delegate, | 58 BrowserAccessibilityDelegate* delegate, |
| 42 BrowserAccessibilityFactory* factory) | 59 BrowserAccessibilityFactory* factory) |
| 43 : parent_view_(parent_view), | 60 : parent_view_(parent_view), |
| 44 delegate_(delegate), | 61 delegate_(delegate), |
| 45 factory_(factory), | 62 factory_(factory), |
| 46 focus_(NULL) { | 63 focus_(NULL) { |
| 47 root_ = CreateAccessibilityTree(NULL, src, 0); | 64 root_ = CreateAccessibilityTree(NULL, src, 0); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 92 renderer_id_to_child_id_map_.find(renderer_id); | 109 renderer_id_to_child_id_map_.find(renderer_id); |
| 93 if (iter == renderer_id_to_child_id_map_.end()) | 110 if (iter == renderer_id_to_child_id_map_.end()) |
| 94 return NULL; | 111 return NULL; |
| 95 | 112 |
| 96 int32 child_id = iter->second; | 113 int32 child_id = iter->second; |
| 97 return GetFromChildID(child_id); | 114 return GetFromChildID(child_id); |
| 98 } | 115 } |
| 99 | 116 |
| 100 void BrowserAccessibilityManager::Remove(int32 child_id, int32 renderer_id) { | 117 void BrowserAccessibilityManager::Remove(int32 child_id, int32 renderer_id) { |
| 101 child_id_map_.erase(child_id); | 118 child_id_map_.erase(child_id); |
| 102 renderer_id_to_child_id_map_.erase(renderer_id); | 119 // Make sure we don't overwrite a newer entry (see UpdateNode for a possible |
| 120 // corner case). | |
| 121 if (renderer_id_to_child_id_map_[renderer_id] == child_id) | |
|
Chris Guillory
2011/08/16 02:10:31
According to our assumptions there should not be a
| |
| 122 renderer_id_to_child_id_map_.erase(renderer_id); | |
| 103 } | 123 } |
| 104 | 124 |
| 105 void BrowserAccessibilityManager::OnAccessibilityNotifications( | 125 void BrowserAccessibilityManager::OnAccessibilityNotifications( |
| 106 const std::vector<ViewHostMsg_AccessibilityNotification_Params>& params) { | 126 const std::vector<ViewHostMsg_AccessibilityNotification_Params>& params) { |
| 107 for (uint32 index = 0; index < params.size(); index++) { | 127 for (uint32 index = 0; index < params.size(); index++) { |
| 108 const ViewHostMsg_AccessibilityNotification_Params& param = params[index]; | 128 const ViewHostMsg_AccessibilityNotification_Params& param = params[index]; |
| 109 | 129 |
| 110 switch (param.notification_type) { | 130 switch (param.notification_type) { |
| 111 case ViewHostMsg_AccessibilityNotification_Type:: | 131 case ViewHostMsg_AccessibilityNotification_Type:: |
| 112 NOTIFICATION_TYPE_CHECK_STATE_CHANGED: | 132 NOTIFICATION_TYPE_CHECK_STATE_CHANGED: |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 177 NotifyAccessibilityEvent( | 197 NotifyAccessibilityEvent( |
| 178 ViewHostMsg_AccessibilityNotification_Type:: | 198 ViewHostMsg_AccessibilityNotification_Type:: |
| 179 NOTIFICATION_TYPE_FOCUS_CHANGED, | 199 NOTIFICATION_TYPE_FOCUS_CHANGED, |
| 180 focus_); | 200 focus_); |
| 181 } | 201 } |
| 182 } | 202 } |
| 183 | 203 |
| 184 void BrowserAccessibilityManager::OnAccessibilityObjectLoadComplete( | 204 void BrowserAccessibilityManager::OnAccessibilityObjectLoadComplete( |
| 185 const WebAccessibility& acc_obj) { | 205 const WebAccessibility& acc_obj) { |
| 186 SetFocus(NULL, false); | 206 SetFocus(NULL, false); |
| 187 root_->InternalReleaseReference(true); | |
| 188 | 207 |
| 189 root_ = CreateAccessibilityTree(NULL, acc_obj, 0); | 208 root_ = UpdateNode(acc_obj, true); |
|
Chris Guillory
2011/08/16 02:10:31
As discussed I think we do not want to use UpdateN
| |
| 190 if (!focus_) | 209 if (!focus_) |
| 191 SetFocus(root_, false); | 210 SetFocus(root_, false); |
| 192 | 211 |
| 193 NotifyAccessibilityEvent( | 212 NotifyAccessibilityEvent( |
| 194 ViewHostMsg_AccessibilityNotification_Type:: | 213 ViewHostMsg_AccessibilityNotification_Type:: |
| 195 NOTIFICATION_TYPE_LOAD_COMPLETE, | 214 NOTIFICATION_TYPE_LOAD_COMPLETE, |
| 196 root_); | 215 root_); |
| 197 if (delegate_ && delegate_->HasFocus()) | 216 if (delegate_ && delegate_->HasFocus()) |
| 198 GotFocus(); | 217 GotFocus(); |
| 199 } | 218 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 240 BrowserAccessibility* BrowserAccessibilityManager::GetFocus( | 259 BrowserAccessibility* BrowserAccessibilityManager::GetFocus( |
| 241 BrowserAccessibility* root) { | 260 BrowserAccessibility* root) { |
| 242 if (focus_ && (!root || focus_->IsDescendantOf(root))) | 261 if (focus_ && (!root || focus_->IsDescendantOf(root))) |
| 243 return focus_; | 262 return focus_; |
| 244 | 263 |
| 245 return NULL; | 264 return NULL; |
| 246 } | 265 } |
| 247 | 266 |
| 248 void BrowserAccessibilityManager::SetFocus( | 267 void BrowserAccessibilityManager::SetFocus( |
| 249 BrowserAccessibility* node, bool notify) { | 268 BrowserAccessibility* node, bool notify) { |
| 250 if (focus_) | 269 if (focus_ != node) { |
|
Chris Guillory
2011/08/16 02:10:31
Why are we removing this check? If focus_ equals n
Chris Guillory
2011/08/16 17:25:12
Please ignore my previous comment. For some reason
| |
| 251 focus_->InternalReleaseReference(false); | 270 if (focus_) |
| 252 focus_ = node; | 271 focus_->InternalReleaseReference(false); |
| 253 if (focus_) | 272 focus_ = node; |
| 254 focus_->InternalAddReference(); | 273 if (focus_) |
| 274 focus_->InternalAddReference(); | |
| 275 } | |
| 255 | 276 |
| 256 if (notify && node && delegate_) | 277 if (notify && node && delegate_) |
| 257 delegate_->SetAccessibilityFocus(node->renderer_id()); | 278 delegate_->SetAccessibilityFocus(node->renderer_id()); |
| 258 } | 279 } |
| 259 | 280 |
| 260 void BrowserAccessibilityManager::DoDefaultAction( | 281 void BrowserAccessibilityManager::DoDefaultAction( |
| 261 const BrowserAccessibility& node) { | 282 const BrowserAccessibility& node) { |
| 262 if (delegate_) | 283 if (delegate_) |
| 263 delegate_->AccessibilityDoDefaultAction(node.renderer_id()); | 284 delegate_->AccessibilityDoDefaultAction(node.renderer_id()); |
| 264 } | 285 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 304 // Build a new tree, reusing old nodes if possible. Each node that's | 325 // Build a new tree, reusing old nodes if possible. Each node that's |
| 305 // reused will have its reference count incremented by one. | 326 // reused will have its reference count incremented by one. |
| 306 current = | 327 current = |
| 307 CreateAccessibilityTree(current_parent, src, current_index_in_parent); | 328 CreateAccessibilityTree(current_parent, src, current_index_in_parent); |
| 308 | 329 |
| 309 // Decrement the reference count of all nodes in the old tree, which will | 330 // Decrement the reference count of all nodes in the old tree, which will |
| 310 // delete any nodes no longer needed. | 331 // delete any nodes no longer needed. |
| 311 for (int i = 0; i < static_cast<int>(old_tree_nodes.size()); i++) | 332 for (int i = 0; i < static_cast<int>(old_tree_nodes.size()); i++) |
| 312 old_tree_nodes[i]->InternalReleaseReference(false); | 333 old_tree_nodes[i]->InternalReleaseReference(false); |
| 313 | 334 |
| 314 DCHECK(focus_); | 335 if (!focus_ || !focus_->instance_active()) |
|
Chris Guillory
2011/08/16 02:10:31
We should keep the DCHECK here unless we plan to h
| |
| 315 if (!focus_->instance_active()) | |
| 316 SetFocus(root_, false); | 336 SetFocus(root_, false); |
| 317 | 337 |
| 318 return current; | 338 return current; |
| 319 } | 339 } |
| 320 | 340 |
| 321 BrowserAccessibility* BrowserAccessibilityManager::CreateAccessibilityTree( | 341 BrowserAccessibility* BrowserAccessibilityManager::CreateAccessibilityTree( |
| 322 BrowserAccessibility* parent, | 342 BrowserAccessibility* parent, |
| 323 const WebAccessibility& src, | 343 const WebAccessibility& src, |
| 324 int index_in_parent) { | 344 int index_in_parent) { |
| 325 BrowserAccessibility* instance = NULL; | 345 BrowserAccessibility* instance = NULL; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 364 if ((src.state >> WebAccessibility::STATE_FOCUSED) & 1) | 384 if ((src.state >> WebAccessibility::STATE_FOCUSED) & 1) |
| 365 SetFocus(instance, false); | 385 SetFocus(instance, false); |
| 366 for (int i = 0; i < static_cast<int>(src.children.size()); ++i) { | 386 for (int i = 0; i < static_cast<int>(src.children.size()); ++i) { |
| 367 BrowserAccessibility* child = CreateAccessibilityTree( | 387 BrowserAccessibility* child = CreateAccessibilityTree( |
| 368 instance, src.children[i], i); | 388 instance, src.children[i], i); |
| 369 instance->AddChild(child); | 389 instance->AddChild(child); |
| 370 } | 390 } |
| 371 | 391 |
| 372 return instance; | 392 return instance; |
| 373 } | 393 } |
| OLD | NEW |