Index: content/browser/accessibility/ax_platform_position.cc |
diff --git a/content/browser/accessibility/ax_platform_position.cc b/content/browser/accessibility/ax_platform_position.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..03376baa88ad78ade82a3ecb3eb96fa73581711b |
--- /dev/null |
+++ b/content/browser/accessibility/ax_platform_position.cc |
@@ -0,0 +1,91 @@ |
+// 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 "content/browser/accessibility/ax_platform_position.h" |
+ |
+#include "content/browser/accessibility/browser_accessibility_manager.h" |
+ |
+namespace content { |
+ |
+AXPlatformPosition::AXPlatformPosition() {} |
+ |
+AXPlatformPosition::~AXPlatformPosition() {} |
+ |
+int AXPlatformPosition::AnchorChildCount() const { |
+ return GetAnchor() ? static_cast<int>(GetAnchor()->PlatformChildCount()) : -1; |
+} |
+ |
+AXPlatformPosition* AXPlatformPosition::GetChildPositionAt( |
+ int child_index) const { |
+ if (IsNullPosition()) |
+ return static_cast<AXPlatformPosition*>(CreateNullPosition()); |
+ |
+ if (child_index < 0 || child_index >= AnchorChildCount()) |
+ return static_cast<AXPlatformPosition*>(CreateNullPosition()); |
+ |
+ BrowserAccessibility* child_anchor = |
+ GetAnchor()->PlatformGetChild(child_index); |
+ DCHECK(child_anchor); |
+ switch (get_kind()) { |
+ case ui::AXPositionKind::NullPosition: |
+ NOTREACHED(); |
+ return static_cast<AXPlatformPosition*>(CreateNullPosition()); |
+ case ui::AXPositionKind::TreePosition: |
+ return static_cast<AXPlatformPosition*>(CreateTreePosition( |
+ get_tree_id(), child_anchor->GetId(), 0 /* child_index */)); |
+ case ui::AXPositionKind::TextPosition: |
+ return static_cast<AXPlatformPosition*>(CreateTextPosition( |
+ get_tree_id(), child_anchor->GetId(), 0 /* text_offset */)); |
+ } |
+ return static_cast<AXPlatformPosition*>(CreateNullPosition()); |
+} |
+ |
+AXPlatformPosition* AXPlatformPosition::GetParentPosition() const { |
+ if (IsNullPosition()) |
+ return static_cast<AXPlatformPosition*>(CreateNullPosition()); |
+ |
+ BrowserAccessibility* parent_anchor = GetAnchor()->GetParent(); |
+ if (!parent_anchor) |
+ return static_cast<AXPlatformPosition*>(CreateNullPosition()); |
+ |
+ switch (get_kind()) { |
+ case ui::AXPositionKind::NullPosition: |
+ NOTREACHED(); |
+ return static_cast<AXPlatformPosition*>(CreateNullPosition()); |
+ case ui::AXPositionKind::TreePosition: |
+ return static_cast<AXPlatformPosition*>(CreateTreePosition( |
+ get_tree_id(), parent_anchor->GetId(), 0 /* child_index */)); |
+ case ui::AXPositionKind::TextPosition: |
+ return static_cast<AXPlatformPosition*>(CreateTextPosition( |
+ get_tree_id(), parent_anchor->GetId(), 0 /* text_offset */)); |
+ } |
+ return static_cast<AXPlatformPosition*>(CreateNullPosition()); |
+} |
+ |
+int AXPlatformPosition::AnchorIndexInParent() const { |
+ return GetAnchor() ? static_cast<int>(GetAnchor()->GetIndexInParent()) : -1; |
+} |
+ |
+BrowserAccessibility* AXPlatformPosition::GetNodeInTree(AXTreeID tree_id, |
+ int32_t node_id) const { |
+ if (IsNullPosition()) |
+ return nullptr; |
+ |
+ auto manager = BrowserAccessibilityManager::FromID(tree_id); |
+ if (!manager) |
+ return nullptr; |
+ return manager->GetFromID(node_id); |
+} |
+ |
+int AXPlatformPosition::MaxTextOffset() const { |
+ if (IsNullPosition()) |
+ return -1; |
+ |
+ BrowserAccessibility* anchor = GetNodeInTree(get_tree_id(), get_anchor_id()); |
+ if (!anchor) |
+ return -1; |
+ return static_cast<int>(anchor->GetText().length()); |
+} |
+ |
+} // namespace content |