| 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 typedef AccessibilityNodeData::BoolAttribute BoolAttribute; | |
| 17 typedef AccessibilityNodeData::FloatAttribute FloatAttribute; | |
| 18 typedef AccessibilityNodeData::IntAttribute IntAttribute; | |
| 19 typedef AccessibilityNodeData::StringAttribute StringAttribute; | |
| 20 | |
| 21 #if !defined(OS_MACOSX) && \ | 16 #if !defined(OS_MACOSX) && \ |
| 22 !defined(OS_WIN) && \ | 17 !defined(OS_WIN) && \ |
| 23 !defined(TOOLKIT_GTK) && \ | 18 !defined(TOOLKIT_GTK) && \ |
| 24 !defined(OS_ANDROID) | 19 !defined(OS_ANDROID) |
| 25 // We have subclassess of BrowserAccessibility on Mac, Linux/GTK, | 20 // We have subclassess of BrowserAccessibility on Mac, Linux/GTK, |
| 26 // and Win. For any other platform, instantiate the base class. | 21 // and Win. For any other platform, instantiate the base class. |
| 27 // static | 22 // static |
| 28 BrowserAccessibility* BrowserAccessibility::Create() { | 23 BrowserAccessibility* BrowserAccessibility::Create() { |
| 29 return new BrowserAccessibility(); | 24 return new BrowserAccessibility(); |
| 30 } | 25 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 44 } | 39 } |
| 45 | 40 |
| 46 bool BrowserAccessibility::PlatformIsLeaf() const { | 41 bool BrowserAccessibility::PlatformIsLeaf() const { |
| 47 if (child_count() == 0) | 42 if (child_count() == 0) |
| 48 return true; | 43 return true; |
| 49 | 44 |
| 50 // All of these roles may have children that we use as internal | 45 // All of these roles may have children that we use as internal |
| 51 // implementation details, but we want to expose them as leaves | 46 // implementation details, but we want to expose them as leaves |
| 52 // to platform accessibility APIs. | 47 // to platform accessibility APIs. |
| 53 switch (role_) { | 48 switch (role_) { |
| 54 case blink::WebAXRoleEditableText: | 49 case ui::AX_ROLE_EDITABLE_TEXT: |
| 55 case blink::WebAXRoleSlider: | 50 case ui::AX_ROLE_SLIDER: |
| 56 case blink::WebAXRoleStaticText: | 51 case ui::AX_ROLE_STATIC_TEXT: |
| 57 case blink::WebAXRoleTextArea: | 52 case ui::AX_ROLE_TEXT_AREA: |
| 58 case blink::WebAXRoleTextField: | 53 case ui::AX_ROLE_TEXT_FIELD: |
| 59 return true; | 54 return true; |
| 60 default: | 55 default: |
| 61 return false; | 56 return false; |
| 62 } | 57 } |
| 63 } | 58 } |
| 64 | 59 |
| 65 uint32 BrowserAccessibility::PlatformChildCount() const { | 60 uint32 BrowserAccessibility::PlatformChildCount() const { |
| 66 return PlatformIsLeaf() ? 0 : children_.size(); | 61 return PlatformIsLeaf() ? 0 : children_.size(); |
| 67 } | 62 } |
| 68 | 63 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 79 BrowserAccessibilityManager* manager, | 74 BrowserAccessibilityManager* manager, |
| 80 BrowserAccessibility* parent, | 75 BrowserAccessibility* parent, |
| 81 int32 renderer_id, | 76 int32 renderer_id, |
| 82 int32 index_in_parent) { | 77 int32 index_in_parent) { |
| 83 manager_ = manager; | 78 manager_ = manager; |
| 84 parent_ = parent; | 79 parent_ = parent; |
| 85 renderer_id_ = renderer_id; | 80 renderer_id_ = renderer_id; |
| 86 index_in_parent_ = index_in_parent; | 81 index_in_parent_ = index_in_parent; |
| 87 } | 82 } |
| 88 | 83 |
| 89 void BrowserAccessibility::InitializeData(const AccessibilityNodeData& src) { | 84 void BrowserAccessibility::InitializeData(const ui::AXNodeData& src) { |
| 90 DCHECK_EQ(renderer_id_, src.id); | 85 DCHECK_EQ(renderer_id_, src.id); |
| 91 role_ = src.role; | 86 role_ = src.role; |
| 92 state_ = src.state; | 87 state_ = src.state; |
| 93 string_attributes_ = src.string_attributes; | 88 string_attributes_ = src.string_attributes; |
| 94 int_attributes_ = src.int_attributes; | 89 int_attributes_ = src.int_attributes; |
| 95 float_attributes_ = src.float_attributes; | 90 float_attributes_ = src.float_attributes; |
| 96 bool_attributes_ = src.bool_attributes; | 91 bool_attributes_ = src.bool_attributes; |
| 97 intlist_attributes_ = src.intlist_attributes; | 92 intlist_attributes_ = src.intlist_attributes; |
| 98 html_attributes_ = src.html_attributes; | 93 html_attributes_ = src.html_attributes; |
| 99 location_ = src.location; | 94 location_ = src.location; |
| 100 instance_active_ = true; | 95 instance_active_ = true; |
| 101 | 96 |
| 102 GetStringAttribute(AccessibilityNodeData::ATTR_NAME, &name_); | 97 GetStringAttribute(ui::AX_ATTR_NAME, &name_); |
| 103 GetStringAttribute(AccessibilityNodeData::ATTR_VALUE, &value_); | 98 GetStringAttribute(ui::AX_ATTR_VALUE, &value_); |
| 104 | 99 |
| 105 PreInitialize(); | 100 PreInitialize(); |
| 106 } | 101 } |
| 107 | 102 |
| 108 bool BrowserAccessibility::IsNative() const { | 103 bool BrowserAccessibility::IsNative() const { |
| 109 return false; | 104 return false; |
| 110 } | 105 } |
| 111 | 106 |
| 112 void BrowserAccessibility::SwapChildren( | 107 void BrowserAccessibility::SwapChildren( |
| 113 std::vector<BrowserAccessibility*>& children) { | 108 std::vector<BrowserAccessibility*>& children) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 } | 154 } |
| 160 | 155 |
| 161 gfx::Rect BrowserAccessibility::GetLocalBoundsRect() const { | 156 gfx::Rect BrowserAccessibility::GetLocalBoundsRect() const { |
| 162 gfx::Rect bounds = location_; | 157 gfx::Rect bounds = location_; |
| 163 | 158 |
| 164 // Walk up the parent chain. Every time we encounter a Web Area, offset | 159 // Walk up the parent chain. Every time we encounter a Web Area, offset |
| 165 // based on the scroll bars and then offset based on the origin of that | 160 // based on the scroll bars and then offset based on the origin of that |
| 166 // nested web area. | 161 // nested web area. |
| 167 BrowserAccessibility* parent = parent_; | 162 BrowserAccessibility* parent = parent_; |
| 168 bool need_to_offset_web_area = | 163 bool need_to_offset_web_area = |
| 169 (role_ == blink::WebAXRoleWebArea || | 164 (role_ == ui::AX_ROLE_WEB_AREA || |
| 170 role_ == blink::WebAXRoleRootWebArea); | 165 role_ == ui::AX_ROLE_ROOT_WEB_AREA); |
| 171 while (parent) { | 166 while (parent) { |
| 172 if (need_to_offset_web_area && | 167 if (need_to_offset_web_area && |
| 173 parent->location().width() > 0 && | 168 parent->location().width() > 0 && |
| 174 parent->location().height() > 0) { | 169 parent->location().height() > 0) { |
| 175 bounds.Offset(parent->location().x(), parent->location().y()); | 170 bounds.Offset(parent->location().x(), parent->location().y()); |
| 176 need_to_offset_web_area = false; | 171 need_to_offset_web_area = false; |
| 177 } | 172 } |
| 178 | 173 |
| 179 // On some platforms, we don't want to take the root scroll offsets | 174 // On some platforms, we don't want to take the root scroll offsets |
| 180 // into account. | 175 // into account. |
| 181 if (parent->role() == blink::WebAXRoleRootWebArea && | 176 if (parent->role() == ui::AX_ROLE_ROOT_WEB_AREA && |
| 182 !manager()->UseRootScrollOffsetsWhenComputingBounds()) { | 177 !manager()->UseRootScrollOffsetsWhenComputingBounds()) { |
| 183 break; | 178 break; |
| 184 } | 179 } |
| 185 | 180 |
| 186 if (parent->role() == blink::WebAXRoleWebArea || | 181 if (parent->role() == ui::AX_ROLE_WEB_AREA || |
| 187 parent->role() == blink::WebAXRoleRootWebArea) { | 182 parent->role() == ui::AX_ROLE_ROOT_WEB_AREA) { |
| 188 int sx = 0; | 183 int sx = 0; |
| 189 int sy = 0; | 184 int sy = 0; |
| 190 if (parent->GetIntAttribute(AccessibilityNodeData::ATTR_SCROLL_X, &sx) && | 185 if (parent->GetIntAttribute(ui::AX_ATTR_SCROLL_X, &sx) && |
| 191 parent->GetIntAttribute(AccessibilityNodeData::ATTR_SCROLL_Y, &sy)) { | 186 parent->GetIntAttribute(ui::AX_ATTR_SCROLL_Y, &sy)) { |
| 192 bounds.Offset(-sx, -sy); | 187 bounds.Offset(-sx, -sy); |
| 193 } | 188 } |
| 194 need_to_offset_web_area = true; | 189 need_to_offset_web_area = true; |
| 195 } | 190 } |
| 196 parent = parent->parent(); | 191 parent = parent->parent(); |
| 197 } | 192 } |
| 198 | 193 |
| 199 return bounds; | 194 return bounds; |
| 200 } | 195 } |
| 201 | 196 |
| 202 gfx::Rect BrowserAccessibility::GetGlobalBoundsRect() const { | 197 gfx::Rect BrowserAccessibility::GetGlobalBoundsRect() const { |
| 203 gfx::Rect bounds = GetLocalBoundsRect(); | 198 gfx::Rect bounds = GetLocalBoundsRect(); |
| 204 | 199 |
| 205 // Adjust the bounds by the top left corner of the containing view's bounds | 200 // Adjust the bounds by the top left corner of the containing view's bounds |
| 206 // in screen coordinates. | 201 // in screen coordinates. |
| 207 bounds.Offset(manager_->GetViewBounds().OffsetFromOrigin()); | 202 bounds.Offset(manager_->GetViewBounds().OffsetFromOrigin()); |
| 208 | 203 |
| 209 return bounds; | 204 return bounds; |
| 210 } | 205 } |
| 211 | 206 |
| 212 gfx::Rect BrowserAccessibility::GetLocalBoundsForRange(int start, int len) | 207 gfx::Rect BrowserAccessibility::GetLocalBoundsForRange(int start, int len) |
| 213 const { | 208 const { |
| 214 if (role_ != blink::WebAXRoleStaticText) { | 209 if (role() != ui::AX_ROLE_STATIC_TEXT) { |
| 215 // Apply recursively to all static text descendants. For example, if | 210 // Apply recursively to all static text descendants. For example, if |
| 216 // you call it on a div with two text node children, it just calls | 211 // you call it on a div with two text node children, it just calls |
| 217 // GetLocalBoundsForRange on each of the two children (adjusting | 212 // GetLocalBoundsForRange on each of the two children (adjusting |
| 218 // |start| for each one) and unions the resulting rects. | 213 // |start| for each one) and unions the resulting rects. |
| 219 gfx::Rect bounds; | 214 gfx::Rect bounds; |
| 220 for (size_t i = 0; i < children_.size(); ++i) { | 215 for (size_t i = 0; i < children_.size(); ++i) { |
| 221 BrowserAccessibility* child = children_[i]; | 216 BrowserAccessibility* child = children_[i]; |
| 222 int child_len = child->GetStaticTextLenRecursive(); | 217 int child_len = child->GetStaticTextLenRecursive(); |
| 223 if (start < child_len && start + len > 0) { | 218 if (start < child_len && start + len > 0) { |
| 224 gfx::Rect child_rect = child->GetLocalBoundsForRange(start, len); | 219 gfx::Rect child_rect = child->GetLocalBoundsForRange(start, len); |
| 225 bounds.Union(child_rect); | 220 bounds.Union(child_rect); |
| 226 } | 221 } |
| 227 start -= child_len; | 222 start -= child_len; |
| 228 } | 223 } |
| 229 return bounds; | 224 return bounds; |
| 230 } | 225 } |
| 231 | 226 |
| 232 int end = start + len; | 227 int end = start + len; |
| 233 int child_start = 0; | 228 int child_start = 0; |
| 234 int child_end = 0; | 229 int child_end = 0; |
| 235 | 230 |
| 236 gfx::Rect bounds; | 231 gfx::Rect bounds; |
| 237 for (size_t i = 0; i < children_.size() && child_end < start + len; ++i) { | 232 for (size_t i = 0; i < children_.size() && child_end < start + len; ++i) { |
| 238 BrowserAccessibility* child = children_[i]; | 233 BrowserAccessibility* child = children_[i]; |
| 239 DCHECK_EQ(child->role(), blink::WebAXRoleInlineTextBox); | 234 DCHECK_EQ(child->role(), ui::AX_ROLE_INLINE_TEXT_BOX); |
| 240 std::string child_text; | 235 std::string child_text; |
| 241 child->GetStringAttribute(AccessibilityNodeData::ATTR_VALUE, &child_text); | 236 child->GetStringAttribute(ui::AX_ATTR_VALUE, &child_text); |
| 242 int child_len = static_cast<int>(child_text.size()); | 237 int child_len = static_cast<int>(child_text.size()); |
| 243 child_start = child_end; | 238 child_start = child_end; |
| 244 child_end += child_len; | 239 child_end += child_len; |
| 245 | 240 |
| 246 if (child_end < start) | 241 if (child_end < start) |
| 247 continue; | 242 continue; |
| 248 | 243 |
| 249 int overlap_start = std::max(start, child_start); | 244 int overlap_start = std::max(start, child_start); |
| 250 int overlap_end = std::min(end, child_end); | 245 int overlap_end = std::min(end, child_end); |
| 251 | 246 |
| 252 int local_start = overlap_start - child_start; | 247 int local_start = overlap_start - child_start; |
| 253 int local_end = overlap_end - child_start; | 248 int local_end = overlap_end - child_start; |
| 254 | 249 |
| 255 gfx::Rect child_rect = child->location(); | 250 gfx::Rect child_rect = child->location(); |
| 256 int text_direction = child->GetIntAttribute( | 251 int text_direction = child->GetIntAttribute( |
| 257 AccessibilityNodeData::ATTR_TEXT_DIRECTION); | 252 ui::AX_ATTR_TEXT_DIRECTION); |
| 258 const std::vector<int32>& character_offsets = child->GetIntListAttribute( | 253 const std::vector<int32>& character_offsets = child->GetIntListAttribute( |
| 259 AccessibilityNodeData::ATTR_CHARACTER_OFFSETS); | 254 ui::AX_ATTR_CHARACTER_OFFSETS); |
| 260 int start_pixel_offset = | 255 int start_pixel_offset = |
| 261 local_start > 0 ? character_offsets[local_start - 1] : 0; | 256 local_start > 0 ? character_offsets[local_start - 1] : 0; |
| 262 int end_pixel_offset = | 257 int end_pixel_offset = |
| 263 local_end > 0 ? character_offsets[local_end - 1] : 0; | 258 local_end > 0 ? character_offsets[local_end - 1] : 0; |
| 264 | 259 |
| 265 gfx::Rect child_overlap_rect; | 260 gfx::Rect child_overlap_rect; |
| 266 switch (text_direction) { | 261 switch (text_direction) { |
| 267 case blink::WebAXTextDirectionLR: { | 262 case ui::AX_TEXT_DIRECTION_LR: { |
| 268 int left = child_rect.x() + start_pixel_offset; | 263 int left = child_rect.x() + start_pixel_offset; |
| 269 int right = child_rect.x() + end_pixel_offset; | 264 int right = child_rect.x() + end_pixel_offset; |
| 270 child_overlap_rect = gfx::Rect(left, child_rect.y(), | 265 child_overlap_rect = gfx::Rect(left, child_rect.y(), |
| 271 right - left, child_rect.height()); | 266 right - left, child_rect.height()); |
| 272 break; | 267 break; |
| 273 } | 268 } |
| 274 case blink::WebAXTextDirectionRL: { | 269 case ui::AX_TEXT_DIRECTION_RL: { |
| 275 int right = child_rect.right() - start_pixel_offset; | 270 int right = child_rect.right() - start_pixel_offset; |
| 276 int left = child_rect.right() - end_pixel_offset; | 271 int left = child_rect.right() - end_pixel_offset; |
| 277 child_overlap_rect = gfx::Rect(left, child_rect.y(), | 272 child_overlap_rect = gfx::Rect(left, child_rect.y(), |
| 278 right - left, child_rect.height()); | 273 right - left, child_rect.height()); |
| 279 break; | 274 break; |
| 280 } | 275 } |
| 281 case blink::WebAXTextDirectionTB: { | 276 case ui::AX_TEXT_DIRECTION_TB: { |
| 282 int top = child_rect.y() + start_pixel_offset; | 277 int top = child_rect.y() + start_pixel_offset; |
| 283 int bottom = child_rect.y() + end_pixel_offset; | 278 int bottom = child_rect.y() + end_pixel_offset; |
| 284 child_overlap_rect = gfx::Rect(child_rect.x(), top, | 279 child_overlap_rect = gfx::Rect(child_rect.x(), top, |
| 285 child_rect.width(), bottom - top); | 280 child_rect.width(), bottom - top); |
| 286 break; | 281 break; |
| 287 } | 282 } |
| 288 case blink::WebAXTextDirectionBT: { | 283 case ui::AX_TEXT_DIRECTION_BT: { |
| 289 int bottom = child_rect.bottom() - start_pixel_offset; | 284 int bottom = child_rect.bottom() - start_pixel_offset; |
| 290 int top = child_rect.bottom() - end_pixel_offset; | 285 int top = child_rect.bottom() - end_pixel_offset; |
| 291 child_overlap_rect = gfx::Rect(child_rect.x(), top, | 286 child_overlap_rect = gfx::Rect(child_rect.x(), top, |
| 292 child_rect.width(), bottom - top); | 287 child_rect.width(), bottom - top); |
| 293 break; | 288 break; |
| 294 } | 289 } |
| 295 default: | 290 default: |
| 296 NOTREACHED(); | 291 NOTREACHED(); |
| 297 } | 292 } |
| 298 | 293 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 ++iter) { | 329 ++iter) { |
| 335 (*iter)->Destroy(); | 330 (*iter)->Destroy(); |
| 336 } | 331 } |
| 337 children_.clear(); | 332 children_.clear(); |
| 338 | 333 |
| 339 // Allow the object to fire a TextRemoved notification. | 334 // Allow the object to fire a TextRemoved notification. |
| 340 name_.clear(); | 335 name_.clear(); |
| 341 value_.clear(); | 336 value_.clear(); |
| 342 PostInitialize(); | 337 PostInitialize(); |
| 343 | 338 |
| 344 manager_->NotifyAccessibilityEvent( | 339 manager_->NotifyAccessibilityEvent(ui::AX_EVENT_HIDE, this); |
| 345 blink::WebAXEventHide, this); | |
| 346 | 340 |
| 347 instance_active_ = false; | 341 instance_active_ = false; |
| 348 manager_->RemoveNode(this); | 342 manager_->RemoveNode(this); |
| 349 NativeReleaseReference(); | 343 NativeReleaseReference(); |
| 350 } | 344 } |
| 351 | 345 |
| 352 void BrowserAccessibility::NativeReleaseReference() { | 346 void BrowserAccessibility::NativeReleaseReference() { |
| 353 delete this; | 347 delete this; |
| 354 } | 348 } |
| 355 | 349 |
| 356 bool BrowserAccessibility::HasBoolAttribute(BoolAttribute attribute) const { | 350 bool BrowserAccessibility::HasBoolAttribute( |
| 351 ui::AXBoolAttribute attribute) const { |
| 357 for (size_t i = 0; i < bool_attributes_.size(); ++i) { | 352 for (size_t i = 0; i < bool_attributes_.size(); ++i) { |
| 358 if (bool_attributes_[i].first == attribute) | 353 if (bool_attributes_[i].first == attribute) |
| 359 return true; | 354 return true; |
| 360 } | 355 } |
| 361 | 356 |
| 362 return false; | 357 return false; |
| 363 } | 358 } |
| 364 | 359 |
| 365 | 360 |
| 366 bool BrowserAccessibility::GetBoolAttribute(BoolAttribute attribute) const { | 361 bool BrowserAccessibility::GetBoolAttribute( |
| 362 ui::AXBoolAttribute attribute) const { |
| 367 for (size_t i = 0; i < bool_attributes_.size(); ++i) { | 363 for (size_t i = 0; i < bool_attributes_.size(); ++i) { |
| 368 if (bool_attributes_[i].first == attribute) | 364 if (bool_attributes_[i].first == attribute) |
| 369 return bool_attributes_[i].second; | 365 return bool_attributes_[i].second; |
| 370 } | 366 } |
| 371 | 367 |
| 372 return false; | 368 return false; |
| 373 } | 369 } |
| 374 | 370 |
| 375 bool BrowserAccessibility::GetBoolAttribute( | 371 bool BrowserAccessibility::GetBoolAttribute( |
| 376 BoolAttribute attribute, bool* value) const { | 372 ui::AXBoolAttribute attribute, bool* value) const { |
| 377 for (size_t i = 0; i < bool_attributes_.size(); ++i) { | 373 for (size_t i = 0; i < bool_attributes_.size(); ++i) { |
| 378 if (bool_attributes_[i].first == attribute) { | 374 if (bool_attributes_[i].first == attribute) { |
| 379 *value = bool_attributes_[i].second; | 375 *value = bool_attributes_[i].second; |
| 380 return true; | 376 return true; |
| 381 } | 377 } |
| 382 } | 378 } |
| 383 | 379 |
| 384 return false; | 380 return false; |
| 385 } | 381 } |
| 386 | 382 |
| 387 bool BrowserAccessibility::HasFloatAttribute(FloatAttribute attribute) const { | 383 bool BrowserAccessibility::HasFloatAttribute( |
| 384 ui::AXFloatAttribute attribute) const { |
| 388 for (size_t i = 0; i < float_attributes_.size(); ++i) { | 385 for (size_t i = 0; i < float_attributes_.size(); ++i) { |
| 389 if (float_attributes_[i].first == attribute) | 386 if (float_attributes_[i].first == attribute) |
| 390 return true; | 387 return true; |
| 391 } | 388 } |
| 392 | 389 |
| 393 return false; | 390 return false; |
| 394 } | 391 } |
| 395 | 392 |
| 396 float BrowserAccessibility::GetFloatAttribute(FloatAttribute attribute) const { | 393 float BrowserAccessibility::GetFloatAttribute( |
| 394 ui::AXFloatAttribute attribute) const { |
| 397 for (size_t i = 0; i < float_attributes_.size(); ++i) { | 395 for (size_t i = 0; i < float_attributes_.size(); ++i) { |
| 398 if (float_attributes_[i].first == attribute) | 396 if (float_attributes_[i].first == attribute) |
| 399 return float_attributes_[i].second; | 397 return float_attributes_[i].second; |
| 400 } | 398 } |
| 401 | 399 |
| 402 return 0.0; | 400 return 0.0; |
| 403 } | 401 } |
| 404 | 402 |
| 405 bool BrowserAccessibility::GetFloatAttribute( | 403 bool BrowserAccessibility::GetFloatAttribute( |
| 406 FloatAttribute attribute, float* value) const { | 404 ui::AXFloatAttribute attribute, float* value) const { |
| 407 for (size_t i = 0; i < float_attributes_.size(); ++i) { | 405 for (size_t i = 0; i < float_attributes_.size(); ++i) { |
| 408 if (float_attributes_[i].first == attribute) { | 406 if (float_attributes_[i].first == attribute) { |
| 409 *value = float_attributes_[i].second; | 407 *value = float_attributes_[i].second; |
| 410 return true; | 408 return true; |
| 411 } | 409 } |
| 412 } | 410 } |
| 413 | 411 |
| 414 return false; | 412 return false; |
| 415 } | 413 } |
| 416 | 414 |
| 417 bool BrowserAccessibility::HasIntAttribute(IntAttribute attribute) const { | 415 bool BrowserAccessibility::HasIntAttribute( |
| 416 ui::AXIntAttribute attribute) const { |
| 418 for (size_t i = 0; i < int_attributes_.size(); ++i) { | 417 for (size_t i = 0; i < int_attributes_.size(); ++i) { |
| 419 if (int_attributes_[i].first == attribute) | 418 if (int_attributes_[i].first == attribute) |
| 420 return true; | 419 return true; |
| 421 } | 420 } |
| 422 | 421 |
| 423 return false; | 422 return false; |
| 424 } | 423 } |
| 425 | 424 |
| 426 int BrowserAccessibility::GetIntAttribute(IntAttribute attribute) const { | 425 int BrowserAccessibility::GetIntAttribute(ui::AXIntAttribute attribute) const { |
| 427 for (size_t i = 0; i < int_attributes_.size(); ++i) { | 426 for (size_t i = 0; i < int_attributes_.size(); ++i) { |
| 428 if (int_attributes_[i].first == attribute) | 427 if (int_attributes_[i].first == attribute) |
| 429 return int_attributes_[i].second; | 428 return int_attributes_[i].second; |
| 430 } | 429 } |
| 431 | 430 |
| 432 return 0; | 431 return 0; |
| 433 } | 432 } |
| 434 | 433 |
| 435 bool BrowserAccessibility::GetIntAttribute( | 434 bool BrowserAccessibility::GetIntAttribute( |
| 436 IntAttribute attribute, int* value) const { | 435 ui::AXIntAttribute attribute, int* value) const { |
| 437 for (size_t i = 0; i < int_attributes_.size(); ++i) { | 436 for (size_t i = 0; i < int_attributes_.size(); ++i) { |
| 438 if (int_attributes_[i].first == attribute) { | 437 if (int_attributes_[i].first == attribute) { |
| 439 *value = int_attributes_[i].second; | 438 *value = int_attributes_[i].second; |
| 440 return true; | 439 return true; |
| 441 } | 440 } |
| 442 } | 441 } |
| 443 | 442 |
| 444 return false; | 443 return false; |
| 445 } | 444 } |
| 446 | 445 |
| 447 bool BrowserAccessibility::HasStringAttribute(StringAttribute attribute) const { | 446 bool BrowserAccessibility::HasStringAttribute( |
| 447 ui::AXStringAttribute attribute) const { |
| 448 for (size_t i = 0; i < string_attributes_.size(); ++i) { | 448 for (size_t i = 0; i < string_attributes_.size(); ++i) { |
| 449 if (string_attributes_[i].first == attribute) | 449 if (string_attributes_[i].first == attribute) |
| 450 return true; | 450 return true; |
| 451 } | 451 } |
| 452 | 452 |
| 453 return false; | 453 return false; |
| 454 } | 454 } |
| 455 | 455 |
| 456 const std::string& BrowserAccessibility::GetStringAttribute( | 456 const std::string& BrowserAccessibility::GetStringAttribute( |
| 457 StringAttribute attribute) const { | 457 ui::AXStringAttribute attribute) const { |
| 458 CR_DEFINE_STATIC_LOCAL(std::string, empty_string, ()); | 458 CR_DEFINE_STATIC_LOCAL(std::string, empty_string, ()); |
| 459 for (size_t i = 0; i < string_attributes_.size(); ++i) { | 459 for (size_t i = 0; i < string_attributes_.size(); ++i) { |
| 460 if (string_attributes_[i].first == attribute) | 460 if (string_attributes_[i].first == attribute) |
| 461 return string_attributes_[i].second; | 461 return string_attributes_[i].second; |
| 462 } | 462 } |
| 463 | 463 |
| 464 return empty_string; | 464 return empty_string; |
| 465 } | 465 } |
| 466 | 466 |
| 467 bool BrowserAccessibility::GetStringAttribute( | 467 bool BrowserAccessibility::GetStringAttribute( |
| 468 StringAttribute attribute, std::string* value) const { | 468 ui::AXStringAttribute attribute, std::string* value) const { |
| 469 for (size_t i = 0; i < string_attributes_.size(); ++i) { | 469 for (size_t i = 0; i < string_attributes_.size(); ++i) { |
| 470 if (string_attributes_[i].first == attribute) { | 470 if (string_attributes_[i].first == attribute) { |
| 471 *value = string_attributes_[i].second; | 471 *value = string_attributes_[i].second; |
| 472 return true; | 472 return true; |
| 473 } | 473 } |
| 474 } | 474 } |
| 475 | 475 |
| 476 return false; | 476 return false; |
| 477 } | 477 } |
| 478 | 478 |
| 479 base::string16 BrowserAccessibility::GetString16Attribute( | 479 base::string16 BrowserAccessibility::GetString16Attribute( |
| 480 StringAttribute attribute) const { | 480 ui::AXStringAttribute attribute) const { |
| 481 std::string value_utf8; | 481 std::string value_utf8; |
| 482 if (!GetStringAttribute(attribute, &value_utf8)) | 482 if (!GetStringAttribute(attribute, &value_utf8)) |
| 483 return base::string16(); | 483 return base::string16(); |
| 484 return base::UTF8ToUTF16(value_utf8); | 484 return base::UTF8ToUTF16(value_utf8); |
| 485 } | 485 } |
| 486 | 486 |
| 487 bool BrowserAccessibility::GetString16Attribute( | 487 bool BrowserAccessibility::GetString16Attribute( |
| 488 StringAttribute attribute, | 488 ui::AXStringAttribute attribute, |
| 489 base::string16* value) const { | 489 base::string16* value) const { |
| 490 std::string value_utf8; | 490 std::string value_utf8; |
| 491 if (!GetStringAttribute(attribute, &value_utf8)) | 491 if (!GetStringAttribute(attribute, &value_utf8)) |
| 492 return false; | 492 return false; |
| 493 *value = base::UTF8ToUTF16(value_utf8); | 493 *value = base::UTF8ToUTF16(value_utf8); |
| 494 return true; | 494 return true; |
| 495 } | 495 } |
| 496 | 496 |
| 497 void BrowserAccessibility::SetStringAttribute( | 497 void BrowserAccessibility::SetStringAttribute( |
| 498 StringAttribute attribute, const std::string& value) { | 498 ui::AXStringAttribute attribute, const std::string& value) { |
| 499 for (size_t i = 0; i < string_attributes_.size(); ++i) { | 499 for (size_t i = 0; i < string_attributes_.size(); ++i) { |
| 500 if (string_attributes_[i].first == attribute) { | 500 if (string_attributes_[i].first == attribute) { |
| 501 string_attributes_[i].second = value; | 501 string_attributes_[i].second = value; |
| 502 return; | 502 return; |
| 503 } | 503 } |
| 504 } | 504 } |
| 505 if (!value.empty()) | 505 if (!value.empty()) |
| 506 string_attributes_.push_back(std::make_pair(attribute, value)); | 506 string_attributes_.push_back(std::make_pair(attribute, value)); |
| 507 } | 507 } |
| 508 | 508 |
| 509 bool BrowserAccessibility::HasIntListAttribute( | 509 bool BrowserAccessibility::HasIntListAttribute( |
| 510 AccessibilityNodeData::IntListAttribute attribute) const { | 510 ui::AXIntListAttribute attribute) const { |
| 511 for (size_t i = 0; i < intlist_attributes_.size(); ++i) { | 511 for (size_t i = 0; i < intlist_attributes_.size(); ++i) { |
| 512 if (intlist_attributes_[i].first == attribute) | 512 if (intlist_attributes_[i].first == attribute) |
| 513 return true; | 513 return true; |
| 514 } | 514 } |
| 515 | 515 |
| 516 return false; | 516 return false; |
| 517 } | 517 } |
| 518 | 518 |
| 519 const std::vector<int32>& BrowserAccessibility::GetIntListAttribute( | 519 const std::vector<int32>& BrowserAccessibility::GetIntListAttribute( |
| 520 AccessibilityNodeData::IntListAttribute attribute) const { | 520 ui::AXIntListAttribute attribute) const { |
| 521 CR_DEFINE_STATIC_LOCAL(std::vector<int32>, empty_vector, ()); | 521 CR_DEFINE_STATIC_LOCAL(std::vector<int32>, empty_vector, ()); |
| 522 for (size_t i = 0; i < intlist_attributes_.size(); ++i) { | 522 for (size_t i = 0; i < intlist_attributes_.size(); ++i) { |
| 523 if (intlist_attributes_[i].first == attribute) | 523 if (intlist_attributes_[i].first == attribute) |
| 524 return intlist_attributes_[i].second; | 524 return intlist_attributes_[i].second; |
| 525 } | 525 } |
| 526 | 526 |
| 527 return empty_vector; | 527 return empty_vector; |
| 528 } | 528 } |
| 529 | 529 |
| 530 bool BrowserAccessibility::GetIntListAttribute( | 530 bool BrowserAccessibility::GetIntListAttribute( |
| 531 AccessibilityNodeData::IntListAttribute attribute, | 531 ui::AXIntListAttribute attribute, |
| 532 std::vector<int32>* value) const { | 532 std::vector<int32>* value) const { |
| 533 for (size_t i = 0; i < intlist_attributes_.size(); ++i) { | 533 for (size_t i = 0; i < intlist_attributes_.size(); ++i) { |
| 534 if (intlist_attributes_[i].first == attribute) { | 534 if (intlist_attributes_[i].first == attribute) { |
| 535 *value = intlist_attributes_[i].second; | 535 *value = intlist_attributes_[i].second; |
| 536 return true; | 536 return true; |
| 537 } | 537 } |
| 538 } | 538 } |
| 539 | 539 |
| 540 return false; | 540 return false; |
| 541 } | 541 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 580 | 580 |
| 581 if (EqualsASCII(value, "true")) | 581 if (EqualsASCII(value, "true")) |
| 582 return true; | 582 return true; |
| 583 | 583 |
| 584 if (EqualsASCII(value, "mixed")) | 584 if (EqualsASCII(value, "mixed")) |
| 585 *is_mixed = true; | 585 *is_mixed = true; |
| 586 | 586 |
| 587 return false; // Not set | 587 return false; // Not set |
| 588 } | 588 } |
| 589 | 589 |
| 590 bool BrowserAccessibility::HasState(blink::WebAXState state_enum) const { | 590 bool BrowserAccessibility::HasState(ui::AXState state_enum) const { |
| 591 return (state_ >> state_enum) & 1; | 591 return (state_ >> state_enum) & 1; |
| 592 } | 592 } |
| 593 | 593 |
| 594 bool BrowserAccessibility::IsEditableText() const { | 594 bool BrowserAccessibility::IsEditableText() const { |
| 595 // These roles don't have readonly set, but they're not editable text. | 595 // These roles don't have readonly set, but they're not editable text. |
| 596 if (role_ == blink::WebAXRoleScrollArea || | 596 if (role_ == ui::AX_ROLE_SCROLL_AREA || |
| 597 role_ == blink::WebAXRoleColumn || | 597 role_ == ui::AX_ROLE_COLUMN || |
| 598 role_ == blink::WebAXRoleTableHeaderContainer) { | 598 role_ == ui::AX_ROLE_TABLE_HEADER_CONTAINER) { |
| 599 return false; | 599 return false; |
| 600 } | 600 } |
| 601 | 601 |
| 602 // Note: WebAXStateReadonly being false means it's either a text control, | 602 // Note: WebAXStateReadonly being false means it's either a text control, |
| 603 // or contenteditable. We also check for editable text roles to cover | 603 // or contenteditable. We also check for editable text roles to cover |
| 604 // another element that has role=textbox set on it. | 604 // another element that has role=textbox set on it. |
| 605 return (!HasState(blink::WebAXStateReadonly) || | 605 return (!HasState(ui::AX_STATE_READONLY) || |
| 606 role_ == blink::WebAXRoleTextField || | 606 role_ == ui::AX_ROLE_TEXT_FIELD || |
| 607 role_ == blink::WebAXRoleTextArea); | 607 role_ == ui::AX_ROLE_TEXT_AREA); |
| 608 } | 608 } |
| 609 | 609 |
| 610 std::string BrowserAccessibility::GetTextRecursive() const { | 610 std::string BrowserAccessibility::GetTextRecursive() const { |
| 611 if (!name_.empty()) { | 611 if (!name_.empty()) { |
| 612 return name_; | 612 return name_; |
| 613 } | 613 } |
| 614 | 614 |
| 615 std::string result; | 615 std::string result; |
| 616 for (uint32 i = 0; i < PlatformChildCount(); ++i) | 616 for (uint32 i = 0; i < PlatformChildCount(); ++i) |
| 617 result += PlatformGetChild(i)->GetTextRecursive(); | 617 result += PlatformGetChild(i)->GetTextRecursive(); |
| 618 return result; | 618 return result; |
| 619 } | 619 } |
| 620 | 620 |
| 621 int BrowserAccessibility::GetStaticTextLenRecursive() const { | 621 int BrowserAccessibility::GetStaticTextLenRecursive() const { |
| 622 if (role_ == blink::WebAXRoleStaticText) { | 622 if (role_ == blink::WebAXRoleStaticText) |
| 623 return static_cast<int>( | 623 return static_cast<int>(GetStringAttribute(ui::AX_ATTR_VALUE).size()); |
| 624 GetStringAttribute(AccessibilityNodeData::ATTR_VALUE).size()); | |
| 625 } | |
| 626 | 624 |
| 627 int len = 0; | 625 int len = 0; |
| 628 for (size_t i = 0; i < children_.size(); ++i) | 626 for (size_t i = 0; i < children_.size(); ++i) |
| 629 len += children_[i]->GetStaticTextLenRecursive(); | 627 len += children_[i]->GetStaticTextLenRecursive(); |
| 630 return len; | 628 return len; |
| 631 } | 629 } |
| 632 | 630 |
| 633 } // namespace content | 631 } // namespace content |
| OLD | NEW |