summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/DOM/Document.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-03-23 17:36:25 +0100
committerAndreas Kling <kling@serenityos.org>2022-03-23 17:38:00 +0100
commite0c77279341f02698a11dc600a8c80ebaf6762f5 (patch)
treefd348cb14bcddd7bf0537bae26ab3f9b462bb85e /Userland/Libraries/LibWeb/DOM/Document.cpp
parentca85ac26d4063bd0ad1be2b80277d9af4cb8944a (diff)
downloadserenity-e0c77279341f02698a11dc600a8c80ebaf6762f5.zip
LibWeb: Fill the whole viewport with the correct background color
CSS2 tells us to use the HTML element's background color if not transparent. Otherwise, the BODY element's background color.
Diffstat (limited to 'Userland/Libraries/LibWeb/DOM/Document.cpp')
-rw-r--r--Userland/Libraries/LibWeb/DOM/Document.cpp27
1 files changed, 15 insertions, 12 deletions
diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp
index 85960232a5..929042dc74 100644
--- a/Userland/Libraries/LibWeb/DOM/Document.cpp
+++ b/Userland/Libraries/LibWeb/DOM/Document.cpp
@@ -489,21 +489,24 @@ void Document::tear_down_layout_tree()
m_layout_root = nullptr;
}
-Color Document::background_color(const Palette& palette) const
+Color Document::background_color(Gfx::Palette const& palette) const
{
- auto default_color = palette.base();
- auto* body_element = body();
- if (!body_element)
- return default_color;
+ // CSS2 says we should use the HTML element's background color unless it's transparent...
+ if (auto* html_element = this->html_element(); html_element && html_element->layout_node()) {
+ auto color = html_element->layout_node()->computed_values().background_color();
+ if (color.alpha())
+ return color;
+ }
- auto* body_layout_node = body_element->layout_node();
- if (!body_layout_node)
- return default_color;
+ // ...in which case we use the BODY element's background color.
+ if (auto* body_element = body(); body_element && body_element->layout_node()) {
+ auto color = body_element->layout_node()->computed_values().background_color();
+ if (color.alpha())
+ return color;
+ }
- auto color = body_layout_node->computed_values().background_color();
- if (!color.alpha())
- return default_color;
- return color;
+ // If both HTML and BODY are transparent, we fall back to the system's "base" palette color.
+ return palette.base();
}
Vector<CSS::BackgroundLayerData> const* Document::background_layers() const