Chromium Code Reviews| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <functional> | |
| 10 | 11 |
| 11 #include "base/logging.h" | 12 #include "base/logging.h" |
| 12 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 15 #include "content/browser/accessibility/browser_accessibility_manager.h" | 16 #include "content/browser/accessibility/browser_accessibility_manager.h" |
| 16 #include "content/common/accessibility_messages.h" | 17 #include "content/common/accessibility_messages.h" |
| 17 #include "ui/accessibility/ax_text_utils.h" | 18 #include "ui/accessibility/ax_text_utils.h" |
| 18 #include "ui/accessibility/platform/ax_platform_node.h" | 19 #include "ui/accessibility/platform/ax_platform_node.h" |
| 19 #include "ui/gfx/geometry/rect_conversions.h" | 20 #include "ui/gfx/geometry/rect_conversions.h" |
| (...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 526 } | 527 } |
| 527 | 528 |
| 528 int BrowserAccessibility::GetLineStartBoundary( | 529 int BrowserAccessibility::GetLineStartBoundary( |
| 529 int start, | 530 int start, |
| 530 ui::TextBoundaryDirection direction, | 531 ui::TextBoundaryDirection direction, |
| 531 ui::AXTextAffinity affinity) const { | 532 ui::AXTextAffinity affinity) const { |
| 532 DCHECK_GE(start, 0); | 533 DCHECK_GE(start, 0); |
| 533 DCHECK_LE(start, static_cast<int>(GetText().length())); | 534 DCHECK_LE(start, static_cast<int>(GetText().length())); |
| 534 | 535 |
| 535 if (IsSimpleTextControl()) { | 536 if (IsSimpleTextControl()) { |
| 536 const std::vector<int32_t>& line_breaks = | 537 return ui::FindAccessibleTextBoundary(GetText(), ComputeLineBreaks(), |
| 537 GetIntListAttribute(ui::AX_ATTR_LINE_BREAKS); | |
| 538 return ui::FindAccessibleTextBoundary(GetText(), line_breaks, | |
| 539 ui::LINE_BOUNDARY, start, direction, | 538 ui::LINE_BOUNDARY, start, direction, |
| 540 affinity); | 539 affinity); |
| 541 } | 540 } |
| 542 | 541 |
| 543 // Keeps track of the start offset of each consecutive line. | 542 // Keeps track of the start offset of each consecutive line. |
| 544 int line_start = 0; | 543 int line_start = 0; |
| 545 // Keeps track of the length of each consecutive line. | 544 // Keeps track of the length of each consecutive line. |
| 546 int line_length = 0; | 545 int line_length = 0; |
| 547 for (size_t i = 0; i < InternalChildCount(); ++i) { | 546 for (size_t i = 0; i < InternalChildCount(); ++i) { |
| 548 const BrowserAccessibility* child = InternalGetChild(i); | 547 const BrowserAccessibility* child = InternalGetChild(i); |
| (...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1135 if (!name.empty()) | 1134 if (!name.empty()) |
| 1136 name += " "; | 1135 name += " "; |
| 1137 name += child_name; | 1136 name += child_name; |
| 1138 } | 1137 } |
| 1139 } | 1138 } |
| 1140 } | 1139 } |
| 1141 | 1140 |
| 1142 return name; | 1141 return name; |
| 1143 } | 1142 } |
| 1144 | 1143 |
| 1144 std::vector<int> BrowserAccessibility::ComputeLineBreaks() const { | |
| 1145 std::vector<int> line_breaks; | |
| 1146 int offset = 0; | |
| 1147 for (size_t i = 0; i < InternalChildCount(); ++i) { | |
| 1148 const BrowserAccessibility* child = InternalGetChild(i); | |
| 1149 DCHECK(child); | |
| 1150 switch | |
| 1151 child->GetRole() { | |
| 1152 case ui::AX_ROLE_INLINE_TEXT_BOX: | |
|
dmazzoni
2016/09/02 15:55:00
This algorithm is fine, it will certainly work cor
| |
| 1153 offset += child->GetText().length(); | |
| 1154 if (!child->IsNextSiblingOnSameLine()) | |
| 1155 line_breaks.push_back(offset); | |
| 1156 break; | |
| 1157 case ui::AX_ROLE_LINE_BREAK: | |
| 1158 line_breaks.push_back(offset); | |
| 1159 offset += child->GetText().length(); | |
| 1160 break; | |
| 1161 default: | |
| 1162 std::vector<int> child_breaks = child->ComputeLineBreaks(); | |
| 1163 std::transform(child_breaks.begin(), child_breaks.end(), child_breaks.be gin(), std::bind2nd()std::plus<int>, offset)); | |
|
dmazzoni
2016/09/02 15:55:00
Needs indentation
Could you write this using a la
| |
| 1164 line_breaks.insert(line_breaks.end(), child_breaks.begin(), | |
| 1165 child_breaks.end()); | |
| 1166 } | |
| 1167 } | |
| 1168 return line_breaks; | |
| 1169 } | |
| 1170 | |
| 1145 base::string16 BrowserAccessibility::GetInnerText() const { | 1171 base::string16 BrowserAccessibility::GetInnerText() const { |
| 1146 if (IsTextOnlyObject()) | 1172 if (IsTextOnlyObject()) |
| 1147 return GetString16Attribute(ui::AX_ATTR_NAME); | 1173 return GetString16Attribute(ui::AX_ATTR_NAME); |
| 1148 | 1174 |
| 1149 base::string16 text; | 1175 base::string16 text; |
| 1150 for (size_t i = 0; i < InternalChildCount(); ++i) | 1176 for (size_t i = 0; i < InternalChildCount(); ++i) |
| 1151 text += InternalGetChild(i)->GetInnerText(); | 1177 text += InternalGetChild(i)->GetInnerText(); |
| 1152 return text; | 1178 return text; |
| 1153 } | 1179 } |
| 1154 | 1180 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1212 } | 1238 } |
| 1213 } | 1239 } |
| 1214 | 1240 |
| 1215 node = container; | 1241 node = container; |
| 1216 } | 1242 } |
| 1217 | 1243 |
| 1218 return gfx::ToEnclosingRect(bounds); | 1244 return gfx::ToEnclosingRect(bounds); |
| 1219 } | 1245 } |
| 1220 | 1246 |
| 1221 } // namespace content | 1247 } // namespace content |
| OLD | NEW |