| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "ui/accessibility/ax_node.h" | 5 #include "ui/accessibility/ax_node.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
| 10 #include "ui/gfx/transform.h" | 10 #include "ui/gfx/transform.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 return parent()->IsDescendantOf(ancestor); | 53 return parent()->IsDescendantOf(ancestor); |
| 54 | 54 |
| 55 return false; | 55 return false; |
| 56 } | 56 } |
| 57 | 57 |
| 58 std::vector<int> AXNode::GetOrComputeLineStartOffsets() { | 58 std::vector<int> AXNode::GetOrComputeLineStartOffsets() { |
| 59 std::vector<int> line_offsets; | 59 std::vector<int> line_offsets; |
| 60 if (data().GetIntListAttribute(AX_ATTR_CACHED_LINE_STARTS, &line_offsets)) | 60 if (data().GetIntListAttribute(AX_ATTR_CACHED_LINE_STARTS, &line_offsets)) |
| 61 return line_offsets; | 61 return line_offsets; |
| 62 | 62 |
| 63 int end_offset = 0; | 63 int start_offset = 0; |
| 64 ComputeLineStartOffsets(&line_offsets, &end_offset); | 64 ComputeLineStartOffsets(&line_offsets, &start_offset); |
| 65 data_.AddIntListAttribute(AX_ATTR_CACHED_LINE_STARTS, line_offsets); | 65 data_.AddIntListAttribute(AX_ATTR_CACHED_LINE_STARTS, line_offsets); |
| 66 return line_offsets; | 66 return line_offsets; |
| 67 } | 67 } |
| 68 | 68 |
| 69 void AXNode::ComputeLineStartOffsets(std::vector<int>* line_offsets, | 69 void AXNode::ComputeLineStartOffsets(std::vector<int>* line_offsets, |
| 70 int* end_offset) const { | 70 int* start_offset) const { |
| 71 DCHECK(line_offsets); | 71 DCHECK(line_offsets); |
| 72 DCHECK(end_offset); | 72 DCHECK(start_offset); |
| 73 for (const AXNode* child : children()) { | 73 for (const AXNode* child : children()) { |
| 74 DCHECK(child); | 74 DCHECK(child); |
| 75 if (child->child_count()) { | 75 if (child->child_count()) { |
| 76 child->ComputeLineStartOffsets(line_offsets, end_offset); | 76 child->ComputeLineStartOffsets(line_offsets, start_offset); |
| 77 continue; | 77 continue; |
| 78 } | 78 } |
| 79 | 79 |
| 80 // Don't report if the first piece of text starts a new line or not. |
| 81 if (*start_offset && |
| 82 !child->data().HasIntAttribute(ui::AX_ATTR_PREVIOUS_ON_LINE_ID)) { |
| 83 // If there are multiple objects with an empty accessible label at the |
| 84 // start of a line, only include a single line start offset. |
| 85 if (line_offsets->empty() || line_offsets->back() != *start_offset) |
| 86 line_offsets->push_back(*start_offset); |
| 87 } |
| 88 |
| 80 base::string16 text = child->data().GetString16Attribute(ui::AX_ATTR_NAME); | 89 base::string16 text = child->data().GetString16Attribute(ui::AX_ATTR_NAME); |
| 81 *end_offset += static_cast<int>(text.length()); | 90 *start_offset += static_cast<int>(text.length()); |
| 82 if (!child->data().HasIntAttribute(ui::AX_ATTR_NEXT_ON_LINE_ID)) | |
| 83 line_offsets->push_back(*end_offset); | |
| 84 } | 91 } |
| 85 } | 92 } |
| 86 | 93 |
| 87 } // namespace ui | 94 } // namespace ui |
| OLD | NEW |