Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(141)

Side by Side Diff: ui/accessibility/ax_node.cc

Issue 2301833005: Get rid of AX_LINE_BREAKS attribute to improve performance. (Closed)
Patch Set: Re-worded comment. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/accessibility/ax_node.h ('k') | ui/accessibility/ax_node_data.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
7 #include <algorithm>
8
9 #include "base/strings/string16.h"
6 #include "ui/gfx/transform.h" 10 #include "ui/gfx/transform.h"
7 11
8 namespace ui { 12 namespace ui {
9 13
10 AXNode::AXNode(AXNode* parent, int32_t id, int32_t index_in_parent) 14 AXNode::AXNode(AXNode* parent, int32_t id, int32_t index_in_parent)
11 : index_in_parent_(index_in_parent), parent_(parent) { 15 : index_in_parent_(index_in_parent), parent_(parent) {
12 data_.id = id; 16 data_.id = id;
13 } 17 }
14 18
15 AXNode::~AXNode() { 19 AXNode::~AXNode() {
(...skipping 28 matching lines...) Expand all
44 48
45 bool AXNode::IsDescendantOf(AXNode* ancestor) { 49 bool AXNode::IsDescendantOf(AXNode* ancestor) {
46 if (this == ancestor) 50 if (this == ancestor)
47 return true; 51 return true;
48 else if (parent()) 52 else if (parent())
49 return parent()->IsDescendantOf(ancestor); 53 return parent()->IsDescendantOf(ancestor);
50 54
51 return false; 55 return false;
52 } 56 }
53 57
58 std::vector<int> AXNode::GetOrComputeLineStartOffsets() {
59 std::vector<int> line_offsets;
60 if (data().GetIntListAttribute(AX_ATTR_CACHED_LINE_STARTS, &line_offsets))
61 return line_offsets;
62
63 int end_offset = 0;
64 ComputeLineStartOffsets(&line_offsets, &end_offset);
65 data_.AddIntListAttribute(AX_ATTR_CACHED_LINE_STARTS, line_offsets);
66 return line_offsets;
67 }
68
69 void AXNode::ComputeLineStartOffsets(std::vector<int>* line_offsets,
70 int* end_offset) const {
71 DCHECK(line_offsets);
72 DCHECK(end_offset);
73 for (const AXNode* child : children()) {
74 DCHECK(child);
75 if (child->child_count()) {
76 child->ComputeLineStartOffsets(line_offsets, end_offset);
David Tseng 2016/09/23 12:43:02 Also, before I forget, if performance is a concern
77 continue;
78 }
79
80 base::string16 text = child->data().GetString16Attribute(ui::AX_ATTR_NAME);
David Tseng 2016/09/23 01:43:57 This isn't equivalent with the way line breaks cur
81 *end_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);
David Tseng 2016/10/06 21:28:03 This is sometimes wrong when you're on the last le
84 }
85 }
86
54 } // namespace ui 87 } // namespace ui
OLDNEW
« no previous file with comments | « ui/accessibility/ax_node.h ('k') | ui/accessibility/ax_node_data.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698