From 928576e0ac40a4766673870acb63bda0e73d8b4a Mon Sep 17 00:00:00 2001 From: Hexeption Date: Tue, 4 Jun 2024 08:04:44 +0100 Subject: [PATCH] LibWeb: Added HTMLLinkElement.as (cherry picked from commit 2f4668edce2effb38563b9da229d00d3ba5dc508, manually amended to move `||` at the start of the line to appease clang-format) --- Base/res/html/misc/linkas.html | 21 +++++++++++++++++ .../Libraries/LibWeb/HTML/AttributeNames.h | 1 + .../Libraries/LibWeb/HTML/HTMLLinkElement.cpp | 23 +++++++++++++++++++ .../Libraries/LibWeb/HTML/HTMLLinkElement.h | 2 ++ .../Libraries/LibWeb/HTML/HTMLLinkElement.idl | 2 +- 5 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 Base/res/html/misc/linkas.html diff --git a/Base/res/html/misc/linkas.html b/Base/res/html/misc/linkas.html new file mode 100644 index 0000000000..e660c0062a --- /dev/null +++ b/Base/res/html/misc/linkas.html @@ -0,0 +1,21 @@ + + + + + Link AS test + + + + + \ No newline at end of file diff --git a/Userland/Libraries/LibWeb/HTML/AttributeNames.h b/Userland/Libraries/LibWeb/HTML/AttributeNames.h index 9d0f51260c..39e6d060d9 100644 --- a/Userland/Libraries/LibWeb/HTML/AttributeNames.h +++ b/Userland/Libraries/LibWeb/HTML/AttributeNames.h @@ -25,6 +25,7 @@ namespace AttributeNames { __ENUMERATE_HTML_ATTRIBUTE(alt) \ __ENUMERATE_HTML_ATTRIBUTE(archive) \ __ENUMERATE_HTML_ATTRIBUTE(async) \ + __ENUMERATE_HTML_ATTRIBUTE(as) \ __ENUMERATE_HTML_ATTRIBUTE(autocomplete) \ __ENUMERATE_HTML_ATTRIBUTE(autofocus) \ __ENUMERATE_HTML_ATTRIBUTE(autoplay) \ diff --git a/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.cpp index dc7a74b672..6525200bf0 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.cpp @@ -90,6 +90,29 @@ void HTMLLinkElement::inserted() } } +// https://html.spec.whatwg.org/multipage/semantics.html#dom-link-as +String HTMLLinkElement::as() const +{ + String attribute_value = get_attribute_value(HTML::AttributeNames::as); + + if (attribute_value.equals_ignoring_ascii_case("fetch"sv) + || attribute_value.equals_ignoring_ascii_case("image"sv) + || attribute_value.equals_ignoring_ascii_case("script"sv) + || attribute_value.equals_ignoring_ascii_case("style"sv) + || attribute_value.equals_ignoring_ascii_case("video"sv) + || attribute_value.equals_ignoring_ascii_case("audio"sv) + || attribute_value.equals_ignoring_ascii_case("track"sv) + || attribute_value.equals_ignoring_ascii_case("font"sv)) + return attribute_value.to_lowercase().release_value(); + + return String {}; +} + +WebIDL::ExceptionOr HTMLLinkElement::set_as(String const& value) +{ + return set_attribute(HTML::AttributeNames::as, move(value)); +} + // https://html.spec.whatwg.org/multipage/semantics.html#dom-link-rellist JS::NonnullGCPtr HTMLLinkElement::rel_list() { diff --git a/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.h b/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.h index 4392d12f78..276ad28d64 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.h @@ -33,6 +33,8 @@ public: String rel() const { return get_attribute_value(HTML::AttributeNames::rel); } String type() const { return get_attribute_value(HTML::AttributeNames::type); } String href() const { return get_attribute_value(HTML::AttributeNames::href); } + String as() const; + WebIDL::ExceptionOr set_as(String const&); JS::NonnullGCPtr rel_list(); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.idl b/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.idl index f031f6c4de..338c9983c6 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.idl +++ b/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.idl @@ -12,7 +12,7 @@ interface HTMLLinkElement : HTMLElement { [CEReactions, Reflect] attribute DOMString href; [CEReactions, Reflect=crossorigin, Enumerated=CORSSettingsAttribute] attribute DOMString? crossOrigin; [CEReactions, Reflect] attribute DOMString rel; - [FIXME, CEReactions] attribute DOMString as; + [CEReactions] attribute DOMString as; [SameObject, PutForwards=value] readonly attribute DOMTokenList relList; [CEReactions, Reflect] attribute DOMString media; [CEReactions, Reflect] attribute DOMString integrity;