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

Unified Diff: ui/accessibility/ax_position.cc

Issue 2234913002: Added support for header and footer inside other sections, according to HTML API Mappings 1.0. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Checked if node if present. Created 4 years, 4 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_position.cc
diff --git a/ui/accessibility/ax_position.cc b/ui/accessibility/ax_position.cc
new file mode 100644
index 0000000000000000000000000000000000000000..00803a171317fb5e97001e2866f5cbd529a4425c
--- /dev/null
+++ b/ui/accessibility/ax_position.cc
@@ -0,0 +1,54 @@
+// 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.h"
+
+namespace ui {
+
+AXPosition::AXPosition() : anchor_(nullptr), offset(-1) {}
+
+AXPosition::AXPosition(AXNode* anchor, int offset)
+ : anchor_(anchor), offset_(offset) {
+ DCHECK(anchor);
+ DCHECK_GE(offset, 0);
+}
+
+AXPosition::~AXPosition() {
+}
+
+bool AXPosition::IsNull() const {
+ return anchor_ == nullptr;
+}
+
+AXPosition AXPosition::ToLeafEquivalent() const {
+ if (IsNull())
+ return AXPosition();
+
+ if (!anchor_->child_count())
+ return AXPosition(anchor_, offset_);
+
+ if (offset_ >= anchor_->child_count())
+ return AXPosition();
+
+ AXNode* child = anchor_->children()[offset_];
+ DCHECK(child);
+ while (child->children()[0])
+ child = child->children()[0];
+ return AXPosition(child, 0);
+}
+
+AXPosition AXPosition::GetCorrespondingPositionInParent(
+ const AXNode& parent) const {
+ auto parent_node = const_cast<AXNode*>(&parent);
+ AXNode* current_node = anchor_;
+ while (current_node && parent_node != current_node->parent())
+ current_node = current_node->parent();
+
+ if (!current_node)
+ return AXPosition();
+
+ return AXPosition(parent_node, current_node->index_in_parent());
+}
+
+} // namespace ui

Powered by Google App Engine
This is Rietveld 408576698