1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:28:12 +00:00

LibWeb: Port DOM::Node from DeprecatedString

This commit is contained in:
Shannon Booth 2023-12-03 08:24:04 +13:00 committed by Andreas Kling
parent 89bbf53745
commit a8f5ebeddd
8 changed files with 26 additions and 27 deletions

View file

@ -720,7 +720,7 @@ DeprecatedString Document::title() const
// element that is a child of the document element.
if (auto const* document_element = this->document_element(); is<SVG::SVGElement>(document_element)) {
if (auto const* title_element = document_element->first_child_of_type<SVG::SVGTitleElement>())
value = title_element->child_text_content();
value = title_element->child_text_content().to_deprecated_string();
}
// 2. Otherwise, let value be the child text content of the title element, or the empty string if the title element
@ -761,7 +761,7 @@ WebIDL::ExceptionOr<void> Document::set_title(String const& title)
}
// 3. String replace all with the given value within element.
element->string_replace_all(title.to_deprecated_string());
element->string_replace_all(title);
}
// -> If the document element is in the HTML namespace
@ -790,7 +790,7 @@ WebIDL::ExceptionOr<void> Document::set_title(String const& title)
}
// 4. String replace all with the given value within element.
element->string_replace_all(title.to_deprecated_string());
element->string_replace_all(title);
}
// -> Otherwise

View file

