mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-29 12:49:05 +00:00
LibWeb/DOM: Implement the Document object's partial attributes
This commit is contained in:
parent
ded344aa2c
commit
75626c6cd2
Notes:
sideshowbarker
2024-07-17 03:35:24 +09:00
Author: https://github.com/PGHales
Commit: 75626c6cd2
Pull-request: https://github.com/SerenityOS/serenity/pull/23956
Reviewed-by: https://github.com/LucasChollet
Reviewed-by: https://github.com/awesomekling
Reviewed-by: https://github.com/tcl3
5 changed files with 125 additions and 0 deletions
|
@ -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
|
|
@ -0,0 +1,18 @@
|
|||
<!DOCTYPE html>
|
||||
<script src="../include.js"></script>
|
||||
<script>
|
||||
test(() => {
|
||||
function testPartialDocumentAttribute(documentAttr, bodyAttr) {
|
||||
println(`before document.${documentAttr}=${document[documentAttr]}`);
|
||||
println(`before body attribute ${bodyAttr}=${document.body.getAttribute(bodyAttr)}`);
|
||||
document[documentAttr] = "red";
|
||||
println(`after document.${documentAttr}=${document[documentAttr]}`);
|
||||
println(`after body attribute ${bodyAttr}=${document.body.getAttribute(bodyAttr)}`);
|
||||
}
|
||||
testPartialDocumentAttribute("fgColor", "text");
|
||||
testPartialDocumentAttribute("linkColor", "link");
|
||||
testPartialDocumentAttribute("alinkColor", "alink");
|
||||
testPartialDocumentAttribute("vlinkColor", "vlink");
|
||||
testPartialDocumentAttribute("bgColor", "bgcolor");
|
||||
});
|
||||
</script>
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue