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/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "content/browser/accessibility/browser_accessibility_manager.h" | 10 #include "content/browser/accessibility/browser_accessibility_manager.h" |
11 #include "content/common/accessibility_messages.h" | 11 #include "content/common/accessibility_messages.h" |
12 | 12 |
13 typedef WebAccessibility::BoolAttribute BoolAttribute; | 13 using content::AccessibilityNodeData; |
14 typedef WebAccessibility::FloatAttribute FloatAttribute; | 14 |
15 typedef WebAccessibility::IntAttribute IntAttribute; | 15 typedef AccessibilityNodeData::BoolAttribute BoolAttribute; |
16 typedef WebAccessibility::StringAttribute StringAttribute; | 16 typedef AccessibilityNodeData::FloatAttribute FloatAttribute; |
| 17 typedef AccessibilityNodeData::IntAttribute IntAttribute; |
| 18 typedef AccessibilityNodeData::StringAttribute StringAttribute; |
17 | 19 |
18 #if !defined(OS_MACOSX) && \ | 20 #if !defined(OS_MACOSX) && \ |
19 !(defined(OS_WIN) && !defined(USE_AURA)) && \ | 21 !(defined(OS_WIN) && !defined(USE_AURA)) && \ |
20 !defined(TOOLKIT_GTK) | 22 !defined(TOOLKIT_GTK) |
21 // We have subclassess of BrowserAccessibility on Mac, Linux/GTK, | 23 // We have subclassess of BrowserAccessibility on Mac, Linux/GTK, |
22 // and non-Aura Win. For any other platform, instantiate the base class. | 24 // and non-Aura Win. For any other platform, instantiate the base class. |
23 // static | 25 // static |
24 BrowserAccessibility* BrowserAccessibility::Create() { | 26 BrowserAccessibility* BrowserAccessibility::Create() { |
25 return new BrowserAccessibility(); | 27 return new BrowserAccessibility(); |
26 } | 28 } |
(...skipping 21 matching lines...) Expand all Loading... |
48 children_[i]->DetachTree(nodes); | 50 children_[i]->DetachTree(nodes); |
49 children_.clear(); | 51 children_.clear(); |
50 parent_ = NULL; | 52 parent_ = NULL; |
51 } | 53 } |
52 | 54 |
53 void BrowserAccessibility::PreInitialize( | 55 void BrowserAccessibility::PreInitialize( |
54 BrowserAccessibilityManager* manager, | 56 BrowserAccessibilityManager* manager, |
55 BrowserAccessibility* parent, | 57 BrowserAccessibility* parent, |
56 int32 child_id, | 58 int32 child_id, |
57 int32 index_in_parent, | 59 int32 index_in_parent, |
58 const webkit_glue::WebAccessibility& src) { | 60 const AccessibilityNodeData& src) { |
59 manager_ = manager; | 61 manager_ = manager; |
60 parent_ = parent; | 62 parent_ = parent; |
61 child_id_ = child_id; | 63 child_id_ = child_id; |
62 index_in_parent_ = index_in_parent; | 64 index_in_parent_ = index_in_parent; |
63 | 65 |
64 // Update all of the rest of the attributes. | 66 // Update all of the rest of the attributes. |
65 name_ = src.name; | 67 name_ = src.name; |
66 value_ = src.value; | 68 value_ = src.value; |
67 role_ = src.role; | 69 role_ = src.role; |
68 state_ = src.state; | 70 state_ = src.state; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 return NULL; | 130 return NULL; |
129 } | 131 } |
130 | 132 |
131 gfx::Rect BrowserAccessibility::GetLocalBoundsRect() { | 133 gfx::Rect BrowserAccessibility::GetLocalBoundsRect() { |
132 gfx::Rect bounds = location_; | 134 gfx::Rect bounds = location_; |
133 | 135 |
134 // Adjust top left position by the root document's scroll offset. | 136 // Adjust top left position by the root document's scroll offset. |
135 BrowserAccessibility* root = manager_->GetRoot(); | 137 BrowserAccessibility* root = manager_->GetRoot(); |
136 int scroll_x = 0; | 138 int scroll_x = 0; |
137 int scroll_y = 0; | 139 int scroll_y = 0; |
138 if (!root->GetIntAttribute(WebAccessibility::ATTR_SCROLL_X, &scroll_x) || | 140 if (!root->GetIntAttribute(AccessibilityNodeData::ATTR_SCROLL_X, &scroll_x) || |
139 !root->GetIntAttribute(WebAccessibility::ATTR_SCROLL_Y, &scroll_y)) { | 141 !root->GetIntAttribute(AccessibilityNodeData::ATTR_SCROLL_Y, &scroll_y)) { |
140 return bounds; | 142 return bounds; |
141 } | 143 } |
142 bounds.Offset(-scroll_x, -scroll_y); | 144 bounds.Offset(-scroll_x, -scroll_y); |
143 | 145 |
144 return bounds; | 146 return bounds; |
145 } | 147 } |
146 | 148 |
147 gfx::Rect BrowserAccessibility::GetGlobalBoundsRect() { | 149 gfx::Rect BrowserAccessibility::GetGlobalBoundsRect() { |
148 gfx::Rect bounds = GetLocalBoundsRect(); | 150 gfx::Rect bounds = GetLocalBoundsRect(); |
149 | 151 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 | 286 |
285 if (EqualsASCII(value, "true")) | 287 if (EqualsASCII(value, "true")) |
286 return true; | 288 return true; |
287 | 289 |
288 if (EqualsASCII(value, "mixed")) | 290 if (EqualsASCII(value, "mixed")) |
289 *is_mixed = true; | 291 *is_mixed = true; |
290 | 292 |
291 return false; // Not set | 293 return false; // Not set |
292 } | 294 } |
293 | 295 |
294 bool BrowserAccessibility::HasState(WebAccessibility::State state_enum) const { | 296 bool BrowserAccessibility::HasState( |
| 297 AccessibilityNodeData::State state_enum) const { |
295 return (state_ >> state_enum) & 1; | 298 return (state_ >> state_enum) & 1; |
296 } | 299 } |
297 | 300 |
298 bool BrowserAccessibility::IsEditableText() const { | 301 bool BrowserAccessibility::IsEditableText() const { |
299 // Note: STATE_READONLY being false means it's either a text control, | 302 // Note: STATE_READONLY being false means it's either a text control, |
300 // or contenteditable. We also check for editable text roles to cover | 303 // or contenteditable. We also check for editable text roles to cover |
301 // another element that has role=textbox set on it. | 304 // another element that has role=textbox set on it. |
302 return (!HasState(WebAccessibility::STATE_READONLY) || | 305 return (!HasState(AccessibilityNodeData::STATE_READONLY) || |
303 role_ == WebAccessibility::ROLE_TEXT_FIELD || | 306 role_ == AccessibilityNodeData::ROLE_TEXT_FIELD || |
304 role_ == WebAccessibility::ROLE_TEXTAREA); | 307 role_ == AccessibilityNodeData::ROLE_TEXTAREA); |
305 } | 308 } |
306 | 309 |
307 string16 BrowserAccessibility::GetTextRecursive() const { | 310 string16 BrowserAccessibility::GetTextRecursive() const { |
308 if (!name_.empty()) { | 311 if (!name_.empty()) { |
309 return name_; | 312 return name_; |
310 } | 313 } |
311 | 314 |
312 string16 result; | 315 string16 result; |
313 for (size_t i = 0; i < children_.size(); ++i) | 316 for (size_t i = 0; i < children_.size(); ++i) |
314 result += children_[i]->GetTextRecursive(); | 317 result += children_[i]->GetTextRecursive(); |
315 return result; | 318 return result; |
316 } | 319 } |
317 | 320 |
318 void BrowserAccessibility::PreInitialize() { | 321 void BrowserAccessibility::PreInitialize() { |
319 instance_active_ = true; | 322 instance_active_ = true; |
320 } | 323 } |
OLD | NEW |