| 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..ff1ff6d441a256555daaa8ea3547a1c2e8641f0a
|
| --- /dev/null
|
| +++ b/content/browser/accessibility/ax_platform_position.cc
|
| @@ -0,0 +1,84 @@
|
| +// 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(AXTreeID tree_id,
|
| + int32_t anchor_id,
|
| + int child_index,
|
| + int text_offset,
|
| + ui::AXPositionType type)
|
| + : AXPosition(tree_id, anchor_id, child_index, text_offset, type) {}
|
| +
|
| +AXPlatformPosition::~AXPlatformPosition() {}
|
| +
|
| +AXPosition* AXPlatformPosition::GetChildPositionAt(int child_index) const {
|
| + if (IsNullPosition())
|
| + return CreateNullPosition();
|
| +
|
| + if (child_index < 0 || child_index >= AnchorChildCount())
|
| + return CreateNullPosition();
|
| +
|
| + AXNodeType* child_anchor = GetAnchor()->PlatformGetChild(child_index);
|
| + DCHECK(child_anchor);
|
| + switch (type_) {
|
| + case AXPositionType::NullPosition:
|
| + NOTREACHED();
|
| + return CreateNullPosition();
|
| + case AXPositionType::TreePosition:
|
| + return CreateTreePosition(tree_id_, child_anchor->id(),
|
| + 0 /* child_index */);
|
| + case AXPositionType::TextPosition:
|
| + return CreateTextPosition(tree_id_, child_anchor->id(),
|
| + 0 /* text_offset */);
|
| + }
|
| +}
|
| +
|
| +AXPosition* AXPlatformPosition::GetParentPosition() const {
|
| + if (IsNullPosition())
|
| + return CreateNullPosition();
|
| +
|
| + AXNodeType* parent_anchor = GetAnchor()->PlatformGetParent();
|
| + if (!parent_anchor)
|
| + return CreateNullPosition();
|
| +
|
| + switch (type_) {
|
| + case AXPositionType::NullPosition:
|
| + NOTREACHED();
|
| + return CreateNullPosition();
|
| + case AXPositionType::TreePosition:
|
| + return CreateTreePosition(tree_id_, parent_anchor->id(),
|
| + 0 /* child_index */);
|
| + case AXPositionType::TextPosition:
|
| + return CreateTextPosition(tree_id_, parent_anchor->id(),
|
| + 0 /* text_offset */);
|
| + }
|
| +}
|
| +
|
| +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
|
|
|