Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
compute_attributes.cc
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
6
7#include <cstddef>
8
9#include "ax/ax_enums.h"
10#include "ax/ax_node_data.h"
12
13namespace ui {
14namespace {
15
16std::optional<int32_t> GetCellAttribute(
17 const ui::AXPlatformNodeDelegate* delegate,
18 ax::mojom::IntAttribute attribute) {
19 switch (attribute) {
21 return delegate->GetTableCellAriaColIndex();
23 return delegate->GetTableCellAriaRowIndex();
25 return delegate->GetTableCellColIndex();
27 return delegate->GetTableCellRowIndex();
29 return delegate->GetTableCellColSpan();
31 return delegate->GetTableCellRowSpan();
32 default:
33 return std::nullopt;
34 }
35}
36
37std::optional<int32_t> GetRowAttribute(
38 const ui::AXPlatformNodeDelegate* delegate,
39 ax::mojom::IntAttribute attribute) {
41 return delegate->GetTableRowRowIndex();
42 }
43 return std::nullopt;
44}
45
46std::optional<int32_t> GetTableAttribute(
47 const ui::AXPlatformNodeDelegate* delegate,
48 ax::mojom::IntAttribute attribute) {
49 switch (attribute) {
51 return delegate->GetTableColCount();
53 return delegate->GetTableRowCount();
55 return delegate->GetTableAriaColCount();
57 return delegate->GetTableAriaRowCount();
58 default:
59 return std::nullopt;
60 }
61}
62
63std::optional<int> GetOrderedSetItemAttribute(
64 const ui::AXPlatformNodeDelegate* delegate,
65 ax::mojom::IntAttribute attribute) {
66 switch (attribute) {
68 return delegate->GetPosInSet();
70 return delegate->GetSetSize();
71 default:
72 return std::nullopt;
73 }
74}
75
76std::optional<int> GetOrderedSetAttribute(
77 const ui::AXPlatformNodeDelegate* delegate,
78 ax::mojom::IntAttribute attribute) {
79 switch (attribute) {
81 return delegate->GetSetSize();
82 default:
83 return std::nullopt;
84 }
85}
86
87std::optional<int32_t> GetFromData(const ui::AXPlatformNodeDelegate* delegate,
88 ax::mojom::IntAttribute attribute) {
89 int32_t value;
90 if (delegate->GetData().GetIntAttribute(attribute, &value)) {
91 return value;
92 }
93 return std::nullopt;
94}
95
96} // namespace
97
98std::optional<int32_t> ComputeAttribute(
99 const ui::AXPlatformNodeDelegate* delegate,
100 ax::mojom::IntAttribute attribute) {
101 std::optional<int32_t> maybe_value = std::nullopt;
102 // Table-related nodes.
103 if (delegate->IsTableCellOrHeader())
104 maybe_value = GetCellAttribute(delegate, attribute);
105 else if (delegate->IsTableRow())
106 maybe_value = GetRowAttribute(delegate, attribute);
107 else if (delegate->IsTable())
108 maybe_value = GetTableAttribute(delegate, attribute);
109 // Ordered-set-related nodes.
110 else if (delegate->IsOrderedSetItem())
111 maybe_value = GetOrderedSetItemAttribute(delegate, attribute);
112 else if (delegate->IsOrderedSet())
113 maybe_value = GetOrderedSetAttribute(delegate, attribute);
114
115 if (!maybe_value.has_value()) {
116 return GetFromData(delegate, attribute);
117 }
118 return maybe_value;
119}
120
121} // namespace ui
virtual bool IsOrderedSetItem() const =0
virtual std::optional< int > GetTableCellRowSpan() const =0
virtual std::optional< int > GetTableRowCount() const =0
virtual bool IsTable() const =0
virtual std::optional< int > GetTableCellAriaColIndex() const =0
virtual std::optional< int > GetSetSize() const =0
virtual std::optional< int > GetTableCellAriaRowIndex() const =0
virtual bool IsOrderedSet() const =0
virtual std::optional< int > GetTableCellRowIndex() const =0
virtual const AXNodeData & GetData() const =0
virtual std::optional< int > GetTableColCount() const =0
virtual std::optional< int > GetPosInSet() const =0
virtual bool IsTableCellOrHeader() const =0
virtual std::optional< int > GetTableRowRowIndex() const =0
virtual bool IsTableRow() const =0
virtual std::optional< int > GetTableAriaColCount() const =0
virtual std::optional< int > GetTableCellColIndex() const =0
virtual std::optional< int > GetTableCellColSpan() const =0
virtual std::optional< int > GetTableAriaRowCount() const =0
uint8_t value
std::optional< int32_t > ComputeAttribute(const ui::AXPlatformNodeDelegate *delegate, ax::mojom::IntAttribute attribute)
int GetIntAttribute(ax::mojom::IntAttribute attribute) const