1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef UI_ACCESSIBILITY_AX_TREE_DATA_H_
6 #define UI_ACCESSIBILITY_AX_TREE_DATA_H_
7 
8 #include <stdint.h>
9 
10 #include <map>
11 #include <string>
12 #include <vector>
13 
14 #include "base/strings/string16.h"
15 #include "base/strings/string_split.h"
16 #include "ui/accessibility/ax_enums.mojom-forward.h"
17 #include "ui/accessibility/ax_export.h"
18 #include "ui/accessibility/ax_node.h"
19 #include "ui/accessibility/ax_tree_id_registry.h"
20 #include "ui/gfx/geometry/rect.h"
21 
22 namespace ui {
23 
24 // The data associated with an accessibility tree that's global to the
25 // tree and not associated with any particular node in the tree.
26 struct AX_EXPORT AXTreeData {
27   AXTreeData();
28   AXTreeData(const AXTreeData& other);
29   virtual ~AXTreeData();
30 
31   // Return a string representation of this data, for debugging.
32   virtual std::string ToString() const;
33 
34   // This is a simple serializable struct. All member variables should be
35   // public and copyable.
36 
37   // The globally unique ID of this accessibility tree.
38   AXTreeID tree_id;
39 
40   // The ID of the accessibility tree that this tree is contained in, if any.
41   AXTreeID parent_tree_id;
42 
43   // The ID of the accessibility tree that has focus. This is typically set
44   // on the root frame in a frame tree.
45   AXTreeID focused_tree_id;
46 
47   // Attributes specific to trees that are web frames.
48   std::string doctype;
49   bool loaded = false;
50   float loading_progress = 0.0f;
51   std::string mimetype;
52   std::string title;
53   std::string url;
54 
55   // The node with keyboard focus within this tree, if any, or
56   // AXNode::kInvalidAXID if no node in this tree has focus.
57   AXNode::AXID focus_id = AXNode::kInvalidAXID;
58 
59   // The current text selection within this tree, if any, expressed as the
60   // node ID and character offset of the anchor (selection start) and focus
61   // (selection end). If the offset could correspond to a position on two
62   // different lines, sel_upstream_affinity means the cursor is on the first
63   // line, otherwise it's on the second line.
64   // Most use cases will want to use ui::OwnerTree::GetUnignoredSelection.
65   bool sel_is_backward = false;
66   AXNode::AXID sel_anchor_object_id = AXNode::kInvalidAXID;
67   int32_t sel_anchor_offset = -1;
68   ax::mojom::TextAffinity sel_anchor_affinity;
69   AXNode::AXID sel_focus_object_id = AXNode::kInvalidAXID;
70   int32_t sel_focus_offset = -1;
71   ax::mojom::TextAffinity sel_focus_affinity;
72 
73   // The node that's used as the root scroller. On some platforms
74   // like Android we need to ignore accessibility scroll offsets for
75   // that node and get them from the viewport instead.
76   AXNode::AXID root_scroller_id = AXNode::kInvalidAXID;
77 };
78 
79 AX_EXPORT bool operator==(const AXTreeData& lhs, const AXTreeData& rhs);
80 AX_EXPORT bool operator!=(const AXTreeData& lhs, const AXTreeData& rhs);
81 
82 }  // namespace ui
83 
84 #endif  // UI_ACCESSIBILITY_AX_TREE_DATA_H_
85