From 4321606bbae895eb3a505e683e0f42119896e1ae Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Fri, 6 Oct 2023 07:43:52 +1300 Subject: [PATCH] LibWeb: Port Element interface from DeprecatedString This is the last IDL interface which was using DeprecatedString! :^) --- Userland/Libraries/LibWeb/ARIA/ARIAMixin.cpp | 49 +++-- Userland/Libraries/LibWeb/ARIA/ARIAMixin.h | 196 +++++++++--------- Userland/Libraries/LibWeb/ARIA/AriaData.cpp | 81 +++++--- Userland/Libraries/LibWeb/ARIA/AriaData.h | 30 +-- Userland/Libraries/LibWeb/DOM/Element.cpp | 57 ++--- Userland/Libraries/LibWeb/DOM/Element.h | 48 +++-- Userland/Libraries/LibWeb/DOM/Element.idl | 10 +- .../Libraries/LibWeb/DOM/ElementFactory.cpp | 5 +- Userland/Libraries/LibWeb/DOM/Node.cpp | 56 ++--- Userland/Libraries/LibWeb/DOM/ParentNode.cpp | 6 +- .../LibWeb/HTML/HTMLHeadingElement.h | 4 +- .../LibWeb/HTML/Parser/HTMLParser.cpp | 4 +- 12 files changed, 295 insertions(+), 251 deletions(-) diff --git a/Userland/Libraries/LibWeb/ARIA/ARIAMixin.cpp b/Userland/Libraries/LibWeb/ARIA/ARIAMixin.cpp index 20989c091b0..1b1d06cce02 100644 --- a/Userland/Libraries/LibWeb/ARIA/ARIAMixin.cpp +++ b/Userland/Libraries/LibWeb/ARIA/ARIAMixin.cpp @@ -14,10 +14,13 @@ namespace Web::ARIA { Optional ARIAMixin::role_or_default() const { // 1. Use the rules of the host language to detect that an element has a role attribute and to identify the attribute value string for it. - auto role_string = role(); + auto maybe_role_string = role(); + if (!maybe_role_string.has_value()) + return default_role(); // 2. Separate the attribute value string for that attribute into a sequence of whitespace-free substrings by separating on whitespace. - auto role_list = role_string.split_view(Infra::is_ascii_whitespace); + auto role_string = maybe_role_string.value(); + auto role_list = role_string.bytes_as_string_view().split_view_if(Infra::is_ascii_whitespace); // 3. Compare the substrings to all the names of the non-abstract WAI-ARIA roles. Case-sensitivity of the comparison inherits from the case-sensitivity of the host language. for (auto const& role_name : role_list) { @@ -38,27 +41,27 @@ Optional ARIAMixin::role_or_default() const // https://www.w3.org/TR/wai-aria-1.2/#global_states bool ARIAMixin::has_global_aria_attribute() const { - return !aria_atomic().is_null() - || !aria_busy().is_null() - || !aria_controls().is_null() - || !aria_current().is_null() - || !aria_described_by().is_null() - || !aria_details().is_null() - || !aria_disabled().is_null() - || !aria_drop_effect().is_null() - || !aria_error_message().is_null() - || !aria_flow_to().is_null() - || !aria_grabbed().is_null() - || !aria_has_popup().is_null() - || !aria_hidden().is_null() - || !aria_invalid().is_null() - || !aria_key_shortcuts().is_null() - || !aria_label().is_null() - || !aria_labelled_by().is_null() - || !aria_live().is_null() - || !aria_owns().is_null() - || !aria_relevant().is_null() - || !aria_role_description().is_null(); + return aria_atomic().has_value() + || aria_busy().has_value() + || aria_controls().has_value() + || aria_current().has_value() + || aria_described_by().has_value() + || aria_details().has_value() + || aria_disabled().has_value() + || aria_drop_effect().has_value() + || aria_error_message().has_value() + || aria_flow_to().has_value() + || aria_grabbed().has_value() + || aria_has_popup().has_value() + || aria_hidden().has_value() + || aria_invalid().has_value() + || aria_key_shortcuts().has_value() + || aria_label().has_value() + || aria_labelled_by().has_value() + || aria_live().has_value() + || aria_owns().has_value() + || aria_relevant().has_value() + || aria_role_description().has_value(); } Optional ARIAMixin::parse_id_reference(DeprecatedString const& id_reference) const diff --git a/Userland/Libraries/LibWeb/ARIA/ARIAMixin.h b/Userland/Libraries/LibWeb/ARIA/ARIAMixin.h index 8b9b06a9c15..1fe70f7531b 100644 --- a/Userland/Libraries/LibWeb/ARIA/ARIAMixin.h +++ b/Userland/Libraries/LibWeb/ARIA/ARIAMixin.h @@ -19,152 +19,152 @@ class ARIAMixin { public: virtual ~ARIAMixin() = default; - virtual DeprecatedString role() const = 0; - virtual WebIDL::ExceptionOr set_role(DeprecatedString const&) = 0; + virtual Optional role() const = 0; + virtual WebIDL::ExceptionOr set_role(Optional const&) = 0; - virtual DeprecatedString aria_active_descendant() const = 0; - virtual WebIDL::ExceptionOr set_aria_active_descendant(DeprecatedString const&) = 0; + virtual Optional aria_active_descendant() const = 0; + virtual WebIDL::ExceptionOr set_aria_active_descendant(Optional const&) = 0; - virtual DeprecatedString aria_atomic() const = 0; - virtual WebIDL::ExceptionOr set_aria_atomic(DeprecatedString const&) = 0; + virtual Optional aria_atomic() const = 0; + virtual WebIDL::ExceptionOr set_aria_atomic(Optional const&) = 0; - virtual DeprecatedString aria_auto_complete() const = 0; - virtual WebIDL::ExceptionOr set_aria_auto_complete(DeprecatedString const&) = 0; + virtual Optional aria_auto_complete() const = 0; + virtual WebIDL::ExceptionOr set_aria_auto_complete(Optional const&) = 0; - virtual DeprecatedString aria_busy() const = 0; - virtual WebIDL::ExceptionOr set_aria_busy(DeprecatedString const&) = 0; + virtual Optional aria_busy() const = 0; + virtual WebIDL::ExceptionOr set_aria_busy(Optional const&) = 0; - virtual DeprecatedString aria_checked() const = 0; - virtual WebIDL::ExceptionOr set_aria_checked(DeprecatedString const&) = 0; + virtual Optional aria_checked() const = 0; + virtual WebIDL::ExceptionOr set_aria_checked(Optional const&) = 0; - virtual DeprecatedString aria_col_count() const = 0; - virtual WebIDL::ExceptionOr set_aria_col_count(DeprecatedString const&) = 0; + virtual Optional aria_col_count() const = 0; + virtual WebIDL::ExceptionOr set_aria_col_count(Optional const&) = 0; - virtual DeprecatedString aria_col_index() const = 0; - virtual WebIDL::ExceptionOr set_aria_col_index(DeprecatedString const&) = 0; + virtual Optional aria_col_index() const = 0; + virtual WebIDL::ExceptionOr set_aria_col_index(Optional const&) = 0; - virtual DeprecatedString aria_col_span() const = 0; - virtual WebIDL::ExceptionOr set_aria_col_span(DeprecatedString const&) = 0; + virtual Optional aria_col_span() const = 0; + virtual WebIDL::ExceptionOr set_aria_col_span(Optional const&) = 0; - virtual DeprecatedString aria_controls() const = 0; - virtual WebIDL::ExceptionOr set_aria_controls(DeprecatedString const&) = 0; + virtual Optional aria_controls() const = 0; + virtual WebIDL::ExceptionOr set_aria_controls(Optional const&) = 0; - virtual DeprecatedString aria_current() const = 0; - virtual WebIDL::ExceptionOr set_aria_current(DeprecatedString const&) = 0; + virtual Optional aria_current() const = 0; + virtual WebIDL::ExceptionOr set_aria_current(Optional const&) = 0; - virtual DeprecatedString aria_described_by() const = 0; - virtual WebIDL::ExceptionOr set_aria_described_by(DeprecatedString const&) = 0; + virtual Optional aria_described_by() const = 0; + virtual WebIDL::ExceptionOr set_aria_described_by(Optional const&) = 0; - virtual DeprecatedString aria_details() const = 0; - virtual WebIDL::ExceptionOr set_aria_details(DeprecatedString const&) = 0; + virtual Optional aria_details() const = 0; + virtual WebIDL::ExceptionOr set_aria_details(Optional const&) = 0; - virtual DeprecatedString aria_disabled() const = 0; - virtual WebIDL::ExceptionOr set_aria_disabled(DeprecatedString const&) = 0; + virtual Optional aria_disabled() const = 0; + virtual WebIDL::ExceptionOr set_aria_disabled(Optional const&) = 0; - virtual DeprecatedString aria_drop_effect() const = 0; - virtual WebIDL::ExceptionOr set_aria_drop_effect(DeprecatedString const&) = 0; + virtual Optional aria_drop_effect() const = 0; + virtual WebIDL::ExceptionOr set_aria_drop_effect(Optional const&) = 0; - virtual DeprecatedString aria_error_message() const = 0; - virtual WebIDL::ExceptionOr set_aria_error_message(DeprecatedString const&) = 0; + virtual Optional aria_error_message() const = 0; + virtual WebIDL::ExceptionOr set_aria_error_message(Optional const&) = 0; - virtual DeprecatedString aria_expanded() const = 0; - virtual WebIDL::ExceptionOr set_aria_expanded(DeprecatedString const&) = 0; + virtual Optional aria_expanded() const = 0; + virtual WebIDL::ExceptionOr set_aria_expanded(Optional const&) = 0; - virtual DeprecatedString aria_flow_to() const = 0; - virtual WebIDL::ExceptionOr set_aria_flow_to(DeprecatedString const&) = 0; + virtual Optional aria_flow_to() const = 0; + virtual WebIDL::ExceptionOr set_aria_flow_to(Optional const&) = 0; - virtual DeprecatedString aria_grabbed() const = 0; - virtual WebIDL::ExceptionOr set_aria_grabbed(DeprecatedString const&) = 0; + virtual Optional aria_grabbed() const = 0; + virtual WebIDL::ExceptionOr set_aria_grabbed(Optional const&) = 0; - virtual DeprecatedString aria_has_popup() const = 0; - virtual WebIDL::ExceptionOr set_aria_has_popup(DeprecatedString const&) = 0; + virtual Optional aria_has_popup() const = 0; + virtual WebIDL::ExceptionOr set_aria_has_popup(Optional const&) = 0; - virtual DeprecatedString aria_hidden() const = 0; - virtual WebIDL::ExceptionOr set_aria_hidden(DeprecatedString const&) = 0; + virtual Optional aria_hidden() const = 0; + virtual WebIDL::ExceptionOr set_aria_hidden(Optional const&) = 0; - virtual DeprecatedString aria_invalid() const = 0; - virtual WebIDL::ExceptionOr set_aria_invalid(DeprecatedString const&) = 0; + virtual Optional aria_invalid() const = 0; + virtual WebIDL::ExceptionOr set_aria_invalid(Optional const&) = 0; - virtual DeprecatedString aria_key_shortcuts() const = 0; - virtual WebIDL::ExceptionOr set_aria_key_shortcuts(DeprecatedString const&) = 0; + virtual Optional aria_key_shortcuts() const = 0; + virtual WebIDL::ExceptionOr set_aria_key_shortcuts(Optional const&) = 0; - virtual DeprecatedString aria_label() const = 0; - virtual WebIDL::ExceptionOr set_aria_label(DeprecatedString const&) = 0; + virtual Optional aria_label() const = 0; + virtual WebIDL::ExceptionOr set_aria_label(Optional const&) = 0; - virtual DeprecatedString aria_labelled_by() const = 0; - virtual WebIDL::ExceptionOr set_aria_labelled_by(DeprecatedString const&) = 0; + virtual Optional aria_labelled_by() const = 0; + virtual WebIDL::ExceptionOr set_aria_labelled_by(Optional const&) = 0; - virtual DeprecatedString aria_level() const = 0; - virtual WebIDL::ExceptionOr set_aria_level(DeprecatedString const&) = 0; + virtual Optional aria_level() const = 0; + virtual WebIDL::ExceptionOr set_aria_level(Optional const&) = 0; - virtual DeprecatedString aria_live() const = 0; - virtual WebIDL::ExceptionOr set_aria_live(DeprecatedString const&) = 0; + virtual Optional aria_live() const = 0; + virtual WebIDL::ExceptionOr set_aria_live(Optional const&) = 0; - virtual DeprecatedString aria_modal() const = 0; - virtual WebIDL::ExceptionOr set_aria_modal(DeprecatedString const&) = 0; + virtual Optional aria_modal() const = 0; + virtual WebIDL::ExceptionOr set_aria_modal(Optional const&) = 0; - virtual DeprecatedString aria_multi_line() const = 0; - virtual WebIDL::ExceptionOr set_aria_multi_line(DeprecatedString const&) = 0; + virtual Optional aria_multi_line() const = 0; + virtual WebIDL::ExceptionOr set_aria_multi_line(Optional const&) = 0; - virtual DeprecatedString aria_multi_selectable() const = 0; - virtual WebIDL::ExceptionOr set_aria_multi_selectable(DeprecatedString const&) = 0; + virtual Optional aria_multi_selectable() const = 0; + virtual WebIDL::ExceptionOr set_aria_multi_selectable(Optional const&) = 0; - virtual DeprecatedString aria_orientation() const = 0; - virtual WebIDL::ExceptionOr set_aria_orientation(DeprecatedString const&) = 0; + virtual Optional aria_orientation() const = 0; + virtual WebIDL::ExceptionOr set_aria_orientation(Optional const&) = 0; - virtual DeprecatedString aria_owns() const = 0; - virtual WebIDL::ExceptionOr set_aria_owns(DeprecatedString const&) = 0; + virtual Optional aria_owns() const = 0; + virtual WebIDL::ExceptionOr set_aria_owns(Optional const&) = 0; - virtual DeprecatedString aria_placeholder() const = 0; - virtual WebIDL::ExceptionOr set_aria_placeholder(DeprecatedString const&) = 0; + virtual Optional aria_placeholder() const = 0; + virtual WebIDL::ExceptionOr set_aria_placeholder(Optional const&) = 0; - virtual DeprecatedString aria_pos_in_set() const = 0; - virtual WebIDL::ExceptionOr set_aria_pos_in_set(DeprecatedString const&) = 0; + virtual Optional aria_pos_in_set() const = 0; + virtual WebIDL::ExceptionOr set_aria_pos_in_set(Optional const&) = 0; - virtual DeprecatedString aria_pressed() const = 0; - virtual WebIDL::ExceptionOr set_aria_pressed(DeprecatedString const&) = 0; + virtual Optional aria_pressed() const = 0; + virtual WebIDL::ExceptionOr set_aria_pressed(Optional const&) = 0; - virtual DeprecatedString aria_read_only() const = 0; - virtual WebIDL::ExceptionOr set_aria_read_only(DeprecatedString const&) = 0; + virtual Optional aria_read_only() const = 0; + virtual WebIDL::ExceptionOr set_aria_read_only(Optional const&) = 0; - virtual DeprecatedString aria_relevant() const = 0; - virtual WebIDL::ExceptionOr set_aria_relevant(DeprecatedString const&) = 0; + virtual Optional aria_relevant() const = 0; + virtual WebIDL::ExceptionOr set_aria_relevant(Optional const&) = 0; - virtual DeprecatedString aria_required() const = 0; - virtual WebIDL::ExceptionOr set_aria_required(DeprecatedString const&) = 0; + virtual Optional aria_required() const = 0; + virtual WebIDL::ExceptionOr set_aria_required(Optional const&) = 0; - virtual DeprecatedString aria_role_description() const = 0; - virtual WebIDL::ExceptionOr set_aria_role_description(DeprecatedString const&) = 0; + virtual Optional aria_role_description() const = 0; + virtual WebIDL::ExceptionOr set_aria_role_description(Optional const&) = 0; - virtual DeprecatedString aria_row_count() const = 0; - virtual WebIDL::ExceptionOr set_aria_row_count(DeprecatedString const&) = 0; + virtual Optional aria_row_count() const = 0; + virtual WebIDL::ExceptionOr set_aria_row_count(Optional const&) = 0; - virtual DeprecatedString aria_row_index() const = 0; - virtual WebIDL::ExceptionOr set_aria_row_index(DeprecatedString const&) = 0; + virtual Optional aria_row_index() const = 0; + virtual WebIDL::ExceptionOr set_aria_row_index(Optional const&) = 0; - virtual DeprecatedString aria_row_span() const = 0; - virtual WebIDL::ExceptionOr set_aria_row_span(DeprecatedString const&) = 0; + virtual Optional aria_row_span() const = 0; + virtual WebIDL::ExceptionOr set_aria_row_span(Optional const&) = 0; - virtual DeprecatedString aria_selected() const = 0; - virtual WebIDL::ExceptionOr set_aria_selected(DeprecatedString const&) = 0; + virtual Optional aria_selected() const = 0; + virtual WebIDL::ExceptionOr set_aria_selected(Optional const&) = 0; - virtual DeprecatedString aria_set_size() const = 0; - virtual WebIDL::ExceptionOr set_aria_set_size(DeprecatedString const&) = 0; + virtual Optional aria_set_size() const = 0; + virtual WebIDL::ExceptionOr set_aria_set_size(Optional const&) = 0; - virtual DeprecatedString aria_sort() const = 0; - virtual WebIDL::ExceptionOr set_aria_sort(DeprecatedString const&) = 0; + virtual Optional aria_sort() const = 0; + virtual WebIDL::ExceptionOr set_aria_sort(Optional const&) = 0; - virtual DeprecatedString aria_value_max() const = 0; - virtual WebIDL::ExceptionOr set_aria_value_max(DeprecatedString const&) = 0; + virtual Optional aria_value_max() const = 0; + virtual WebIDL::ExceptionOr set_aria_value_max(Optional const&) = 0; - virtual DeprecatedString aria_value_min() const = 0; - virtual WebIDL::ExceptionOr set_aria_value_min(DeprecatedString const&) = 0; + virtual Optional aria_value_min() const = 0; + virtual WebIDL::ExceptionOr set_aria_value_min(Optional const&) = 0; - virtual DeprecatedString aria_value_now() const = 0; - virtual WebIDL::ExceptionOr set_aria_value_now(DeprecatedString const&) = 0; + virtual Optional aria_value_now() const = 0; + virtual WebIDL::ExceptionOr set_aria_value_now(Optional const&) = 0; - virtual DeprecatedString aria_value_text() const = 0; - virtual WebIDL::ExceptionOr set_aria_value_text(DeprecatedString const&) = 0; + virtual Optional aria_value_text() const = 0; + virtual WebIDL::ExceptionOr set_aria_value_text(Optional const&) = 0; // https://www.w3.org/TR/html-aria/#docconformance virtual Optional default_role() const { return {}; } diff --git a/Userland/Libraries/LibWeb/ARIA/AriaData.cpp b/Userland/Libraries/LibWeb/ARIA/AriaData.cpp index 5baccad4efd..4a80db90568 100644 --- a/Userland/Libraries/LibWeb/ARIA/AriaData.cpp +++ b/Userland/Libraries/LibWeb/ARIA/AriaData.cpp @@ -9,9 +9,16 @@ namespace Web::ARIA { +static DeprecatedString to_deprecated_string(Optional const& value) +{ + if (!value.has_value()) + return {}; + return value->to_deprecated_string(); +} + AriaData::AriaData(Web::ARIA::ARIAMixin const& source) { - m_aria_active_descendant = source.aria_active_descendant(); + m_aria_active_descendant = to_deprecated_string(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()); @@ -19,36 +26,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(source.aria_controls()); + m_aria_controls = source.parse_id_reference_list(to_deprecated_string(source.aria_controls())); m_aria_current = AriaData::parse_aria_current(source.aria_current()); - 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_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_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(source.aria_error_message()); + m_aria_error_message = source.parse_id_reference(to_deprecated_string(source.aria_error_message())); m_aria_expanded = AriaData::parse_true_false_undefined(source.aria_expanded()); - m_aria_flow_to = source.parse_id_reference_list(source.aria_flow_to()); + m_aria_flow_to = source.parse_id_reference_list(to_deprecated_string(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 = source.aria_key_shortcuts(); - m_aria_label = source.aria_label(); - m_aria_labelled_by = source.parse_id_reference_list(source.aria_labelled_by()); + 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_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(source.aria_owns()); - m_aria_placeholder = source.aria_placeholder(); + 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_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 = source.aria_role_description(); + m_aria_role_description = to_deprecated_string(source.aria_role_description()); 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()); @@ -58,10 +65,10 @@ 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 = source.aria_value_text(); + m_aria_value_text = to_deprecated_string(source.aria_value_text()); } -bool AriaData::parse_true_false(StringView value) +bool AriaData::parse_true_false(Optional const& value) { if (value == "true"sv) return true; @@ -70,7 +77,7 @@ bool AriaData::parse_true_false(StringView value) return false; } -Tristate AriaData::parse_tristate(StringView value) +Tristate AriaData::parse_tristate(Optional const& value) { if (value == "true"sv) return Tristate::True; @@ -83,7 +90,7 @@ Tristate AriaData::parse_tristate(StringView value) return Tristate::Undefined; } -Optional AriaData::parse_true_false_undefined(StringView value) +Optional AriaData::parse_true_false_undefined(Optional const& value) { if (value == "true"sv) return true; @@ -94,14 +101,18 @@ Optional AriaData::parse_true_false_undefined(StringView value) return {}; } -Optional AriaData::parse_integer(StringView value) +Optional AriaData::parse_integer(Optional const& value) { - return value.to_int(); + if (!value.has_value()) + return {}; + return value->bytes_as_string_view().to_int(); } -Optional AriaData::parse_number(StringView value) +Optional AriaData::parse_number(Optional const& value) { - return value.to_double(TrimWhitespace::Yes); + if (!value.has_value()) + return {}; + return value->bytes_as_string_view().to_double(TrimWhitespace::Yes); } Optional AriaData::aria_active_descendant_or_default() const @@ -361,7 +372,7 @@ DeprecatedString AriaData::aria_value_text_or_default() const return m_aria_value_text; } -AriaAutocomplete AriaData::parse_aria_autocomplete(StringView value) +AriaAutocomplete AriaData::parse_aria_autocomplete(Optional const& value) { if (value == "inline"sv) return AriaAutocomplete::Inline; @@ -374,7 +385,7 @@ AriaAutocomplete AriaData::parse_aria_autocomplete(StringView value) return AriaAutocomplete::None; } -AriaCurrent AriaData::parse_aria_current(StringView value) +AriaCurrent AriaData::parse_aria_current(Optional const& value) { if (value == "page"sv) return AriaCurrent::Page; @@ -393,11 +404,14 @@ AriaCurrent AriaData::parse_aria_current(StringView value) return AriaCurrent::False; } -Vector AriaData::parse_aria_drop_effect(StringView value) +Vector AriaData::parse_aria_drop_effect(Optional const& value) { + if (!value.has_value()) + return {}; + Vector result; - for (auto token : value.split_view_if(Infra::is_ascii_whitespace)) { + for (auto token : value->bytes_as_string_view().split_view_if(Infra::is_ascii_whitespace)) { if (token == "copy"sv) result.append(AriaDropEffect::Copy); else if (token == "execute"sv) @@ -417,7 +431,7 @@ Vector AriaData::parse_aria_drop_effect(StringView value) return result; } -AriaHasPopup AriaData::parse_aria_has_popup(StringView value) +AriaHasPopup AriaData::parse_aria_has_popup(Optional const& value) { if (value == "false"sv) return AriaHasPopup::False; @@ -436,7 +450,7 @@ AriaHasPopup AriaData::parse_aria_has_popup(StringView value) return AriaHasPopup::False; } -AriaInvalid AriaData::parse_aria_invalid(StringView value) +AriaInvalid AriaData::parse_aria_invalid(Optional const& value) { if (value == "grammar"sv) return AriaInvalid::Grammar; @@ -449,7 +463,7 @@ AriaInvalid AriaData::parse_aria_invalid(StringView value) return AriaInvalid::False; } -Optional AriaData::parse_aria_live(StringView value) +Optional AriaData::parse_aria_live(Optional const& value) { if (value == "assertive"sv) return AriaLive::Assertive; @@ -460,7 +474,7 @@ Optional AriaData::parse_aria_live(StringView value) return {}; } -Optional AriaData::parse_aria_orientation(StringView value) +Optional AriaData::parse_aria_orientation(Optional const& value) { if (value == "horizontal"sv) return AriaOrientation::Horizontal; @@ -471,10 +485,13 @@ Optional AriaData::parse_aria_orientation(StringView value) return {}; } -Vector AriaData::parse_aria_relevant(StringView value) +Vector AriaData::parse_aria_relevant(Optional const& value) { + if (!value.has_value()) + return {}; + Vector result; - auto tokens = value.split_view_if(Infra::is_ascii_whitespace); + auto tokens = value->bytes_as_string_view().split_view_if(Infra::is_ascii_whitespace); for (size_t i = 0; i < tokens.size(); i++) { if (tokens[i] == "additions"sv) { if (i + 1 < tokens.size()) { @@ -504,7 +521,7 @@ Vector AriaData::parse_aria_relevant(StringView value) return result; } -AriaSort AriaData::parse_aria_sort(StringView value) +AriaSort AriaData::parse_aria_sort(Optional const& value) { if (value == "ascending"sv) return AriaSort::Ascending; @@ -517,7 +534,7 @@ AriaSort AriaData::parse_aria_sort(StringView value) return AriaSort::None; } -Optional AriaData::parse_optional_true_false(StringView value) +Optional AriaData::parse_optional_true_false(Optional const& value) { if (value == "true"sv) return true; diff --git a/Userland/Libraries/LibWeb/ARIA/AriaData.h b/Userland/Libraries/LibWeb/ARIA/AriaData.h index 76962c75acc..d2ed242cbbe 100644 --- a/Userland/Libraries/LibWeb/ARIA/AriaData.h +++ b/Userland/Libraries/LibWeb/ARIA/AriaData.h @@ -205,32 +205,32 @@ private: // https://www.w3.org/TR/wai-aria-1.2/#valuetype_true-false // The default value for this value type is false unless otherwise specified. - static bool parse_true_false(StringView); + static bool parse_true_false(Optional const&); // https://www.w3.org/TR/wai-aria-1.2/#valuetype_tristate // The default value for this value type is undefined unless otherwise specified. - static Tristate parse_tristate(StringView); + static Tristate parse_tristate(Optional const&); // https://www.w3.org/TR/wai-aria-1.2/#valuetype_true-false-undefined // The default value for this value type is undefined unless otherwise specified. - static Optional parse_true_false_undefined(StringView); + static Optional parse_true_false_undefined(Optional const&); // https://www.w3.org/TR/wai-aria-1.2/#valuetype_integer - static Optional parse_integer(StringView); + static Optional parse_integer(Optional const&); // https://www.w3.org/TR/wai-aria-1.2/#valuetype_number - static Optional parse_number(StringView); + static Optional parse_number(Optional const&); - static AriaAutocomplete parse_aria_autocomplete(StringView); - static AriaCurrent parse_aria_current(StringView); - static Vector parse_aria_drop_effect(StringView); - static AriaHasPopup parse_aria_has_popup(StringView); - static AriaInvalid parse_aria_invalid(StringView); - static Optional parse_aria_live(StringView); - static Optional parse_aria_orientation(StringView); - static Vector parse_aria_relevant(StringView); - static AriaSort parse_aria_sort(StringView); - static Optional parse_optional_true_false(StringView); + static AriaAutocomplete parse_aria_autocomplete(Optional const&); + static AriaCurrent parse_aria_current(Optional const&); + static Vector parse_aria_drop_effect(Optional const&); + static AriaHasPopup parse_aria_has_popup(Optional const&); + static AriaInvalid parse_aria_invalid(Optional const&); + static Optional parse_aria_live(Optional const&); + static Optional parse_aria_orientation(Optional const&); + static Vector parse_aria_relevant(Optional const&); + static AriaSort parse_aria_sort(Optional const&); + static Optional parse_optional_true_false(Optional const&); Optional m_aria_active_descendant; Optional m_aria_atomic; diff --git a/Userland/Libraries/LibWeb/DOM/Element.cpp b/Userland/Libraries/LibWeb/DOM/Element.cpp index 704be39cb8b..4eeb5f3127a 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.cpp +++ b/Userland/Libraries/LibWeb/DOM/Element.cpp @@ -170,7 +170,7 @@ DeprecatedString Element::get_attribute_value(StringView local_name, DeprecatedF } // https://dom.spec.whatwg.org/#dom-element-getattributenode -JS::GCPtr Element::get_attribute_node(DeprecatedFlyString const& name) const +JS::GCPtr Element::get_attribute_node(FlyString const& name) const { // The getAttributeNode(qualifiedName) method steps are to return the result of getting an attribute given qualifiedName and this. return m_attributes->get_attribute(name); @@ -258,13 +258,17 @@ WebIDL::ExceptionOr validate_and_extract(JS::Realm& realm, Deprec } // https://dom.spec.whatwg.org/#dom-element-setattributens -WebIDL::ExceptionOr Element::set_attribute_ns(DeprecatedFlyString const& namespace_, DeprecatedFlyString const& qualified_name, DeprecatedString const& value) +WebIDL::ExceptionOr Element::set_attribute_ns(Optional const& namespace_, FlyString const& qualified_name, FlyString const& value) { + DeprecatedFlyString deprecated_namespace; + if (namespace_.has_value()) + deprecated_namespace = namespace_->to_deprecated_string(); + // 1. Let namespace, prefix, and localName be the result of passing namespace and qualifiedName to validate and extract. - auto extracted_qualified_name = TRY(validate_and_extract(realm(), namespace_, qualified_name)); + auto extracted_qualified_name = TRY(validate_and_extract(realm(), deprecated_namespace, qualified_name.to_deprecated_fly_string())); // 2. Set an attribute value for this using localName, value, and also prefix and namespace. - set_attribute_value(extracted_qualified_name.local_name().to_deprecated_fly_string(), value, extracted_qualified_name.deprecated_prefix(), extracted_qualified_name.deprecated_namespace_()); + set_attribute_value(extracted_qualified_name.local_name().to_deprecated_fly_string(), value.to_deprecated_fly_string(), extracted_qualified_name.deprecated_prefix(), extracted_qualified_name.deprecated_namespace_()); return {}; } @@ -319,18 +323,22 @@ bool Element::has_attribute(StringView name) const } // https://dom.spec.whatwg.org/#dom-element-hasattributens -bool Element::has_attribute_ns(StringView namespace_, StringView name) const +bool Element::has_attribute_ns(Optional const& namespace_, StringView name) const { + StringView namespace_view; + if (namespace_.has_value()) + namespace_view = namespace_->bytes_as_string_view(); + // 1. If namespace is the empty string, then set it to null. - if (namespace_.is_empty()) - namespace_ = {}; + if (namespace_view.is_empty()) + namespace_view = {}; // 2. Return true if this has an attribute whose namespace is namespace and local name is localName; otherwise false. - return m_attributes->get_attribute_ns(namespace_, name) != nullptr; + return m_attributes->get_attribute_ns(namespace_view, name) != nullptr; } // https://dom.spec.whatwg.org/#dom-element-toggleattribute -WebIDL::ExceptionOr Element::toggle_attribute(DeprecatedFlyString const& name, Optional force) +WebIDL::ExceptionOr Element::toggle_attribute(FlyString const& name, Optional force) { // 1. If qualifiedName does not match the Name production in XML, then throw an "InvalidCharacterError" DOMException. // FIXME: Proper name validation @@ -349,7 +357,7 @@ WebIDL::ExceptionOr Element::toggle_attribute(DeprecatedFlyString const& n // 1. If force is not given or is true, create an attribute whose local name is qualifiedName, value is the empty // string, and node document is this’s node document, then append this attribute to this, and then return true. if (!force.has_value() || force.value()) { - auto new_attribute = Attr::create(document(), MUST(String::from_deprecated_string(insert_as_lowercase ? name.to_lowercase() : name)), String {}); + auto new_attribute = Attr::create(document(), insert_as_lowercase ? MUST(Infra::to_ascii_lowercase(name)) : name.to_string(), String {}); m_attributes->append_attribute(new_attribute); return true; @@ -370,13 +378,13 @@ WebIDL::ExceptionOr Element::toggle_attribute(DeprecatedFlyString const& n } // https://dom.spec.whatwg.org/#dom-element-getattributenames -Vector Element::get_attribute_names() const +Vector Element::get_attribute_names() const { // The getAttributeNames() method steps are to return the qualified names of the attributes in this’s attribute list, in order; otherwise a new list. - Vector names; + Vector names; for (size_t i = 0; i < m_attributes->length(); ++i) { auto const* attribute = m_attributes->item(i); - names.append(attribute->name().to_deprecated_fly_string()); + names.append(attribute->name().to_string()); } return names; } @@ -733,9 +741,10 @@ WebIDL::ExceptionOr Element::set_inner_html(StringView markup) } // https://w3c.github.io/DOM-Parsing/#dom-innerhtml-innerhtml -WebIDL::ExceptionOr Element::inner_html() const +WebIDL::ExceptionOr Element::inner_html() const { - return serialize_fragment(DOMParsing::RequireWellFormed::Yes); + auto inner_html = TRY(serialize_fragment(DOMParsing::RequireWellFormed::Yes)); + return MUST(String::from_deprecated_string(inner_html)); } bool Element::is_focused() const @@ -805,7 +814,7 @@ void Element::make_html_uppercased_qualified_name() { // This is allowed by the spec: "User agents could optimize qualified name and HTML-uppercased qualified name by storing them in internal slots." if (namespace_() == Namespace::HTML && document().document_type() == Document::Type::HTML) - m_html_uppercased_qualified_name = DeprecatedString(qualified_name()).to_uppercase(); + m_html_uppercased_qualified_name = MUST(Infra::to_ascii_uppercase(qualified_name())); else m_html_uppercased_qualified_name = qualified_name(); } @@ -1359,7 +1368,7 @@ bool Element::is_actually_disabled() const } // https://w3c.github.io/DOM-Parsing/#dom-element-insertadjacenthtml -WebIDL::ExceptionOr Element::insert_adjacent_html(DeprecatedString position, DeprecatedString text) +WebIDL::ExceptionOr Element::insert_adjacent_html(String const& position, String const& text) { JS::GCPtr context; // 1. Use the first matching item from this list: @@ -1475,24 +1484,24 @@ WebIDL::ExceptionOr> Element::insert_adjacent(DeprecatedString c } // https://dom.spec.whatwg.org/#dom-element-insertadjacentelement -WebIDL::ExceptionOr> Element::insert_adjacent_element(DeprecatedString const& where, JS::NonnullGCPtr element) +WebIDL::ExceptionOr> Element::insert_adjacent_element(String const& where, JS::NonnullGCPtr element) { // The insertAdjacentElement(where, element) method steps are to return the result of running insert adjacent, give this, where, and element. - auto returned_node = TRY(insert_adjacent(where, move(element))); + auto returned_node = TRY(insert_adjacent(where.to_deprecated_string(), move(element))); if (!returned_node) return JS::GCPtr { nullptr }; return JS::GCPtr { verify_cast(*returned_node) }; } // https://dom.spec.whatwg.org/#dom-element-insertadjacenttext -WebIDL::ExceptionOr Element::insert_adjacent_text(DeprecatedString const& where, DeprecatedString const& data) +WebIDL::ExceptionOr Element::insert_adjacent_text(String const& where, String const& data) { // 1. Let text be a new Text node whose data is data and node document is this’s node document. - auto text = heap().allocate(realm(), document(), MUST(String::from_deprecated_string(data))); + auto text = heap().allocate(realm(), document(), data); // 2. Run insert adjacent, given this, where, and text. // Spec Note: This method returns nothing because it existed before we had a chance to design it. - (void)TRY(insert_adjacent(where, text)); + (void)TRY(insert_adjacent(where.to_deprecated_string(), text)); return {}; } @@ -1859,9 +1868,9 @@ void Element::setup_custom_element_from_constructor(HTML::CustomElementDefinitio m_is_value = is_value; } -void Element::set_prefix(DeprecatedFlyString const& value) +void Element::set_prefix(Optional value) { - m_qualified_name.set_prefix(MUST(FlyString::from_deprecated_fly_string(value))); + m_qualified_name.set_prefix(move(value)); } void Element::for_each_attribute(Function callback) const diff --git a/Userland/Libraries/LibWeb/DOM/Element.h b/Userland/Libraries/LibWeb/DOM/Element.h index 0b7cb0d5237..fe7fad308ae 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.h +++ b/Userland/Libraries/LibWeb/DOM/Element.h @@ -74,30 +74,30 @@ class Element public: virtual ~Element() override; - DeprecatedFlyString qualified_name() const { return m_qualified_name.as_string().to_deprecated_fly_string(); } - DeprecatedString const& html_uppercased_qualified_name() const { return m_html_uppercased_qualified_name; } + FlyString const& qualified_name() const { return m_qualified_name.as_string(); } + FlyString const& html_uppercased_qualified_name() const { return m_html_uppercased_qualified_name; } - virtual FlyString node_name() const final { return MUST(FlyString::from_deprecated_fly_string(html_uppercased_qualified_name())); } + virtual FlyString node_name() const final { return html_uppercased_qualified_name(); } DeprecatedFlyString deprecated_local_name() const { return m_qualified_name.local_name().to_deprecated_fly_string(); } FlyString const& local_name() const { return m_qualified_name.local_name(); } // NOTE: This is for the JS bindings - FlyString tag_name() const { return MUST(FlyString::from_deprecated_fly_string(html_uppercased_qualified_name())); } - DeprecatedString const& deprecated_tag_name() const { return html_uppercased_qualified_name(); } + FlyString const& tag_name() const { return html_uppercased_qualified_name(); } + DeprecatedString deprecated_tag_name() const { return html_uppercased_qualified_name().to_deprecated_fly_string(); } Optional const& prefix() const { return m_qualified_name.prefix(); } DeprecatedFlyString deprecated_prefix() const { return m_qualified_name.deprecated_prefix(); } - void set_prefix(DeprecatedFlyString const& value); + void set_prefix(Optional value); DeprecatedFlyString namespace_() const { return m_qualified_name.deprecated_namespace_(); } // NOTE: This is for the JS bindings - DeprecatedFlyString namespace_uri() const { return namespace_(); } + Optional const& namespace_uri() const { return m_qualified_name.namespace_(); } - // FIXME: This should be taking a 'FlyString const&' + // FIXME: This should be taking a 'FlyString const&' / 'Optional const&' bool has_attribute(StringView name) const; - bool has_attribute_ns(StringView namespace_, StringView name) const; + bool has_attribute_ns(Optional const& namespace_, StringView name) const; bool has_attributes() const; // FIXME: This should be taking a 'FlyString const&' @@ -111,7 +111,13 @@ public: WebIDL::ExceptionOr set_attribute(DeprecatedFlyString const& name, DeprecatedString const& value); WebIDL::ExceptionOr set_attribute(DeprecatedFlyString const& name, Optional const& value); - WebIDL::ExceptionOr set_attribute_ns(DeprecatedFlyString const& namespace_, DeprecatedFlyString const& qualified_name, DeprecatedString const& value); + WebIDL::ExceptionOr set_attribute(FlyString const& name, Optional const& value) + { + return set_attribute(name.to_deprecated_fly_string(), value); + } + + // FIXME: This should be taking an Optional + WebIDL::ExceptionOr set_attribute_ns(Optional const& namespace_, FlyString const& qualified_name, FlyString const& value); void set_attribute_value(DeprecatedFlyString const& local_name, DeprecatedString const& value, DeprecatedFlyString const& prefix = {}, DeprecatedFlyString const& namespace_ = {}); WebIDL::ExceptionOr> set_attribute_node(Attr&); WebIDL::ExceptionOr> set_attribute_node_ns(Attr&); @@ -119,12 +125,12 @@ public: // FIXME: This should take a 'FlyString cosnt&' void remove_attribute(StringView name); - WebIDL::ExceptionOr toggle_attribute(DeprecatedFlyString const& name, Optional force); + WebIDL::ExceptionOr toggle_attribute(FlyString const& name, Optional force); size_t attribute_list_size() const; NamedNodeMap const* attributes() const { return m_attributes.ptr(); } - Vector get_attribute_names() const; + Vector get_attribute_names() const; - JS::GCPtr get_attribute_node(DeprecatedFlyString const& name) const; + JS::GCPtr get_attribute_node(FlyString const& name) const; DOMTokenList* class_list(); @@ -189,10 +195,10 @@ public: CSS::CSSStyleDeclaration* style_for_bindings(); - WebIDL::ExceptionOr inner_html() const; + WebIDL::ExceptionOr inner_html() const; WebIDL::ExceptionOr set_inner_html(StringView); - WebIDL::ExceptionOr insert_adjacent_html(DeprecatedString position, DeprecatedString text); + WebIDL::ExceptionOr insert_adjacent_html(String const& position, String const& text); bool is_focused() const; bool is_active() const; @@ -244,20 +250,20 @@ public: bool is_actually_disabled() const; - WebIDL::ExceptionOr> insert_adjacent_element(DeprecatedString const& where, JS::NonnullGCPtr element); - WebIDL::ExceptionOr insert_adjacent_text(DeprecatedString const& where, DeprecatedString const& data); + WebIDL::ExceptionOr> insert_adjacent_element(String const& where, JS::NonnullGCPtr element); + WebIDL::ExceptionOr insert_adjacent_text(String const& where, String const& data); // https://w3c.github.io/csswg-drafts/cssom-view-1/#dom-element-scrollintoview ErrorOr scroll_into_view(Optional> = {}); // https://www.w3.org/TR/wai-aria-1.2/#ARIAMixin #define ARIA_IMPL(name, attribute) \ - DeprecatedString name() const override \ + Optional name() const override \ { \ - return deprecated_get_attribute(attribute); \ + return get_attribute(attribute); \ } \ \ - WebIDL::ExceptionOr set_##name(DeprecatedString const& value) override \ + WebIDL::ExceptionOr set_##name(Optional const& value) override \ { \ TRY(set_attribute(attribute, value)); \ return {}; \ @@ -387,7 +393,7 @@ private: void enqueue_an_element_on_the_appropriate_element_queue(); QualifiedName m_qualified_name; - DeprecatedString m_html_uppercased_qualified_name; + FlyString m_html_uppercased_qualified_name; JS::GCPtr m_attributes; Vector m_attribute_change_steps; diff --git a/Userland/Libraries/LibWeb/DOM/Element.idl b/Userland/Libraries/LibWeb/DOM/Element.idl index c68edd068e3..182c94395d6 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.idl +++ b/Userland/Libraries/LibWeb/DOM/Element.idl @@ -21,14 +21,14 @@ dictionary ScrollIntoViewOptions : ScrollOptions { }; // https://dom.spec.whatwg.org/#element -[Exposed=Window, UseDeprecatedAKString] +[Exposed=Window] interface Element : Node { readonly attribute DOMString? namespaceURI; - [ImplementedAs=deprecated_prefix] readonly attribute DOMString? prefix; - [ImplementedAs=deprecated_local_name] readonly attribute DOMString localName; - [ImplementedAs=deprecated_tag_name] readonly attribute DOMString tagName; + readonly attribute DOMString? prefix; + readonly attribute DOMString localName; + readonly attribute DOMString tagName; - [ImplementedAs=deprecated_get_attribute] DOMString? getAttribute(DOMString qualifiedName); + DOMString? getAttribute(DOMString qualifiedName); [CEReactions] undefined setAttribute(DOMString qualifiedName, DOMString value); [CEReactions] undefined setAttributeNS(DOMString? namespace , DOMString qualifiedName , DOMString value); [CEReactions] Attr? setAttributeNode(Attr attr); diff --git a/Userland/Libraries/LibWeb/DOM/ElementFactory.cpp b/Userland/Libraries/LibWeb/DOM/ElementFactory.cpp index 214a95b1110..397001cb2d6 100644 --- a/Userland/Libraries/LibWeb/DOM/ElementFactory.cpp +++ b/Userland/Libraries/LibWeb/DOM/ElementFactory.cpp @@ -581,7 +581,10 @@ WebIDL::ExceptionOr> create_element(Document& document return JS::throw_completion(WebIDL::NotSupportedError::create(realm, "Synchronously created custom element must have the same local name that element creation was invoked with"_fly_string)); // 10. Set result’s namespace prefix to prefix. - element->set_prefix(prefix); + if (prefix.is_null()) + element->set_prefix({}); + else + element->set_prefix(MUST(FlyString::from_deprecated_fly_string(prefix))); // 11. Set result’s is value to null. element->set_is_value(Optional {}); diff --git a/Userland/Libraries/LibWeb/DOM/Node.cpp b/Userland/Libraries/LibWeb/DOM/Node.cpp index 407015de451..5692d729d2c 100644 --- a/Userland/Libraries/LibWeb/DOM/Node.cpp +++ b/Userland/Libraries/LibWeb/DOM/Node.cpp @@ -1786,17 +1786,19 @@ ErrorOr Node::name_or_description(NameOrDescription target, Document con // process its IDREFs in the order they occur: // - or, if computing a description, and the current node has an aria-describedby attribute that contains at least one valid IDREF, and the current node is not already part of an aria-describedby traversal, // process its IDREFs in the order they occur: - if ((target == NameOrDescription::Name && Node::first_valid_id(element->aria_labelled_by(), document).has_value()) - || (target == NameOrDescription::Description && Node::first_valid_id(element->aria_described_by(), document).has_value())) { + auto aria_labelled_by = element->aria_labelled_by(); + auto aria_described_by = element->aria_described_by(); + if ((target == NameOrDescription::Name && aria_labelled_by.has_value() && Node::first_valid_id(aria_labelled_by->to_deprecated_string(), document).has_value()) + || (target == NameOrDescription::Description && aria_described_by.has_value() && Node::first_valid_id(aria_described_by->to_deprecated_string(), document).has_value())) { // i. Set the accumulated text to the empty string. total_accumulated_text.clear(); Vector id_list; if (target == NameOrDescription::Name) { - id_list = element->aria_labelled_by().split_view(Infra::is_ascii_whitespace); + id_list = aria_labelled_by->bytes_as_string_view().split_view_if(Infra::is_ascii_whitespace); } else { - id_list = element->aria_described_by().split_view(Infra::is_ascii_whitespace); + id_list = aria_described_by->bytes_as_string_view().split_view_if(Infra::is_ascii_whitespace); } // ii. For each IDREF: for (auto const& id_ref : id_list) { @@ -1817,10 +1819,10 @@ ErrorOr Node::name_or_description(NameOrDescription target, Document con return total_accumulated_text.to_string(); } // C. Otherwise, if computing a name, and if the current node has an aria-label attribute whose value is not the empty string, nor, when trimmed of white space, is not the empty string: - if (target == NameOrDescription::Name && !element->aria_label().is_empty() && !element->aria_label().trim_whitespace().is_empty()) { + if (target == NameOrDescription::Name && element->aria_label().has_value() && !element->aria_label()->is_empty() && !element->aria_label()->bytes_as_string_view().is_whitespace()) { // TODO: - If traversal of the current node is due to recursion and the current node is an embedded control as defined in step 2E, ignore aria-label and skip to rule 2E. // - Otherwise, return the value of aria-label. - return String::from_deprecated_string(element->aria_label()); + return element->aria_label().value(); } // TODO: D. Otherwise, if the current node's native markup provides an attribute (e.g. title) or element (e.g. HTML label) that defines a text alternative, // return that alternative in the form of a flat string as defined by the host language, unless the element is marked as presentational (role="presentation" or role="none"). @@ -1908,29 +1910,33 @@ ErrorOr Node::accessible_description(Document const& document) const { // If aria-describedby is present, user agents MUST compute the accessible description by concatenating the text alternatives for elements referenced by an aria-describedby attribute on the current element. // The text alternatives for the referenced elements are computed using a number of methods, outlined below in the section titled Accessible Name and Description Computation. - if (is_element()) { - HashTable visited_nodes; - StringBuilder builder; - auto const* element = static_cast(this); - auto id_list = element->aria_described_by().split_view(Infra::is_ascii_whitespace); - for (auto const& id : id_list) { - if (auto description_element = document.get_element_by_id(id)) { - auto description = TRY( - description_element->name_or_description(NameOrDescription::Description, document, - visited_nodes)); - if (!description.is_empty()) { - if (builder.is_empty()) { - builder.append(description); - } else { - builder.append(" "sv); - builder.append(description); - } + if (!is_element()) + return String {}; + + auto const* element = static_cast(this); + auto described_by = element->aria_described_by(); + if (!described_by.has_value()) + return String {}; + + HashTable visited_nodes; + StringBuilder builder; + auto id_list = described_by->bytes_as_string_view().split_view_if(Infra::is_ascii_whitespace); + for (auto const& id : id_list) { + if (auto description_element = document.get_element_by_id(id)) { + auto description = TRY( + description_element->name_or_description(NameOrDescription::Description, document, + visited_nodes)); + if (!description.is_empty()) { + if (builder.is_empty()) { + builder.append(description); + } else { + builder.append(" "sv); + builder.append(description); } } } - return builder.to_string(); } - return String {}; + return builder.to_string(); } Optional Node::first_valid_id(DeprecatedString const& value, Document const& document) diff --git a/Userland/Libraries/LibWeb/DOM/ParentNode.cpp b/Userland/Libraries/LibWeb/DOM/ParentNode.cpp index 8ebf45d45c5..2dbe54677b1 100644 --- a/Userland/Libraries/LibWeb/DOM/ParentNode.cpp +++ b/Userland/Libraries/LibWeb/DOM/ParentNode.cpp @@ -146,20 +146,20 @@ JS::NonnullGCPtr ParentNode::get_elements_by_tag_name(Deprecated // 2. Otherwise, if root’s node document is an HTML document, return a HTMLCollection rooted at root, whose filter matches the following descendant elements: if (root().document().document_type() == Document::Type::HTML) { - auto qualified_name_in_ascii_lowercase = qualified_name.to_lowercase(); + auto qualified_name_in_ascii_lowercase = MUST(FlyString::from_deprecated_fly_string(qualified_name.to_lowercase())); return HTMLCollection::create(*this, HTMLCollection::Scope::Descendants, [qualified_name, qualified_name_in_ascii_lowercase](Element const& element) { // - Whose namespace is the HTML namespace and whose qualified name is qualifiedName, in ASCII lowercase. if (element.namespace_() == Namespace::HTML) return element.qualified_name() == qualified_name_in_ascii_lowercase; // - Whose namespace is not the HTML namespace and whose qualified name is qualifiedName. - return element.qualified_name() == qualified_name; + return element.qualified_name().to_deprecated_fly_string() == qualified_name; }); } // 3. Otherwise, return a HTMLCollection rooted at root, whose filter matches descendant elements whose qualified name is qualifiedName. return HTMLCollection::create(*this, HTMLCollection::Scope::Descendants, [qualified_name](Element const& element) { - return element.qualified_name() == qualified_name; + return element.qualified_name().to_deprecated_fly_string() == qualified_name; }); } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLHeadingElement.h b/Userland/Libraries/LibWeb/HTML/HTMLHeadingElement.h index a880505dfd3..f2b9ec905fd 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLHeadingElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLHeadingElement.h @@ -22,10 +22,10 @@ public: // https://www.w3.org/TR/html-aria/#el-h1-h6 virtual Optional default_role() const override { return ARIA::Role::heading; } - virtual DeprecatedString aria_level() const override + virtual Optional aria_level() const override { // TODO: aria-level = the number in the element's tag name - return deprecated_get_attribute("aria-level"sv); + return get_attribute("aria-level"sv); } private: diff --git a/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp b/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp index 157a67e367d..a94a6a60451 100644 --- a/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp +++ b/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp @@ -3895,10 +3895,10 @@ DeprecatedString HTMLParser::serialize_html_fragment(DOM::Node const& node) // 1. If current node is an element in the HTML namespace, the MathML namespace, or the SVG namespace, then let tagname be current node's local name. // Otherwise, let tagname be current node's qualified name. - DeprecatedString tag_name; + FlyString tag_name; if (element.namespace_().is_one_of(Namespace::HTML, Namespace::MathML, Namespace::SVG)) - tag_name = element.local_name().to_deprecated_fly_string(); + tag_name = element.local_name(); else tag_name = element.qualified_name();