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 "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #include "content/browser/accessibility/browser_accessibility_manager.h" | 11 #include "content/browser/accessibility/browser_accessibility_manager.h" |
12 #include "content/common/accessibility_messages.h" | 12 #include "content/common/accessibility_messages.h" |
13 | 13 |
14 namespace content { | 14 namespace content { |
15 | 15 |
16 #if !defined(OS_MACOSX) && \ | 16 #if !defined(OS_MACOSX) && \ |
17 !defined(OS_WIN) && \ | 17 !defined(OS_WIN) && \ |
18 !defined(OS_ANDROID) | 18 !defined(OS_ANDROID) |
19 // We have subclassess of BrowserAccessibility on Mac and Win. For any other | 19 // We have subclassess of BrowserAccessibility on Mac and Win. For any other |
20 // platform, instantiate the base class. | 20 // platform, instantiate the base class. |
21 // static | 21 // static |
22 BrowserAccessibility* BrowserAccessibility::Create() { | 22 BrowserAccessibility* BrowserAccessibility::Create() { |
23 return new BrowserAccessibility(); | 23 return new BrowserAccessibility(); |
24 } | 24 } |
25 #endif | 25 #endif |
26 | 26 |
27 BrowserAccessibility::BrowserAccessibility() | 27 BrowserAccessibility::BrowserAccessibility() |
28 : manager_(NULL), | 28 : manager_(nullptr), |
29 node_(NULL) { | 29 node_(nullptr) { |
30 } | 30 } |
31 | 31 |
32 BrowserAccessibility::~BrowserAccessibility() { | 32 BrowserAccessibility::~BrowserAccessibility() { |
33 } | 33 } |
34 | 34 |
35 void BrowserAccessibility::Init(BrowserAccessibilityManager* manager, | 35 void BrowserAccessibility::Init(BrowserAccessibilityManager* manager, |
36 ui::AXNode* node) { | 36 ui::AXNode* node) { |
37 manager_ = manager; | 37 manager_ = manager; |
38 node_ = node; | 38 node_ = node; |
39 } | 39 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 result = child_manager->GetRoot(); | 93 result = child_manager->GetRoot(); |
94 } | 94 } |
95 | 95 |
96 return result; | 96 return result; |
97 } | 97 } |
98 | 98 |
99 BrowserAccessibility* BrowserAccessibility::GetPreviousSibling() { | 99 BrowserAccessibility* BrowserAccessibility::GetPreviousSibling() { |
100 if (GetParent() && GetIndexInParent() > 0) | 100 if (GetParent() && GetIndexInParent() > 0) |
101 return GetParent()->InternalGetChild(GetIndexInParent() - 1); | 101 return GetParent()->InternalGetChild(GetIndexInParent() - 1); |
102 | 102 |
103 return NULL; | 103 return nullptr; |
104 } | 104 } |
105 | 105 |
106 BrowserAccessibility* BrowserAccessibility::GetNextSibling() { | 106 BrowserAccessibility* BrowserAccessibility::GetNextSibling() { |
107 if (GetParent() && | 107 if (GetParent() && |
108 GetIndexInParent() >= 0 && | 108 GetIndexInParent() >= 0 && |
109 GetIndexInParent() < static_cast<int>( | 109 GetIndexInParent() < static_cast<int>( |
110 GetParent()->InternalChildCount() - 1)) { | 110 GetParent()->InternalChildCount() - 1)) { |
111 return GetParent()->InternalGetChild(GetIndexInParent() + 1); | 111 return GetParent()->InternalGetChild(GetIndexInParent() + 1); |
112 } | 112 } |
113 | 113 |
114 return NULL; | 114 return nullptr; |
115 } | 115 } |
116 | 116 |
117 uint32 BrowserAccessibility::InternalChildCount() const { | 117 uint32 BrowserAccessibility::InternalChildCount() const { |
118 if (!node_ || !manager_) | 118 if (!node_ || !manager_) |
119 return 0; | 119 return 0; |
120 return static_cast<uint32>(node_->child_count()); | 120 return static_cast<uint32>(node_->child_count()); |
121 } | 121 } |
122 | 122 |
123 BrowserAccessibility* BrowserAccessibility::InternalGetChild( | 123 BrowserAccessibility* BrowserAccessibility::InternalGetChild( |
124 uint32 child_index) const { | 124 uint32 child_index) const { |
125 if (!node_ || !manager_) | 125 if (!node_ || !manager_) |
126 return NULL; | 126 return nullptr; |
127 return manager_->GetFromAXNode(node_->children()[child_index]); | 127 return manager_->GetFromAXNode(node_->children()[child_index]); |
128 } | 128 } |
129 | 129 |
130 BrowserAccessibility* BrowserAccessibility::GetParent() const { | 130 BrowserAccessibility* BrowserAccessibility::GetParent() const { |
131 if (!node_ || !manager_) | 131 if (!node_ || !manager_) |
132 return NULL; | 132 return nullptr; |
133 ui::AXNode* parent = node_->parent(); | 133 ui::AXNode* parent = node_->parent(); |
134 if (parent) | 134 if (parent) |
135 return manager_->GetFromAXNode(parent); | 135 return manager_->GetFromAXNode(parent); |
136 | 136 |
137 if (!manager_->delegate()) | 137 if (!manager_->delegate()) |
138 return NULL; | 138 return nullptr; |
139 | 139 |
140 BrowserAccessibility* host_node = | 140 BrowserAccessibility* host_node = |
141 manager_->delegate()->AccessibilityGetParentFrame(); | 141 manager_->delegate()->AccessibilityGetParentFrame(); |
142 if (!host_node) | 142 if (!host_node) |
143 return NULL; | 143 return nullptr; |
144 | 144 |
145 return host_node->GetParent(); | 145 return host_node->GetParent(); |
146 } | 146 } |
147 | 147 |
148 int32 BrowserAccessibility::GetIndexInParent() const { | 148 int32 BrowserAccessibility::GetIndexInParent() const { |
149 return node_ ? node_->index_in_parent() : -1; | 149 return node_ ? node_->index_in_parent() : -1; |
150 } | 150 } |
151 | 151 |
152 int32 BrowserAccessibility::GetId() const { | 152 int32 BrowserAccessibility::GetId() const { |
153 return node_ ? node_->id() : -1; | 153 return node_ ? node_->id() : -1; |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 // Adjust the bounds by the top left corner of the containing view's bounds | 333 // Adjust the bounds by the top left corner of the containing view's bounds |
334 // in screen coordinates. | 334 // in screen coordinates. |
335 bounds.Offset(manager_->GetViewBounds().OffsetFromOrigin()); | 335 bounds.Offset(manager_->GetViewBounds().OffsetFromOrigin()); |
336 | 336 |
337 return bounds; | 337 return bounds; |
338 } | 338 } |
339 | 339 |
340 BrowserAccessibility* BrowserAccessibility::BrowserAccessibilityForPoint( | 340 BrowserAccessibility* BrowserAccessibility::BrowserAccessibilityForPoint( |
341 const gfx::Point& point) { | 341 const gfx::Point& point) { |
342 // The best result found that's a child of this object. | 342 // The best result found that's a child of this object. |
343 BrowserAccessibility* child_result = NULL; | 343 BrowserAccessibility* child_result = nullptr; |
344 // The best result that's an indirect descendant like grandchild, etc. | 344 // The best result that's an indirect descendant like grandchild, etc. |
345 BrowserAccessibility* descendant_result = NULL; | 345 BrowserAccessibility* descendant_result = nullptr; |
346 | 346 |
347 // Walk the children recursively looking for the BrowserAccessibility that | 347 // Walk the children recursively looking for the BrowserAccessibility that |
348 // most tightly encloses the specified point. Walk backwards so that in | 348 // most tightly encloses the specified point. Walk backwards so that in |
349 // the absence of any other information, we assume the object that occurs | 349 // the absence of any other information, we assume the object that occurs |
350 // later in the tree is on top of one that comes before it. | 350 // later in the tree is on top of one that comes before it. |
351 for (int i = static_cast<int>(PlatformChildCount()) - 1; i >= 0; --i) { | 351 for (int i = static_cast<int>(PlatformChildCount()) - 1; i >= 0; --i) { |
352 BrowserAccessibility* child = PlatformGetChild(i); | 352 BrowserAccessibility* child = PlatformGetChild(i); |
353 | 353 |
354 // Skip table columns because cells are only contained in rows, | 354 // Skip table columns because cells are only contained in rows, |
355 // not columns. | 355 // not columns. |
(...skipping 25 matching lines...) Expand all Loading... |
381 | 381 |
382 return this; | 382 return this; |
383 } | 383 } |
384 | 384 |
385 void BrowserAccessibility::Destroy() { | 385 void BrowserAccessibility::Destroy() { |
386 // Allow the object to fire a TextRemoved notification. | 386 // Allow the object to fire a TextRemoved notification. |
387 name_.clear(); | 387 name_.clear(); |
388 value_.clear(); | 388 value_.clear(); |
389 | 389 |
390 manager_->NotifyAccessibilityEvent(ui::AX_EVENT_HIDE, this); | 390 manager_->NotifyAccessibilityEvent(ui::AX_EVENT_HIDE, this); |
391 node_ = NULL; | 391 node_ = nullptr; |
392 manager_ = NULL; | 392 manager_ = nullptr; |
393 | 393 |
394 NativeReleaseReference(); | 394 NativeReleaseReference(); |
395 } | 395 } |
396 | 396 |
397 void BrowserAccessibility::NativeReleaseReference() { | 397 void BrowserAccessibility::NativeReleaseReference() { |
398 delete this; | 398 delete this; |
399 } | 399 } |
400 | 400 |
401 bool BrowserAccessibility::HasBoolAttribute( | 401 bool BrowserAccessibility::HasBoolAttribute( |
402 ui::AXBoolAttribute attribute) const { | 402 ui::AXBoolAttribute attribute) const { |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
694 if (GetRole() == ui::AX_ROLE_STATIC_TEXT) | 694 if (GetRole() == ui::AX_ROLE_STATIC_TEXT) |
695 return static_cast<int>(GetStringAttribute(ui::AX_ATTR_VALUE).size()); | 695 return static_cast<int>(GetStringAttribute(ui::AX_ATTR_VALUE).size()); |
696 | 696 |
697 int len = 0; | 697 int len = 0; |
698 for (size_t i = 0; i < InternalChildCount(); ++i) | 698 for (size_t i = 0; i < InternalChildCount(); ++i) |
699 len += InternalGetChild(i)->GetStaticTextLenRecursive(); | 699 len += InternalGetChild(i)->GetStaticTextLenRecursive(); |
700 return len; | 700 return len; |
701 } | 701 } |
702 | 702 |
703 } // namespace content | 703 } // namespace content |
OLD | NEW |