mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:47:44 +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:
parent
daf6d8173c
commit
aeee98b3a1
189 changed files with 597 additions and 652 deletions
|
@ -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;
|
||||
|
|
|
@ -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(); }
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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(); }
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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".
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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); }
|
||||
|
|
|
@ -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({});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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)); }
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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 element’s name to the empty string.
|
||||
if (value.is_empty())
|
||||
if (!value.has_value())
|
||||
set_slot_name({});
|
||||
// 5. Otherwise, set element’s 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 element’s root.
|
||||
DOM::assign_slottables_for_a_tree(root());
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 };
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue