| 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.h" | 5 #include "content/browser/accessibility/browser_accessibility.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <iterator> | 10 #include <iterator> |
| 11 | 11 |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 15 #include "content/browser/accessibility/browser_accessibility_manager.h" | 15 #include "content/browser/accessibility/browser_accessibility_manager.h" |
| 16 #include "content/browser/accessibility/browser_accessibility_state_impl.h" | 16 #include "content/browser/accessibility/browser_accessibility_state_impl.h" |
| 17 #include "content/common/accessibility_messages.h" | 17 #include "content/common/accessibility_messages.h" |
| 18 #include "ui/accessibility/ax_role_properties.h" | 18 #include "ui/accessibility/ax_role_properties.h" |
| 19 #include "ui/accessibility/ax_text_utils.h" | 19 #include "ui/accessibility/ax_text_utils.h" |
| 20 #include "ui/accessibility/platform/ax_platform_unique_id.h" | |
| 21 #include "ui/gfx/geometry/rect_conversions.h" | 20 #include "ui/gfx/geometry/rect_conversions.h" |
| 22 #include "ui/gfx/geometry/rect_f.h" | 21 #include "ui/gfx/geometry/rect_f.h" |
| 23 | 22 |
| 24 namespace content { | 23 namespace content { |
| 25 | 24 |
| 26 namespace { | |
| 27 | |
| 28 // Map from unique_id to BrowserAccessibility | |
| 29 using UniqueIDMap = base::hash_map<int32_t, BrowserAccessibility*>; | |
| 30 base::LazyInstance<UniqueIDMap>::DestructorAtExit g_unique_id_map = | |
| 31 LAZY_INSTANCE_INITIALIZER; | |
| 32 } | |
| 33 | |
| 34 #if !defined(PLATFORM_HAS_NATIVE_ACCESSIBILITY_IMPL) | 25 #if !defined(PLATFORM_HAS_NATIVE_ACCESSIBILITY_IMPL) |
| 35 // static | 26 // static |
| 36 BrowserAccessibility* BrowserAccessibility::Create() { | 27 BrowserAccessibility* BrowserAccessibility::Create() { |
| 37 return new BrowserAccessibility(); | 28 return new BrowserAccessibility(); |
| 38 } | 29 } |
| 39 #endif | 30 #endif |
| 40 | 31 |
| 41 BrowserAccessibility::BrowserAccessibility() | 32 BrowserAccessibility::BrowserAccessibility() |
| 42 : manager_(nullptr), | 33 : manager_(nullptr), node_(nullptr) {} |
| 43 node_(nullptr), | |
| 44 unique_id_(ui::GetNextAXPlatformNodeUniqueId()) { | |
| 45 g_unique_id_map.Get()[unique_id_] = this; | |
| 46 } | |
| 47 | 34 |
| 48 BrowserAccessibility::~BrowserAccessibility() { | 35 BrowserAccessibility::~BrowserAccessibility() { |
| 49 if (unique_id_) | |
| 50 g_unique_id_map.Get().erase(unique_id_); | |
| 51 } | |
| 52 | |
| 53 // static | |
| 54 BrowserAccessibility* BrowserAccessibility::GetFromUniqueID(int32_t unique_id) { | |
| 55 auto iter = g_unique_id_map.Get().find(unique_id); | |
| 56 if (iter == g_unique_id_map.Get().end()) | |
| 57 return nullptr; | |
| 58 | |
| 59 return iter->second; | |
| 60 } | 36 } |
| 61 | 37 |
| 62 void BrowserAccessibility::Init(BrowserAccessibilityManager* manager, | 38 void BrowserAccessibility::Init(BrowserAccessibilityManager* manager, |
| 63 ui::AXNode* node) { | 39 ui::AXNode* node) { |
| 64 manager_ = manager; | 40 manager_ = manager; |
| 65 node_ = node; | 41 node_ = node; |
| 66 } | 42 } |
| 67 | 43 |
| 68 bool BrowserAccessibility::PlatformIsLeaf() const { | 44 bool BrowserAccessibility::PlatformIsLeaf() const { |
| 69 if (InternalChildCount() == 0) | 45 if (InternalChildCount() == 0) |
| (...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 | 542 |
| 567 void BrowserAccessibility::Destroy() { | 543 void BrowserAccessibility::Destroy() { |
| 568 // Allow the object to fire a TextRemoved notification. | 544 // Allow the object to fire a TextRemoved notification. |
| 569 manager()->NotifyAccessibilityEvent( | 545 manager()->NotifyAccessibilityEvent( |
| 570 BrowserAccessibilityEvent::FromTreeChange, | 546 BrowserAccessibilityEvent::FromTreeChange, |
| 571 ui::AX_EVENT_HIDE, | 547 ui::AX_EVENT_HIDE, |
| 572 this); | 548 this); |
| 573 node_ = NULL; | 549 node_ = NULL; |
| 574 manager_ = NULL; | 550 manager_ = NULL; |
| 575 | 551 |
| 576 if (unique_id_) | |
| 577 g_unique_id_map.Get().erase(unique_id_); | |
| 578 unique_id_ = 0; | |
| 579 | |
| 580 NativeReleaseReference(); | 552 NativeReleaseReference(); |
| 581 } | 553 } |
| 582 | 554 |
| 583 void BrowserAccessibility::NativeReleaseReference() { | 555 void BrowserAccessibility::NativeReleaseReference() { |
| 584 delete this; | 556 delete this; |
| 585 } | 557 } |
| 586 | 558 |
| 587 bool BrowserAccessibility::HasBoolAttribute( | 559 bool BrowserAccessibility::HasBoolAttribute( |
| 588 ui::AXBoolAttribute attribute) const { | 560 ui::AXBoolAttribute attribute) const { |
| 589 return GetData().HasBoolAttribute(attribute); | 561 return GetData().HasBoolAttribute(attribute); |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1020 return false; | 992 return false; |
| 1021 } | 993 } |
| 1022 | 994 |
| 1023 bool BrowserAccessibility::ShouldIgnoreHoveredStateForTesting() { | 995 bool BrowserAccessibility::ShouldIgnoreHoveredStateForTesting() { |
| 1024 BrowserAccessibilityStateImpl* accessibility_state = | 996 BrowserAccessibilityStateImpl* accessibility_state = |
| 1025 BrowserAccessibilityStateImpl::GetInstance(); | 997 BrowserAccessibilityStateImpl::GetInstance(); |
| 1026 return accessibility_state->disable_hot_tracking_for_testing(); | 998 return accessibility_state->disable_hot_tracking_for_testing(); |
| 1027 } | 999 } |
| 1028 | 1000 |
| 1029 } // namespace content | 1001 } // namespace content |
| OLD | NEW |