| 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.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/accessibility_messages.h" | 9 #include "content/common/accessibility_messages.h" |
| 10 #include "ui/accessibility/ax_tree_serializer.h" | 10 #include "ui/accessibility/ax_tree_serializer.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 return new BrowserAccessibilityManager(initial_tree, delegate, factory); | 62 return new BrowserAccessibilityManager(initial_tree, delegate, factory); |
| 63 } | 63 } |
| 64 #endif | 64 #endif |
| 65 | 65 |
| 66 BrowserAccessibilityManager::BrowserAccessibilityManager( | 66 BrowserAccessibilityManager::BrowserAccessibilityManager( |
| 67 BrowserAccessibilityDelegate* delegate, | 67 BrowserAccessibilityDelegate* delegate, |
| 68 BrowserAccessibilityFactory* factory) | 68 BrowserAccessibilityFactory* factory) |
| 69 : delegate_(delegate), | 69 : delegate_(delegate), |
| 70 factory_(factory), | 70 factory_(factory), |
| 71 tree_(new ui::AXSerializableTree()), | 71 tree_(new ui::AXSerializableTree()), |
| 72 focus_(NULL), | 72 focus_(nullptr), |
| 73 osk_state_(OSK_ALLOWED) { | 73 osk_state_(OSK_ALLOWED) { |
| 74 tree_->SetDelegate(this); | 74 tree_->SetDelegate(this); |
| 75 } | 75 } |
| 76 | 76 |
| 77 BrowserAccessibilityManager::BrowserAccessibilityManager( | 77 BrowserAccessibilityManager::BrowserAccessibilityManager( |
| 78 const ui::AXTreeUpdate& initial_tree, | 78 const ui::AXTreeUpdate& initial_tree, |
| 79 BrowserAccessibilityDelegate* delegate, | 79 BrowserAccessibilityDelegate* delegate, |
| 80 BrowserAccessibilityFactory* factory) | 80 BrowserAccessibilityFactory* factory) |
| 81 : delegate_(delegate), | 81 : delegate_(delegate), |
| 82 factory_(factory), | 82 factory_(factory), |
| 83 tree_(new ui::AXSerializableTree()), | 83 tree_(new ui::AXSerializableTree()), |
| 84 focus_(NULL), | 84 focus_(nullptr), |
| 85 osk_state_(OSK_ALLOWED) { | 85 osk_state_(OSK_ALLOWED) { |
| 86 tree_->SetDelegate(this); | 86 tree_->SetDelegate(this); |
| 87 Initialize(initial_tree); | 87 Initialize(initial_tree); |
| 88 } | 88 } |
| 89 | 89 |
| 90 BrowserAccessibilityManager::~BrowserAccessibilityManager() { | 90 BrowserAccessibilityManager::~BrowserAccessibilityManager() { |
| 91 tree_.reset(NULL); | 91 tree_.reset(nullptr); |
| 92 } | 92 } |
| 93 | 93 |
| 94 void BrowserAccessibilityManager::Initialize( | 94 void BrowserAccessibilityManager::Initialize( |
| 95 const ui::AXTreeUpdate& initial_tree) { | 95 const ui::AXTreeUpdate& initial_tree) { |
| 96 if (!tree_->Unserialize(initial_tree)) { | 96 if (!tree_->Unserialize(initial_tree)) { |
| 97 if (delegate_) { | 97 if (delegate_) { |
| 98 LOG(ERROR) << tree_->error(); | 98 LOG(ERROR) << tree_->error(); |
| 99 delegate_->AccessibilityFatalError(); | 99 delegate_->AccessibilityFatalError(); |
| 100 } else { | 100 } else { |
| 101 LOG(FATAL) << tree_->error(); | 101 LOG(FATAL) << tree_->error(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 123 BrowserAccessibility* BrowserAccessibilityManager::GetFromAXNode( | 123 BrowserAccessibility* BrowserAccessibilityManager::GetFromAXNode( |
| 124 ui::AXNode* node) { | 124 ui::AXNode* node) { |
| 125 return GetFromID(node->id()); | 125 return GetFromID(node->id()); |
| 126 } | 126 } |
| 127 | 127 |
| 128 BrowserAccessibility* BrowserAccessibilityManager::GetFromID(int32 id) { | 128 BrowserAccessibility* BrowserAccessibilityManager::GetFromID(int32 id) { |
| 129 base::hash_map<int32, BrowserAccessibility*>::iterator iter = | 129 base::hash_map<int32, BrowserAccessibility*>::iterator iter = |
| 130 id_wrapper_map_.find(id); | 130 id_wrapper_map_.find(id); |
| 131 if (iter != id_wrapper_map_.end()) | 131 if (iter != id_wrapper_map_.end()) |
| 132 return iter->second; | 132 return iter->second; |
| 133 return NULL; | 133 return nullptr; |
| 134 } | 134 } |
| 135 | 135 |
| 136 void BrowserAccessibilityManager::OnWindowFocused() { | 136 void BrowserAccessibilityManager::OnWindowFocused() { |
| 137 if (focus_) | 137 if (focus_) |
| 138 NotifyAccessibilityEvent(ui::AX_EVENT_FOCUS, GetFromAXNode(focus_)); | 138 NotifyAccessibilityEvent(ui::AX_EVENT_FOCUS, GetFromAXNode(focus_)); |
| 139 } | 139 } |
| 140 | 140 |
| 141 void BrowserAccessibilityManager::OnWindowBlurred() { | 141 void BrowserAccessibilityManager::OnWindowBlurred() { |
| 142 if (focus_) | 142 if (focus_) |
| 143 NotifyAccessibilityEvent(ui::AX_EVENT_BLUR, GetFromAXNode(focus_)); | 143 NotifyAccessibilityEvent(ui::AX_EVENT_BLUR, GetFromAXNode(focus_)); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 ui::AXNode* node = obj->node(); | 222 ui::AXNode* node = obj->node(); |
| 223 node->SetLocation(params[i].new_location); | 223 node->SetLocation(params[i].new_location); |
| 224 obj->OnLocationChanged(); | 224 obj->OnLocationChanged(); |
| 225 } | 225 } |
| 226 } | 226 } |
| 227 | 227 |
| 228 BrowserAccessibility* BrowserAccessibilityManager::GetActiveDescendantFocus( | 228 BrowserAccessibility* BrowserAccessibilityManager::GetActiveDescendantFocus( |
| 229 BrowserAccessibility* root) { | 229 BrowserAccessibility* root) { |
| 230 BrowserAccessibility* node = BrowserAccessibilityManager::GetFocus(root); | 230 BrowserAccessibility* node = BrowserAccessibilityManager::GetFocus(root); |
| 231 if (!node) | 231 if (!node) |
| 232 return NULL; | 232 return nullptr; |
| 233 | 233 |
| 234 int active_descendant_id; | 234 int active_descendant_id; |
| 235 if (node->GetIntAttribute(ui::AX_ATTR_ACTIVEDESCENDANT_ID, | 235 if (node->GetIntAttribute(ui::AX_ATTR_ACTIVEDESCENDANT_ID, |
| 236 &active_descendant_id)) { | 236 &active_descendant_id)) { |
| 237 BrowserAccessibility* active_descendant = | 237 BrowserAccessibility* active_descendant = |
| 238 node->manager()->GetFromID(active_descendant_id); | 238 node->manager()->GetFromID(active_descendant_id); |
| 239 if (active_descendant) | 239 if (active_descendant) |
| 240 return active_descendant; | 240 return active_descendant; |
| 241 } | 241 } |
| 242 return node; | 242 return node; |
| 243 } | 243 } |
| 244 | 244 |
| 245 BrowserAccessibility* BrowserAccessibilityManager::GetFocus( | 245 BrowserAccessibility* BrowserAccessibilityManager::GetFocus( |
| 246 BrowserAccessibility* root) { | 246 BrowserAccessibility* root) { |
| 247 if (focus_ && (!root || focus_->IsDescendantOf(root->node()))) | 247 if (focus_ && (!root || focus_->IsDescendantOf(root->node()))) |
| 248 return GetFromAXNode(focus_); | 248 return GetFromAXNode(focus_); |
| 249 | 249 |
| 250 return NULL; | 250 return nullptr; |
| 251 } | 251 } |
| 252 | 252 |
| 253 void BrowserAccessibilityManager::SetFocus(ui::AXNode* node, bool notify) { | 253 void BrowserAccessibilityManager::SetFocus(ui::AXNode* node, bool notify) { |
| 254 if (focus_ != node) | 254 if (focus_ != node) |
| 255 focus_ = node; | 255 focus_ = node; |
| 256 | 256 |
| 257 if (notify && node && delegate_) | 257 if (notify && node && delegate_) |
| 258 delegate_->AccessibilitySetFocus(node->id()); | 258 delegate_->AccessibilitySetFocus(node->id()); |
| 259 } | 259 } |
| 260 | 260 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 | 294 |
| 295 gfx::Rect BrowserAccessibilityManager::GetViewBounds() { | 295 gfx::Rect BrowserAccessibilityManager::GetViewBounds() { |
| 296 if (delegate_) | 296 if (delegate_) |
| 297 return delegate_->AccessibilityGetViewBounds(); | 297 return delegate_->AccessibilityGetViewBounds(); |
| 298 return gfx::Rect(); | 298 return gfx::Rect(); |
| 299 } | 299 } |
| 300 | 300 |
| 301 BrowserAccessibility* BrowserAccessibilityManager::NextInTreeOrder( | 301 BrowserAccessibility* BrowserAccessibilityManager::NextInTreeOrder( |
| 302 BrowserAccessibility* node) { | 302 BrowserAccessibility* node) { |
| 303 if (!node) | 303 if (!node) |
| 304 return NULL; | 304 return nullptr; |
| 305 | 305 |
| 306 if (node->PlatformChildCount() > 0) | 306 if (node->PlatformChildCount() > 0) |
| 307 return node->PlatformGetChild(0); | 307 return node->PlatformGetChild(0); |
| 308 while (node) { | 308 while (node) { |
| 309 if (node->GetParent() && | 309 if (node->GetParent() && |
| 310 node->GetIndexInParent() < | 310 node->GetIndexInParent() < |
| 311 static_cast<int>(node->GetParent()->PlatformChildCount()) - 1) { | 311 static_cast<int>(node->GetParent()->PlatformChildCount()) - 1) { |
| 312 return node->GetParent()->PlatformGetChild(node->GetIndexInParent() + 1); | 312 return node->GetParent()->PlatformGetChild(node->GetIndexInParent() + 1); |
| 313 } | 313 } |
| 314 node = node->GetParent(); | 314 node = node->GetParent(); |
| 315 } | 315 } |
| 316 | 316 |
| 317 return NULL; | 317 return nullptr; |
| 318 } | 318 } |
| 319 | 319 |
| 320 BrowserAccessibility* BrowserAccessibilityManager::PreviousInTreeOrder( | 320 BrowserAccessibility* BrowserAccessibilityManager::PreviousInTreeOrder( |
| 321 BrowserAccessibility* node) { | 321 BrowserAccessibility* node) { |
| 322 if (!node) | 322 if (!node) |
| 323 return NULL; | 323 return nullptr; |
| 324 | 324 |
| 325 if (node->GetParent() && node->GetIndexInParent() > 0) { | 325 if (node->GetParent() && node->GetIndexInParent() > 0) { |
| 326 node = node->GetParent()->PlatformGetChild(node->GetIndexInParent() - 1); | 326 node = node->GetParent()->PlatformGetChild(node->GetIndexInParent() - 1); |
| 327 while (node->PlatformChildCount() > 0) | 327 while (node->PlatformChildCount() > 0) |
| 328 node = node->PlatformGetChild(node->PlatformChildCount() - 1); | 328 node = node->PlatformGetChild(node->PlatformChildCount() - 1); |
| 329 return node; | 329 return node; |
| 330 } | 330 } |
| 331 | 331 |
| 332 return node->GetParent(); | 332 return node->GetParent(); |
| 333 } | 333 } |
| 334 | 334 |
| 335 void BrowserAccessibilityManager::OnNodeWillBeDeleted(ui::AXNode* node) { | 335 void BrowserAccessibilityManager::OnNodeWillBeDeleted(ui::AXNode* node) { |
| 336 if (node == focus_ && tree_) { | 336 if (node == focus_ && tree_) { |
| 337 if (node != tree_->GetRoot()) | 337 if (node != tree_->GetRoot()) |
| 338 SetFocus(tree_->GetRoot(), false); | 338 SetFocus(tree_->GetRoot(), false); |
| 339 else | 339 else |
| 340 focus_ = NULL; | 340 focus_ = nullptr; |
| 341 } | 341 } |
| 342 if (id_wrapper_map_.find(node->id()) == id_wrapper_map_.end()) | 342 if (id_wrapper_map_.find(node->id()) == id_wrapper_map_.end()) |
| 343 return; | 343 return; |
| 344 GetFromAXNode(node)->Destroy(); | 344 GetFromAXNode(node)->Destroy(); |
| 345 id_wrapper_map_.erase(node->id()); | 345 id_wrapper_map_.erase(node->id()); |
| 346 } | 346 } |
| 347 | 347 |
| 348 void BrowserAccessibilityManager::OnNodeCreated(ui::AXNode* node) { | 348 void BrowserAccessibilityManager::OnNodeCreated(ui::AXNode* node) { |
| 349 BrowserAccessibility* wrapper = factory_->Create(); | 349 BrowserAccessibility* wrapper = factory_->Create(); |
| 350 wrapper->Init(this, node); | 350 wrapper->Init(this, node); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 367 ui::AXTreeUpdate BrowserAccessibilityManager::SnapshotAXTreeForTesting() { | 367 ui::AXTreeUpdate BrowserAccessibilityManager::SnapshotAXTreeForTesting() { |
| 368 scoped_ptr<ui::AXTreeSource<const ui::AXNode*> > tree_source( | 368 scoped_ptr<ui::AXTreeSource<const ui::AXNode*> > tree_source( |
| 369 tree_->CreateTreeSource()); | 369 tree_->CreateTreeSource()); |
| 370 ui::AXTreeSerializer<const ui::AXNode*> serializer(tree_source.get()); | 370 ui::AXTreeSerializer<const ui::AXNode*> serializer(tree_source.get()); |
| 371 ui::AXTreeUpdate update; | 371 ui::AXTreeUpdate update; |
| 372 serializer.SerializeChanges(tree_->GetRoot(), &update); | 372 serializer.SerializeChanges(tree_->GetRoot(), &update); |
| 373 return update; | 373 return update; |
| 374 } | 374 } |
| 375 | 375 |
| 376 } // namespace content | 376 } // namespace content |
| OLD | NEW |