summaryrefslogtreecommitdiff
path: root/chromium/ui/accessibility/ax_node_position.h
blob: e7d03f6c302ae723905f9a0f3855556124035ff3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// 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.

#ifndef UI_ACCESSIBILITY_AX_NODE_POSITION_H_
#define UI_ACCESSIBILITY_AX_NODE_POSITION_H_

#include <stdint.h>

#include <vector>

#include "base/containers/stack.h"
#include "base/strings/string16.h"
#include "ui/accessibility/ax_enums.mojom-forward.h"
#include "ui/accessibility/ax_export.h"
#include "ui/accessibility/ax_node.h"
#include "ui/accessibility/ax_position.h"
#include "ui/accessibility/ax_tree_id.h"

namespace ui {

// AXNodePosition includes implementations of AXPosition methods which require
// knowledge of the AXPosition AXNodeType (which is unknown by AXPosition).
class AX_EXPORT AXNodePosition : public AXPosition<AXNodePosition, AXNode> {
 public:
  // Creates either a text or a tree position, depending on the type of the node
  // provided.
  static AXPositionInstance CreatePosition(
      const AXNode& node,
      int child_index_or_text_offset,
      ax::mojom::TextAffinity affinity = ax::mojom::TextAffinity::kDownstream);

  AXNodePosition();
  ~AXNodePosition() override;
  AXNodePosition(const AXNodePosition& other);

  AXPositionInstance Clone() const override;

  base::string16 GetText() const override;
  bool IsInLineBreak() const override;
  bool IsInTextObject() const override;
  bool IsInWhiteSpace() const override;
  int MaxTextOffset() const override;

 protected:
  void AnchorChild(int child_index,
                   AXTreeID* tree_id,
                   AXNode::AXID* child_id) const override;
  int AnchorChildCount() const override;
  int AnchorUnignoredChildCount() const override;
  int AnchorIndexInParent() const override;
  int AnchorSiblingCount() const override;
  base::stack<AXNode*> GetAncestorAnchors() const override;
  AXNode* GetLowestUnignoredAncestor() const override;
  void AnchorParent(AXTreeID* tree_id, AXNode::AXID* parent_id) const override;
  AXNode* GetNodeInTree(AXTreeID tree_id, AXNode::AXID node_id) const override;
  AXNode::AXID GetAnchorID(AXNode* node) const override;
  AXTreeID GetTreeID(AXNode* node) const override;

  bool IsEmbeddedObjectInParent() const override;
  bool IsInLineBreakingObject() const override;
  ax::mojom::Role GetAnchorRole() const override;
  ax::mojom::Role GetRole(AXNode* node) const override;
  AXNodeTextStyles GetTextStyles() const override;
  std::vector<int32_t> GetWordStartOffsets() const override;
  std::vector<int32_t> GetWordEndOffsets() const override;
  AXNode::AXID GetNextOnLineID(AXNode::AXID node_id) const override;
  AXNode::AXID GetPreviousOnLineID(AXNode::AXID node_id) const override;

 private:
  // Returns the parent node of the provided child. Returns the parent
  // node's tree id and node id through the provided output parameters,
  // |parent_tree_id| and |parent_id|.
  static AXNode* GetParent(AXNode* child,
                           AXTreeID child_tree_id,
                           AXTreeID* parent_tree_id,
                           AXNode::AXID* parent_id);
};

}  // namespace ui

#endif  // UI_ACCESSIBILITY_AX_NODE_POSITION_H_