LibWeb: Port AriaData from DeprecatedString to String

This commit is contained in:
Shannon Booth 2023-11-20 21:59:45 +13:00 committed by Andreas Kling
parent 6c42de3e8b
commit c5d3ccca00
Notes: sideshowbarker 2024-07-17 02:35:27 +09:00
8 changed files with 86 additions and 86 deletions

View file

@ -64,18 +64,26 @@ bool ARIAMixin::has_global_aria_attribute() const
|| aria_role_description().has_value();
}
Optional<DeprecatedString> ARIAMixin::parse_id_reference(DeprecatedString const& id_reference) const
Optional<String> ARIAMixin::parse_id_reference(Optional<String> const& id_reference) const
{
if (id_reference_exists(id_reference))
return id_reference;
if (!id_reference.has_value())
return {};
if (id_reference_exists(id_reference.value()))
return id_reference.value();
return {};
}
Vector<DeprecatedString> ARIAMixin::parse_id_reference_list(DeprecatedString const& id_list) const
Vector<String> ARIAMixin::parse_id_reference_list(Optional<String> const& id_list) const
{
Vector<DeprecatedString> result;
auto id_references = id_list.split_view(Infra::is_ascii_whitespace);
for (auto const id_reference : id_references) {
Vector<String> result;
if (!id_list.has_value())
return result;
auto id_references = id_list->bytes_as_string_view().split_view_if(Infra::is_ascii_whitespace);
for (auto const id_reference_view : id_references) {
auto id_reference = MUST(String::from_utf8(id_reference_view));
if (id_reference_exists(id_reference))
result.append(id_reference);
}

View file

@ -6,7 +6,7 @@
#pragma once
#include <AK/DeprecatedString.h>
#include <AK/String.h>
#include <AK/Vector.h>
#include <LibWeb/ARIA/AriaData.h>
#include <LibWeb/ARIA/Roles.h>
@ -180,15 +180,15 @@ public:
bool has_global_aria_attribute() const;
// https://www.w3.org/TR/wai-aria-1.2/#valuetype_idref
Optional<DeprecatedString> parse_id_reference(DeprecatedString const&) const;
Optional<String> parse_id_reference(Optional<String> const&) const;
// https://www.w3.org/TR/wai-aria-1.2/#valuetype_idref_list
Vector<DeprecatedString> parse_id_reference_list(DeprecatedString const&) const;
Vector<String> parse_id_reference_list(Optional<String> const&) const;
protected:
ARIAMixin() = default;
virtual bool id_reference_exists(DeprecatedString const&) const = 0;
virtual bool id_reference_exists(String const&) const = 0;
};
}

View file

