From 75626c6cd2789f08f3afb12f427ffd4bd0e7babc Mon Sep 17 00:00:00 2001 From: PGHales Date: Thu, 18 Apr 2024 13:58:48 -0600 Subject: [PATCH] LibWeb/DOM: Implement the Document object's partial attributes --- .../DOM/Document-set-partial-attributes.txt | 20 ++++++ .../DOM/Document-set-partial-attributes.html | 18 +++++ Userland/Libraries/LibWeb/DOM/Document.cpp | 65 +++++++++++++++++++ Userland/Libraries/LibWeb/DOM/Document.h | 15 +++++ Userland/Libraries/LibWeb/DOM/Document.idl | 7 ++ 5 files changed, 125 insertions(+) create mode 100644 Tests/LibWeb/Text/expected/DOM/Document-set-partial-attributes.txt create mode 100644 Tests/LibWeb/Text/input/DOM/Document-set-partial-attributes.html diff --git a/Tests/LibWeb/Text/expected/DOM/Document-set-partial-attributes.txt b/Tests/LibWeb/Text/expected/DOM/Document-set-partial-attributes.txt new file mode 100644 index 00000000000..0edbe53f297 --- /dev/null +++ b/Tests/LibWeb/Text/expected/DOM/Document-set-partial-attributes.txt @@ -0,0 +1,20 @@ +before document.fgColor= +before body attribute text=null +after document.fgColor=red +after body attribute text=red +before document.linkColor= +before body attribute link=null +after document.linkColor=red +after body attribute link=red +before document.alinkColor= +before body attribute alink=null +after document.alinkColor=red +after body attribute alink=red +before document.vlinkColor= +before body attribute vlink=null +after document.vlinkColor=red +after body attribute vlink=red +before document.bgColor= +before body attribute bgcolor=null +after document.bgColor=red +after body attribute bgcolor=red diff --git a/Tests/LibWeb/Text/input/DOM/Document-set-partial-attributes.html b/Tests/LibWeb/Text/input/DOM/Document-set-partial-attributes.html new file mode 100644 index 00000000000..c3cee2a89be --- /dev/null +++ b/Tests/LibWeb/Text/input/DOM/Document-set-partial-attributes.html @@ -0,0 +1,18 @@ + + + diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index fcb94e648e1..d326d425e3f 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -2285,6 +2285,71 @@ void Document::set_cookie(StringView cookie_string, Cookie::Source source) page().client().page_did_set_cookie(m_url, cookie.value(), source); } +String Document::fg_color() const +{ + if (auto* body_element = body(); body_element && !is(*body_element)) + return body_element->get_attribute_value(HTML::AttributeNames::text); + return ""_string; +} + +void Document::set_fg_color(String const& value) +{ + if (auto* body_element = body(); body_element && !is(*body_element)) + MUST(body_element->set_attribute(HTML::AttributeNames::text, value)); +} + +String Document::link_color() const +{ + if (auto* body_element = body(); body_element && !is(*body_element)) + return body_element->get_attribute_value(HTML::AttributeNames::link); + return ""_string; +} + +void Document::set_link_color(String const& value) +{ + if (auto* body_element = body(); body_element && !is(*body_element)) + MUST(body_element->set_attribute(HTML::AttributeNames::link, value)); +} + +String Document::vlink_color() const +{ + if (auto* body_element = body(); body_element && !is(*body_element)) + return body_element->get_attribute_value(HTML::AttributeNames::vlink); + return ""_string; +} + +void Document::set_vlink_color(String const& value) +{ + if (auto* body_element = body(); body_element && !is(*body_element)) + MUST(body_element->set_attribute(HTML::AttributeNames::vlink, value)); +} + +String Document::alink_color() const +{ + if (auto* body_element = body(); body_element && !is(*body_element)) + return body_element->get_attribute_value(HTML::AttributeNames::alink); + return ""_string; +} + +void Document::set_alink_color(String const& value) +{ + if (auto* body_element = body(); body_element && !is(*body_element)) + MUST(body_element->set_attribute(HTML::AttributeNames::alink, value)); +} + +String Document::bg_color() const +{ + if (auto* body_element = body(); body_element && !is(*body_element)) + return body_element->get_attribute_value(HTML::AttributeNames::bgcolor); + return ""_string; +} + +void Document::set_bg_color(String const& value) +{ + if (auto* body_element = body(); body_element && !is(*body_element)) + MUST(body_element->set_attribute(HTML::AttributeNames::bgcolor, value)); +} + String Document::dump_dom_tree_as_json() const { StringBuilder builder; diff --git a/Userland/Libraries/LibWeb/DOM/Document.h b/Userland/Libraries/LibWeb/DOM/Document.h index 90c64400180..7c108699288 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.h +++ b/Userland/Libraries/LibWeb/DOM/Document.h @@ -110,6 +110,21 @@ public: String cookie(Cookie::Source = Cookie::Source::NonHttp); void set_cookie(StringView, Cookie::Source = Cookie::Source::NonHttp); + String fg_color() const; + void set_fg_color(String const&); + + String link_color() const; + void set_link_color(String const&); + + String vlink_color() const; + void set_vlink_color(String const&); + + String alink_color() const; + void set_alink_color(String const&); + + String bg_color() const; + void set_bg_color(String const&); + String referrer() const; void set_referrer(String); diff --git a/Userland/Libraries/LibWeb/DOM/Document.idl b/Userland/Libraries/LibWeb/DOM/Document.idl index 1753b027c27..db18fc3d355 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.idl +++ b/Userland/Libraries/LibWeb/DOM/Document.idl @@ -57,6 +57,13 @@ interface Document : Node { attribute DOMString cookie; + // https://html.spec.whatwg.org/#Document-partial + [CEReactions, LegacyNullToEmptyString] attribute DOMString fgColor; + [CEReactions, LegacyNullToEmptyString] attribute DOMString linkColor; + [CEReactions, LegacyNullToEmptyString] attribute DOMString vlinkColor; + [CEReactions, LegacyNullToEmptyString] attribute DOMString alinkColor; + [CEReactions, LegacyNullToEmptyString] attribute DOMString bgColor; + readonly attribute USVString referrer; readonly attribute Element? activeElement;