1 // Copyright 2018 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_ASSISTANT_STRUCTURE_H_
6 #define UI_ACCESSIBILITY_AX_ASSISTANT_STRUCTURE_H_
7 
8 #include <cstdint>
9 #include <vector>
10 
11 #include "base/macros.h"
12 #include "base/optional.h"
13 #include "base/strings/string16.h"
14 #include "ui/accessibility/ax_enums.mojom-forward.h"
15 #include "ui/accessibility/ax_export.h"
16 #include "ui/accessibility/ax_tree_update.h"
17 #include "ui/gfx/geometry/rect.h"
18 #include "ui/gfx/range/range.h"
19 
20 namespace ui {
21 
22 struct AssistantNode {
23   AssistantNode();
24   AssistantNode(const AssistantNode& other);
25   AssistantNode& operator=(const AssistantNode&) = delete;
26   ~AssistantNode();
27 
28   std::vector<int32_t> children_indices;
29 
30   // Geometry of the view in pixels
31   gfx::Rect rect;
32 
33   // Text of the view.
34   base::string16 text;
35 
36   // Text properties
37   float text_size;
38   uint32_t color;
39   uint32_t bgcolor;
40   bool bold;
41   bool italic;
42   bool underline;
43   bool line_through;
44 
45   // Selected portion of the text.
46   base::Optional<gfx::Range> selection;
47 
48   // Fake Android view class name of the element.  Each node is assigned
49   // a closest approximation of Android's views to keep the server happy.
50   std::string class_name;
51 
52   // Accessibility functionality of the node inferred from DOM or based on HTML
53   // role attribute.
54   base::Optional<std::string> role;
55 };
56 
57 struct AssistantTree {
58   AssistantTree();
59   AssistantTree(const AssistantTree& other);
60   AssistantTree& operator=(const AssistantTree&) = delete;
61   ~AssistantTree();
62 
63   std::vector<std::unique_ptr<AssistantNode>> nodes;
64 };
65 
66 std::unique_ptr<AssistantTree> CreateAssistantTree(const AXTreeUpdate& update,
67                                                    bool show_password);
68 
69 base::string16 AXUrlBaseText(base::string16 url);
70 const char* AXRoleToAndroidClassName(ax::mojom::Role role, bool has_parent);
71 
72 }  // namespace ui
73 
74 #endif  // UI_ACCESSIBILITY_AX_ASSISTANT_STRUCTURE_H_
75