@ -1,5 +1,6 @@
/*
* Copyright (c) 2023, Jonah Shafran <jonahshafran@gmail.com>
* Copyright (c) 2023, Shannon Booth <shannon@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -9,16 +10,9 @@
namespace Web::ARIA {
static DeprecatedString to_deprecated_string(Optional<String> const& value)
{
if (!value.has_value())
return {};
return value->to_deprecated_string();
}
AriaData::AriaData(Web::ARIA::ARIAMixin const& source)
{
m_aria_active_descendant = to_deprecated_string(source.aria_active_descendant());
m_aria_active_descendant = source.aria_active_descendant();
m_aria_atomic = AriaData::parse_optional_true_false(source.aria_atomic());
m_aria_auto_complete = AriaData::parse_aria_autocomplete(source.aria_auto_complete());
m_aria_busy = AriaData::parse_true_false(source.aria_busy());
@ -26,36 +20,36 @@ AriaData::AriaData(Web::ARIA::ARIAMixin const& source)
m_aria_col_count = AriaData::parse_integer(source.aria_col_count());
m_aria_col_index = AriaData::parse_integer(source.aria_col_index());
m_aria_col_span = AriaData::parse_integer(source.aria_col_span());
m_aria_controls = source.parse_id_reference_list(to_deprecated_string(source.aria_controls()));
m_aria_controls = source.parse_id_reference_list(source.aria_controls());
m_aria_current = AriaData::parse_aria_current(source.aria_current());
m_aria_described_by = source.parse_id_reference_list(to_deprecated_string(source.aria_described_by()));
m_aria_details = source.parse_id_reference(to_deprecated_string(source.aria_details()));
m_aria_described_by = source.parse_id_reference_list(source.aria_described_by());
m_aria_details = source.parse_id_reference(source.aria_details());
m_aria_disabled = AriaData::parse_true_false(source.aria_disabled());
m_aria_drop_effect = AriaData::parse_aria_drop_effect(source.aria_drop_effect());
m_aria_error_message = source.parse_id_reference(to_deprecated_string(source.aria_error_message()));
m_aria_error_message = source.parse_id_reference(source.aria_error_message());
m_aria_expanded = AriaData::parse_true_false_undefined(source.aria_expanded());
m_aria_flow_to = source.parse_id_reference_list(to_deprecated_string(source.aria_flow_to()));
m_aria_flow_to = source.parse_id_reference_list(source.aria_flow_to());
m_aria_grabbed = AriaData::parse_true_false_undefined(source.aria_grabbed());
m_aria_has_popup = AriaData::parse_aria_has_popup(source.aria_has_popup());
m_aria_hidden = AriaData::parse_true_false_undefined(source.aria_hidden());
m_aria_invalid = AriaData::parse_aria_invalid(source.aria_invalid());
m_aria_key_shortcuts = to_deprecated_string(source.aria_key_shortcuts());
m_aria_label = to_deprecated_string(source.aria_label());
m_aria_labelled_by = source.parse_id_reference_list(to_deprecated_string(source.aria_labelled_by()));
m_aria_key_shortcuts = source.aria_key_shortcuts().value_or(String {});
m_aria_label = source.aria_label().value_or(String {});
m_aria_labelled_by = source.parse_id_reference_list(source.aria_labelled_by());
m_aria_level = AriaData::parse_integer(source.aria_level());
m_aria_live = AriaData::parse_aria_live(source.aria_live());
m_aria_modal = AriaData::parse_true_false(source.aria_modal());
m_aria_multi_line = AriaData::parse_true_false(source.aria_multi_line());
m_aria_multi_selectable = AriaData::parse_true_false(source.aria_multi_selectable());
m_aria_orientation = AriaData::parse_aria_orientation(source.aria_orientation());
m_aria_owns = source.parse_id_reference_list(to_deprecated_string(source.aria_owns()));
m_aria_placeholder = to_deprecated_string(source.aria_placeholder());
m_aria_owns = source.parse_id_reference_list(source.aria_owns());
m_aria_placeholder = source.aria_placeholder().value_or(String {});
m_aria_pos_in_set = AriaData::parse_integer(source.aria_pos_in_set());
m_aria_pressed = AriaData::parse_tristate(source.aria_pressed());
m_aria_read_only = AriaData::parse_true_false(source.aria_read_only());
m_aria_relevant = AriaData::parse_aria_relevant(source.aria_relevant());
m_aria_required = AriaData::parse_true_false(source.aria_required());
m_aria_role_description = to_deprecated_string(source.aria_role_description());
m_aria_role_description = source.aria_role_description().value_or(String {});
m_aria_row_count = AriaData::parse_integer(source.aria_row_count());
m_aria_row_index = AriaData::parse_integer(source.aria_row_index());
m_aria_row_span = AriaData::parse_integer(source.aria_row_span());
@ -65,7 +59,7 @@ AriaData::AriaData(Web::ARIA::ARIAMixin const& source)
m_aria_value_max = AriaData::parse_number(source.aria_value_max());
m_aria_value_min = AriaData::parse_number(source.aria_value_min());
m_aria_value_now = AriaData::parse_number(source.aria_value_now());
m_aria_value_text = to_deprecated_string(source.aria_value_text());
m_aria_value_text = source.aria_value_text().value_or(String {});
}
bool AriaData::parse_true_false(Optional<String> const& value)
@ -115,7 +109,7 @@ Optional<f64> AriaData::parse_number(Optional<String> const& value)
return value->bytes_as_string_view().to_double(TrimWhitespace::Yes);
}
Optional<DeprecatedString> AriaData::aria_active_descendant_or_default() const
Optional<String> AriaData::aria_active_descendant_or_default() const
{
return m_aria_active_descendant;
}
@ -158,7 +152,7 @@ Optional<i32> AriaData::aria_col_span_or_default() const
return m_aria_col_span;
}
Vector<DeprecatedString> AriaData::aria_controls_or_default() const
Vector<String> AriaData::aria_controls_or_default() const
{
return m_aria_controls;
}
@ -168,12 +162,12 @@ AriaCurrent AriaData::aria_current_or_default() const
return m_aria_current;
}
Vector<DeprecatedString> AriaData::aria_described_by_or_default() const
Vector<String> AriaData::aria_described_by_or_default() const
{
return m_aria_described_by;
}
Optional<DeprecatedString> AriaData::aria_details_or_default() const
Optional<String> AriaData::aria_details_or_default() const
{
return m_aria_details;
}
@ -188,7 +182,7 @@ Vector<AriaDropEffect> AriaData::aria_drop_effect_or_default() const
return m_aria_drop_effect;
}
Optional<DeprecatedString> AriaData::aria_error_message_or_default() const
Optional<String> AriaData::aria_error_message_or_default() const
{
return m_aria_error_message;
}
@ -198,7 +192,7 @@ Optional<bool> AriaData::aria_expanded_or_default() const
return m_aria_expanded;
}
Vector<DeprecatedString> AriaData::aria_flow_to_or_default() const
Vector<String> AriaData::aria_flow_to_or_default() const
{
return m_aria_flow_to;
}
@ -223,17 +217,17 @@ AriaInvalid AriaData::aria_invalid_or_default() const
return m_aria_invalid;
}
DeprecatedString AriaData::aria_key_shortcuts_or_default() const
String AriaData::aria_key_shortcuts_or_default() const
{
return m_aria_key_shortcuts;
}
DeprecatedString AriaData::aria_label_or_default() const
String AriaData::aria_label_or_default() const
{
return m_aria_label;
}
Vector<DeprecatedString> AriaData::aria_labelled_by_or_default() const
Vector<String> AriaData::aria_labelled_by_or_default() const
{
return m_aria_labelled_by;
}
@ -276,12 +270,12 @@ AriaOrientation AriaData::aria_orientation_or_default(AriaOrientation default_va
return value.value();
}
Vector<DeprecatedString> AriaData::aria_owns_or_default() const
Vector<String> AriaData::aria_owns_or_default() const
{
return m_aria_owns;
}
DeprecatedString AriaData::aria_placeholder_or_default() const
String AriaData::aria_placeholder_or_default() const
{
return m_aria_placeholder;
}
@ -311,7 +305,7 @@ bool AriaData::aria_required_or_default() const
return m_aria_required;
}
DeprecatedString AriaData::aria_role_description_or_default() const
String AriaData::aria_role_description_or_default() const
{
return m_aria_role_description;
}
@ -367,7 +361,7 @@ Optional<f64> AriaData::aria_value_now_or_default() const
return m_aria_value_now;
}
DeprecatedString AriaData::aria_value_text_or_default() const
String AriaData::aria_value_text_or_default() const
{
return m_aria_value_text;
}

View file

@ -151,7 +151,7 @@ public:
static ErrorOr<NonnullOwnPtr<AriaData>> build_data(ARIAMixin const& mixin) { return adopt_nonnull_own_or_enomem(new (nothrow) AriaData(mixin)); }
Optional<DeprecatedString> aria_active_descendant_or_default() const;
Optional<String> aria_active_descendant_or_default() const;
bool aria_atomic_or_default(bool default_value = false) const;
AriaAutocomplete aria_auto_complete_or_default() const;
bool aria_busy_or_default() const;
@ -159,36 +159,36 @@ public:
Optional<i32> aria_col_count_or_default() const;
Optional<i32> aria_col_index_or_default() const;
Optional<i32> aria_col_span_or_default() const;
Vector<DeprecatedString> aria_controls_or_default() const;
Vector<String> aria_controls_or_default() const;
AriaCurrent aria_current_or_default() const;
Vector<DeprecatedString> aria_described_by_or_default() const;
Optional<DeprecatedString> aria_details_or_default() const;
Vector<String> aria_described_by_or_default() const;
Optional<String> aria_details_or_default() const;
bool aria_disabled_or_default() const;
Vector<AriaDropEffect> aria_drop_effect_or_default() const;
Optional<DeprecatedString> aria_error_message_or_default() const;
Optional<String> aria_error_message_or_default() const;
Optional<bool> aria_expanded_or_default() const;
Vector<DeprecatedString> aria_flow_to_or_default() const;
Vector<String> aria_flow_to_or_default() const;
Optional<bool> aria_grabbed_or_default() const;
AriaHasPopup aria_has_popup_or_default() const;
Optional<bool> aria_hidden_or_default() const;
AriaInvalid aria_invalid_or_default() const;
DeprecatedString aria_key_shortcuts_or_default() const;
DeprecatedString aria_label_or_default() const;
Vector<DeprecatedString> aria_labelled_by_or_default() const;
String aria_key_shortcuts_or_default() const;
String aria_label_or_default() const;
Vector<String> aria_labelled_by_or_default() const;
Optional<i32> aria_level_or_default() const;
AriaLive aria_live_or_default(AriaLive default_value = AriaLive::Off) const;
bool aria_modal_or_default() const;
bool aria_multi_line_or_default() const;
bool aria_multi_selectable_or_default() const;
AriaOrientation aria_orientation_or_default(AriaOrientation default_value = AriaOrientation::Undefined) const;
Vector<DeprecatedString> aria_owns_or_default() const;
DeprecatedString aria_placeholder_or_default() const;
Vector<String> aria_owns_or_default() const;
String aria_placeholder_or_default() const;
Optional<i32> aria_pos_in_set_or_default() const;
Tristate aria_pressed_or_default() const;
bool aria_read_only_or_default() const;
Vector<AriaRelevant> aria_relevant_or_default() const;
bool aria_required_or_default() const;
DeprecatedString aria_role_description_or_default() const;
String aria_role_description_or_default() const;
Optional<i32> aria_row_count_or_default() const;
Optional<i32> aria_row_index_or_default() const;
Optional<i32> aria_row_span_or_default() const;
@ -198,7 +198,7 @@ public:
Optional<f64> aria_value_max_or_default(Optional<f64> default_value = {}) const;
Optional<f64> aria_value_min_or_default(Optional<f64> default_value = {}) const;
Optional<f64> aria_value_now_or_default() const;
DeprecatedString aria_value_text_or_default() const;
String aria_value_text_or_default() const;
private:
explicit AriaData(ARIAMixin const&);
@ -232,7 +232,7 @@ private:
static AriaSort parse_aria_sort(Optional<String> const&);
static Optional<bool> parse_optional_true_false(Optional<String> const&);
Optional<DeprecatedString> m_aria_active_descendant;
Optional<String> m_aria_active_descendant;
Optional<bool> m_aria_atomic;
AriaAutocomplete m_aria_auto_complete;
bool m_aria_busy;
@ -240,36 +240,36 @@ private:
Optional<i32> m_aria_col_count;
Optional<i32> m_aria_col_index;
Optional<i32> m_aria_col_span;
Vector<DeprecatedString> m_aria_controls;
Vector<String> m_aria_controls;
AriaCurrent m_aria_current;
Vector<DeprecatedString> m_aria_described_by;
Optional<DeprecatedString> m_aria_details;
Vector<String> m_aria_described_by;
Optional<String> m_aria_details;
bool m_aria_disabled;
Vector<AriaDropEffect> m_aria_drop_effect;
Optional<DeprecatedString> m_aria_error_message;
Optional<String> m_aria_error_message;
Optional<bool> m_aria_expanded;
Vector<DeprecatedString> m_aria_flow_to;
Vector<String> m_aria_flow_to;
Optional<bool> m_aria_grabbed;
AriaHasPopup m_aria_has_popup;
Optional<bool> m_aria_hidden;
AriaInvalid m_aria_invalid;
DeprecatedString m_aria_key_shortcuts;
DeprecatedString m_aria_label;
Vector<DeprecatedString> m_aria_labelled_by;
String m_aria_key_shortcuts;
String m_aria_label;
Vector<String> m_aria_labelled_by;
Optional<i32> m_aria_level;
Optional<AriaLive> m_aria_live;
bool m_aria_modal;
bool m_aria_multi_line;
bool m_aria_multi_selectable;
Optional<AriaOrientation> m_aria_orientation;
Vector<DeprecatedString> m_aria_owns;
DeprecatedString m_aria_placeholder;
Vector<String> m_aria_owns;
String m_aria_placeholder;
Optional<i32> m_aria_pos_in_set;
Tristate m_aria_pressed;
bool m_aria_read_only;
Vector<AriaRelevant> m_aria_relevant;
bool m_aria_required;
DeprecatedString m_aria_role_description;
String m_aria_role_description;
Optional<i32> m_aria_row_count;
Optional<i32> m_aria_row_index;
Optional<i32> m_aria_row_span;
@ -279,7 +279,7 @@ private:
Optional<f64> m_aria_value_max;
Optional<f64> m_aria_value_min;
Optional<f64> m_aria_value_now;
DeprecatedString m_aria_value_text;
String m_aria_value_text;
};
}

View file

@ -13,8 +13,7 @@ ErrorOr<String> state_or_property_to_string_value(StateAndProperties state_or_pr
{
switch (state_or_property) {
case StateAndProperties::AriaActiveDescendant: {
auto value = aria_data.aria_active_descendant_or_default();
return value.has_value() ? String::from_deprecated_string(value.value()) : String::from_utf8(""sv);
return aria_data.aria_active_descendant_or_default().value_or(String {});
}
case StateAndProperties::AriaAtomic: {
bool value;
@ -73,8 +72,7 @@ ErrorOr<String> state_or_property_to_string_value(StateAndProperties state_or_pr
case StateAndProperties::AriaDescribedBy:
return id_reference_list_to_string(aria_data.aria_described_by_or_default());
case StateAndProperties::AriaDetails: {
auto value = aria_data.aria_details_or_default();
return value.has_value() ? String::from_deprecated_string(value.value()) : String::from_utf8(""sv);
return aria_data.aria_details_or_default().value_or(String {});
}
case StateAndProperties::AriaDisabled:
return aria_data.aria_disabled_or_default() ? "true"_string : "false"_string;
@ -113,8 +111,7 @@ ErrorOr<String> state_or_property_to_string_value(StateAndProperties state_or_pr
return builder.to_string();
}
case StateAndProperties::AriaErrorMessage: {
auto value = aria_data.aria_error_message_or_default();
return value.has_value() ? String::from_deprecated_string(value.value()) : String {};
return aria_data.aria_error_message_or_default().value_or(String {});
}
case StateAndProperties::AriaExpanded:
return ARIA::optional_bool_to_string(aria_data.aria_expanded_or_default());
@ -159,9 +156,9 @@ ErrorOr<String> state_or_property_to_string_value(StateAndProperties state_or_pr
VERIFY_NOT_REACHED();
}
case StateAndProperties::AriaKeyShortcuts:
return String::from_deprecated_string(aria_data.aria_key_shortcuts_or_default());
return aria_data.aria_key_shortcuts_or_default();
case StateAndProperties::AriaLabel:
return String::from_deprecated_string(aria_data.aria_label_or_default());
return aria_data.aria_label_or_default();
case StateAndProperties::AriaLabelledBy:
return id_reference_list_to_string(aria_data.aria_labelled_by_or_default());
case StateAndProperties::AriaLevel:
@ -209,7 +206,7 @@ ErrorOr<String> state_or_property_to_string_value(StateAndProperties state_or_pr
case StateAndProperties::AriaOwns:
return id_reference_list_to_string(aria_data.aria_owns_or_default());
case StateAndProperties::AriaPlaceholder:
return String::from_deprecated_string(aria_data.aria_placeholder_or_default());
return aria_data.aria_placeholder_or_default();
case StateAndProperties::AriaPosInSet:
return ARIA::optional_integer_to_string(aria_data.aria_pos_in_set_or_default());
case StateAndProperties::AriaPressed:
@ -250,7 +247,7 @@ ErrorOr<String> state_or_property_to_string_value(StateAndProperties state_or_pr
case StateAndProperties::AriaRequired:
return String::from_utf8(aria_data.aria_required_or_default() ? "true"sv : "false"sv);
case StateAndProperties::AriaRoleDescription:
return String::from_deprecated_string(aria_data.aria_role_description_or_default());
return aria_data.aria_role_description_or_default();
case StateAndProperties::AriaRowCount:
return ARIA::optional_integer_to_string(aria_data.aria_row_count_or_default());
case StateAndProperties::AriaRowIndex:
@ -288,7 +285,7 @@ ErrorOr<String> state_or_property_to_string_value(StateAndProperties state_or_pr
case StateAndProperties::AriaValueNow:
return ARIA::optional_number_to_string(aria_data.aria_value_now_or_default());
case StateAndProperties::AriaValueText:
return String::from_deprecated_string(aria_data.aria_value_text_or_default());
return aria_data.aria_value_text_or_default();
}
VERIFY_NOT_REACHED();
}
@ -330,7 +327,8 @@ ErrorOr<String> optional_number_to_string(Optional<f64> value)
return "undefined"_string;
return String::number(value.value());
}
ErrorOr<String> id_reference_list_to_string(Vector<DeprecatedString> const& value)
ErrorOr<String> id_reference_list_to_string(Vector<String> const& value)
{
StringBuilder builder;
for (auto const& id : value) {

View file

@ -69,7 +69,7 @@ ErrorOr<String> tristate_to_string(Tristate);
ErrorOr<String> optional_integer_to_string(Optional<i32>);
ErrorOr<String> optional_bool_to_string(Optional<bool>);
ErrorOr<String> optional_number_to_string(Optional<f64>);
ErrorOr<String> id_reference_list_to_string(Vector<DeprecatedString> const&);
ErrorOr<String> id_reference_list_to_string(Vector<String> const&);
StringView state_or_property_to_string(StateAndProperties);
}

View file

@ -2062,9 +2062,9 @@ void Element::scroll(HTML::ScrollToOptions const&)
dbgln("FIXME: Implement Element::scroll(ScrollToOptions)");
}
bool Element::id_reference_exists(DeprecatedString const& id_reference) const
bool Element::id_reference_exists(String const& id_reference) const
{
return document().get_element_by_id(MUST(FlyString::from_deprecated_fly_string(id_reference)));
return document().get_element_by_id(id_reference);
}
void Element::register_intersection_observer(Badge<IntersectionObserver::IntersectionObserver>, IntersectionObserver::IntersectionObserverRegistration registration)

View file

@ -381,7 +381,7 @@ protected:
virtual void visit_edges(Cell::Visitor&) override;
virtual bool id_reference_exists(DeprecatedString const&) const override;
virtual bool id_reference_exists(String const&) const override;
private:
void make_html_uppercased_qualified_name();