Avi Drissman | 3e1a26c | 2022-09-15 20:26:03 | [diff] [blame] | 1 | // Copyright 2019 The Chromium Authors |
Kurt Catti-Schmidt | f738bce | 2019-05-08 01:06:56 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Nektarios Paisios | 70b6a5e5 | 2021-08-03 05:32:36 | [diff] [blame] | 5 | #include "ui/accessibility/ax_text_attributes.h" |
Kurt Catti-Schmidt | f738bce | 2019-05-08 01:06:56 | [diff] [blame] | 6 | |
Kevin Ellis | 50039ca | 2024-09-23 14:00:30 | [diff] [blame] | 7 | #include "ui/accessibility/ax_node_data.h" |
| 8 | |
Kurt Catti-Schmidt | f738bce | 2019-05-08 01:06:56 | [diff] [blame] | 9 | namespace ui { |
Nektarios Paisios | c78cd72 | 2021-08-03 14:35:52 | [diff] [blame] | 10 | |
Kevin Ellis | 50039ca | 2024-09-23 14:00:30 | [diff] [blame] | 11 | namespace { |
| 12 | |
| 13 | void 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 | |
| 22 | void UpdateProperty(ax::mojom::FloatAttribute attribute, |
| 23 | const AXNodeData& node_data, |
| 24 | float* value) { |
Jayson Adams | d464be3 | 2024-10-24 22:20:44 | [diff] [blame] | 25 | float maybe_value = node_data.GetFloatAttribute(attribute); |
Kevin Ellis | 50039ca | 2024-09-23 14:00:30 | [diff] [blame] | 26 | if (maybe_value || node_data.HasFloatAttribute(attribute)) { |
| 27 | *value = maybe_value; |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | } // namespace |
| 32 | |
Nektarios Paisios | c78cd72 | 2021-08-03 14:35:52 | [diff] [blame] | 33 | AXTextAttributes::AXTextAttributes() = default; |
| 34 | |
| 35 | AXTextAttributes::~AXTextAttributes() = default; |
Kurt Catti-Schmidt | f738bce | 2019-05-08 01:06:56 | [diff] [blame] | 36 | |
Kevin Ellis | 50039ca | 2024-09-23 14:00:30 | [diff] [blame] | 37 | AXTextAttributes::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 Paisios | 70b6a5e5 | 2021-08-03 05:32:36 | [diff] [blame] | 65 | AXTextAttributes::AXTextAttributes(AXTextAttributes&& other) |
Kurt Catti-Schmidt | f738bce | 2019-05-08 01:06:56 | [diff] [blame] | 66 | : 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 Beaudry | 6d656d36 | 2022-02-24 21:21:55 | [diff] [blame] | 77 | 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-Schmidt | f738bce | 2019-05-08 01:06:56 | [diff] [blame] | 80 | |
Nektarios Paisios | 70b6a5e5 | 2021-08-03 05:32:36 | [diff] [blame] | 81 | AXTextAttributes& AXTextAttributes::operator=(AXTextAttributes&& other) { |
Nektarios Paisios | c78cd72 | 2021-08-03 14:35:52 | [diff] [blame] | 82 | if (this == &other) |
| 83 | return *this; |
| 84 | |
Kurt Catti-Schmidt | f738bce | 2019-05-08 01:06:56 | [diff] [blame] | 85 | 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 Beaudry | 6d656d36 | 2022-02-24 21:21:55 | [diff] [blame] | 97 | marker_types = other.marker_types; |
| 98 | highlight_types = other.highlight_types; |
Kurt Catti-Schmidt | f738bce | 2019-05-08 01:06:56 | [diff] [blame] | 99 | |
| 100 | return *this; |
| 101 | } |
| 102 | |
Nektarios Paisios | 70b6a5e5 | 2021-08-03 05:32:36 | [diff] [blame] | 103 | bool AXTextAttributes::IsUnset() const { |
Jayson Adams | d464be3 | 2024-10-24 22:20:44 | [diff] [blame] | 104 | 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-Schmidt | f738bce | 2019-05-08 01:06:56 | [diff] [blame] | 111 | } |
| 112 | |
Sara Tang | 049c143 | 2023-03-20 20:42:02 | [diff] [blame] | 113 | bool 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-Schmidt | f738bce | 2019-05-08 01:06:56 | [diff] [blame] | 120 | } // namespace ui |