@ -179,7 +179,7 @@ void Node::set_text_content(Optional<String> const& maybe_content)
{
// The textContent setter steps are to, if the given value is null, act as if it was the empty string instead,
// and then do as described below, switching on the interface this implements:
auto content = maybe_content.value_or(String {}).to_deprecated_string();
auto content = maybe_content.value_or(String {});
// If DocumentFragment or Element, string replace all with the given value within this.
if (is<DocumentFragment>(this) || is<Element>(this)) {
@ -190,7 +190,7 @@ void Node::set_text_content(Optional<String> const& maybe_content)
else if (is<CharacterData>(this)) {
auto* character_data_node = verify_cast<CharacterData>(this);
character_data_node->set_data(MUST(String::from_deprecated_string(content)));
character_data_node->set_data(content);
// FIXME: CharacterData::set_data is not spec compliant. Make this match the spec when set_data becomes spec compliant.
// Do note that this will make this function able to throw an exception.
@ -198,7 +198,7 @@ void Node::set_text_content(Optional<String> const& maybe_content)
// If Attr, set an existing attribute value with this and the given value.
if (is<Attr>(*this)) {
static_cast<Attr&>(*this).set_value(MUST(String::from_deprecated_string(content)));
static_cast<Attr&>(*this).set_value(content);
}
// Otherwise, do nothing.
@ -278,10 +278,10 @@ void Node::invalidate_style()
document().schedule_style_update();
}
DeprecatedString Node::child_text_content() const
String Node::child_text_content() const
{
if (!is<ParentNode>(*this))
return DeprecatedString::empty();
return String {};
StringBuilder builder;
verify_cast<ParentNode>(*this).for_each_child([&](auto& child) {
@ -291,7 +291,7 @@ DeprecatedString Node::child_text_content() const
builder.append(maybe_content.value());
}
});
return builder.to_deprecated_string();
return MUST(builder.to_string());
}
// https://dom.spec.whatwg.org/#concept-tree-root
@ -1316,14 +1316,14 @@ void Node::replace_all(JS::GCPtr<Node> node)
}
// https://dom.spec.whatwg.org/#string-replace-all
void Node::string_replace_all(DeprecatedString const& string)
void Node::string_replace_all(String const& string)
{
// 1. Let node be null.
JS::GCPtr<Node> node;
// 2. If string is not the empty string, then set node to a new Text node whose data is string and node document is parents node document.
if (!string.is_empty())
node = heap().allocate<Text>(realm(), document(), MUST(String::from_deprecated_string(string)));
node = heap().allocate<Text>(realm(), document(), string);
// 3. Replace all with node within parent.
replace_all(node);
@ -1471,18 +1471,18 @@ JS::NonnullGCPtr<Node> Node::get_root_node(GetRootNodeOptions const& options)
return root();
}
DeprecatedString Node::debug_description() const
String Node::debug_description() const
{
StringBuilder builder;
builder.append(node_name().to_deprecated_fly_string().to_lowercase());
if (is_element()) {
auto& element = static_cast<DOM::Element const&>(*this);
auto const& element = static_cast<DOM::Element const&>(*this);
if (auto id = element.get_attribute(HTML::AttributeNames::id); id.has_value())
builder.appendff("#{}", id.value());
for (auto const& class_name : element.class_names())
builder.appendff(".{}", class_name);
}
return builder.to_deprecated_string();
return MUST(builder.to_string());
}
// https://dom.spec.whatwg.org/#concept-node-length
@ -1935,9 +1935,9 @@ ErrorOr<String> Node::accessible_description(Document const& document) const
return builder.to_string();
}
Optional<StringView> Node::first_valid_id(DeprecatedString const& value, Document const& document)
Optional<StringView> Node::first_valid_id(StringView value, Document const& document)
{
auto id_list = value.split_view(Infra::is_ascii_whitespace);
auto id_list = value.split_view_if(Infra::is_ascii_whitespace);
for (auto const& id : id_list) {
if (document.get_element_by_id(MUST(FlyString::from_utf8(id))))
return id;

View file

@ -7,7 +7,6 @@
#pragma once
#include <AK/Badge.h>
#include <AK/DeprecatedString.h>
#include <AK/FlyString.h>
#include <AK/JsonObjectSerializer.h>
#include <AK/RefPtr.h>
@ -161,7 +160,7 @@ public:
const HTML::HTMLElement* enclosing_html_element() const;
const HTML::HTMLElement* enclosing_html_element_with_attribute(FlyString const&) const;
DeprecatedString child_text_content() const;
String child_text_content() const;
Node& root();
Node const& root() const
@ -242,7 +241,7 @@ public:
WebIDL::ExceptionOr<String> serialize_fragment(DOMParsing::RequireWellFormed) const;
void replace_all(JS::GCPtr<Node>);
void string_replace_all(DeprecatedString const&);
void string_replace_all(String const&);
bool is_same_node(Node const*) const;
bool is_equal_node(Node const*) const;
@ -251,7 +250,7 @@ public:
bool is_uninteresting_whitespace_node() const;
DeprecatedString debug_description() const;
String debug_description() const;
size_t length() const;
@ -707,7 +706,7 @@ private:
void append_child_impl(JS::NonnullGCPtr<Node>);
void remove_child_impl(JS::NonnullGCPtr<Node>);
static Optional<StringView> first_valid_id(DeprecatedString const&, Document const&);
static Optional<StringView> first_valid_id(StringView, Document const&);
static ErrorOr<void> append_without_space(StringBuilder, StringView const&);
static ErrorOr<void> append_with_space(StringBuilder, StringView const&);
static ErrorOr<void> prepend_without_space(StringBuilder, StringView const&);

View file

@ -114,7 +114,7 @@ String HTMLAnchorElement::text() const
void HTMLAnchorElement::set_text(String const& text)
{
// The text attribute's setter must string replace all with the given value within this element.
string_replace_all(text.to_deprecated_string());
string_replace_all(text);
}
// https://html.spec.whatwg.org/multipage/text-level-semantics.html#dom-a-referrerpolicy

View file

@ -106,7 +106,7 @@ String HTMLOptionElement::text() const
// https://html.spec.whatwg.org/multipage/form-elements.html#dom-option-text
void HTMLOptionElement::set_text(String const& text)
{
string_replace_all(text.to_deprecated_string());
string_replace_all(text);
}
// https://html.spec.whatwg.org/multipage/form-elements.html#concept-option-index

View file

@ -429,7 +429,7 @@ void HTMLScriptElement::prepare_script()
// 2. Fetch an inline module script graph, given source text, base URL, settings object, options, and with the following steps given result:
// FIXME: Pass options
fetch_inline_module_script_graph(realm(), m_document->url().to_deprecated_string(), source_text, base_url, document().relevant_settings_object(), steps);
fetch_inline_module_script_graph(realm(), m_document->url().to_deprecated_string(), source_text.to_deprecated_string(), base_url, document().relevant_settings_object(), steps);
}
// -> "importmap"
else if (m_script_type == ScriptType::ImportMap) {

View file

@ -38,14 +38,14 @@ void HTMLTitleElement::children_changed()
DeprecatedString HTMLTitleElement::text()
{
// The text attribute's getter must return this title element's child text content.
return child_text_content();
return child_text_content().to_deprecated_string();
}
// https://html.spec.whatwg.org/multipage/semantics.html#dom-title-text
void HTMLTitleElement::set_text(String const& value)
{
// The text attribute's setter must string replace all with the given value within this title element.
string_replace_all(value.to_deprecated_string());
string_replace_all(value);
}
}

View file

@ -47,7 +47,7 @@ Optional<TextAnchor> SVGTextContentElement::text_anchor() const
DeprecatedString SVGTextContentElement::text_contents() const
{
return child_text_content().trim_whitespace();
return child_text_content().to_deprecated_string().trim_whitespace();
}
// https://svgwg.org/svg2-draft/text.html#__svg__SVGTextContentElement__getNumberOfChars