1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 09:47:35 +00:00

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.
This commit is contained in:
Andreas Kling 2022-03-23 17:36:25 +01:00
parent ca85ac26d4
commit e0c7727934
2 changed files with 16 additions and 13 deletions

View file

@ -489,21 +489,24 @@ void Document::tear_down_layout_tree()
m_layout_root = nullptr; 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(); // CSS2 says we should use the HTML element's background color unless it's transparent...
auto* body_element = body(); if (auto* html_element = this->html_element(); html_element && html_element->layout_node()) {
if (!body_element) auto color = html_element->layout_node()->computed_values().background_color();
return default_color; if (color.alpha())
return color;
}
auto* body_layout_node = body_element->layout_node(); // ...in which case we use the BODY element's background color.
if (!body_layout_node) if (auto* body_element = body(); body_element && body_element->layout_node()) {
return default_color; 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 both HTML and BODY are transparent, we fall back to the system's "base" palette color.
if (!color.alpha()) return palette.base();
return default_color;
return color;
} }
Vector<CSS::BackgroundLayerData> const* Document::background_layers() const Vector<CSS::BackgroundLayerData> const* Document::background_layers() const

View file

@ -47,7 +47,7 @@ void InitialContainingBlock::build_stacking_context_tree()
void InitialContainingBlock::paint_all_phases(PaintContext& context) void InitialContainingBlock::paint_all_phases(PaintContext& context)
{ {
build_stacking_context_tree_if_needed(); 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()); context.painter().translate(-context.viewport_rect().location());
paint_box()->stacking_context()->paint(context); paint_box()->stacking_context()->paint(context);
} }