LibWeb/DOM: Implement the Document object's partial attributes

This commit is contained in:
PGHales 2024-04-18 13:58:48 -06:00 committed by Andreas Kling
commit 75626c6cd2
Notes: sideshowbarker 2024-07-17 03:35:24 +09:00
5 changed files with 125 additions and 0 deletions

View file

@ -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<HTML::HTMLFrameSetElement>(*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<HTML::HTMLFrameSetElement>(*body_element))
MUST(body_element->set_attribute(HTML::AttributeNames::text, value));
}
String Document::link_color() const
{
if (auto* body_element = body(); body_element && !is<HTML::HTMLFrameSetElement>(*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<HTML::HTMLFrameSetElement>(*body_element))
MUST(body_element->set_attribute(HTML::AttributeNames::link, value));
}
String Document::vlink_color() const
{
if (auto* body_element = body(); body_element && !is<HTML::HTMLFrameSetElement>(*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<HTML::HTMLFrameSetElement>(*body_element))
MUST(body_element->set_attribute(HTML::AttributeNames::vlink, value));
}
String Document::alink_color() const
{
if (auto* body_element = body(); body_element && !is<HTML::HTMLFrameSetElement>(*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<HTML::HTMLFrameSetElement>(*body_element))
MUST(body_element->set_attribute(HTML::AttributeNames::alink, value));
}
String Document::bg_color() const
{
if (auto* body_element = body(); body_element && !is<HTML::HTMLFrameSetElement>(*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<HTML::HTMLFrameSetElement>(*body_element))
MUST(body_element->set_attribute(HTML::AttributeNames::bgcolor, value));
}
String Document::dump_dom_tree_as_json() const
{
StringBuilder builder;

View file

@ -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);

View file

@ -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;