blob: 5a2288e1ec8870bf940720f13fb624565ffb442c [file] [log] [blame]
Avi Drissman3e1a26c2022-09-15 20:26:031// Copyright 2019 The Chromium Authors
Kurt Catti-Schmidtf738bce2019-05-08 01:06:562// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Nektarios Paisios70b6a5e52021-08-03 05:32:365#include "ui/accessibility/ax_text_attributes.h"
Kurt Catti-Schmidtf738bce2019-05-08 01:06:566
Kevin Ellis50039ca2024-09-23 14:00:307#include "ui/accessibility/ax_node_data.h"
8
Kurt Catti-Schmidtf738bce2019-05-08 01:06:569namespace ui {
Nektarios Paisiosc78cd722021-08-03 14:35:5210
Kevin Ellis50039ca2024-09-23 14:00:3011namespace {
12
13void UpdateProperty(ax::mojom::IntAttribute attribute,
14 const AXNodeData& node_data,
15 int* value) {
16 int maybe_value = node_data.GetIntAttribute(attribute);
17 if (maybe_value || node_data.HasIntAttribute(attribute)) {
18 *value = maybe_value;
19 }
20}
21
22void UpdateProperty(ax::mojom::FloatAttribute attribute,
23 const AXNodeData& node_data,
24 float* value) {
Jayson Adamsd464be32024-10-24 22:20:4425 float maybe_value = node_data.GetFloatAttribute(attribute);
Kevin Ellis50039ca2024-09-23 14:00:3026 if (maybe_value || node_data.HasFloatAttribute(attribute)) {
27 *value = maybe_value;
28 }
29}
30
31} // namespace
32
Nektarios Paisiosc78cd722021-08-03 14:35:5233AXTextAttributes::AXTextAttributes() = default;
34
35AXTextAttributes::~AXTextAttributes() = default;
Kurt Catti-Schmidtf738bce2019-05-08 01:06:5636
Kevin Ellis50039ca2024-09-23 14:00:3037AXTextAttributes::AXTextAttributes(const AXNodeData& node_data) {
38 UpdateProperty(ax::mojom::IntAttribute::kBackgroundColor, node_data,
39 &background_color);
40 UpdateProperty(ax::mojom::IntAttribute::kColor, node_data, &color);
41 UpdateProperty(ax::mojom::IntAttribute::kInvalidState, node_data,
42 &invalid_state);
43 UpdateProperty(ax::mojom::IntAttribute::kTextOverlineStyle, node_data,
44 &overline_style);
45 UpdateProperty(ax::mojom::IntAttribute::kTextDirection, node_data,
46 &text_direction);
47 UpdateProperty(ax::mojom::IntAttribute::kTextPosition, node_data,
48 &text_position);
49 UpdateProperty(ax::mojom::IntAttribute::kTextStrikethroughStyle, node_data,
50 &strikethrough_style);
51 UpdateProperty(ax::mojom::IntAttribute::kTextStyle, node_data, &text_style);
52 UpdateProperty(ax::mojom::IntAttribute::kTextUnderlineStyle, node_data,
53 &underline_style);
54 UpdateProperty(ax::mojom::FloatAttribute::kFontSize, node_data, &font_size);
55 UpdateProperty(ax::mojom::FloatAttribute::kFontWeight, node_data,
56 &font_weight);
57 font_family =
58 node_data.GetStringAttribute(ax::mojom::StringAttribute::kFontFamily);
59 marker_types =
60 node_data.GetIntListAttribute(ax::mojom::IntListAttribute::kMarkerTypes);
61 highlight_types = node_data.GetIntListAttribute(
62 ax::mojom::IntListAttribute::kHighlightTypes);
63}
64
Nektarios Paisios70b6a5e52021-08-03 05:32:3665AXTextAttributes::AXTextAttributes(AXTextAttributes&& other)
Kurt Catti-Schmidtf738bce2019-05-08 01:06:5666 : background_color(other.background_color),
67 color(other.color),
68 invalid_state(other.invalid_state),
69 overline_style(other.overline_style),
70 strikethrough_style(other.strikethrough_style),
71 text_direction(other.text_direction),
72 text_position(other.text_position),
73 text_style(other.text_style),
74 underline_style(other.underline_style),
75 font_size(other.font_size),
76 font_weight(other.font_weight),
Benjamin Beaudry6d656d362022-02-24 21:21:5577 font_family(std::move(other.font_family)),
78 marker_types(std::move(other.marker_types)),
79 highlight_types(std::move(other.highlight_types)) {}
Kurt Catti-Schmidtf738bce2019-05-08 01:06:5680
Nektarios Paisios70b6a5e52021-08-03 05:32:3681AXTextAttributes& AXTextAttributes::operator=(AXTextAttributes&& other) {
Nektarios Paisiosc78cd722021-08-03 14:35:5282 if (this == &other)
83 return *this;
84
Kurt Catti-Schmidtf738bce2019-05-08 01:06:5685 background_color = other.background_color;
86 color = other.color;
87 invalid_state = other.invalid_state;
88 overline_style = other.overline_style;
89 strikethrough_style = other.strikethrough_style;
90 text_direction = other.text_direction;
91 text_position = other.text_position;
92 text_style = other.text_style;
93 underline_style = other.underline_style;
94 font_size = other.font_size;
95 font_weight = other.font_weight;
96 font_family = other.font_family;
Benjamin Beaudry6d656d362022-02-24 21:21:5597 marker_types = other.marker_types;
98 highlight_types = other.highlight_types;
Kurt Catti-Schmidtf738bce2019-05-08 01:06:5699
100 return *this;
101}
102
Nektarios Paisios70b6a5e52021-08-03 05:32:36103bool AXTextAttributes::IsUnset() const {
Jayson Adamsd464be32024-10-24 22:20:44104 return background_color == kUnsetValue && color == kUnsetValue &&
105 invalid_state == kUnsetValue && overline_style == kUnsetValue &&
106 strikethrough_style == kUnsetValue && text_position == kUnsetValue &&
107 font_size == kUnsetValue && font_weight == kUnsetValue &&
108 text_style == kUnsetValue && underline_style == kUnsetValue &&
109 font_family.length() == 0 && marker_types.size() == 0 &&
110 highlight_types.size() == 0;
Kurt Catti-Schmidtf738bce2019-05-08 01:06:56111}
112
Sara Tang049c1432023-03-20 20:42:02113bool AXTextAttributes::HasTextStyle(
114 ax::mojom::TextStyle text_style_enum) const {
115 return text_style != kUnsetValue &&
116 (static_cast<uint32_t>(text_style) &
117 (1U << static_cast<uint32_t>(text_style_enum))) != 0;
118}
119
Kurt Catti-Schmidtf738bce2019-05-08 01:06:56120} // namespace ui