| 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 | 10 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "content/browser/accessibility/browser_accessibility_manager.h" | 15 #include "content/browser/accessibility/browser_accessibility_manager.h" |
| 16 #include "content/common/accessibility_messages.h" | 16 #include "content/common/accessibility_messages.h" |
| 17 #include "ui/accessibility/ax_text_utils.h" | 17 #include "ui/accessibility/ax_text_utils.h" |
| 18 #include "ui/accessibility/platform/ax_platform_node.h" |
| 18 | 19 |
| 19 namespace content { | 20 namespace content { |
| 20 | 21 |
| 22 namespace { |
| 23 |
| 24 // Map from unique_id to BrowserAccessibility |
| 25 using UniqueIDMap = base::hash_map<int32_t, BrowserAccessibility*>; |
| 26 base::LazyInstance<UniqueIDMap> g_unique_id_map = LAZY_INSTANCE_INITIALIZER; |
| 27 |
| 28 } |
| 29 |
| 21 #if !defined(PLATFORM_HAS_NATIVE_ACCESSIBILITY_IMPL) | 30 #if !defined(PLATFORM_HAS_NATIVE_ACCESSIBILITY_IMPL) |
| 22 // static | 31 // static |
| 23 BrowserAccessibility* BrowserAccessibility::Create() { | 32 BrowserAccessibility* BrowserAccessibility::Create() { |
| 24 return new BrowserAccessibility(); | 33 return new BrowserAccessibility(); |
| 25 } | 34 } |
| 26 #endif | 35 #endif |
| 27 | 36 |
| 28 BrowserAccessibility::BrowserAccessibility() | 37 BrowserAccessibility::BrowserAccessibility() |
| 29 : manager_(NULL), | 38 : manager_(NULL), |
| 30 node_(NULL) { | 39 node_(NULL), |
| 40 unique_id_(ui::AXPlatformNode::GetNextUniqueId()) { |
| 41 g_unique_id_map.Get()[unique_id_] = this; |
| 31 } | 42 } |
| 32 | 43 |
| 33 BrowserAccessibility::~BrowserAccessibility() { | 44 BrowserAccessibility::~BrowserAccessibility() { |
| 45 if (unique_id_) |
| 46 g_unique_id_map.Get().erase(unique_id_); |
| 47 } |
| 48 |
| 49 // static |
| 50 BrowserAccessibility* BrowserAccessibility::GetFromUniqueID(int32_t unique_id) { |
| 51 auto iter = g_unique_id_map.Get().find(unique_id); |
| 52 if (iter == g_unique_id_map.Get().end()) |
| 53 return nullptr; |
| 54 |
| 55 return iter->second; |
| 34 } | 56 } |
| 35 | 57 |
| 36 void BrowserAccessibility::Init(BrowserAccessibilityManager* manager, | 58 void BrowserAccessibility::Init(BrowserAccessibilityManager* manager, |
| 37 ui::AXNode* node) { | 59 ui::AXNode* node) { |
| 38 manager_ = manager; | 60 manager_ = manager; |
| 39 node_ = node; | 61 node_ = node; |
| 40 } | 62 } |
| 41 | 63 |
| 42 bool BrowserAccessibility::PlatformIsLeaf() const { | 64 bool BrowserAccessibility::PlatformIsLeaf() const { |
| 43 if (InternalChildCount() == 0) | 65 if (InternalChildCount() == 0) |
| (...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 | 609 |
| 588 return this; | 610 return this; |
| 589 } | 611 } |
| 590 | 612 |
| 591 void BrowserAccessibility::Destroy() { | 613 void BrowserAccessibility::Destroy() { |
| 592 // Allow the object to fire a TextRemoved notification. | 614 // Allow the object to fire a TextRemoved notification. |
| 593 manager_->NotifyAccessibilityEvent(ui::AX_EVENT_HIDE, this); | 615 manager_->NotifyAccessibilityEvent(ui::AX_EVENT_HIDE, this); |
| 594 node_ = NULL; | 616 node_ = NULL; |
| 595 manager_ = NULL; | 617 manager_ = NULL; |
| 596 | 618 |
| 619 if (unique_id_) |
| 620 g_unique_id_map.Get().erase(unique_id_); |
| 621 unique_id_ = 0; |
| 622 |
| 597 NativeReleaseReference(); | 623 NativeReleaseReference(); |
| 598 } | 624 } |
| 599 | 625 |
| 600 void BrowserAccessibility::NativeReleaseReference() { | 626 void BrowserAccessibility::NativeReleaseReference() { |
| 601 delete this; | 627 delete this; |
| 602 } | 628 } |
| 603 | 629 |
| 604 bool BrowserAccessibility::HasBoolAttribute( | 630 bool BrowserAccessibility::HasBoolAttribute( |
| 605 ui::AXBoolAttribute attribute) const { | 631 ui::AXBoolAttribute attribute) const { |
| 606 return GetData().HasBoolAttribute(attribute); | 632 return GetData().HasBoolAttribute(attribute); |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 909 } | 935 } |
| 910 need_to_offset_web_area = true; | 936 need_to_offset_web_area = true; |
| 911 } | 937 } |
| 912 parent = parent->GetParent(); | 938 parent = parent->GetParent(); |
| 913 } | 939 } |
| 914 | 940 |
| 915 return bounds; | 941 return bounds; |
| 916 } | 942 } |
| 917 | 943 |
| 918 } // namespace content | 944 } // namespace content |
| OLD | NEW |