Chromium Code Reviews| 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..63bacb9f9174fa437c7e68bace0cbd369b39a3c5 |
| --- /dev/null |
| +++ b/content/browser/accessibility/ax_platform_position.cc |
| @@ -0,0 +1,64 @@ |
| +// 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() {} |
| + |
| +int32_t AXPlatformPosition::AnchorChildID(int child_index) const { |
|
dmazzoni
2016/10/18 23:59:11
I just realized that this won't work across iframe
|
| + if (child_index < 0 || child_index >= AnchorChildCount()) |
| + return AXPosition::INVALID_ANCHOR_ID; |
| + |
| + BrowserAccessibility* child = GetAnchor()->PlatformGetChild(child_index); |
| + DCHECK(child); |
| + int32_t child_id = child->GetId(); |
| + DCHECK_NE(child_id, AXPosition::INVALID_ANCHOR_ID); |
| + return child_id; |
| +} |
| + |
| +int AXPlatformPosition::AnchorChildCount() const { |
| + return GetAnchor() ? static_cast<int>(GetAnchor()->PlatformChildCount()) : 0; |
| +} |
| + |
| +int AXPlatformPosition::AnchorIndexInParent() const { |
| + return GetAnchor() ? static_cast<int>(GetAnchor()->GetIndexInParent()) |
| + : AXPosition::INVALID_INDEX; |
| +} |
| + |
| +int32_t AXPlatformPosition::AnchorParentID() const { |
| + if (!GetAnchor() || !GetAnchor()->GetParent()) |
| + return AXPosition::INVALID_ANCHOR_ID; |
| + return GetAnchor()->GetParent()->GetId(); |
| +} |
| + |
| +BrowserAccessibility* AXPlatformPosition::GetNodeInTree(AXTreeID tree_id, |
| + int32_t node_id) const { |
| + if (tree_id == AXPosition::INVALID_TREE_ID || |
| + node_id == AXPosition::INVALID_ANCHOR_ID) { |
| + return nullptr; |
| + } |
| + |
| + auto manager = BrowserAccessibilityManager::FromID(tree_id); |
| + if (!manager) |
| + return nullptr; |
| + return manager->GetFromID(node_id); |
| +} |
| + |
| +int AXPlatformPosition::MaxTextOffset() const { |
| + if (IsNullPosition()) |
| + return AXPosition::INVALID_OFFSET; |
| + |
| + BrowserAccessibility* anchor = GetNodeInTree(tree_id(), anchor_id()); |
| + if (!anchor) |
| + return AXPosition::INVALID_OFFSET; |
| + return static_cast<int>(anchor->GetText().length()); |
| +} |
| + |
| +} // namespace content |