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

Unified Diff: ui/accessibility/ax_node_position.cc

Issue 2271893002: Creates AXPosition to uniquely identify a position in the accessibility tree (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed AXRange class. 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 side-by-side diff with in-line comments
Download patch
Index: ui/accessibility/ax_node_position.cc
diff --git a/ui/accessibility/ax_node_position.cc b/ui/accessibility/ax_node_position.cc
new file mode 100644
index 0000000000000000000000000000000000000000..28005465e1b255619c8764bd5e75a0db881c1d54
--- /dev/null
+++ b/ui/accessibility/ax_node_position.cc
@@ -0,0 +1,63 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/accessibility/ax_node_position.h"
+
+#include "base/strings/string16.h"
+#include "ui/accessibility/ax_enums.h"
+
+namespace ui {
+
+AXTree* AXNodePosition::tree_ = nullptr;
+
+AXNodePosition::AXNodePosition() {}
+
+AXNodePosition::~AXNodePosition() {}
+
+int32_t AXNodePosition::AnchorChildID(int child_index) const {
+ if (child_index < 0 || child_index >= AnchorChildCount())
+ return AXPosition::INVALID_ANCHOR_ID;
+
+ AXNode* child = GetAnchor()->ChildAtIndex(child_index);
+ DCHECK(child);
+ int32_t child_id = child->id();
+ DCHECK_NE(child_id, AXPosition::INVALID_ANCHOR_ID);
+ return child_id;
+}
+
+int AXNodePosition::AnchorChildCount() const {
+ return GetAnchor() ? GetAnchor()->child_count() : 0;
+}
+
+int AXNodePosition::AnchorIndexInParent() const {
+ return GetAnchor() ? GetAnchor()->index_in_parent()
+ : AXPosition::INVALID_INDEX;
+}
+
+int32_t AXNodePosition::AnchorParentID() const {
+ if (!GetAnchor() || !GetAnchor()->parent())
+ return INVALID_ANCHOR_ID;
+ return GetAnchor()->parent()->id();
+}
+
+AXNode* AXNodePosition::GetNodeInTree(int tree_id, int32_t node_id) const {
+ if (!tree_ || node_id == AXPosition::INVALID_ANCHOR_ID)
+ return nullptr;
+ return AXNodePosition::tree_->GetFromId(node_id);
+}
+
+int AXNodePosition::MaxTextOffset() const {
+ if (IsTextPosition()) {
+ DCHECK(GetAnchor());
+ base::string16 name =
+ GetAnchor()->data().GetString16Attribute(AX_ATTR_NAME);
+ return static_cast<int>(name.length());
+ } else if (IsTreePosition()) {
+ return 0;
+ }
+
+ return AXPosition::INVALID_INDEX;
+}
+
+} // namespace ui

Powered by Google App Engine
This is Rietveld 408576698