| 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 | 10 |
| 11 using webkit_glue::WebAccessibility; | 11 using content::AccessibilityNodeData; |
| 12 | 12 |
| 13 BrowserAccessibility* BrowserAccessibilityFactory::Create() { | 13 BrowserAccessibility* BrowserAccessibilityFactory::Create() { |
| 14 return BrowserAccessibility::Create(); | 14 return BrowserAccessibility::Create(); |
| 15 } | 15 } |
| 16 | 16 |
| 17 // Start child IDs at -1 and decrement each time, because clients use | 17 // Start child IDs at -1 and decrement each time, because clients use |
| 18 // child IDs of 1, 2, 3, ... to access the children of an object by | 18 // child IDs of 1, 2, 3, ... to access the children of an object by |
| 19 // index, so we use negative IDs to clearly distinguish between indices | 19 // index, so we use negative IDs to clearly distinguish between indices |
| 20 // and unique IDs. | 20 // and unique IDs. |
| 21 // static | 21 // static |
| 22 int32 BrowserAccessibilityManager::next_child_id_ = -1; | 22 int32 BrowserAccessibilityManager::next_child_id_ = -1; |
| 23 | 23 |
| 24 #if !defined(OS_MACOSX) && \ | 24 #if !defined(OS_MACOSX) && \ |
| 25 !(defined(OS_WIN) && !defined(USE_AURA)) && \ | 25 !(defined(OS_WIN) && !defined(USE_AURA)) && \ |
| 26 !defined(TOOLKIT_GTK) | 26 !defined(TOOLKIT_GTK) |
| 27 // We have subclassess of BrowserAccessibilityManager on Mac, Linux/GTK, | 27 // We have subclassess of BrowserAccessibilityManager on Mac, Linux/GTK, |
| 28 // and non-Aura Win. For any other platform, instantiate the base class. | 28 // and non-Aura Win. For any other platform, instantiate the base class. |
| 29 // static | 29 // static |
| 30 BrowserAccessibilityManager* BrowserAccessibilityManager::Create( | 30 BrowserAccessibilityManager* BrowserAccessibilityManager::Create( |
| 31 gfx::NativeView parent_view, | 31 gfx::NativeView parent_view, |
| 32 const WebAccessibility& src, | 32 const AccessibilityNodeData& src, |
| 33 BrowserAccessibilityDelegate* delegate, | 33 BrowserAccessibilityDelegate* delegate, |
| 34 BrowserAccessibilityFactory* factory) { | 34 BrowserAccessibilityFactory* factory) { |
| 35 return new BrowserAccessibilityManager( | 35 return new BrowserAccessibilityManager( |
| 36 parent_view, src, delegate, factory); | 36 parent_view, src, delegate, factory); |
| 37 } | 37 } |
| 38 #endif | 38 #endif |
| 39 | 39 |
| 40 // static | 40 // static |
| 41 BrowserAccessibilityManager* BrowserAccessibilityManager::CreateEmptyDocument( | 41 BrowserAccessibilityManager* BrowserAccessibilityManager::CreateEmptyDocument( |
| 42 gfx::NativeView parent_view, | 42 gfx::NativeView parent_view, |
| 43 WebAccessibility::State state, | 43 AccessibilityNodeData::State state, |
| 44 BrowserAccessibilityDelegate* delegate, | 44 BrowserAccessibilityDelegate* delegate, |
| 45 BrowserAccessibilityFactory* factory) { | 45 BrowserAccessibilityFactory* factory) { |
| 46 // Use empty document to process notifications | 46 // Use empty document to process notifications |
| 47 webkit_glue::WebAccessibility empty_document; | 47 AccessibilityNodeData empty_document; |
| 48 empty_document.id = 0; | 48 empty_document.id = 0; |
| 49 empty_document.role = WebAccessibility::ROLE_ROOT_WEB_AREA; | 49 empty_document.role = AccessibilityNodeData::ROLE_ROOT_WEB_AREA; |
| 50 empty_document.state = state | (1 << WebAccessibility::STATE_READONLY); | 50 empty_document.state = state | (1 << AccessibilityNodeData::STATE_READONLY); |
| 51 return BrowserAccessibilityManager::Create( | 51 return BrowserAccessibilityManager::Create( |
| 52 parent_view, empty_document, delegate, factory); | 52 parent_view, empty_document, delegate, factory); |
| 53 } | 53 } |
| 54 | 54 |
| 55 BrowserAccessibilityManager::BrowserAccessibilityManager( | 55 BrowserAccessibilityManager::BrowserAccessibilityManager( |
| 56 gfx::NativeView parent_view, | 56 gfx::NativeView parent_view, |
| 57 const WebAccessibility& src, | 57 const AccessibilityNodeData& src, |
| 58 BrowserAccessibilityDelegate* delegate, | 58 BrowserAccessibilityDelegate* delegate, |
| 59 BrowserAccessibilityFactory* factory) | 59 BrowserAccessibilityFactory* factory) |
| 60 : parent_view_(parent_view), | 60 : parent_view_(parent_view), |
| 61 delegate_(delegate), | 61 delegate_(delegate), |
| 62 factory_(factory), | 62 factory_(factory), |
| 63 focus_(NULL) { | 63 focus_(NULL) { |
| 64 root_ = CreateAccessibilityTree(NULL, src, 0, false); | 64 root_ = CreateAccessibilityTree(NULL, src, 0, false); |
| 65 if (!focus_) | 65 if (!focus_) |
| 66 SetFocus(root_, false); | 66 SetFocus(root_, false); |
| 67 } | 67 } |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 } | 232 } |
| 233 } | 233 } |
| 234 | 234 |
| 235 gfx::Rect BrowserAccessibilityManager::GetViewBounds() { | 235 gfx::Rect BrowserAccessibilityManager::GetViewBounds() { |
| 236 if (delegate_) | 236 if (delegate_) |
| 237 return delegate_->GetViewBounds(); | 237 return delegate_->GetViewBounds(); |
| 238 return gfx::Rect(); | 238 return gfx::Rect(); |
| 239 } | 239 } |
| 240 | 240 |
| 241 void BrowserAccessibilityManager::UpdateNode( | 241 void BrowserAccessibilityManager::UpdateNode( |
| 242 const WebAccessibility& src, | 242 const AccessibilityNodeData& src, |
| 243 bool include_children) { | 243 bool include_children) { |
| 244 BrowserAccessibility* current = NULL; | 244 BrowserAccessibility* current = NULL; |
| 245 | 245 |
| 246 // Look for the node to replace. Either we're replacing the whole tree | 246 // Look for the node to replace. Either we're replacing the whole tree |
| 247 // (role is ROOT_WEB_AREA) or we look it up based on its renderer ID. | 247 // (role is ROOT_WEB_AREA) or we look it up based on its renderer ID. |
| 248 if (src.role == WebAccessibility::ROLE_ROOT_WEB_AREA) { | 248 if (src.role == AccessibilityNodeData::ROLE_ROOT_WEB_AREA) { |
| 249 current = root_; | 249 current = root_; |
| 250 } else { | 250 } else { |
| 251 base::hash_map<int32, int32>::iterator iter = | 251 base::hash_map<int32, int32>::iterator iter = |
| 252 renderer_id_to_child_id_map_.find(src.id); | 252 renderer_id_to_child_id_map_.find(src.id); |
| 253 if (iter != renderer_id_to_child_id_map_.end()) { | 253 if (iter != renderer_id_to_child_id_map_.end()) { |
| 254 int32 child_id = iter->second; | 254 int32 child_id = iter->second; |
| 255 current = GetFromChildID(child_id); | 255 current = GetFromChildID(child_id); |
| 256 } | 256 } |
| 257 } | 257 } |
| 258 | 258 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 if (focus_ && focus_->ref_count() == 1) { | 299 if (focus_ && focus_->ref_count() == 1) { |
| 300 SetFocus(root_, false); | 300 SetFocus(root_, false); |
| 301 | 301 |
| 302 if (delegate_ && delegate_->HasFocus()) | 302 if (delegate_ && delegate_->HasFocus()) |
| 303 NotifyAccessibilityEvent(AccessibilityNotificationBlur, focus_); | 303 NotifyAccessibilityEvent(AccessibilityNotificationBlur, focus_); |
| 304 } | 304 } |
| 305 } | 305 } |
| 306 | 306 |
| 307 BrowserAccessibility* BrowserAccessibilityManager::CreateAccessibilityTree( | 307 BrowserAccessibility* BrowserAccessibilityManager::CreateAccessibilityTree( |
| 308 BrowserAccessibility* parent, | 308 BrowserAccessibility* parent, |
| 309 const WebAccessibility& src, | 309 const AccessibilityNodeData& src, |
| 310 int index_in_parent, | 310 int index_in_parent, |
| 311 bool send_show_events) { | 311 bool send_show_events) { |
| 312 BrowserAccessibility* instance = NULL; | 312 BrowserAccessibility* instance = NULL; |
| 313 int32 child_id = 0; | 313 int32 child_id = 0; |
| 314 bool children_can_send_show_events = send_show_events; | 314 bool children_can_send_show_events = send_show_events; |
| 315 base::hash_map<int32, int32>::iterator iter = | 315 base::hash_map<int32, int32>::iterator iter = |
| 316 renderer_id_to_child_id_map_.find(src.id); | 316 renderer_id_to_child_id_map_.find(src.id); |
| 317 | 317 |
| 318 // If a BrowserAccessibility instance for this ID already exists, add a | 318 // If a BrowserAccessibility instance for this ID already exists, add a |
| 319 // new reference to it and retrieve its children vector. | 319 // new reference to it and retrieve its children vector. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 345 // Otherwise, create a new instance. | 345 // Otherwise, create a new instance. |
| 346 instance = factory_->Create(); | 346 instance = factory_->Create(); |
| 347 child_id = GetNextChildID(); | 347 child_id = GetNextChildID(); |
| 348 children_can_send_show_events = false; | 348 children_can_send_show_events = false; |
| 349 } | 349 } |
| 350 | 350 |
| 351 instance->PreInitialize(this, parent, child_id, index_in_parent, src); | 351 instance->PreInitialize(this, parent, child_id, index_in_parent, src); |
| 352 child_id_map_[child_id] = instance; | 352 child_id_map_[child_id] = instance; |
| 353 renderer_id_to_child_id_map_[src.id] = child_id; | 353 renderer_id_to_child_id_map_[src.id] = child_id; |
| 354 | 354 |
| 355 if ((src.state >> WebAccessibility::STATE_FOCUSED) & 1) | 355 if ((src.state >> AccessibilityNodeData::STATE_FOCUSED) & 1) |
| 356 SetFocus(instance, false); | 356 SetFocus(instance, false); |
| 357 | 357 |
| 358 for (int i = 0; i < static_cast<int>(src.children.size()); ++i) { | 358 for (int i = 0; i < static_cast<int>(src.children.size()); ++i) { |
| 359 BrowserAccessibility* child = CreateAccessibilityTree( | 359 BrowserAccessibility* child = CreateAccessibilityTree( |
| 360 instance, src.children[i], i, children_can_send_show_events); | 360 instance, src.children[i], i, children_can_send_show_events); |
| 361 instance->AddChild(child); | 361 instance->AddChild(child); |
| 362 } | 362 } |
| 363 | 363 |
| 364 if (src.role == WebAccessibility::ROLE_ROOT_WEB_AREA) | 364 if (src.role == AccessibilityNodeData::ROLE_ROOT_WEB_AREA) |
| 365 root_ = instance; | 365 root_ = instance; |
| 366 | 366 |
| 367 // Note: the purpose of send_show_events and children_can_send_show_events | 367 // Note: the purpose of send_show_events and children_can_send_show_events |
| 368 // is so that we send a single ObjectShow event for the root of a subtree | 368 // is so that we send a single ObjectShow event for the root of a subtree |
| 369 // that just appeared for the first time, but not on any descendant of | 369 // that just appeared for the first time, but not on any descendant of |
| 370 // that subtree. | 370 // that subtree. |
| 371 if (send_show_events) | 371 if (send_show_events) |
| 372 NotifyAccessibilityEvent(AccessibilityNotificationObjectShow, instance); | 372 NotifyAccessibilityEvent(AccessibilityNotificationObjectShow, instance); |
| 373 | 373 |
| 374 instance->PostInitialize(); | 374 instance->PostInitialize(); |
| 375 | 375 |
| 376 return instance; | 376 return instance; |
| 377 } | 377 } |
| OLD | NEW |