diff options
author | Andreas Kling <kling@serenityos.org> | 2022-03-23 17:36:25 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-03-23 17:38:00 +0100 |
commit | e0c77279341f02698a11dc600a8c80ebaf6762f5 (patch) | |
tree | fd348cb14bcddd7bf0537bae26ab3f9b462bb85e /Userland | |
parent | ca85ac26d4063bd0ad1be2b80277d9af4cb8944a (diff) | |
download | serenity-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')
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/Document.cpp | 27 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/InitialContainingBlock.cpp | 2 |
2 files changed, 16 insertions, 13 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 diff --git a/Userland/Libraries/LibWeb/Layout/InitialContainingBlock.cpp b/Userland/Libraries/LibWeb/Layout/InitialContainingBlock.cpp index a077dfcdcf..8bb8b3582f 100644 --- a/Userland/Libraries/LibWeb/Layout/InitialContainingBlock.cpp +++ b/Userland/Libraries/LibWeb/Layout/InitialContainingBlock.cpp @@ -47,7 +47,7 @@ void InitialContainingBlock::build_stacking_context_tree() void InitialContainingBlock::paint_all_phases(PaintContext& context) { build_stacking_context_tree_if_needed(); - context.painter().fill_rect(enclosing_int_rect(paint_box()->absolute_rect()), context.palette().base()); + context.painter().fill_rect(enclosing_int_rect(paint_box()->absolute_rect()), document().background_color(context.palette())); context.painter().translate(-context.viewport_rect().location()); paint_box()->stacking_context()->paint(context); } |