| 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" |
| 20 #include "ui/gfx/geometry/rect_conversions.h" | 21 #include "ui/gfx/geometry/rect_conversions.h" |
| 21 #include "ui/gfx/geometry/rect_f.h" | 22 #include "ui/gfx/geometry/rect_f.h" |
| 22 | 23 |
| 23 namespace content { | 24 namespace content { |
| 24 | 25 |
| 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 |
| 25 #if !defined(PLATFORM_HAS_NATIVE_ACCESSIBILITY_IMPL) | 34 #if !defined(PLATFORM_HAS_NATIVE_ACCESSIBILITY_IMPL) |
| 26 // static | 35 // static |
| 27 BrowserAccessibility* BrowserAccessibility::Create() { | 36 BrowserAccessibility* BrowserAccessibility::Create() { |
| 28 return new BrowserAccessibility(); | 37 return new BrowserAccessibility(); |
| 29 } | 38 } |
| 30 #endif | 39 #endif |
| 31 | 40 |
| 32 BrowserAccessibility::BrowserAccessibility() | 41 BrowserAccessibility::BrowserAccessibility() |
| 33 : manager_(nullptr), node_(nullptr) {} | 42 : manager_(nullptr), |
| 43 node_(nullptr), |
| 44 unique_id_(ui::GetNextAXPlatformNodeUniqueId()) { |
| 45 g_unique_id_map.Get()[unique_id_] = this; |
| 46 } |
| 34 | 47 |
| 35 BrowserAccessibility::~BrowserAccessibility() { | 48 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; |
| 36 } | 60 } |
| 37 | 61 |
| 38 void BrowserAccessibility::Init(BrowserAccessibilityManager* manager, | 62 void BrowserAccessibility::Init(BrowserAccessibilityManager* manager, |
| 39 ui::AXNode* node) { | 63 ui::AXNode* node) { |
| 40 manager_ = manager; | 64 manager_ = manager; |
| 41 node_ = node; | 65 node_ = node; |
| 42 } | 66 } |
| 43 | 67 |
| 44 bool BrowserAccessibility::PlatformIsLeaf() const { | 68 bool BrowserAccessibility::PlatformIsLeaf() const { |
| 45 if (InternalChildCount() == 0) | 69 if (InternalChildCount() == 0) |
| (...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 542 | 566 |
| 543 void BrowserAccessibility::Destroy() { | 567 void BrowserAccessibility::Destroy() { |
| 544 // Allow the object to fire a TextRemoved notification. | 568 // Allow the object to fire a TextRemoved notification. |
| 545 manager()->NotifyAccessibilityEvent( | 569 manager()->NotifyAccessibilityEvent( |
| 546 BrowserAccessibilityEvent::FromTreeChange, | 570 BrowserAccessibilityEvent::FromTreeChange, |
| 547 ui::AX_EVENT_HIDE, | 571 ui::AX_EVENT_HIDE, |
| 548 this); | 572 this); |
| 549 node_ = NULL; | 573 node_ = NULL; |
| 550 manager_ = NULL; | 574 manager_ = NULL; |
| 551 | 575 |
| 576 if (unique_id_) |
| 577 g_unique_id_map.Get().erase(unique_id_); |
| 578 unique_id_ = 0; |
| 579 |
| 552 NativeReleaseReference(); | 580 NativeReleaseReference(); |
| 553 } | 581 } |
| 554 | 582 |
| 555 void BrowserAccessibility::NativeReleaseReference() { | 583 void BrowserAccessibility::NativeReleaseReference() { |
| 556 delete this; | 584 delete this; |
| 557 } | 585 } |
| 558 | 586 |
| 559 bool BrowserAccessibility::HasBoolAttribute( | 587 bool BrowserAccessibility::HasBoolAttribute( |
| 560 ui::AXBoolAttribute attribute) const { | 588 ui::AXBoolAttribute attribute) const { |
| 561 return GetData().HasBoolAttribute(attribute); | 589 return GetData().HasBoolAttribute(attribute); |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 992 return false; | 1020 return false; |
| 993 } | 1021 } |
| 994 | 1022 |
| 995 bool BrowserAccessibility::ShouldIgnoreHoveredStateForTesting() { | 1023 bool BrowserAccessibility::ShouldIgnoreHoveredStateForTesting() { |
| 996 BrowserAccessibilityStateImpl* accessibility_state = | 1024 BrowserAccessibilityStateImpl* accessibility_state = |
| 997 BrowserAccessibilityStateImpl::GetInstance(); | 1025 BrowserAccessibilityStateImpl::GetInstance(); |
| 998 return accessibility_state->disable_hot_tracking_for_testing(); | 1026 return accessibility_state->disable_hot_tracking_for_testing(); |
| 999 } | 1027 } |
| 1000 | 1028 |
| 1001 } // namespace content | 1029 } // namespace content |
| OLD | NEW |