| 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 namespace content { | 13 namespace content { |
| 14 | 14 |
| 15 typedef AccessibilityNodeData::BoolAttribute BoolAttribute; | 15 typedef AccessibilityNodeData::BoolAttribute BoolAttribute; |
| 16 typedef AccessibilityNodeData::FloatAttribute FloatAttribute; | 16 typedef AccessibilityNodeData::FloatAttribute FloatAttribute; |
| 17 typedef AccessibilityNodeData::IntAttribute IntAttribute; | 17 typedef AccessibilityNodeData::IntAttribute IntAttribute; |
| 18 typedef AccessibilityNodeData::StringAttribute StringAttribute; | 18 typedef AccessibilityNodeData::StringAttribute StringAttribute; |
| 19 | 19 |
| 20 #if !defined(OS_MACOSX) && \ | 20 #if !defined(OS_MACOSX) && \ |
| 21 !defined(OS_WIN) && \ | 21 !defined(OS_WIN) && \ |
| 22 !defined(TOOLKIT_GTK) | 22 !defined(TOOLKIT_GTK) && \ |
| 23 !defined(OS_ANDROID) |
| 23 // We have subclassess of BrowserAccessibility on Mac, Linux/GTK, | 24 // We have subclassess of BrowserAccessibility on Mac, Linux/GTK, |
| 24 // and Win. For any other platform, instantiate the base class. | 25 // and Win. For any other platform, instantiate the base class. |
| 25 // static | 26 // static |
| 26 BrowserAccessibility* BrowserAccessibility::Create() { | 27 BrowserAccessibility* BrowserAccessibility::Create() { |
| 27 return new BrowserAccessibility(); | 28 return new BrowserAccessibility(); |
| 28 } | 29 } |
| 29 #endif | 30 #endif |
| 30 | 31 |
| 31 BrowserAccessibility::BrowserAccessibility() | 32 BrowserAccessibility::BrowserAccessibility() |
| 32 : manager_(NULL), | 33 : manager_(NULL), |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 BrowserAccessibility* ancestor) { | 106 BrowserAccessibility* ancestor) { |
| 106 if (this == ancestor) { | 107 if (this == ancestor) { |
| 107 return true; | 108 return true; |
| 108 } else if (parent_) { | 109 } else if (parent_) { |
| 109 return parent_->IsDescendantOf(ancestor); | 110 return parent_->IsDescendantOf(ancestor); |
| 110 } | 111 } |
| 111 | 112 |
| 112 return false; | 113 return false; |
| 113 } | 114 } |
| 114 | 115 |
| 115 BrowserAccessibility* BrowserAccessibility::GetChild(uint32 child_index) { | 116 BrowserAccessibility* BrowserAccessibility::GetChild(uint32 child_index) const { |
| 116 DCHECK(child_index < children_.size()); | 117 DCHECK(child_index < children_.size()); |
| 117 return children_[child_index]; | 118 return children_[child_index]; |
| 118 } | 119 } |
| 119 | 120 |
| 120 BrowserAccessibility* BrowserAccessibility::GetPreviousSibling() { | 121 BrowserAccessibility* BrowserAccessibility::GetPreviousSibling() { |
| 121 if (parent_ && index_in_parent_ > 0) | 122 if (parent_ && index_in_parent_ > 0) |
| 122 return parent_->children_[index_in_parent_ - 1]; | 123 return parent_->children_[index_in_parent_ - 1]; |
| 123 | 124 |
| 124 return NULL; | 125 return NULL; |
| 125 } | 126 } |
| 126 | 127 |
| 127 BrowserAccessibility* BrowserAccessibility::GetNextSibling() { | 128 BrowserAccessibility* BrowserAccessibility::GetNextSibling() { |
| 128 if (parent_ && | 129 if (parent_ && |
| 129 index_in_parent_ >= 0 && | 130 index_in_parent_ >= 0 && |
| 130 index_in_parent_ < static_cast<int>(parent_->children_.size() - 1)) { | 131 index_in_parent_ < static_cast<int>(parent_->children_.size() - 1)) { |
| 131 return parent_->children_[index_in_parent_ + 1]; | 132 return parent_->children_[index_in_parent_ + 1]; |
| 132 } | 133 } |
| 133 | 134 |
| 134 return NULL; | 135 return NULL; |
| 135 } | 136 } |
| 136 | 137 |
| 137 gfx::Rect BrowserAccessibility::GetLocalBoundsRect() { | 138 gfx::Rect BrowserAccessibility::GetLocalBoundsRect() const { |
| 138 gfx::Rect bounds = location_; | 139 gfx::Rect bounds = location_; |
| 139 | 140 |
| 140 // Walk up the parent chain. Every time we encounter a Web Area, offset | 141 // Walk up the parent chain. Every time we encounter a Web Area, offset |
| 141 // based on the scroll bars and then offset based on the origin of that | 142 // based on the scroll bars and then offset based on the origin of that |
| 142 // nested web area. | 143 // nested web area. |
| 143 BrowserAccessibility* parent = parent_; | 144 BrowserAccessibility* parent = parent_; |
| 144 bool need_to_offset_web_area = | 145 bool need_to_offset_web_area = |
| 145 (role_ == AccessibilityNodeData::ROLE_WEB_AREA || | 146 (role_ == AccessibilityNodeData::ROLE_WEB_AREA || |
| 146 role_ == AccessibilityNodeData::ROLE_ROOT_WEB_AREA); | 147 role_ == AccessibilityNodeData::ROLE_ROOT_WEB_AREA); |
| 147 while (parent) { | 148 while (parent) { |
| 148 if (need_to_offset_web_area && | 149 if (need_to_offset_web_area && |
| 149 parent->location().width() > 0 && | 150 parent->location().width() > 0 && |
| 150 parent->location().height() > 0) { | 151 parent->location().height() > 0) { |
| 151 bounds.Offset(parent->location().x(), parent->location().y()); | 152 bounds.Offset(parent->location().x(), parent->location().y()); |
| 152 need_to_offset_web_area = false; | 153 need_to_offset_web_area = false; |
| 153 } | 154 } |
| 155 |
| 156 // On some platforms, we don't want to take the root scroll offsets |
| 157 // into account. |
| 158 if (parent->role() == AccessibilityNodeData::ROLE_ROOT_WEB_AREA && |
| 159 !manager()->UseRootScrollOffsetsWhenComputingBounds()) { |
| 160 break; |
| 161 } |
| 162 |
| 154 if (parent->role() == AccessibilityNodeData::ROLE_WEB_AREA || | 163 if (parent->role() == AccessibilityNodeData::ROLE_WEB_AREA || |
| 155 parent->role() == AccessibilityNodeData::ROLE_ROOT_WEB_AREA) { | 164 parent->role() == AccessibilityNodeData::ROLE_ROOT_WEB_AREA) { |
| 156 int sx = 0; | 165 int sx = 0; |
| 157 int sy = 0; | 166 int sy = 0; |
| 158 if (parent->GetIntAttribute(AccessibilityNodeData::ATTR_SCROLL_X, &sx) && | 167 if (parent->GetIntAttribute(AccessibilityNodeData::ATTR_SCROLL_X, &sx) && |
| 159 parent->GetIntAttribute(AccessibilityNodeData::ATTR_SCROLL_Y, &sy)) { | 168 parent->GetIntAttribute(AccessibilityNodeData::ATTR_SCROLL_Y, &sy)) { |
| 160 bounds.Offset(-sx, -sy); | 169 bounds.Offset(-sx, -sy); |
| 161 } | 170 } |
| 162 need_to_offset_web_area = true; | 171 need_to_offset_web_area = true; |
| 163 } | 172 } |
| 164 parent = parent->parent(); | 173 parent = parent->parent(); |
| 165 } | 174 } |
| 166 | 175 |
| 167 return bounds; | 176 return bounds; |
| 168 } | 177 } |
| 169 | 178 |
| 170 gfx::Rect BrowserAccessibility::GetGlobalBoundsRect() { | 179 gfx::Rect BrowserAccessibility::GetGlobalBoundsRect() const { |
| 171 gfx::Rect bounds = GetLocalBoundsRect(); | 180 gfx::Rect bounds = GetLocalBoundsRect(); |
| 172 | 181 |
| 173 // Adjust the bounds by the top left corner of the containing view's bounds | 182 // Adjust the bounds by the top left corner of the containing view's bounds |
| 174 // in screen coordinates. | 183 // in screen coordinates. |
| 175 bounds.Offset(manager_->GetViewBounds().OffsetFromOrigin()); | 184 bounds.Offset(manager_->GetViewBounds().OffsetFromOrigin()); |
| 176 | 185 |
| 177 return bounds; | 186 return bounds; |
| 178 } | 187 } |
| 179 | 188 |
| 180 BrowserAccessibility* BrowserAccessibility::BrowserAccessibilityForPoint( | 189 BrowserAccessibility* BrowserAccessibility::BrowserAccessibilityForPoint( |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 | 305 |
| 297 return false; // Not set | 306 return false; // Not set |
| 298 } | 307 } |
| 299 | 308 |
| 300 bool BrowserAccessibility::HasState( | 309 bool BrowserAccessibility::HasState( |
| 301 AccessibilityNodeData::State state_enum) const { | 310 AccessibilityNodeData::State state_enum) const { |
| 302 return (state_ >> state_enum) & 1; | 311 return (state_ >> state_enum) & 1; |
| 303 } | 312 } |
| 304 | 313 |
| 305 bool BrowserAccessibility::IsEditableText() const { | 314 bool BrowserAccessibility::IsEditableText() const { |
| 315 // These roles don't have readonly set, but they're not editable text. |
| 316 if (role_ == AccessibilityNodeData::ROLE_SCROLLAREA || |
| 317 role_ == AccessibilityNodeData::ROLE_COLUMN || |
| 318 role_ == AccessibilityNodeData::ROLE_TABLE_HEADER_CONTAINER) { |
| 319 return false; |
| 320 } |
| 321 |
| 306 // Note: STATE_READONLY being false means it's either a text control, | 322 // Note: STATE_READONLY being false means it's either a text control, |
| 307 // or contenteditable. We also check for editable text roles to cover | 323 // or contenteditable. We also check for editable text roles to cover |
| 308 // another element that has role=textbox set on it. | 324 // another element that has role=textbox set on it. |
| 309 return (!HasState(AccessibilityNodeData::STATE_READONLY) || | 325 return (!HasState(AccessibilityNodeData::STATE_READONLY) || |
| 310 role_ == AccessibilityNodeData::ROLE_TEXT_FIELD || | 326 role_ == AccessibilityNodeData::ROLE_TEXT_FIELD || |
| 311 role_ == AccessibilityNodeData::ROLE_TEXTAREA); | 327 role_ == AccessibilityNodeData::ROLE_TEXTAREA); |
| 312 } | 328 } |
| 313 | 329 |
| 314 string16 BrowserAccessibility::GetTextRecursive() const { | 330 string16 BrowserAccessibility::GetTextRecursive() const { |
| 315 if (!name_.empty()) { | 331 if (!name_.empty()) { |
| 316 return name_; | 332 return name_; |
| 317 } | 333 } |
| 318 | 334 |
| 319 string16 result; | 335 string16 result; |
| 320 for (size_t i = 0; i < children_.size(); ++i) | 336 for (size_t i = 0; i < children_.size(); ++i) |
| 321 result += children_[i]->GetTextRecursive(); | 337 result += children_[i]->GetTextRecursive(); |
| 322 return result; | 338 return result; |
| 323 } | 339 } |
| 324 | 340 |
| 325 } // namespace content | 341 } // namespace content |
| OLD | NEW |