Flutter Engine
The Flutter Engine
ax_table_info.h
Go to the documentation of this file.
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_TABLE_INFO_H_
6#define UI_ACCESSIBILITY_AX_TABLE_INFO_H_
7
8#include <map>
9#include <set>
10#include <string>
11#include <unordered_map>
12#include <vector>
13
14#include "ax_export.h"
15
16namespace ui {
17
18class AXTree;
19class AXNode;
20
21// This helper class computes info about tables and grids in AXTrees.
23 public:
24 struct CellData {
26 int32_t cell_id;
27 size_t col_index;
28 size_t row_index;
29 size_t col_span;
30 size_t row_span;
33 };
34
35 // Returns nullptr if the node is not a valid table or grid node.
36 static AXTableInfo* Create(AXTree* tree, AXNode* table_node);
37
39
40 // Called automatically on Create(), but must be called again any time
41 // the table is invalidated. Returns true if this is still a table.
42 bool Update();
43
44 // Whether the data is valid. Whenever the tree is updated in any way,
45 // every AXTableInfo is invalidated and needs to be recomputed, just
46 // to be safe.
47 bool valid() const { return valid_; }
48 void Invalidate();
49
50 // The real row count, guaranteed to be at least as large as the
51 // maximum row index of any cell.
52 size_t row_count = 0;
53
54 // The real column count, guaranteed to be at least as large as the
55 // maximum column index of any cell.
56 size_t col_count = 0;
57
58 // List of column header nodes IDs for each column index.
59 std::vector<std::vector<int32_t>> col_headers;
60
61 // List of row header node IDs for each row index.
62 std::vector<std::vector<int32_t>> row_headers;
63
64 // All header cells.
65 std::vector<int32_t> all_headers;
66
67 // The id of the element with the caption tag or ARIA role.
68 int32_t caption_id;
69
70 // 2-D array of [row][column] -> cell node ID.
71 // This may contain duplicates if there is a rowspan or
72 // colspan. The entry is empty (zero) only if the cell
73 // really is missing from the table.
74 std::vector<std::vector<int32_t>> cell_ids;
75
76 // Array of cell data for every unique cell in the table.
77 std::vector<CellData> cell_data_vector;
78
79 // Set of all unique cell node IDs in the table.
80 std::vector<int32_t> unique_cell_ids;
81
82 // Extra computed nodes for the accessibility tree for macOS:
83 // one column node for each table column, followed by one
84 // table header container node.
85 std::vector<AXNode*> extra_mac_nodes;
86
87 // Map from each cell's node ID to its index in unique_cell_ids.
88 std::unordered_map<int32_t, size_t> cell_id_to_index;
89
90 // Map from each row's node ID to its row index.
91 std::unordered_map<int32_t, size_t> row_id_to_index;
92
93 // List of ax nodes that represent the rows of the table.
94 std::vector<AXNode*> row_nodes;
95
96 // The ARIA row count and column count, if any ARIA table or grid
97 // attributes are used in the table at all.
98 int aria_row_count = 0;
99 int aria_col_count = 0;
100
101 std::string ToString() const;
102
103 private:
104 AXTableInfo(AXTree* tree, AXNode* table_node);
105
106 void ClearVectors();
107 void BuildCellDataVectorFromRowAndCellNodes(
108 const std::vector<AXNode*>& row_node_list,
109 const std::vector<std::vector<AXNode*>>& cell_nodes_per_row);
110 void BuildCellAndHeaderVectorsFromCellData();
111 void UpdateExtraMacNodes();
112 void ClearExtraMacNodes();
113 AXNode* CreateExtraMacColumnNode(size_t col_index);
114 AXNode* CreateExtraMacTableHeaderNode();
115 void UpdateExtraMacColumnNodeAttributes(size_t col_index);
116
117 AXTree* tree_ = nullptr;
118 AXNode* table_node_ = nullptr;
119 bool valid_ = false;
120 std::map<int, std::map<int, CellData>> incremental_row_col_map_;
121};
122
123} // namespace ui
124
125#endif // UI_ACCESSIBILITY_TABLE_INFO
static sk_sp< Effect > Create()
Definition: RefCntTest.cpp:117
#define AX_EXPORT
Definition: ax_export.h:29
std::vector< std::vector< int32_t > > col_headers
Definition: ax_table_info.h:59
std::vector< CellData > cell_data_vector
Definition: ax_table_info.h:77
bool valid() const
Definition: ax_table_info.h:47
std::vector< std::vector< int32_t > > cell_ids
Definition: ax_table_info.h:74
std::unordered_map< int32_t, size_t > row_id_to_index
Definition: ax_table_info.h:91
std::vector< AXNode * > extra_mac_nodes
Definition: ax_table_info.h:85
std::unordered_map< int32_t, size_t > cell_id_to_index
Definition: ax_table_info.h:88
std::vector< AXNode * > row_nodes
Definition: ax_table_info.h:94
std::vector< int32_t > all_headers
Definition: ax_table_info.h:65
std::vector< std::vector< int32_t > > row_headers
Definition: ax_table_info.h:62
int32_t caption_id
Definition: ax_table_info.h:68
std::vector< int32_t > unique_cell_ids
Definition: ax_table_info.h:80
const char * ToString(ax::mojom::Event event)
Definition: ax_enum_util.cc:9
def Update(force=False, no_download=False)