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" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 return role_ == WebKit::WebAXRoleStaticText || child_count() == 0; | 47 return role_ == WebKit::WebAXRoleStaticText || child_count() == 0; |
48 } | 48 } |
49 | 49 |
50 uint32 BrowserAccessibility::PlatformChildCount() const { | 50 uint32 BrowserAccessibility::PlatformChildCount() const { |
51 return PlatformIsLeaf() ? 0 : children_.size(); | 51 return PlatformIsLeaf() ? 0 : children_.size(); |
52 } | 52 } |
53 | 53 |
54 void BrowserAccessibility::DetachTree( | 54 void BrowserAccessibility::DetachTree( |
55 std::vector<BrowserAccessibility*>* nodes) { | 55 std::vector<BrowserAccessibility*>* nodes) { |
56 nodes->push_back(this); | 56 nodes->push_back(this); |
57 for (size_t i = 0; i < children_.size(); i++) | 57 for (size_t i = 0; i < children_.size(); ++i) |
58 children_[i]->DetachTree(nodes); | 58 children_[i]->DetachTree(nodes); |
59 children_.clear(); | 59 children_.clear(); |
60 parent_ = NULL; | 60 parent_ = NULL; |
61 } | 61 } |
62 | 62 |
63 void BrowserAccessibility::InitializeTreeStructure( | 63 void BrowserAccessibility::InitializeTreeStructure( |
64 BrowserAccessibilityManager* manager, | 64 BrowserAccessibilityManager* manager, |
65 BrowserAccessibility* parent, | 65 BrowserAccessibility* parent, |
66 int32 renderer_id, | 66 int32 renderer_id, |
67 int32 index_in_parent) { | 67 int32 index_in_parent) { |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 gfx::Rect BrowserAccessibility::GetGlobalBoundsRect() const { | 187 gfx::Rect BrowserAccessibility::GetGlobalBoundsRect() const { |
188 gfx::Rect bounds = GetLocalBoundsRect(); | 188 gfx::Rect bounds = GetLocalBoundsRect(); |
189 | 189 |
190 // Adjust the bounds by the top left corner of the containing view's bounds | 190 // Adjust the bounds by the top left corner of the containing view's bounds |
191 // in screen coordinates. | 191 // in screen coordinates. |
192 bounds.Offset(manager_->GetViewBounds().OffsetFromOrigin()); | 192 bounds.Offset(manager_->GetViewBounds().OffsetFromOrigin()); |
193 | 193 |
194 return bounds; | 194 return bounds; |
195 } | 195 } |
196 | 196 |
| 197 gfx::Rect BrowserAccessibility::GetLocalBoundsForRange(int start, int len) |
| 198 const { |
| 199 DCHECK_EQ(role_, WebKit::WebAXRoleStaticText); |
| 200 int end = start + len; |
| 201 int child_start = 0; |
| 202 int child_end = 0; |
| 203 |
| 204 gfx::Rect bounds; |
| 205 for (size_t i = 0; i < children_.size() && child_end < start + len; ++i) { |
| 206 BrowserAccessibility* child = children_[i]; |
| 207 DCHECK_EQ(child->role(), WebKit::WebAXRoleInlineTextBox); |
| 208 std::string child_text; |
| 209 child->GetStringAttribute(AccessibilityNodeData::ATTR_VALUE, &child_text); |
| 210 int child_len = static_cast<int>(child_text.size()); |
| 211 child_start = child_end; |
| 212 child_end += child_len; |
| 213 |
| 214 if (child_end < start) |
| 215 continue; |
| 216 |
| 217 int overlap_start = std::max(start, child_start); |
| 218 int overlap_end = std::min(end, child_end); |
| 219 |
| 220 int local_start = overlap_start - child_start; |
| 221 int local_end = overlap_end - child_start; |
| 222 |
| 223 gfx::Rect child_rect = child->location(); |
| 224 int text_direction = child->GetIntAttribute( |
| 225 AccessibilityNodeData::ATTR_TEXT_DIRECTION); |
| 226 const std::vector<int32>& character_offsets = child->GetIntListAttribute( |
| 227 AccessibilityNodeData::ATTR_CHARACTER_OFFSETS); |
| 228 int start_pixel_offset = |
| 229 local_start > 0 ? character_offsets[local_start - 1] : 0; |
| 230 int end_pixel_offset = |
| 231 local_end > 0 ? character_offsets[local_end - 1] : 0; |
| 232 |
| 233 gfx::Rect child_overlap_rect; |
| 234 switch (text_direction) { |
| 235 case WebKit::WebAXTextDirectionLR: { |
| 236 int left = child_rect.x() + start_pixel_offset; |
| 237 int right = child_rect.x() + end_pixel_offset; |
| 238 child_overlap_rect = gfx::Rect(left, child_rect.y(), |
| 239 right - left, child_rect.height()); |
| 240 break; |
| 241 } |
| 242 case WebKit::WebAXTextDirectionRL: { |
| 243 int right = child_rect.right() - start_pixel_offset; |
| 244 int left = child_rect.right() - end_pixel_offset; |
| 245 child_overlap_rect = gfx::Rect(left, child_rect.y(), |
| 246 right - left, child_rect.height()); |
| 247 break; |
| 248 } |
| 249 case WebKit::WebAXTextDirectionTB: { |
| 250 int top = child_rect.y() + start_pixel_offset; |
| 251 int bottom = child_rect.y() + end_pixel_offset; |
| 252 child_overlap_rect = gfx::Rect(child_rect.x(), top, |
| 253 child_rect.width(), bottom - top); |
| 254 break; |
| 255 } |
| 256 case WebKit::WebAXTextDirectionBT: { |
| 257 int bottom = child_rect.bottom() - start_pixel_offset; |
| 258 int top = child_rect.bottom() - end_pixel_offset; |
| 259 child_overlap_rect = gfx::Rect(child_rect.x(), top, |
| 260 child_rect.width(), bottom - top); |
| 261 break; |
| 262 } |
| 263 default: |
| 264 NOTREACHED(); |
| 265 } |
| 266 |
| 267 if (bounds.width() == 0 && bounds.height() == 0) |
| 268 bounds = child_overlap_rect; |
| 269 else |
| 270 bounds.Union(child_overlap_rect); |
| 271 } |
| 272 |
| 273 return bounds; |
| 274 } |
| 275 |
| 276 gfx::Rect BrowserAccessibility::GetGlobalBoundsForRange(int start, int len) |
| 277 const { |
| 278 gfx::Rect bounds = GetLocalBoundsForRange(start, len); |
| 279 |
| 280 // Adjust the bounds by the top left corner of the containing view's bounds |
| 281 // in screen coordinates. |
| 282 bounds.Offset(manager_->GetViewBounds().OffsetFromOrigin()); |
| 283 |
| 284 return bounds; |
| 285 } |
| 286 |
197 BrowserAccessibility* BrowserAccessibility::BrowserAccessibilityForPoint( | 287 BrowserAccessibility* BrowserAccessibility::BrowserAccessibilityForPoint( |
198 const gfx::Point& point) { | 288 const gfx::Point& point) { |
199 // Walk the children recursively looking for the BrowserAccessibility that | 289 // Walk the children recursively looking for the BrowserAccessibility that |
200 // most tightly encloses the specified point. | 290 // most tightly encloses the specified point. |
201 for (int i = children_.size() - 1; i >= 0; --i) { | 291 for (int i = children_.size() - 1; i >= 0; --i) { |
202 BrowserAccessibility* child = children_[i]; | 292 BrowserAccessibility* child = children_[i]; |
203 if (child->GetGlobalBoundsRect().Contains(point)) | 293 if (child->GetGlobalBoundsRect().Contains(point)) |
204 return child->BrowserAccessibilityForPoint(point); | 294 return child->BrowserAccessibilityForPoint(point); |
205 } | 295 } |
206 return this; | 296 return this; |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 *value = intlist_attributes_[i].second; | 503 *value = intlist_attributes_[i].second; |
414 return true; | 504 return true; |
415 } | 505 } |
416 } | 506 } |
417 | 507 |
418 return false; | 508 return false; |
419 } | 509 } |
420 | 510 |
421 bool BrowserAccessibility::GetHtmlAttribute( | 511 bool BrowserAccessibility::GetHtmlAttribute( |
422 const char* html_attr, std::string* value) const { | 512 const char* html_attr, std::string* value) const { |
423 for (size_t i = 0; i < html_attributes_.size(); i++) { | 513 for (size_t i = 0; i < html_attributes_.size(); ++i) { |
424 const std::string& attr = html_attributes_[i].first; | 514 const std::string& attr = html_attributes_[i].first; |
425 if (LowerCaseEqualsASCII(attr, html_attr)) { | 515 if (LowerCaseEqualsASCII(attr, html_attr)) { |
426 *value = html_attributes_[i].second; | 516 *value = html_attributes_[i].second; |
427 return true; | 517 return true; |
428 } | 518 } |
429 } | 519 } |
430 | 520 |
431 return false; | 521 return false; |
432 } | 522 } |
433 | 523 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 return name_; | 580 return name_; |
491 } | 581 } |
492 | 582 |
493 std::string result; | 583 std::string result; |
494 for (size_t i = 0; i < children_.size(); ++i) | 584 for (size_t i = 0; i < children_.size(); ++i) |
495 result += children_[i]->GetTextRecursive(); | 585 result += children_[i]->GetTextRecursive(); |
496 return result; | 586 return result; |
497 } | 587 } |
498 | 588 |
499 } // namespace content | 589 } // namespace content |
OLD | NEW |