1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 13:07:46 +00:00

AK+Everywhere: Remove the null state of DeprecatedString

This commit removes DeprecatedString's "null" state, and replaces all
its users with one of the following:
- A normal, empty DeprecatedString
- Optional<DeprecatedString>

Note that null states of DeprecatedFlyString/StringView/etc are *not*
affected by this commit. However, DeprecatedString::empty() is now
considered equal to a null StringView.
This commit is contained in:
Ali Mohammad Pur 2023-10-10 15:00:58 +03:30 committed by Ali Mohammad Pur
parent daf6d8173c
commit aeee98b3a1
189 changed files with 597 additions and 652 deletions

View file

@ -40,7 +40,7 @@ DeprecatedString CSSNamespaceRule::serialized() const
builder.append("@namespace "sv);
// followed by the serialization as an identifier of the prefix attribute (if any),
if (!m_prefix.is_empty() && !m_prefix.is_null()) {
if (!m_prefix.is_empty()) {
serialize_an_identifier(builder, m_prefix);
// followed by a single SPACE (U+0020) if there is a prefix,
builder.append(" "sv);

View file

@ -53,23 +53,23 @@ DeprecatedString CSSStyleRule::serialized() const
builder.append(" {"sv);
// 2. Let decls be the result of performing serialize a CSS declaration block on the rules associated declarations, or null if there are no such declarations.
auto decls = declaration().serialized();
auto decls = declaration().length() > 0 ? declaration().serialized() : Optional<DeprecatedString>();
// FIXME: 3. Let rules be the result of performing serialize a CSS rule on each rule in the rules cssRules list, or null if there are no such rules.
DeprecatedString rules;
Optional<DeprecatedString> rules;
// 4. If decls and rules are both null, append " }" to s (i.e. a single SPACE (U+0020) followed by RIGHT CURLY BRACKET (U+007D)) and return s.
if (decls.is_null() && rules.is_null()) {
if (!decls.has_value() && !rules.has_value()) {
builder.append(" }"sv);
return builder.to_deprecated_string();
}
// 5. If rules is null:
if (rules.is_null()) {
if (!rules.has_value()) {
// 1. Append a single SPACE (U+0020) to s
builder.append(' ');
// 2. Append decls to s
builder.append(decls);
builder.append(*decls);
// 3. Append " }" to s (i.e. a single SPACE (U+0020) followed by RIGHT CURLY BRACKET (U+007D)).
builder.append(" }"sv);
// 4. Return s.

View file

@ -36,9 +36,9 @@ static inline bool matches_lang_pseudo_class(DOM::Element const& element, Vector
{
FlyString element_language;
for (auto const* e = &element; e; e = e->parent_element()) {
auto lang = e->deprecated_attribute(HTML::AttributeNames::lang);
if (!lang.is_null()) {
element_language = FlyString::from_deprecated_fly_string(lang).release_value_but_fixme_should_propagate_errors();
auto lang = e->attribute(HTML::AttributeNames::lang);
if (lang.has_value()) {
element_language = lang.release_value();
break;
}
}

View file

@ -92,7 +92,7 @@ void Attr::change_attribute(String value)
}
// https://dom.spec.whatwg.org/#handle-attribute-changes
void Attr::handle_attribute_changes(Element& element, DeprecatedString const& old_value, DeprecatedString const& new_value)
void Attr::handle_attribute_changes(Element& element, Optional<DeprecatedString> old_value, Optional<DeprecatedString> new_value)
{
DeprecatedString deprecated_namespace_uri;
if (namespace_uri().has_value())
@ -107,8 +107,8 @@ void Attr::handle_attribute_changes(Element& element, DeprecatedString const& ol
JS::MarkedVector<JS::Value> arguments { vm.heap() };
arguments.append(JS::PrimitiveString::create(vm, local_name()));
arguments.append(old_value.is_null() ? JS::js_null() : JS::PrimitiveString::create(vm, old_value));
arguments.append(new_value.is_null() ? JS::js_null() : JS::PrimitiveString::create(vm, new_value));
arguments.append(!old_value.has_value() ? JS::js_null() : JS::PrimitiveString::create(vm, old_value.release_value()));
arguments.append(!new_value.has_value() ? JS::js_null() : JS::PrimitiveString::create(vm, new_value.release_value()));
arguments.append(!namespace_uri().has_value() ? JS::js_null() : JS::PrimitiveString::create(vm, namespace_uri().value()));
element.enqueue_a_custom_element_callback_reaction(HTML::CustomElementReactionNames::attributeChangedCallback, move(arguments));

View file

@ -41,7 +41,7 @@ public:
// Always returns true: https://dom.spec.whatwg.org/#dom-attr-specified
constexpr bool specified() const { return true; }
void handle_attribute_changes(Element&, DeprecatedString const& old_value, DeprecatedString const& new_value);
void handle_attribute_changes(Element&, Optional<DeprecatedString> old_value, Optional<DeprecatedString> new_value);
private:
Attr(Document&, QualifiedName, String value, Element*);

View file

@ -82,19 +82,19 @@ Element::Element(Document& document, DOM::QualifiedName qualified_name)
return;
// 2. If value is null and oldValue is the empty string, then return.
if (value.is_null() && old_value == DeprecatedString::empty())
if (!value.has_value() && old_value == DeprecatedString::empty())
return;
// 3. If value is the empty string and oldValue is null, then return.
if (value == DeprecatedString::empty() && old_value.is_null())
if (value == DeprecatedString::empty() && !old_value.has_value())
return;
// 4. If value is null or the empty string, then set elements name to the empty string.
if (value.is_empty())
if (!value.has_value() || value->is_empty())
set_slottable_name({});
// 5. Otherwise, set elements name to value.
else
set_slottable_name(MUST(String::from_deprecated_string(value)));
set_slottable_name(MUST(String::from_deprecated_string(*value)));
// 6. If element is assigned, then run assign slottables for elements assigned slot.
if (auto assigned_slot = assigned_slot_internal())
@ -468,7 +468,7 @@ void Element::add_attribute_change_steps(AttributeChangeSteps steps)
m_attribute_change_steps.append(move(steps));
}
void Element::run_attribute_change_steps(FlyString const& local_name, DeprecatedString const& old_value, DeprecatedString const& value, DeprecatedFlyString const& namespace_)
void Element::run_attribute_change_steps(FlyString const& local_name, Optional<DeprecatedString> const& old_value, Optional<DeprecatedString> const& value, DeprecatedFlyString const& namespace_)
{
for (auto const& attribute_change_steps : m_attribute_change_steps)
attribute_change_steps(local_name, old_value, value, namespace_);
@ -478,19 +478,21 @@ void Element::run_attribute_change_steps(FlyString const& local_name, Deprecated
invalidate_style_after_attribute_change(local_name);
}
void Element::attribute_changed(FlyString const& name, DeprecatedString const& value)
void Element::attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value)
{
auto value_or_empty = value.value_or("");
if (name == HTML::AttributeNames::class_) {
auto new_classes = value.split_view(Infra::is_ascii_whitespace);
auto new_classes = value_or_empty.split_view(Infra::is_ascii_whitespace);
m_classes.clear();
m_classes.ensure_capacity(new_classes.size());
for (auto& new_class : new_classes) {
m_classes.unchecked_append(FlyString::from_utf8(new_class).release_value_but_fixme_should_propagate_errors());
}
if (m_class_list)
m_class_list->associated_attribute_changed(value);
m_class_list->associated_attribute_changed(value_or_empty);
} else if (name == HTML::AttributeNames::style) {
if (value.is_null()) {
if (!value.has_value()) {
if (!m_inline_style) {
m_inline_style = nullptr;
set_needs_style_update(true);
@ -499,16 +501,16 @@ void Element::attribute_changed(FlyString const& name, DeprecatedString const& v
// https://drafts.csswg.org/cssom/#ref-for-cssstyledeclaration-updating-flag
if (m_inline_style && m_inline_style->is_updating())
return;
m_inline_style = parse_css_style_attribute(CSS::Parser::ParsingContext(document()), value, *this);
m_inline_style = parse_css_style_attribute(CSS::Parser::ParsingContext(document()), *value, *this);
set_needs_style_update(true);
}
} else if (name == HTML::AttributeNames::dir) {
// https://html.spec.whatwg.org/multipage/dom.html#attr-dir
if (value.equals_ignoring_ascii_case("ltr"sv))
if (value_or_empty.equals_ignoring_ascii_case("ltr"sv))
m_dir = Dir::Ltr;
else if (value.equals_ignoring_ascii_case("rtl"sv))
else if (value_or_empty.equals_ignoring_ascii_case("rtl"sv))
m_dir = Dir::Rtl;
else if (value.equals_ignoring_ascii_case("auto"sv))
else if (value_or_empty.equals_ignoring_ascii_case("auto"sv))
m_dir = Dir::Auto;
else
m_dir = {};

View file

@ -153,11 +153,11 @@ public:
virtual void apply_presentational_hints(CSS::StyleProperties&) const { }
// https://dom.spec.whatwg.org/#concept-element-attributes-change-ext
using AttributeChangeSteps = Function<void(FlyString const& /*local_name*/, DeprecatedString const& /*old_value*/, DeprecatedString const& /*value*/, DeprecatedFlyString const& /*namespace_*/)>;
using AttributeChangeSteps = Function<void(FlyString const& /*local_name*/, Optional<DeprecatedString> const& /*old_value*/, Optional<DeprecatedString> const& /*value*/, DeprecatedFlyString const& /*namespace_*/)>;
void add_attribute_change_steps(AttributeChangeSteps steps);
void run_attribute_change_steps(FlyString const& local_name, DeprecatedString const& old_value, DeprecatedString const& value, DeprecatedFlyString const& namespace_);
virtual void attribute_changed(FlyString const& name, DeprecatedString const& value);
void run_attribute_change_steps(FlyString const& local_name, Optional<DeprecatedString> const& old_value, Optional<DeprecatedString> const& value, DeprecatedFlyString const& namespace_);
virtual void attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value);
struct [[nodiscard]] RequiredInvalidationAfterStyleChange {
bool repaint { false };

View file

@ -1533,7 +1533,7 @@ Painting::PaintableBox* Node::paintable_box()
}
// https://dom.spec.whatwg.org/#queue-a-mutation-record
void Node::queue_mutation_record(FlyString const& type, DeprecatedString attribute_name, DeprecatedString attribute_namespace, DeprecatedString old_value, Vector<JS::Handle<Node>> added_nodes, Vector<JS::Handle<Node>> removed_nodes, Node* previous_sibling, Node* next_sibling) const
void Node::queue_mutation_record(FlyString const& type, Optional<DeprecatedString> attribute_name, Optional<DeprecatedString> attribute_namespace, Optional<DeprecatedString> old_value, Vector<JS::Handle<Node>> added_nodes, Vector<JS::Handle<Node>> removed_nodes, Node* previous_sibling, Node* next_sibling) const
{
// NOTE: We defer garbage collection until the end of the scope, since we can't safely use MutationObserver* as a hashmap key otherwise.
// FIXME: This is a total hack.
@ -1541,7 +1541,7 @@ void Node::queue_mutation_record(FlyString const& type, DeprecatedString attribu
// 1. Let interestedObservers be an empty map.
// mutationObserver -> mappedOldValue
OrderedHashMap<MutationObserver*, DeprecatedString> interested_observers;
OrderedHashMap<MutationObserver*, Optional<DeprecatedString>> interested_observers;
// 2. Let nodes be the inclusive ancestors of target.
Vector<JS::Handle<Node const>> nodes;
@ -1565,7 +1565,7 @@ void Node::queue_mutation_record(FlyString const& type, DeprecatedString attribu
// then:
if (!(node.ptr() != this && !options.subtree)
&& !(type == MutationType::attributes && (!options.attributes.has_value() || !options.attributes.value()))
&& !(type == MutationType::attributes && options.attribute_filter.has_value() && (!attribute_namespace.is_null() || !options.attribute_filter->contains_slow(attribute_name.view())))
&& !(type == MutationType::attributes && options.attribute_filter.has_value() && (attribute_namespace.has_value() || !options.attribute_filter->contains_slow(attribute_name.value_or("").view())))
&& !(type == MutationType::characterData && (!options.character_data.has_value() || !options.character_data.value()))
&& !(type == MutationType::childList && !options.child_list)) {
// 1. Let mo be registereds observer.
@ -1593,17 +1593,9 @@ void Node::queue_mutation_record(FlyString const& type, DeprecatedString attribu
for (auto& interested_observer : interested_observers) {
// 1. Let record be a new MutationRecord object with its type set to type, target set to target, attributeName set to name, attributeNamespace set to namespace, oldValue set to mappedOldValue,
// addedNodes set to addedNodes, removedNodes set to removedNodes, previousSibling set to previousSibling, and nextSibling set to nextSibling.
Optional<String> maybe_attribute_name;
if (!attribute_name.is_null())
maybe_attribute_name = MUST(String::from_deprecated_string(attribute_name));
Optional<String> maybe_attribute_namespace;
if (!attribute_namespace.is_null())
maybe_attribute_namespace = MUST(String::from_deprecated_string(attribute_namespace));
Optional<String> maybe_interested_observer;
if (!interested_observer.value.is_null())
maybe_interested_observer = MUST(String::from_deprecated_string(interested_observer.value));
auto maybe_attribute_name = attribute_name.map([](auto& name) { return MUST(String::from_deprecated_string(name)); });
auto maybe_attribute_namespace = attribute_namespace.map([](auto& ns) { return MUST(String::from_deprecated_string(ns)); });
auto maybe_interested_observer = interested_observer.value.map([](auto& value) { return MUST(String::from_deprecated_string(value)); });
auto record = MutationRecord::create(realm(), type, *this, added_nodes_list, removed_nodes_list, previous_sibling, next_sibling, maybe_attribute_name, maybe_attribute_namespace, /* mappedOldValue */ maybe_interested_observer);
@ -1888,8 +1880,8 @@ ErrorOr<String> Node::name_or_description(NameOrDescription target, Document con
if (is<HTML::HTMLElement>(this)) {
auto const* element = static_cast<HTML::HTMLElement const*>(this);
auto tooltip = element->title();
if (!tooltip.is_empty() && !tooltip.is_null())
return String::from_deprecated_string(tooltip);
if (!tooltip.has_value() && !tooltip->is_empty())
return tooltip.release_value();
}
// Append the result of each step above, with a space, to the total accumulated text.
//

View file

@ -259,7 +259,7 @@ public:
void add_registered_observer(RegisteredObserver& registered_observer) { m_registered_observer_list.append(registered_observer); }
void queue_mutation_record(FlyString const& type, DeprecatedString attribute_name, DeprecatedString attribute_namespace, DeprecatedString old_value, Vector<JS::Handle<Node>> added_nodes, Vector<JS::Handle<Node>> removed_nodes, Node* previous_sibling, Node* next_sibling) const;
void queue_mutation_record(FlyString const& type, Optional<DeprecatedString> attribute_name, Optional<DeprecatedString> attribute_namespace, Optional<DeprecatedString> old_value, Vector<JS::Handle<Node>> added_nodes, Vector<JS::Handle<Node>> removed_nodes, Node* previous_sibling, Node* next_sibling) const;
// https://dom.spec.whatwg.org/#concept-shadow-including-inclusive-descendant
template<typename Callback>

View file

@ -43,8 +43,8 @@ void StyleElementUtils::update_a_style_block(DOM::Element& style_element)
return;
// 4. If element's type attribute is present and its value is neither the empty string nor an ASCII case-insensitive match for "text/css", then return.
auto type_attribute = style_element.deprecated_attribute(HTML::AttributeNames::type);
if (!type_attribute.is_null() && !type_attribute.is_empty() && !Infra::is_ascii_case_insensitive_match(type_attribute, "text/css"sv))
auto type_attribute = style_element.attribute(HTML::AttributeNames::type);
if (type_attribute.has_value() && !type_attribute->is_empty() && !Infra::is_ascii_case_insensitive_match(type_attribute->bytes_as_string_view(), "text/css"sv))
return;
// FIXME: 5. If the Should element's inline behavior be blocked by Content Security Policy? algorithm returns "Blocked" when executed upon the style element, "style", and the style element's child text content, then return. [CSP]
@ -86,7 +86,7 @@ void StyleElementUtils::remove_a_css_style_sheet(DOM::Document& document, CSS::C
}
// https://www.w3.org/TR/cssom/#create-a-css-style-sheet
void StyleElementUtils::create_a_css_style_sheet(DOM::Document& document, DeprecatedString type, DOM::Element* owner_node, DeprecatedString media, DeprecatedString title, bool alternate, bool origin_clean, DeprecatedString location, CSS::CSSStyleSheet* parent_style_sheet, CSS::CSSRule* owner_rule, CSS::CSSStyleSheet& sheet)
void StyleElementUtils::create_a_css_style_sheet(DOM::Document& document, DeprecatedString type, DOM::Element* owner_node, DeprecatedString media, DeprecatedString title, bool alternate, bool origin_clean, Optional<DeprecatedString> location, CSS::CSSStyleSheet* parent_style_sheet, CSS::CSSRule* owner_rule, CSS::CSSStyleSheet& sheet)
{
// 1. Create a new CSS style sheet object and set its properties as specified.
// FIXME: We receive `sheet` from the caller already. This is weird.
@ -96,16 +96,13 @@ void StyleElementUtils::create_a_css_style_sheet(DOM::Document& document, Deprec
sheet.set_owner_node(owner_node);
sheet.set_type(MUST(String::from_deprecated_string(type)));
sheet.set_media(move(media));
if (title.is_null())
sheet.set_title({});
else
sheet.set_title(MUST(String::from_deprecated_string(title)));
sheet.set_title(MUST(String::from_deprecated_string(title)));
sheet.set_alternate(alternate);
sheet.set_origin_clean(origin_clean);
if (location.is_null())
if (!location.has_value())
sheet.set_location({});
else
sheet.set_location(MUST(String::from_deprecated_string(location)));
sheet.set_location(MUST(String::from_deprecated_string(*location)));
// 2. Then run the add a CSS style sheet steps for the newly created CSS style sheet.
add_a_css_style_sheet(document, sheet);

View file

@ -20,7 +20,7 @@ public:
private:
void remove_a_css_style_sheet(DOM::Document& document, CSS::CSSStyleSheet& sheet);
void create_a_css_style_sheet(DOM::Document& document, DeprecatedString type, DOM::Element* owner_node, DeprecatedString media, DeprecatedString title, bool alternate, bool origin_clean, DeprecatedString location, CSS::CSSStyleSheet* parent_style_sheet, CSS::CSSRule* owner_rule, CSS::CSSStyleSheet& sheet);
void create_a_css_style_sheet(DOM::Document& document, DeprecatedString type, DOM::Element* owner_node, DeprecatedString media, DeprecatedString title, bool alternate, bool origin_clean, Optional<DeprecatedString> location, CSS::CSSStyleSheet* parent_style_sheet, CSS::CSSRule* owner_rule, CSS::CSSStyleSheet& sheet);
void add_a_css_style_sheet(DOM::Document& document, CSS::CSSStyleSheet& sheet);
// https://www.w3.org/TR/cssom/#associated-css-style-sheet

View file

@ -257,14 +257,14 @@ static Optional<DeprecatedString> record_namespace_information(DOM::Element cons
auto const& prefix_definition = attribute->local_name().to_deprecated_fly_string();
// 2. Let namespace definition be the value of attr's value.
auto namespace_definition = attribute->value().to_deprecated_string();
DeprecatedFlyString namespace_definition = attribute->value().to_deprecated_string();
// 3. If namespace definition is the XML namespace, then stop running these steps, and return to Main to visit the next attribute.
if (namespace_definition == Namespace::XML)
continue;
// 4. If namespace definition is the empty string (the declarative form of having no namespace), then let namespace definition be null instead.
if (namespace_definition.is_empty())
if (namespace_definition == ""sv)
namespace_definition = {};
// 5. If prefix definition is found in map given the namespace namespace definition, then stop running these steps, and return to Main to visit the next attribute.
@ -284,17 +284,19 @@ static Optional<DeprecatedString> record_namespace_information(DOM::Element cons
}
// https://w3c.github.io/DOM-Parsing/#dfn-serializing-an-attribute-value
static WebIDL::ExceptionOr<DeprecatedString> serialize_an_attribute_value(DeprecatedString const& attribute_value, [[maybe_unused]] RequireWellFormed require_well_formed)
static WebIDL::ExceptionOr<DeprecatedString> serialize_an_attribute_value(OneOf<DeprecatedString, DeprecatedFlyString> auto const& attribute_value, [[maybe_unused]] RequireWellFormed require_well_formed)
{
// FIXME: 1. If the require well-formed flag is set (its value is true), and attribute value contains characters that are not matched by the XML Char production,
// then throw an exception; the serialization of this attribute value would fail to produce a well-formed element serialization.
// 2. If attribute value is null, then return the empty string.
if (attribute_value.is_null())
return DeprecatedString::empty();
if constexpr (requires { attribute_value.is_null(); }) {
if (attribute_value.is_null())
return DeprecatedString::empty();
}
// 3. Otherwise, attribute value is a string. Return the value of attribute value, first replacing any occurrences of the following:
auto final_attribute_value = attribute_value;
DeprecatedString final_attribute_value = attribute_value;
// 1. "&" with "&amp;"
final_attribute_value = final_attribute_value.replace("&"sv, "&amp;"sv, ReplaceMode::All);

View file

@ -821,7 +821,7 @@ ErrorOr<void> dump_namespace_rule(StringBuilder& builder, CSS::CSSNamespaceRule
{
indent(builder, indent_levels);
TRY(builder.try_appendff(" Namespace: {}\n", namespace_.namespace_uri()));
if (!namespace_.prefix().is_null() && !namespace_.prefix().is_empty())
if (!namespace_.prefix().is_empty())
TRY(builder.try_appendff(" Prefix: {}\n", namespace_.prefix()));
return {};

View file

@ -27,7 +27,7 @@ void HTMLAnchorElement::initialize(JS::Realm& realm)
set_prototype(&Bindings::ensure_web_prototype<Bindings::HTMLAnchorElementPrototype>(realm, "HTMLAnchorElement"));
}
void HTMLAnchorElement::attribute_changed(FlyString const& name, DeprecatedString const& value)
void HTMLAnchorElement::attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value)
{
HTMLElement::attribute_changed(name, value);
if (name == HTML::AttributeNames::href) {
@ -35,9 +35,9 @@ void HTMLAnchorElement::attribute_changed(FlyString const& name, DeprecatedStrin
}
}
DeprecatedString HTMLAnchorElement::hyperlink_element_utils_href() const
Optional<String> HTMLAnchorElement::hyperlink_element_utils_href() const
{
return deprecated_attribute(HTML::AttributeNames::href);
return attribute(HTML::AttributeNames::href);
}
WebIDL::ExceptionOr<void> HTMLAnchorElement::set_hyperlink_element_utils_href(String href)
@ -98,7 +98,7 @@ i32 HTMLAnchorElement::default_tab_index_value() const
Optional<ARIA::Role> HTMLAnchorElement::default_role() const
{
// https://www.w3.org/TR/html-aria/#el-a-no-href
if (!href().is_null())
if (!href().is_empty())
return ARIA::Role::link;
// https://www.w3.org/TR/html-aria/#el-a
return ARIA::Role::generic;

View file

@ -43,12 +43,12 @@ private:
void run_activation_behavior(Web::DOM::Event const&);
// ^DOM::Element
virtual void attribute_changed(FlyString const& name, DeprecatedString const& value) override;
virtual void attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value) override;
virtual i32 default_tab_index_value() const override;
// ^HTML::HTMLHyperlinkElementUtils
virtual DOM::Document& hyperlink_element_utils_document() override { return document(); }
virtual DeprecatedString hyperlink_element_utils_href() const override;
virtual Optional<String> hyperlink_element_utils_href() const override;
virtual WebIDL::ExceptionOr<void> set_hyperlink_element_utils_href(String) override;
virtual bool hyperlink_element_utils_is_html_anchor_element() const final { return true; }
virtual bool hyperlink_element_utils_is_connected() const final { return is_connected(); }

View file

@ -23,7 +23,7 @@ void HTMLAreaElement::initialize(JS::Realm& realm)
set_prototype(&Bindings::ensure_web_prototype<Bindings::HTMLAreaElementPrototype>(realm, "HTMLAreaElement"));
}
void HTMLAreaElement::attribute_changed(FlyString const& name, DeprecatedString const& value)
void HTMLAreaElement::attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value)
{
HTMLElement::attribute_changed(name, value);
if (name == HTML::AttributeNames::href) {
@ -31,9 +31,9 @@ void HTMLAreaElement::attribute_changed(FlyString const& name, DeprecatedString
}
}
DeprecatedString HTMLAreaElement::hyperlink_element_utils_href() const
Optional<String> HTMLAreaElement::hyperlink_element_utils_href() const
{
return deprecated_attribute(HTML::AttributeNames::href);
return attribute(HTML::AttributeNames::href);
}
WebIDL::ExceptionOr<void> HTMLAreaElement::set_hyperlink_element_utils_href(String href)
@ -51,7 +51,7 @@ i32 HTMLAreaElement::default_tab_index_value() const
Optional<ARIA::Role> HTMLAreaElement::default_role() const
{
// https://www.w3.org/TR/html-aria/#el-area-no-href
if (!href().is_null())
if (!href().is_empty())
return ARIA::Role::link;
// https://www.w3.org/TR/html-aria/#el-area
return ARIA::Role::generic;

View file

@ -26,12 +26,12 @@ private:
virtual void initialize(JS::Realm&) override;
// ^DOM::Element
virtual void attribute_changed(FlyString const& name, DeprecatedString const& value) override;
virtual void attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value) override;
virtual i32 default_tab_index_value() const override;
// ^HTML::HTMLHyperlinkElementUtils
virtual DOM::Document& hyperlink_element_utils_document() override { return document(); }
virtual DeprecatedString hyperlink_element_utils_href() const override;
virtual Optional<String> hyperlink_element_utils_href() const override;
virtual WebIDL::ExceptionOr<void> set_hyperlink_element_utils_href(String) override;
virtual bool hyperlink_element_utils_is_html_anchor_element() const override { return false; }
virtual bool hyperlink_element_utils_is_connected() const override { return is_connected(); }

View file

@ -43,7 +43,7 @@ void HTMLBaseElement::removed_from(Node* parent)
document().update_base_element({});
}
void HTMLBaseElement::attribute_changed(FlyString const& name, DeprecatedString const& value)
void HTMLBaseElement::attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value)
{
HTMLElement::attribute_changed(name, value);

View file

@ -23,7 +23,7 @@ public:
virtual void inserted() override;
virtual void removed_from(Node*) override;
virtual void attribute_changed(FlyString const& name, DeprecatedString const& value) override;
virtual void attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value) override;
private:
HTMLBaseElement(DOM::Document&, DOM::QualifiedName);

View file

@ -55,26 +55,26 @@ void HTMLBodyElement::apply_presentational_hints(CSS::StyleProperties& style) co
});
}
void HTMLBodyElement::attribute_changed(FlyString const& name, DeprecatedString const& value)
void HTMLBodyElement::attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value)
{
HTMLElement::attribute_changed(name, value);
if (name.equals_ignoring_ascii_case("link"sv)) {
// https://html.spec.whatwg.org/multipage/rendering.html#the-page:rules-for-parsing-a-legacy-colour-value-3
auto color = parse_legacy_color_value(value);
auto color = parse_legacy_color_value(value.value_or(""));
if (color.has_value())
document().set_link_color(color.value());
} else if (name.equals_ignoring_ascii_case("alink"sv)) {
// https://html.spec.whatwg.org/multipage/rendering.html#the-page:rules-for-parsing-a-legacy-colour-value-5
auto color = parse_legacy_color_value(value);
auto color = parse_legacy_color_value(value.value_or(""));
if (color.has_value())
document().set_active_link_color(color.value());
} else if (name.equals_ignoring_ascii_case("vlink"sv)) {
// https://html.spec.whatwg.org/multipage/rendering.html#the-page:rules-for-parsing-a-legacy-colour-value-4
auto color = parse_legacy_color_value(value);
auto color = parse_legacy_color_value(value.value_or(""));
if (color.has_value())
document().set_visited_link_color(color.value());
} else if (name.equals_ignoring_ascii_case("background"sv)) {
m_background_style_value = CSS::ImageStyleValue::create(document().parse_url(value));
m_background_style_value = CSS::ImageStyleValue::create(document().parse_url(value.value_or("")));
m_background_style_value->on_animate = [this] {
if (layout_node()) {
layout_node()->set_needs_display();
@ -83,9 +83,9 @@ void HTMLBodyElement::attribute_changed(FlyString const& name, DeprecatedString
}
#undef __ENUMERATE
#define __ENUMERATE(attribute_name, event_name) \
if (name == HTML::AttributeNames::attribute_name) { \
element_event_handler_attribute_changed(event_name, String::from_deprecated_string(value).release_value()); \
#define __ENUMERATE(attribute_name, event_name) \
if (name == HTML::AttributeNames::attribute_name) { \
element_event_handler_attribute_changed(event_name, value.map([](auto& v) { return MUST(String::from_deprecated_string(v)); })); \
}
ENUMERATE_WINDOW_EVENT_HANDLERS(__ENUMERATE)
#undef __ENUMERATE

View file

@ -20,7 +20,7 @@ class HTMLBodyElement final
public:
virtual ~HTMLBodyElement() override;
virtual void attribute_changed(FlyString const&, DeprecatedString const&) override;
virtual void attribute_changed(FlyString const&, Optional<DeprecatedString> const&) override;
virtual void apply_presentational_hints(CSS::StyleProperties&) const override;
// https://www.w3.org/TR/html-aria/#el-body

View file

@ -41,14 +41,14 @@ void HTMLDetailsElement::initialize(JS::Realm& realm)
create_shadow_tree(realm).release_value_but_fixme_should_propagate_errors();
}
void HTMLDetailsElement::attribute_changed(FlyString const& name, DeprecatedString const& value)
void HTMLDetailsElement::attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value)
{
Base::attribute_changed(name, value);
// https://html.spec.whatwg.org/multipage/interactive-elements.html#details-notification-task-steps
if (name == HTML::AttributeNames::open) {
// 1. If the open attribute is added, queue a details toggle event task given the details element, "closed", and "open".
if (!value.is_null()) {
if (value.has_value()) {
queue_a_details_toggle_event_task("closed"_string, "open"_string);
}
// 2. Otherwise, queue a details toggle event task given the details element, "open", and "closed".

View file

@ -31,7 +31,7 @@ private:
virtual void visit_edges(Cell::Visitor&) override;
virtual void children_changed() override;
virtual void attribute_changed(FlyString const& name, DeprecatedString const& value) override;
virtual void attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value) override;
void queue_a_details_toggle_event_task(String old_state, String new_state);

View file

@ -224,18 +224,18 @@ bool HTMLElement::cannot_navigate() const
return !is<HTML::HTMLAnchorElement>(this) && !is_connected();
}
void HTMLElement::attribute_changed(FlyString const& name, DeprecatedString const& value)
void HTMLElement::attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value)
{
Element::attribute_changed(name, value);
if (name == HTML::AttributeNames::contenteditable) {
if (value.is_null()) {
if (!value.has_value()) {
m_content_editable_state = ContentEditableState::Inherit;
} else {
if (value.is_empty() || value.equals_ignoring_ascii_case("true"sv)) {
if (value->is_empty() || value->equals_ignoring_ascii_case("true"sv)) {
// "true", an empty string or a missing value map to the "true" state.
m_content_editable_state = ContentEditableState::True;
} else if (value.equals_ignoring_ascii_case("false"sv)) {
} else if (value->equals_ignoring_ascii_case("false"sv)) {
// "false" maps to the "false" state.
m_content_editable_state = ContentEditableState::False;
} else {
@ -248,9 +248,9 @@ void HTMLElement::attribute_changed(FlyString const& name, DeprecatedString cons
// 1. If namespace is not null, or localName is not the name of an event handler content attribute on element, then return.
// FIXME: Add the namespace part once we support attribute namespaces.
#undef __ENUMERATE
#define __ENUMERATE(attribute_name, event_name) \
if (name == HTML::AttributeNames::attribute_name) { \
element_event_handler_attribute_changed(event_name, String::from_deprecated_string(value).release_value()); \
#define __ENUMERATE(attribute_name, event_name) \
if (name == HTML::AttributeNames::attribute_name) { \
element_event_handler_attribute_changed(event_name, value.map([](auto& v) { return MUST(String::from_deprecated_string(v)); })); \
}
ENUMERATE_GLOBAL_EVENT_HANDLERS(__ENUMERATE)
#undef __ENUMERATE

View file

@ -27,7 +27,7 @@ class HTMLElement
public:
virtual ~HTMLElement() override;
DeprecatedString title() const { return deprecated_attribute(HTML::AttributeNames::title); }
Optional<String> title() const { return attribute(HTML::AttributeNames::title); }
StringView dir() const;
void set_dir(String const&);
@ -70,7 +70,7 @@ protected:
virtual void initialize(JS::Realm&) override;
virtual void attribute_changed(FlyString const& name, DeprecatedString const& value) override;
virtual void attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value) override;
virtual void visit_edges(Cell::Visitor&) override;

View file

@ -23,14 +23,14 @@ void HTMLFrameSetElement::initialize(JS::Realm& realm)
set_prototype(&Bindings::ensure_web_prototype<Bindings::HTMLFrameSetElementPrototype>(realm, "HTMLFrameSetElement"));
}
void HTMLFrameSetElement::attribute_changed(FlyString const& name, DeprecatedString const& value)
void HTMLFrameSetElement::attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value)
{
HTMLElement::attribute_changed(name, value);
#undef __ENUMERATE
#define __ENUMERATE(attribute_name, event_name) \
if (name == HTML::AttributeNames::attribute_name) { \
element_event_handler_attribute_changed(event_name, String::from_deprecated_string(value).release_value()); \
#define __ENUMERATE(attribute_name, event_name) \
if (name == HTML::AttributeNames::attribute_name) { \
element_event_handler_attribute_changed(event_name, value.map([](auto& v) { return MUST(String::from_deprecated_string(v)); })); \
}
ENUMERATE_WINDOW_EVENT_HANDLERS(__ENUMERATE)
#undef __ENUMERATE

View file

@ -24,7 +24,7 @@ private:
HTMLFrameSetElement(DOM::Document&, DOM::QualifiedName);
virtual void initialize(JS::Realm&) override;
virtual void attribute_changed(FlyString const&, DeprecatedString const&) override;
virtual void attribute_changed(FlyString const&, Optional<DeprecatedString> const&) override;
// ^HTML::GlobalEventHandlers
virtual EventTarget& global_event_handlers_to_event_target(FlyString const& event_name) override;

View file

@ -29,14 +29,14 @@ void HTMLHyperlinkElementUtils::set_the_url()
{
// 1. If this element's href content attribute is absent, set this element's url to null.
auto href_content_attribute = hyperlink_element_utils_href();
if (href_content_attribute.is_null()) {
if (!href_content_attribute.has_value()) {
m_url = {};
return;
}
// 2. Otherwise, parse this element's href content attribute value relative to this element's node document.
// If parsing is successful, set this element's url to the result; otherwise, set this element's url to null.
m_url = hyperlink_element_utils_document().parse_url(href_content_attribute);
m_url = hyperlink_element_utils_document().parse_url(*href_content_attribute);
}
// https://html.spec.whatwg.org/multipage/links.html#dom-hyperlink-origin
@ -429,12 +429,12 @@ DeprecatedString HTMLHyperlinkElementUtils::href() const
// 3. If url is null and this element has no href content attribute, return the empty string.
auto href_content_attribute = hyperlink_element_utils_href();
if (!url.has_value() && href_content_attribute.is_null())
if (!url.has_value() && !href_content_attribute.has_value())
return DeprecatedString::empty();
// 4. Otherwise, if url is null, return this element's href content attribute's value.
if (!url->is_valid())
return href_content_attribute;
return href_content_attribute->to_deprecated_string();
// 5. Return url, serialized.
return url->serialize();

View file

@ -51,7 +51,7 @@ public:
protected:
virtual DOM::Document& hyperlink_element_utils_document() = 0;
virtual DeprecatedString hyperlink_element_utils_href() const = 0;
virtual Optional<String> hyperlink_element_utils_href() const = 0;
virtual WebIDL::ExceptionOr<void> set_hyperlink_element_utils_href(String) = 0;
virtual bool hyperlink_element_utils_is_html_anchor_element() const = 0;
virtual bool hyperlink_element_utils_is_connected() const = 0;

View file

@ -33,7 +33,7 @@ JS::GCPtr<Layout::Node> HTMLIFrameElement::create_layout_node(NonnullRefPtr<CSS:
return heap().allocate_without_realm<Layout::FrameBox>(document(), *this, move(style));
}
void HTMLIFrameElement::attribute_changed(FlyString const& name, DeprecatedString const& value)
void HTMLIFrameElement::attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value)
{
HTMLElement::attribute_changed(name, value);
if (m_content_navigable)

View file

@ -36,7 +36,7 @@ private:
// ^DOM::Element
virtual void inserted() override;
virtual void removed_from(Node*) override;
virtual void attribute_changed(FlyString const& name, DeprecatedString const& value) override;
virtual void attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value) override;
virtual i32 default_tab_index_value() const override;
// https://html.spec.whatwg.org/multipage/iframe-embed-object.html#process-the-iframe-attributes

View file

@ -95,15 +95,15 @@ void HTMLImageElement::apply_presentational_hints(CSS::StyleProperties& style) c
});
}
void HTMLImageElement::attribute_changed(FlyString const& name, DeprecatedString const& value)
void HTMLImageElement::attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value)
{
HTMLElement::attribute_changed(name, value);
if (name == HTML::AttributeNames::crossorigin) {
if (value.is_null()) {
if (!value.has_value()) {
m_cors_setting = CORSSettingAttribute::NoCORS;
} else {
m_cors_setting = cors_setting_attribute_from_keyword(String::from_deprecated_string(value).release_value_but_fixme_should_propagate_errors());
m_cors_setting = cors_setting_attribute_from_keyword(String::from_deprecated_string(*value).release_value_but_fixme_should_propagate_errors());
}
}
@ -255,7 +255,7 @@ bool HTMLImageElement::complete() const
return true;
// - The srcset attribute is omitted and the src attribute's value is the empty string.
if (!has_attribute(HTML::AttributeNames::srcset) && deprecated_attribute(HTML::AttributeNames::src) == ""sv)
if (!has_attribute(HTML::AttributeNames::srcset) && attribute(HTML::AttributeNames::src).value().is_empty())
return true;
// - The img element's current request's state is completely available and its pending request is null.
@ -273,7 +273,7 @@ Optional<ARIA::Role> HTMLImageElement::default_role() const
{
// https://www.w3.org/TR/html-aria/#el-img
// https://www.w3.org/TR/html-aria/#el-img-no-alt
if (alt().is_null() || !alt().is_empty())
if (!alt().is_empty())
return ARIA::Role::img;
// https://www.w3.org/TR/html-aria/#el-img-empty-alt
return ARIA::Role::presentation;
@ -870,38 +870,38 @@ static void update_the_source_set(DOM::Element& element)
// 4. If el is an img element that has a srcset attribute, then set srcset to that attribute's value.
if (is<HTMLImageElement>(element)) {
if (auto srcset_value = element.deprecated_attribute(HTML::AttributeNames::srcset); !srcset_value.is_null())
srcset = String::from_deprecated_string(srcset_value).release_value_but_fixme_should_propagate_errors();
if (auto srcset_value = element.attribute(HTML::AttributeNames::srcset); srcset_value.has_value())
srcset = srcset_value.release_value();
}
// 5. Otherwise, if el is a link element that has an imagesrcset attribute, then set srcset to that attribute's value.
else if (is<HTMLLinkElement>(element)) {
if (auto imagesrcset_value = element.deprecated_attribute(HTML::AttributeNames::imagesrcset); !imagesrcset_value.is_null())
srcset = String::from_deprecated_string(imagesrcset_value).release_value_but_fixme_should_propagate_errors();
if (auto imagesrcset_value = element.attribute(HTML::AttributeNames::imagesrcset); imagesrcset_value.has_value())
srcset = imagesrcset_value.release_value();
}
// 6. If el is an img element that has a sizes attribute, then set sizes to that attribute's value.
if (is<HTMLImageElement>(element)) {
if (auto sizes_value = element.deprecated_attribute(HTML::AttributeNames::sizes); !sizes_value.is_null())
sizes = String::from_deprecated_string(sizes_value).release_value_but_fixme_should_propagate_errors();
if (auto sizes_value = element.attribute(HTML::AttributeNames::sizes); sizes_value.has_value())
sizes = sizes_value.release_value();
}
// 7. Otherwise, if el is a link element that has an imagesizes attribute, then set sizes to that attribute's value.
else if (is<HTMLLinkElement>(element)) {
if (auto imagesizes_value = element.deprecated_attribute(HTML::AttributeNames::imagesizes); !imagesizes_value.is_null())
sizes = String::from_deprecated_string(imagesizes_value).release_value_but_fixme_should_propagate_errors();
if (auto imagesizes_value = element.attribute(HTML::AttributeNames::imagesizes); imagesizes_value.has_value())
sizes = imagesizes_value.release_value();
}
// 8. If el is an img element that has a src attribute, then set default source to that attribute's value.
if (is<HTMLImageElement>(element)) {
if (auto src_value = element.deprecated_attribute(HTML::AttributeNames::src); !src_value.is_null())
default_source = String::from_deprecated_string(src_value).release_value_but_fixme_should_propagate_errors();
if (auto src_value = element.attribute(HTML::AttributeNames::src); src_value.has_value())
default_source = src_value.release_value();
}
// 9. Otherwise, if el is a link element that has an href attribute, then set default source to that attribute's value.
else if (is<HTMLLinkElement>(element)) {
if (auto href_value = element.deprecated_attribute(HTML::AttributeNames::href); !href_value.is_null())
default_source = String::from_deprecated_string(href_value).release_value_but_fixme_should_propagate_errors();
if (auto href_value = element.attribute(HTML::AttributeNames::href); href_value.has_value())
default_source = href_value.release_value();
}
// 10. Let el's source set be the result of creating a source set given default source, srcset, and sizes.

View file

@ -32,7 +32,7 @@ class HTMLImageElement final
public:
virtual ~HTMLImageElement() override;
virtual void attribute_changed(FlyString const& name, DeprecatedString const& value) override;
virtual void attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value) override;
DeprecatedString alt() const { return deprecated_attribute(HTML::AttributeNames::alt); }
DeprecatedString src() const { return deprecated_attribute(HTML::AttributeNames::src); }

View file

@ -523,8 +523,6 @@ void HTMLInputElement::create_shadow_tree_if_needed()
auto shadow_root = heap().allocate<DOM::ShadowRoot>(realm(), document(), *this, Bindings::ShadowRootMode::Closed);
auto initial_value = m_value;
if (initial_value.is_null())
initial_value = DeprecatedString::empty();
auto element = DOM::create_element(document(), HTML::TagNames::div, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
MUST(element->set_attribute(HTML::AttributeNames::style, R"~~~(
display: flex;
@ -552,7 +550,11 @@ void HTMLInputElement::create_shadow_tree_if_needed()
// NOTE: file upload state is mutable, but we don't allow the text node to be modifed
m_text_node->set_always_editable(false);
} else {
handle_readonly_attribute(deprecated_attribute(HTML::AttributeNames::readonly));
auto readonly = attribute(HTML::AttributeNames::readonly);
if (readonly.has_value())
handle_readonly_attribute(readonly->to_deprecated_string());
else
handle_readonly_attribute({});
}
m_text_node->set_editable_text_node_owner(Badge<HTMLInputElement> {}, *this);
@ -587,11 +589,11 @@ void HTMLInputElement::did_lose_focus()
});
}
void HTMLInputElement::attribute_changed(FlyString const& name, DeprecatedString const& value)
void HTMLInputElement::attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value)
{
HTMLElement::attribute_changed(name, value);
if (name == HTML::AttributeNames::checked) {
if (value.is_null()) {
if (!value.has_value()) {
// When the checked content attribute is removed, if the control does not have dirty checkedness,
// the user agent must set the checkedness of the element to false.
if (!m_dirty_checkedness)
@ -603,24 +605,27 @@ void HTMLInputElement::attribute_changed(FlyString const& name, DeprecatedString
set_checked(true, ChangeSource::Programmatic);
}
} else if (name == HTML::AttributeNames::type) {
m_type = parse_type_attribute(value);
m_type = parse_type_attribute(value.value_or(""));
} else if (name == HTML::AttributeNames::value) {
if (value.is_null()) {
if (!value.has_value()) {
if (!m_dirty_value) {
m_value = DeprecatedString::empty();
update_placeholder_visibility();
}
} else {
if (!m_dirty_value) {
m_value = value_sanitization_algorithm(value);
m_value = value_sanitization_algorithm(*value);
update_placeholder_visibility();
}
}
} else if (name == HTML::AttributeNames::placeholder) {
if (m_placeholder_text_node)
m_placeholder_text_node->set_data(MUST(String::from_deprecated_string(value)));
m_placeholder_text_node->set_data(MUST(String::from_deprecated_string(value.value_or(""))));
} else if (name == HTML::AttributeNames::readonly) {
handle_readonly_attribute(value);
if (value.has_value())
handle_readonly_attribute(*value);
else
handle_readonly_attribute({});
}
}

View file

@ -111,7 +111,7 @@ public:
virtual bool is_focusable() const override { return m_type != TypeAttributeState::Hidden; }
// ^HTMLElement
virtual void attribute_changed(FlyString const&, DeprecatedString const&) override;
virtual void attribute_changed(FlyString const&, Optional<DeprecatedString> const&) override;
// ^FormAssociatedElement
// https://html.spec.whatwg.org/multipage/forms.html#category-listed

View file

@ -18,7 +18,7 @@ public:
virtual JS::GCPtr<Layout::Node> create_layout_node(NonnullRefPtr<CSS::StyleProperties>) override;
DeprecatedString for_() const { return deprecated_attribute(HTML::AttributeNames::for_); }
Optional<String> for_() const { return attribute(HTML::AttributeNames::for_); }
private:
HTMLLabelElement(DOM::Document&, DOM::QualifiedName);

View file

@ -77,7 +77,7 @@ bool HTMLLinkElement::has_loaded_icon() const
return m_relationship & Relationship::Icon && resource() && resource()->is_loaded() && resource()->has_encoded_data();
}
void HTMLLinkElement::attribute_changed(FlyString const& name, DeprecatedString const& value)
void HTMLLinkElement::attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value)
{
HTMLElement::attribute_changed(name, value);
@ -85,7 +85,7 @@ void HTMLLinkElement::attribute_changed(FlyString const& name, DeprecatedString
if (name == HTML::AttributeNames::rel) {
m_relationship = 0;
// Keywords are always ASCII case-insensitive, and must be compared as such.
auto lowercased_value = value.to_lowercase();
auto lowercased_value = value.value_or("").to_lowercase();
// To determine which link types apply to a link, a, area, or form element,
// the element's rel attribute must be split on ASCII whitespace.
// The resulting tokens are the keywords for the link types that apply to that element.
@ -341,13 +341,14 @@ void HTMLLinkElement::process_stylesheet_resource(bool success, Fetch::Infrastru
// 1. If the element has a charset attribute, get an encoding from that attribute's value. If that succeeds, return the resulting encoding. [ENCODING]
// 2. Otherwise, return the document's character encoding. [DOM]
DeprecatedString encoding;
if (auto charset = deprecated_attribute(HTML::AttributeNames::charset); !charset.is_null())
encoding = charset;
else
encoding = document().encoding_or_default().to_deprecated_string();
Optional<String> encoding;
if (auto charset = attribute(HTML::AttributeNames::charset); charset.has_value())
encoding = charset.release_value();
auto decoder = TextCodec::decoder_for(encoding);
if (!encoding.has_value())
encoding = document().encoding_or_default();
auto decoder = TextCodec::decoder_for(*encoding);
if (!decoder.has_value()) {
// If we don't support the encoding yet, let's error out instead of trying to decode it as something it's most likely not.

View file

@ -39,7 +39,7 @@ private:
HTMLLinkElement(DOM::Document&, DOM::QualifiedName);
virtual void initialize(JS::Realm&) override;
void attribute_changed(FlyString const&, DeprecatedString const&) override;
void attribute_changed(FlyString const&, Optional<DeprecatedString> const&) override;
// ^ResourceClient
virtual void resource_did_fail() override;

View file

@ -83,17 +83,17 @@ void HTMLMediaElement::visit_edges(Cell::Visitor& visitor)
visitor.visit(m_fetch_controller);
}
void HTMLMediaElement::attribute_changed(FlyString const& name, DeprecatedString const& value)
void HTMLMediaElement::attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value)
{
Base::attribute_changed(name, value);
if (name == HTML::AttributeNames::src) {
load_element().release_value_but_fixme_should_propagate_errors();
} else if (name == HTML::AttributeNames::crossorigin) {
if (value.is_null())
if (!value.has_value())
m_crossorigin = cors_setting_attribute_from_keyword({});
else
m_crossorigin = cors_setting_attribute_from_keyword(String::from_deprecated_string(value).release_value_but_fixme_should_propagate_errors());
m_crossorigin = cors_setting_attribute_from_keyword(String::from_deprecated_string(*value).release_value_but_fixme_should_propagate_errors());
} else if (name == HTML::AttributeNames::muted) {
set_muted(true);
}

View file

@ -134,7 +134,7 @@ protected:
virtual void initialize(JS::Realm&) override;
virtual void visit_edges(Cell::Visitor&) override;
virtual void attribute_changed(FlyString const& name, DeprecatedString const& value) override;
virtual void attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value) override;
virtual void removed_from(DOM::Node*) override;
virtual void children_changed() override;

View file

@ -45,7 +45,7 @@ void HTMLObjectElement::visit_edges(Cell::Visitor& visitor)
visitor.visit(m_image_request);
}
void HTMLObjectElement::attribute_changed(FlyString const& name, DeprecatedString const& value)
void HTMLObjectElement::attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value)
{
NavigableContainer::attribute_changed(name, value);

View file

@ -34,7 +34,7 @@ class HTMLObjectElement final
public:
virtual ~HTMLObjectElement() override;
virtual void attribute_changed(FlyString const& name, DeprecatedString const& value) override;
virtual void attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value) override;
String data() const;
void set_data(String const& data) { MUST(set_attribute(HTML::AttributeNames::data, data)); }

View file

@ -31,12 +31,12 @@ void HTMLOptionElement::initialize(JS::Realm& realm)
set_prototype(&Bindings::ensure_web_prototype<Bindings::HTMLOptionElementPrototype>(realm, "HTMLOptionElement"));
}
void HTMLOptionElement::attribute_changed(FlyString const& name, DeprecatedString const& value)
void HTMLOptionElement::attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value)
{
HTMLElement::attribute_changed(name, value);
if (name == HTML::AttributeNames::selected) {
if (value.is_null()) {
if (!value.has_value()) {
// Whenever an option element's selected attribute is removed, if its dirtiness is false, its selectedness must be set to false.
if (!m_dirty)
m_selected = false;

View file

@ -40,7 +40,7 @@ private:
virtual void initialize(JS::Realm&) override;
void attribute_changed(FlyString const& name, DeprecatedString const& value) override;
void attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value) override;
void ask_for_a_reset();

View file

@ -45,20 +45,20 @@ void HTMLScriptElement::visit_edges(Cell::Visitor& visitor)
visitor.visit(m_preparation_time_document.ptr());
}
void HTMLScriptElement::attribute_changed(FlyString const& name, DeprecatedString const& value)
void HTMLScriptElement::attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value)
{
Base::attribute_changed(name, value);
if (name == HTML::AttributeNames::crossorigin) {
if (value.is_null())
if (!value.has_value())
m_crossorigin = cors_setting_attribute_from_keyword({});
else
m_crossorigin = cors_setting_attribute_from_keyword(String::from_deprecated_string(value).release_value_but_fixme_should_propagate_errors());
m_crossorigin = cors_setting_attribute_from_keyword(String::from_deprecated_string(*value).release_value_but_fixme_should_propagate_errors());
} else if (name == HTML::AttributeNames::referrerpolicy) {
if (value.is_null())
if (!value.has_value())
m_referrer_policy.clear();
else
m_referrer_policy = ReferrerPolicy::from_string(value);
m_referrer_policy = ReferrerPolicy::from_string(*value);
}
}

View file

@ -62,7 +62,7 @@ private:
virtual void initialize(JS::Realm&) override;
virtual void visit_edges(Cell::Visitor&) override;
virtual void attribute_changed(FlyString const& name, DeprecatedString const& value) override;
virtual void attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value) override;
// https://html.spec.whatwg.org/multipage/scripting.html#prepare-the-script-element
void prepare_script();

View file

@ -24,19 +24,19 @@ HTMLSlotElement::HTMLSlotElement(DOM::Document& document, DOM::QualifiedName qua
return;
// 2. If value is null and oldValue is the empty string, then return.
if (value.is_null() && old_value == DeprecatedString::empty())
if (!value.has_value() && old_value == DeprecatedString::empty())
return;
// 3. If value is the empty string and oldValue is null, then return.
if (value == DeprecatedString::empty() && old_value.is_null())
if (value == DeprecatedString::empty() && !old_value.has_value())
return;
// 4. If value is null or the empty string, then set elements name to the empty string.
if (value.is_empty())
if (!value.has_value())
set_slot_name({});
// 5. Otherwise, set elements name to value.
else
set_slot_name(MUST(String::from_deprecated_string(value)));
set_slot_name(MUST(String::from_deprecated_string(*value)));
// 6. Run assign slottables for a tree with elements root.
DOM::assign_slottables_for_a_tree(root());

View file

@ -40,15 +40,15 @@ void HTMLVideoElement::visit_edges(Cell::Visitor& visitor)
visitor.visit(m_fetch_controller);
}
void HTMLVideoElement::attribute_changed(FlyString const& name, DeprecatedString const& value)
void HTMLVideoElement::attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value)
{
Base::attribute_changed(name, value);
if (name == HTML::AttributeNames::poster) {
if (value.is_null())
if (!value.has_value())
determine_element_poster_frame({}).release_value_but_fixme_should_propagate_errors();
else
determine_element_poster_frame(value).release_value_but_fixme_should_propagate_errors();
determine_element_poster_frame(*value).release_value_but_fixme_should_propagate_errors();
}
}

View file

@ -47,7 +47,7 @@ private:
virtual void initialize(JS::Realm&) override;
virtual void visit_edges(Cell::Visitor&) override;
virtual void attribute_changed(FlyString const& name, DeprecatedString const& value) override;
virtual void attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value) override;
virtual JS::GCPtr<Layout::Node> create_layout_node(NonnullRefPtr<CSS::StyleProperties>) override;

View file

@ -76,8 +76,8 @@ WebIDL::ExceptionOr<void> NavigableContainer::create_new_child_navigable()
Optional<String> target_name;
// 5. If element has a name content attribute, then set targetName to the value of that attribute.
if (auto value = deprecated_attribute(HTML::AttributeNames::name); !value.is_null())
target_name = String::from_deprecated_string(value).release_value_but_fixme_should_propagate_errors();
if (auto value = attribute(HTML::AttributeNames::name); value.has_value())
target_name = move(value);
// 6. Let documentState be a new document state, with
// - document: document
@ -195,7 +195,7 @@ Optional<AK::URL> NavigableContainer::shared_attribute_processing_steps_for_ifra
// then parse the value of that attribute relative to element's node document.
// If this is successful, then set url to the resulting URL record.
auto src_attribute_value = deprecated_attribute(HTML::AttributeNames::src);
if (!src_attribute_value.is_null() && !src_attribute_value.is_empty()) {
if (!src_attribute_value.is_empty()) {
auto parsed_src = document().parse_url(src_attribute_value);
if (parsed_src.is_valid())
url = parsed_src;

View file

@ -16,7 +16,7 @@ namespace Web::HTML {
class Origin {
public:
Origin() = default;
Origin(DeprecatedString const& scheme, AK::URL::Host const& host, u16 port)
Origin(Optional<DeprecatedString> const& scheme, AK::URL::Host const& host, u16 port)
: m_scheme(scheme)
, m_host(host)
, m_port(port)
@ -24,9 +24,12 @@ public:
}
// https://html.spec.whatwg.org/multipage/origin.html#concept-origin-opaque
bool is_opaque() const { return m_scheme.is_null() && m_host.has<Empty>() && m_port == 0; }
bool is_opaque() const { return !m_scheme.has_value() && m_host.has<Empty>() && m_port == 0; }
DeprecatedString const& scheme() const { return m_scheme; }
StringView scheme() const
{
return m_scheme.map([](auto& str) { return str.view(); }).value_or(StringView {});
}
AK::URL::Host const& host() const { return m_host; }
u16 port() const { return m_port; }
@ -110,7 +113,7 @@ public:
bool operator==(Origin const& other) const { return is_same_origin(other); }
private:
DeprecatedString m_scheme;
Optional<DeprecatedString> m_scheme;
AK::URL::Host m_host;
u16 m_port { 0 };
};

View file

@ -1092,10 +1092,11 @@ void BlockFormattingContext::layout_list_item_marker(ListItemBox const& list_ite
CSSPixels default_marker_width = max(4, marker.font().pixel_size_rounded_up() - 4);
if (marker.text().is_empty()) {
auto marker_text = marker.text().value_or("");
if (marker_text.is_empty()) {
marker_state.set_content_width(image_width + default_marker_width);
} else {
auto text_width = marker.font().width(marker.text());
auto text_width = marker.font().width(marker_text);
marker_state.set_content_width(image_width + CSSPixels::nearest_value_for(text_width));
}

View file

@ -93,7 +93,7 @@ Label const* Label::label_for_control_node(LabelableNode const& control)
// same tree as the label element. If the attribute is specified and there is an element in the tree
// whose ID is equal to the value of the for attribute, and the first such element in tree order is
// a labelable element, then that element is the label element's labeled control.
if (auto id = control.dom_node().deprecated_attribute(HTML::AttributeNames::id); !id.is_empty()) {
if (auto id = control.dom_node().attribute(HTML::AttributeNames::id); id.has_value() && !id->is_empty()) {
Label const* label = nullptr;
control.document().layout_node()->for_each_in_inclusive_subtree_of_type<Label>([&](auto& node) {
@ -126,9 +126,9 @@ LabelableNode* Label::labeled_control()
// same tree as the label element. If the attribute is specified and there is an element in the tree
// whose ID is equal to the value of the for attribute, and the first such element in tree order is
// a labelable element, then that element is the label element's labeled control.
if (auto for_ = dom_node().for_(); !for_.is_null()) {
if (auto for_ = dom_node().for_(); for_.has_value()) {
document().layout_node()->for_each_in_inclusive_subtree_of_type<LabelableNode>([&](auto& node) {
if (node.dom_node().deprecated_attribute(HTML::AttributeNames::id) == for_) {
if (node.dom_node().attribute(HTML::AttributeNames::id) == for_) {
control = &node;
return IterationDecision::Break;
}

View file

@ -18,7 +18,7 @@ public:
explicit ListItemMarkerBox(DOM::Document&, CSS::ListStyleType, CSS::ListStylePosition, size_t index, NonnullRefPtr<CSS::StyleProperties>);
virtual ~ListItemMarkerBox() override;
DeprecatedString const& text() const { return m_text; }
Optional<DeprecatedString> const& text() const { return m_text; }
virtual JS::GCPtr<Painting::Paintable> create_paintable() const override;
@ -33,7 +33,7 @@ private:
CSS::ListStylePosition m_list_style_position { CSS::ListStylePosition::Outside };
size_t m_index;
DeprecatedString m_text {};
Optional<DeprecatedString> m_text {};
};
template<>

View file

@ -306,9 +306,9 @@ void TextNode::invalidate_text_for_rendering()
DeprecatedString const& TextNode::text_for_rendering() const
{
if (m_text_for_rendering.is_null())
if (!m_text_for_rendering.has_value())
const_cast<TextNode*>(this)->compute_text_for_rendering();
return m_text_for_rendering;
return *m_text_for_rendering;
}
// NOTE: This collapses whitespace into a single ASCII space if the CSS white-space property tells us to.

View file

@ -55,7 +55,7 @@ public:
private:
virtual bool is_text_node() const final { return true; }
DeprecatedString m_text_for_rendering;
Optional<DeprecatedString> m_text_for_rendering;
};
template<>

View file

@ -533,8 +533,8 @@ bool EventHandler::handle_mousemove(CSSPixelPoint position, CSSPixelPoint screen
if (hovered_node_changed) {
JS::GCPtr<HTML::HTMLElement const> hovered_html_element = document.hovered_node() ? document.hovered_node()->enclosing_html_element_with_attribute(HTML::AttributeNames::title) : nullptr;
if (hovered_html_element && !hovered_html_element->title().is_null()) {
page->client().page_did_enter_tooltip_area(m_browsing_context->to_top_level_position(position), hovered_html_element->title());
if (hovered_html_element && hovered_html_element->title().has_value()) {
page->client().page_did_enter_tooltip_area(m_browsing_context->to_top_level_position(position), hovered_html_element->title()->to_deprecated_string());
} else {
page->client().page_did_leave_tooltip_area();
}

View file

@ -113,13 +113,15 @@ void MarkerPaintable::paint(PaintContext& context, PaintPhase phase) const
case CSS::ListStyleType::LowerRoman:
case CSS::ListStyleType::UpperAlpha:
case CSS::ListStyleType::UpperLatin:
case CSS::ListStyleType::UpperRoman:
if (layout_box().text().is_null())
case CSS::ListStyleType::UpperRoman: {
auto text = layout_box().text();
if (!text.has_value())
break;
// FIXME: This should use proper text layout logic!
// This does not line up with the text in the <li> element which looks very sad :(
context.painter().draw_text(device_enclosing.to_type<int>(), layout_box().text(), layout_box().scaled_font(context), Gfx::TextAlignment::Center, color);
context.painter().draw_text(device_enclosing.to_type<int>(), *text, layout_box().scaled_font(context), Gfx::TextAlignment::Center, color);
break;
}
case CSS::ListStyleType::None:
return;

View file

@ -22,18 +22,18 @@ void SVGCircleElement::initialize(JS::Realm& realm)
set_prototype(&Bindings::ensure_web_prototype<Bindings::SVGCircleElementPrototype>(realm, "SVGCircleElement"));
}
void SVGCircleElement::attribute_changed(FlyString const& name, DeprecatedString const& value)
void SVGCircleElement::attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value)
{
SVGGeometryElement::attribute_changed(name, value);
if (name == SVG::AttributeNames::cx) {
m_center_x = AttributeParser::parse_coordinate(value);
m_center_x = AttributeParser::parse_coordinate(value.value_or(""));
m_path.clear();
} else if (name == SVG::AttributeNames::cy) {
m_center_y = AttributeParser::parse_coordinate(value);
m_center_y = AttributeParser::parse_coordinate(value.value_or(""));
m_path.clear();
} else if (name == SVG::AttributeNames::r) {
m_radius = AttributeParser::parse_positive_length(value);
m_radius = AttributeParser::parse_positive_length(value.value_or(""));
m_path.clear();
}
}

View file

@ -17,7 +17,7 @@ class SVGCircleElement final : public SVGGeometryElement {
public:
virtual ~SVGCircleElement() override = default;
virtual void attribute_changed(FlyString const& name, DeprecatedString const& value) override;
virtual void attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value) override;
virtual Gfx::Path& get_path() override;

View file

@ -34,7 +34,7 @@ void SVGElement::visit_edges(Cell::Visitor& visitor)
visitor.visit(m_dataset);
}
void SVGElement::attribute_changed(FlyString const& name, DeprecatedString const& value)
void SVGElement::attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value)
{
Base::attribute_changed(name, value);

View file

@ -17,7 +17,7 @@ class SVGElement : public DOM::Element {
public:
virtual bool requires_svg_container() const override { return true; }
virtual void attribute_changed(FlyString const& name, DeprecatedString const& value) override;
virtual void attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value) override;
virtual void children_changed() override;
virtual void inserted() override;

View file

@ -22,21 +22,21 @@ void SVGEllipseElement::initialize(JS::Realm& realm)
set_prototype(&Bindings::ensure_web_prototype<Bindings::SVGEllipseElementPrototype>(realm, "SVGEllipseElement"));
}
void SVGEllipseElement::attribute_changed(FlyString const& name, DeprecatedString const& value)
void SVGEllipseElement::attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value)
{
SVGGeometryElement::attribute_changed(name, value);
if (name == SVG::AttributeNames::cx) {
m_center_x = AttributeParser::parse_coordinate(value);
m_center_x = AttributeParser::parse_coordinate(value.value_or(""));
m_path.clear();
} else if (name == SVG::AttributeNames::cy) {
m_center_y = AttributeParser::parse_coordinate(value);
m_center_y = AttributeParser::parse_coordinate(value.value_or(""));
m_path.clear();
} else if (name == SVG::AttributeNames::rx) {
m_radius_x = AttributeParser::parse_positive_length(value);
m_radius_x = AttributeParser::parse_positive_length(value.value_or(""));
m_path.clear();
} else if (name == SVG::AttributeNames::ry) {
m_radius_y = AttributeParser::parse_positive_length(value);
m_radius_y = AttributeParser::parse_positive_length(value.value_or(""));
m_path.clear();
}
}

View file

@ -17,7 +17,7 @@ class SVGEllipseElement final : public SVGGeometryElement {
public:
virtual ~SVGEllipseElement() override = default;
virtual void attribute_changed(FlyString const& name, DeprecatedString const& value) override;
virtual void attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value) override;
virtual Gfx::Path& get_path() override;

View file

@ -17,15 +17,15 @@ SVGGradientElement::SVGGradientElement(DOM::Document& document, DOM::QualifiedNa
{
}
void SVGGradientElement::attribute_changed(FlyString const& name, DeprecatedString const& value)
void SVGGradientElement::attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value)
{
SVGElement::attribute_changed(name, value);
if (name == AttributeNames::gradientUnits) {
m_gradient_units = AttributeParser::parse_units(value);
m_gradient_units = AttributeParser::parse_units(value.value_or(""));
} else if (name == AttributeNames::spreadMethod) {
m_spread_method = AttributeParser::parse_spread_method(value);
m_spread_method = AttributeParser::parse_spread_method(value.value_or(""));
} else if (name == AttributeNames::gradientTransform) {
if (auto transform_list = AttributeParser::parse_transform(value); transform_list.has_value()) {
if (auto transform_list = AttributeParser::parse_transform(value.value_or("")); transform_list.has_value()) {
m_gradient_transform = transform_from_transform_list(*transform_list);
} else {
m_gradient_transform = {};

View file

@ -40,7 +40,7 @@ class SVGGradientElement : public SVGElement {
public:
virtual ~SVGGradientElement() override = default;
virtual void attribute_changed(FlyString const& name, DeprecatedString const& value) override;
virtual void attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value) override;
virtual Optional<Gfx::PaintStyle const&> to_gfx_paint_style(SVGPaintContext const&) const = 0;

View file

@ -32,11 +32,11 @@ void SVGGraphicsElement::initialize(JS::Realm& realm)
set_prototype(&Bindings::ensure_web_prototype<Bindings::SVGGraphicsElementPrototype>(realm, "SVGGraphicsElement"));
}
void SVGGraphicsElement::attribute_changed(FlyString const& name, DeprecatedString const& value)
void SVGGraphicsElement::attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value)
{
SVGElement::attribute_changed(name, value);
if (name == "transform"sv) {
auto transform_list = AttributeParser::parse_transform(value);
auto transform_list = AttributeParser::parse_transform(value.value_or(""));
if (transform_list.has_value())
m_transform = transform_from_transform_list(*transform_list);
}

View file

@ -25,7 +25,7 @@ class SVGGraphicsElement : public SVGElement {
public:
virtual void apply_presentational_hints(CSS::StyleProperties&) const override;
virtual void attribute_changed(FlyString const& name, DeprecatedString const& value) override;
virtual void attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value) override;
Optional<Gfx::Color> fill_color() const;
Optional<FillRule> fill_rule() const;

View file

@ -22,21 +22,21 @@ void SVGLineElement::initialize(JS::Realm& realm)
set_prototype(&Bindings::ensure_web_prototype<Bindings::SVGLineElementPrototype>(realm, "SVGLineElement"));
}
void SVGLineElement::attribute_changed(FlyString const& name, DeprecatedString const& value)
void SVGLineElement::attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value)
{
SVGGeometryElement::attribute_changed(name, value);
if (name == SVG::AttributeNames::x1) {
m_x1 = AttributeParser::parse_coordinate(value);
m_x1 = AttributeParser::parse_coordinate(value.value_or(""));
m_path.clear();
} else if (name == SVG::AttributeNames::y1) {
m_y1 = AttributeParser::parse_coordinate(value);
m_y1 = AttributeParser::parse_coordinate(value.value_or(""));
m_path.clear();
} else if (name == SVG::AttributeNames::x2) {
m_x2 = AttributeParser::parse_coordinate(value);
m_x2 = AttributeParser::parse_coordinate(value.value_or(""));
m_path.clear();
} else if (name == SVG::AttributeNames::y2) {
m_y2 = AttributeParser::parse_coordinate(value);
m_y2 = AttributeParser::parse_coordinate(value.value_or(""));
m_path.clear();
}
}

View file

@ -17,7 +17,7 @@ class SVGLineElement final : public SVGGeometryElement {
public:
virtual ~SVGLineElement() override = default;
virtual void attribute_changed(FlyString const& name, DeprecatedString const& value) override;
virtual void attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value) override;
virtual Gfx::Path& get_path() override;

View file

@ -24,22 +24,22 @@ void SVGLinearGradientElement::initialize(JS::Realm& realm)
set_prototype(&Bindings::ensure_web_prototype<Bindings::SVGLinearGradientElementPrototype>(realm, "SVGLinearGradientElement"));
}
void SVGLinearGradientElement::attribute_changed(FlyString const& name, DeprecatedString const& value)
void SVGLinearGradientElement::attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value)
{
SVGGradientElement::attribute_changed(name, value);
// FIXME: Should allow for `<number-percentage> | <length>` for x1, x2, y1, y2
if (name == SVG::AttributeNames::x1) {
m_x1 = AttributeParser::parse_number_percentage(value);
m_x1 = AttributeParser::parse_number_percentage(value.value_or(""));
m_paint_style = nullptr;
} else if (name == SVG::AttributeNames::y1) {
m_y1 = AttributeParser::parse_number_percentage(value);
m_y1 = AttributeParser::parse_number_percentage(value.value_or(""));
m_paint_style = nullptr;
} else if (name == SVG::AttributeNames::x2) {
m_x2 = AttributeParser::parse_number_percentage(value);
m_x2 = AttributeParser::parse_number_percentage(value.value_or(""));
m_paint_style = nullptr;
} else if (name == SVG::AttributeNames::y2) {
m_y2 = AttributeParser::parse_number_percentage(value);
m_y2 = AttributeParser::parse_number_percentage(value.value_or(""));
m_paint_style = nullptr;
}
}

View file

@ -18,7 +18,7 @@ class SVGLinearGradientElement : public SVGGradientElement {
public:
virtual ~SVGLinearGradientElement() override = default;
virtual void attribute_changed(FlyString const& name, DeprecatedString const& value) override;
virtual void attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value) override;
virtual Optional<Gfx::PaintStyle const&> to_gfx_paint_style(SVGPaintContext const&) const override;

View file

@ -31,13 +31,13 @@ JS::GCPtr<Layout::Node> SVGMaskElement::create_layout_node(NonnullRefPtr<CSS::St
return heap().allocate_without_realm<Layout::SVGGraphicsBox>(document(), *this, move(style));
}
void SVGMaskElement::attribute_changed(FlyString const& name, DeprecatedString const& value)
void SVGMaskElement::attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value)
{
SVGGraphicsElement::attribute_changed(name, value);
if (name == AttributeNames::maskUnits) {
m_mask_units = AttributeParser::parse_units(value);
m_mask_units = AttributeParser::parse_units(value.value_or(""));
} else if (name == AttributeNames::maskContentUnits) {
m_mask_content_units = AttributeParser::parse_units(value);
m_mask_content_units = AttributeParser::parse_units(value.value_or(""));
}
}

View file

@ -17,7 +17,7 @@ class SVGMaskElement final : public SVGGraphicsElement {
public:
virtual ~SVGMaskElement() override;
virtual void attribute_changed(FlyString const& name, DeprecatedString const& value) override;
virtual void attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value) override;
virtual JS::GCPtr<Layout::Node> create_layout_node(NonnullRefPtr<CSS::StyleProperties>) override;

View file

@ -95,12 +95,12 @@ void SVGPathElement::initialize(JS::Realm& realm)
set_prototype(&Bindings::ensure_web_prototype<Bindings::SVGPathElementPrototype>(realm, "SVGPathElement"));
}
void SVGPathElement::attribute_changed(FlyString const& name, DeprecatedString const& value)
void SVGPathElement::attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value)
{
SVGGeometryElement::attribute_changed(name, value);
if (name == "d") {
m_instructions = AttributeParser::parse_path_data(value);
m_instructions = AttributeParser::parse_path_data(value.value_or(""));
m_path.clear();
}
}

View file

@ -19,7 +19,7 @@ class SVGPathElement final : public SVGGeometryElement {
public:
virtual ~SVGPathElement() override = default;
virtual void attribute_changed(FlyString const& name, DeprecatedString const& value) override;
virtual void attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value) override;
virtual Gfx::Path& get_path() override;

View file

@ -22,12 +22,12 @@ void SVGPolygonElement::initialize(JS::Realm& realm)
set_prototype(&Bindings::ensure_web_prototype<Bindings::SVGPolygonElementPrototype>(realm, "SVGPolygonElement"));
}
void SVGPolygonElement::attribute_changed(FlyString const& name, DeprecatedString const& value)
void SVGPolygonElement::attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value)
{
SVGGeometryElement::attribute_changed(name, value);
if (name == SVG::AttributeNames::points) {
m_points = AttributeParser::parse_points(value);
m_points = AttributeParser::parse_points(value.value_or(""));
m_path.clear();
}
}

View file

@ -16,7 +16,7 @@ class SVGPolygonElement final : public SVGGeometryElement {
public:
virtual ~SVGPolygonElement() override = default;
virtual void attribute_changed(FlyString const& name, DeprecatedString const& value) override;
virtual void attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value) override;
virtual Gfx::Path& get_path() override;

View file

@ -22,12 +22,12 @@ void SVGPolylineElement::initialize(JS::Realm& realm)
set_prototype(&Bindings::ensure_web_prototype<Bindings::SVGPolylineElementPrototype>(realm, "SVGPolylineElement"));
}
void SVGPolylineElement::attribute_changed(FlyString const& name, DeprecatedString const& value)
void SVGPolylineElement::attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value)
{
SVGGeometryElement::attribute_changed(name, value);
if (name == SVG::AttributeNames::points) {
m_points = AttributeParser::parse_points(value);
m_points = AttributeParser::parse_points(value.value_or(""));
m_path.clear();
}
}

View file

@ -16,7 +16,7 @@ class SVGPolylineElement final : public SVGGeometryElement {
public:
virtual ~SVGPolylineElement() override = default;
virtual void attribute_changed(FlyString const& name, DeprecatedString const& value) override;
virtual void attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value) override;
virtual Gfx::Path& get_path() override;

View file

@ -21,29 +21,29 @@ void SVGRadialGradientElement::initialize(JS::Realm& realm)
set_prototype(&Bindings::ensure_web_prototype<Bindings::SVGRadialGradientElementPrototype>(realm, "SVGRadialGradientElement"));
}
void SVGRadialGradientElement::attribute_changed(FlyString const& name, DeprecatedString const& value)
void SVGRadialGradientElement::attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value)
{
SVGGradientElement::attribute_changed(name, value);
// FIXME: These are <length> or <coordinate> in the spec, but all examples seem to allow percentages
// and unitless values.
if (name == SVG::AttributeNames::cx) {
m_cx = AttributeParser::parse_number_percentage(value);
m_cx = AttributeParser::parse_number_percentage(value.value_or(""));
m_paint_style = nullptr;
} else if (name == SVG::AttributeNames::cy) {
m_cy = AttributeParser::parse_number_percentage(value);
m_cy = AttributeParser::parse_number_percentage(value.value_or(""));
m_paint_style = nullptr;
} else if (name == SVG::AttributeNames::fx) {
m_fx = AttributeParser::parse_number_percentage(value);
m_fx = AttributeParser::parse_number_percentage(value.value_or(""));
m_paint_style = nullptr;
} else if (name == SVG::AttributeNames::fy) {
m_fy = AttributeParser::parse_number_percentage(value);
m_fy = AttributeParser::parse_number_percentage(value.value_or(""));
m_paint_style = nullptr;
} else if (name == SVG::AttributeNames::fr) {
m_fr = AttributeParser::parse_number_percentage(value);
m_fr = AttributeParser::parse_number_percentage(value.value_or(""));
m_paint_style = nullptr;
} else if (name == SVG::AttributeNames::r) {
m_r = AttributeParser::parse_number_percentage(value);
m_r = AttributeParser::parse_number_percentage(value.value_or(""));
m_paint_style = nullptr;
}
}

View file

@ -18,7 +18,7 @@ class SVGRadialGradientElement : public SVGGradientElement {
public:
virtual ~SVGRadialGradientElement() override = default;
virtual void attribute_changed(FlyString const& name, DeprecatedString const& value) override;
virtual void attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value) override;
virtual Optional<Gfx::PaintStyle const&> to_gfx_paint_style(SVGPaintContext const&) const override;

View file

@ -24,27 +24,27 @@ void SVGRectElement::initialize(JS::Realm& realm)
set_prototype(&Bindings::ensure_web_prototype<Bindings::SVGRectElementPrototype>(realm, "SVGRectElement"));
}
void SVGRectElement::attribute_changed(FlyString const& name, DeprecatedString const& value)
void SVGRectElement::attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value)
{
SVGGeometryElement::attribute_changed(name, value);
if (name == SVG::AttributeNames::x) {
m_x = AttributeParser::parse_coordinate(value);
m_x = AttributeParser::parse_coordinate(value.value_or(""));
m_path.clear();
} else if (name == SVG::AttributeNames::y) {
m_y = AttributeParser::parse_coordinate(value);
m_y = AttributeParser::parse_coordinate(value.value_or(""));
m_path.clear();
} else if (name == SVG::AttributeNames::width) {
m_width = AttributeParser::parse_positive_length(value);
m_width = AttributeParser::parse_positive_length(value.value_or(""));
m_path.clear();
} else if (name == SVG::AttributeNames::height) {
m_height = AttributeParser::parse_positive_length(value);
m_height = AttributeParser::parse_positive_length(value.value_or(""));
m_path.clear();
} else if (name == SVG::AttributeNames::rx) {
m_radius_x = AttributeParser::parse_length(value);
m_radius_x = AttributeParser::parse_length(value.value_or(""));
m_path.clear();
} else if (name == SVG::AttributeNames::ry) {
m_radius_y = AttributeParser::parse_length(value);
m_radius_y = AttributeParser::parse_length(value.value_or(""));
m_path.clear();
}
}

View file

@ -17,7 +17,7 @@ class SVGRectElement final : public SVGGeometryElement {
public:
virtual ~SVGRectElement() override = default;
virtual void attribute_changed(FlyString const& name, DeprecatedString const& value) override;
virtual void attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value) override;
virtual Gfx::Path& get_path() override;

View file

@ -38,7 +38,7 @@ void SVGSVGElement::apply_presentational_hints(CSS::StyleProperties& style) cons
{
Base::apply_presentational_hints(style);
auto width_attribute = deprecated_attribute(SVG::AttributeNames::width);
auto width_attribute = attribute(SVG::AttributeNames::width);
auto parsing_context = CSS::Parser::ParsingContext { document(), CSS::Parser::ParsingContext::Mode::SVGPresentationAttribute };
if (auto width_value = parse_css_value(parsing_context, deprecated_attribute(Web::HTML::AttributeNames::width), CSS::PropertyID::Width)) {
style.set_property(CSS::PropertyID::Width, width_value.release_nonnull());
@ -50,7 +50,7 @@ void SVGSVGElement::apply_presentational_hints(CSS::StyleProperties& style) cons
}
// Height defaults to 100%
auto height_attribute = deprecated_attribute(SVG::AttributeNames::height);
auto height_attribute = attribute(SVG::AttributeNames::height);
if (auto height_value = parse_css_value(parsing_context, deprecated_attribute(Web::HTML::AttributeNames::height), CSS::PropertyID::Height)) {
style.set_property(CSS::PropertyID::Height, height_value.release_nonnull());
} else if (height_attribute == "") {
@ -61,14 +61,14 @@ void SVGSVGElement::apply_presentational_hints(CSS::StyleProperties& style) cons
}
}
void SVGSVGElement::attribute_changed(FlyString const& name, DeprecatedString const& value)
void SVGSVGElement::attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value)
{
SVGGraphicsElement::attribute_changed(name, value);
if (name.equals_ignoring_ascii_case(SVG::AttributeNames::viewBox))
m_view_box = try_parse_view_box(value);
m_view_box = try_parse_view_box(value.value_or(""));
if (name.equals_ignoring_ascii_case(SVG::AttributeNames::preserveAspectRatio))
m_preserve_aspect_ratio = AttributeParser::parse_preserve_aspect_ratio(value);
m_preserve_aspect_ratio = AttributeParser::parse_preserve_aspect_ratio(value.value_or(""));
if (name.equals_ignoring_ascii_case(SVG::AttributeNames::width) || name.equals_ignoring_ascii_case(SVG::AttributeNames::height))
update_fallback_view_box_for_svg_as_image();
}

View file

@ -36,7 +36,7 @@ private:
virtual bool is_svg_svg_element() const override { return true; }
virtual void attribute_changed(FlyString const& name, DeprecatedString const& value) override;
virtual void attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value) override;
void update_fallback_view_box_for_svg_as_image();

View file

@ -19,11 +19,11 @@ SVGStopElement::SVGStopElement(DOM::Document& document, DOM::QualifiedName quali
{
}
void SVGStopElement::attribute_changed(FlyString const& name, DeprecatedString const& value)
void SVGStopElement::attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value)
{
SVGElement::attribute_changed(name, value);
if (name == SVG::AttributeNames::offset) {
m_offset = AttributeParser::parse_number_percentage(value);
m_offset = AttributeParser::parse_number_percentage(value.value_or(""));
}
}

View file

@ -19,7 +19,7 @@ class SVGStopElement final : public SVGElement {
public:
virtual ~SVGStopElement() override = default;
virtual void attribute_changed(FlyString const& name, DeprecatedString const& value) override;
virtual void attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value) override;
JS::NonnullGCPtr<SVGAnimatedNumber> offset() const;

View file

@ -39,10 +39,10 @@ void SVGSymbolElement::apply_presentational_hints(CSS::StyleProperties& style) c
}
}
void SVGSymbolElement::attribute_changed(FlyString const& name, DeprecatedString const& value)
void SVGSymbolElement::attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value)
{
if (name.equals_ignoring_ascii_case(SVG::AttributeNames::viewBox))
m_view_box = try_parse_view_box(value);
m_view_box = try_parse_view_box(value.value_or(""));
}
bool SVGSymbolElement::is_direct_child_of_use_shadow_tree() const

View file

@ -29,7 +29,7 @@ private:
bool is_direct_child_of_use_shadow_tree() const;
virtual void attribute_changed(FlyString const& name, DeprecatedString const& value) override;
virtual void attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value) override;
Optional<ViewBox> m_view_box;
};

View file

@ -28,18 +28,18 @@ void SVGTextPositioningElement::initialize(JS::Realm& realm)
set_prototype(&Bindings::ensure_web_prototype<Bindings::SVGTextPositioningElementPrototype>(realm, "SVGTextPositioningElement"));
}
void SVGTextPositioningElement::attribute_changed(FlyString const& name, DeprecatedString const& value)
void SVGTextPositioningElement::attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value)
{
SVGGraphicsElement::attribute_changed(name, value);
if (name == SVG::AttributeNames::x) {
m_x = AttributeParser::parse_coordinate(value).value_or(m_x);
m_x = AttributeParser::parse_coordinate(value.value_or("")).value_or(m_x);
} else if (name == SVG::AttributeNames::y) {
m_y = AttributeParser::parse_coordinate(value).value_or(m_y);
m_y = AttributeParser::parse_coordinate(value.value_or("")).value_or(m_y);
} else if (name == SVG::AttributeNames::dx) {
m_dx = AttributeParser::parse_coordinate(value).value_or(m_dx);
m_dx = AttributeParser::parse_coordinate(value.value_or("")).value_or(m_dx);
} else if (name == SVG::AttributeNames::dy) {
m_dy = AttributeParser::parse_coordinate(value).value_or(m_dy);
m_dy = AttributeParser::parse_coordinate(value.value_or("")).value_or(m_dy);
}
}

View file

@ -16,7 +16,7 @@ class SVGTextPositioningElement : public SVGTextContentElement {
WEB_PLATFORM_OBJECT(SVGTextPositioningElement, SVGTextContentElement);
public:
virtual void attribute_changed(FlyString const& name, DeprecatedString const& value) override;
virtual void attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value) override;
Gfx::FloatPoint get_offset() const;

View file

@ -45,18 +45,18 @@ void SVGUseElement::visit_edges(Cell::Visitor& visitor)
visitor.visit(m_document_observer);
}
void SVGUseElement::attribute_changed(FlyString const& name, DeprecatedString const& value)
void SVGUseElement::attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value)
{
Base::attribute_changed(name, value);
// https://svgwg.org/svg2-draft/struct.html#UseLayout
if (name == SVG::AttributeNames::x) {
m_x = AttributeParser::parse_coordinate(value);
m_x = AttributeParser::parse_coordinate(value.value_or(""));
} else if (name == SVG::AttributeNames::y) {
m_y = AttributeParser::parse_coordinate(value);
m_y = AttributeParser::parse_coordinate(value.value_or(""));
} else if (name == SVG::AttributeNames::href) {
// FIXME: Support the xlink:href attribute as a fallback
m_referenced_id = parse_id_from_href(value);
m_referenced_id = parse_id_from_href(value.value_or(""));
clone_element_tree_as_our_shadow_tree(referenced_element());
}

View file

@ -20,7 +20,7 @@ class SVGUseElement final : public SVGGraphicsElement {
public:
virtual ~SVGUseElement() override = default;
virtual void attribute_changed(FlyString const& name, DeprecatedString const& value) override;
virtual void attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value) override;
virtual void inserted() override;

View file

@ -512,7 +512,7 @@ WebIDL::ExceptionOr<void> XMLHttpRequest::open(String const& method_string, Stri
// Unset thiss upload listener flag.
m_upload_listener = false;
// Set thiss request method to method.
m_request_method = move(normalized_method);
m_request_method = normalized_method.span();
// Set thiss request URL to parsedURL.
m_request_url = parsed_url;
// Set thiss synchronous flag if async is false; otherwise unset thiss synchronous flag.