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

Unified 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, 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/accessibility/ax_node.cc
diff --git a/ui/accessibility/ax_node.cc b/ui/accessibility/ax_node.cc
index a0e53fad6a25f2f6d91bd4dabc1ab238437450ee..459095eef929ad0b4aa66e1e92efda852674b993 100644
--- a/ui/accessibility/ax_node.cc
+++ b/ui/accessibility/ax_node.cc
@@ -3,6 +3,10 @@
// found in the LICENSE file.
#include "ui/accessibility/ax_node.h"
+
+#include <algorithm>
+
+#include "base/strings/string16.h"
#include "ui/gfx/transform.h"
namespace ui {
@@ -51,4 +55,33 @@ bool AXNode::IsDescendantOf(AXNode* ancestor) {
return false;
}
+std::vector<int> AXNode::GetOrComputeLineStartOffsets() {
+ std::vector<int> line_offsets;
+ if (data().GetIntListAttribute(AX_ATTR_CACHED_LINE_STARTS, &line_offsets))
+ return line_offsets;
+
+ int end_offset = 0;
+ ComputeLineStartOffsets(&line_offsets, &end_offset);
+ data_.AddIntListAttribute(AX_ATTR_CACHED_LINE_STARTS, line_offsets);
+ return line_offsets;
+}
+
+void AXNode::ComputeLineStartOffsets(std::vector<int>* line_offsets,
+ int* end_offset) const {
+ DCHECK(line_offsets);
+ DCHECK(end_offset);
+ for (const AXNode* child : children()) {
+ DCHECK(child);
+ if (child->child_count()) {
+ child->ComputeLineStartOffsets(line_offsets, end_offset);
David Tseng 2016/09/23 12:43:02 Also, before I forget, if performance is a concern
+ continue;
+ }
+
+ 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
+ *end_offset += static_cast<int>(text.length());
+ if (!child->data().HasIntAttribute(ui::AX_ATTR_NEXT_ON_LINE_ID))
+ 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
+ }
+}
+
} // namespace ui
« 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