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

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

Issue 2301833005: Get rid of AX_LINE_BREAKS attribute to improve performance. (Closed)
Patch Set: Fixed line length issue. Created 4 years, 3 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
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(ui::AX_ATTR_LINE_STARTS, &line_offsets))
61 return line_offsets;
62
63 int end_offset;
64 ComputeLineStartOffsets(&line_offsets, &end_offset);
65 data_.AddIntListAttribute(ui::AX_ATTR_LINE_STARTS, line_offsets);
66 return line_offsets;
67 }
68
69 void AXNode::ComputeLineStartOffsets(std::vector<int>* line_offsets,
70 int* end_offset) const {
David Tseng 2016/09/13 17:41:27 Is this meant to work on any node (e.g. <div aria-
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);
77 continue;
78 }
79
80 base::string16 text = child->data().GetString16Attribute(ui::AX_ATTR_NAME);
81 *end_offset += static_cast<int>(text.length());
David Tseng 2016/09/13 17:41:27 Just make end_offset a size_t
82 if (!child->data().HasIntAttribute(ui::AX_ATTR_NEXT_ON_LINE_ID))
83 line_offsets->push_back(*end_offset);
84 }
85 }
86
54 } // namespace ui 87 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698