| 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> |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 #if !defined(PLATFORM_HAS_NATIVE_ACCESSIBILITY_IMPL) | 33 #if !defined(PLATFORM_HAS_NATIVE_ACCESSIBILITY_IMPL) |
| 34 // static | 34 // static |
| 35 BrowserAccessibility* BrowserAccessibility::Create() { | 35 BrowserAccessibility* BrowserAccessibility::Create() { |
| 36 return new BrowserAccessibility(); | 36 return new BrowserAccessibility(); |
| 37 } | 37 } |
| 38 #endif | 38 #endif |
| 39 | 39 |
| 40 BrowserAccessibility::BrowserAccessibility() | 40 BrowserAccessibility::BrowserAccessibility() |
| 41 : manager_(nullptr), | 41 : manager_(nullptr), |
| 42 node_(nullptr), | 42 node_(nullptr), |
| 43 unique_id_(ui::GetNextAXPlatformNodeUniqueId()), | 43 unique_id_(ui::GetNextAXPlatformNodeUniqueId()) { |
| 44 platform_node_(nullptr) { | |
| 45 g_unique_id_map.Get()[unique_id_] = this; | 44 g_unique_id_map.Get()[unique_id_] = this; |
| 46 } | 45 } |
| 47 | 46 |
| 48 BrowserAccessibility::~BrowserAccessibility() { | 47 BrowserAccessibility::~BrowserAccessibility() { |
| 49 if (unique_id_) | 48 if (unique_id_) |
| 50 g_unique_id_map.Get().erase(unique_id_); | 49 g_unique_id_map.Get().erase(unique_id_); |
| 51 if (platform_node_) | |
| 52 platform_node_->Destroy(); | |
| 53 } | 50 } |
| 54 | 51 |
| 55 // static | 52 // static |
| 56 BrowserAccessibility* BrowserAccessibility::GetFromUniqueID(int32_t unique_id) { | 53 BrowserAccessibility* BrowserAccessibility::GetFromUniqueID(int32_t unique_id) { |
| 57 auto iter = g_unique_id_map.Get().find(unique_id); | 54 auto iter = g_unique_id_map.Get().find(unique_id); |
| 58 if (iter == g_unique_id_map.Get().end()) | 55 if (iter == g_unique_id_map.Get().end()) |
| 59 return nullptr; | 56 return nullptr; |
| 60 | 57 |
| 61 return iter->second; | 58 return iter->second; |
| 62 } | 59 } |
| 63 | 60 |
| 64 void BrowserAccessibility::Init(BrowserAccessibilityManager* manager, | 61 void BrowserAccessibility::Init(BrowserAccessibilityManager* manager, |
| 65 ui::AXNode* node) { | 62 ui::AXNode* node) { |
| 66 manager_ = manager; | 63 manager_ = manager; |
| 67 node_ = node; | 64 node_ = node; |
| 68 | |
| 69 // Here we create the AXPlatformNode which contains a platform-specific | |
| 70 // implementation of requried accessibility APIS for this node. At this point, | |
| 71 // we only are creating this object for Windows. See http://crbug.com/703369 | |
| 72 #if defined(OS_WIN) | |
| 73 platform_node_ = ui::AXPlatformNode::Create(this); | |
| 74 #endif | |
| 75 } | 65 } |
| 76 | 66 |
| 77 bool BrowserAccessibility::PlatformIsLeaf() const { | 67 bool BrowserAccessibility::PlatformIsLeaf() const { |
| 78 if (InternalChildCount() == 0) | 68 if (InternalChildCount() == 0) |
| 79 return true; | 69 return true; |
| 80 | 70 |
| 81 // These types of objects may have children that we use as internal | 71 // These types of objects may have children that we use as internal |
| 82 // implementation details, but we want to expose them as leaves to platform | 72 // implementation details, but we want to expose them as leaves to platform |
| 83 // accessibility APIs because screen readers might be confused if they find | 73 // accessibility APIs because screen readers might be confused if they find |
| 84 // any children. | 74 // any children. |
| (...skipping 1047 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1132 bounds.Offset(-sx, -sy); | 1122 bounds.Offset(-sx, -sy); |
| 1133 } | 1123 } |
| 1134 } | 1124 } |
| 1135 | 1125 |
| 1136 node = container; | 1126 node = container; |
| 1137 } | 1127 } |
| 1138 | 1128 |
| 1139 return gfx::ToEnclosingRect(bounds); | 1129 return gfx::ToEnclosingRect(bounds); |
| 1140 } | 1130 } |
| 1141 | 1131 |
| 1132 gfx::NativeViewAccessible BrowserAccessibility::GetNativeViewAccessible() { |
| 1133 // TODO(703369) On Windows, where we have started to migrate to an |
| 1134 // AXPlatformNode implementation, the BrowserAccessibilityWin subclass has |
| 1135 // overridden this method. On all other platforms, this method should not be |
| 1136 // called yet. In the future, when all subclasses have moved over to be |
| 1137 // implemented by AXPlatformNode, we may make this method completely virtual. |
| 1138 NOTREACHED(); |
| 1139 return nullptr; |
| 1140 } |
| 1141 |
| 1142 // | 1142 // |
| 1143 // AXPlatformNodeDelegate. | 1143 // AXPlatformNodeDelegate. |
| 1144 // | 1144 // |
| 1145 const ui::AXNodeData& BrowserAccessibility::GetData() const { | 1145 const ui::AXNodeData& BrowserAccessibility::GetData() const { |
| 1146 CR_DEFINE_STATIC_LOCAL(ui::AXNodeData, empty_data, ()); | 1146 CR_DEFINE_STATIC_LOCAL(ui::AXNodeData, empty_data, ()); |
| 1147 if (node_) | 1147 if (node_) |
| 1148 return node_->data(); | 1148 return node_->data(); |
| 1149 else | 1149 else |
| 1150 return empty_data; | 1150 return empty_data; |
| 1151 } | 1151 } |
| 1152 | 1152 |
| 1153 gfx::NativeWindow BrowserAccessibility::GetTopLevelWidget() { | 1153 gfx::NativeWindow BrowserAccessibility::GetTopLevelWidget() { |
| 1154 NOTREACHED(); | 1154 NOTREACHED(); |
| 1155 return nullptr; | 1155 return nullptr; |
| 1156 } | 1156 } |
| 1157 | 1157 |
| 1158 gfx::NativeViewAccessible BrowserAccessibility::GetParent() { | 1158 gfx::NativeViewAccessible BrowserAccessibility::GetParent() { |
| 1159 auto* parent = PlatformGetParent(); | 1159 auto* parent = PlatformGetParent(); |
| 1160 if (parent && parent->platform_node_) | 1160 if (!parent) |
| 1161 return parent->platform_node_->GetNativeViewAccessible(); | 1161 return nullptr; |
| 1162 return nullptr; | 1162 |
| 1163 return parent->GetNativeViewAccessible(); |
| 1163 } | 1164 } |
| 1164 | 1165 |
| 1165 int BrowserAccessibility::GetChildCount() { | 1166 int BrowserAccessibility::GetChildCount() { |
| 1166 return PlatformChildCount(); | 1167 return PlatformChildCount(); |
| 1167 } | 1168 } |
| 1168 | 1169 |
| 1169 gfx::NativeViewAccessible BrowserAccessibility::ChildAtIndex(int index) { | 1170 gfx::NativeViewAccessible BrowserAccessibility::ChildAtIndex(int index) { |
| 1170 auto* child = PlatformGetChild(index); | 1171 auto* child = PlatformGetChild(index); |
| 1171 if (child && child->platform_node_) | 1172 if (!child) |
| 1172 return child->platform_node_->GetNativeViewAccessible(); | 1173 return nullptr; |
| 1173 return nullptr; | 1174 |
| 1175 return child->GetNativeViewAccessible(); |
| 1174 } | 1176 } |
| 1175 | 1177 |
| 1176 gfx::Rect BrowserAccessibility::GetScreenBoundsRect() const { | 1178 gfx::Rect BrowserAccessibility::GetScreenBoundsRect() const { |
| 1177 gfx::Rect bounds = GetPageBoundsRect(); | 1179 gfx::Rect bounds = GetPageBoundsRect(); |
| 1178 | 1180 |
| 1179 // Adjust the bounds by the top left corner of the containing view's bounds | 1181 // Adjust the bounds by the top left corner of the containing view's bounds |
| 1180 // in screen coordinates. | 1182 // in screen coordinates. |
| 1181 bounds.Offset(manager_->GetViewBounds().OffsetFromOrigin()); | 1183 bounds.Offset(manager_->GetViewBounds().OffsetFromOrigin()); |
| 1182 | 1184 |
| 1183 return bounds; | 1185 return bounds; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1199 return gfx::kNullAcceleratedWidget; | 1201 return gfx::kNullAcceleratedWidget; |
| 1200 } | 1202 } |
| 1201 | 1203 |
| 1202 bool BrowserAccessibility::AccessibilityPerformAction( | 1204 bool BrowserAccessibility::AccessibilityPerformAction( |
| 1203 const ui::AXActionData& data) { | 1205 const ui::AXActionData& data) { |
| 1204 NOTREACHED(); | 1206 NOTREACHED(); |
| 1205 return false; | 1207 return false; |
| 1206 } | 1208 } |
| 1207 | 1209 |
| 1208 } // namespace content | 1210 } // namespace content |
| OLD | NEW |