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..c221cbf86a2dc49eb76e4c03bb79354fcb0af4af |
--- /dev/null |
+++ b/content/browser/accessibility/ax_platform_position.cc |
@@ -0,0 +1,76 @@ |
+// 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" |
+ |
+namespace content { |
+ |
+AXPlatformPosition::AXPlatformPosition( |
+ AXTreeIDRegistry::AXTreeID tree_id, |
+ int32_t anchor_id, |
+ int child_index, |
+ int text_offset, |
+ ui::AXPositionType type, |
+ std::unique_ptr<ui::AXPositionFactory> factory) |
+ : ui::AXPosition(tree_id, |
+ anchor_id, |
+ child_index, |
+ text_offset, |
+ type, |
+ factory) {} |
+ |
+AXPlatformPosition::~AXPlatformPosition() {} |
+ |
+ui::AXPosition AXPlatformPositionFactory::CreateNullPosition() { |
+ return AXPlatformPosition(-1 /* tree_id */, -1 /* anchor_id */, |
+ -1 /* child_index */, -1 /* text_offset */, |
+ ui::AXPositionType::NullPosition); |
+} |
+ |
+ui::AXPosition AXPlatformPositionFactory::CreateTreePosition(int tree_id, |
+ int32_t anchor_id, |
+ int child_index) { |
+ return AXPlatformPosition(tree_id, anchor_id, child_index, |
+ -1 /* text_offset */, |
+ ui::AXPositionType::TreePosition); |
+} |
+ |
+ui::AXPosition AXPlatformPositionFactory::CreateTextPosition(int tree_id, |
+ int32_t anchor_id, |
+ int text_offset) { |
+ return AXPlatformPosition(tree_id, anchor_id, -1 /* child_index */, |
+ text_offset, ui::AXPositionType::TextPosition); |
+} |
+ |
+BrowserAccessibility* AXPlatformPosition::GetPlatformNodeInTree( |
+ AXTreeIDRegistry::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); |
+} |
+ |
+ui::AXNode* AXPlatformPosition::GetNodeInTree( |
+ AXTreeIDRegistry::AXTreeID tree_id, |
+ int32_t node_id) const { |
+ BrowserAccessibility* anchor = GetPlatformNodeInTree(tree_id, node_id); |
+ return anchor ? anchor->node() : nullptr; |
+} |
+ |
+int AXPlatformPosition::MaxTextOffset() const { |
+ if (IsNullPosition()) |
+ return -1; |
+ |
+ BrowserAccessibility* anchor = |
+ GetPlatformNodeInTree(get_tree_id(), get_anchor_id()); |
+ if (!anchor) |
+ return -1; |
+ return static_cast<int>(anchor->GetText().length()); |
+} |
+ |
+} // namespace content |