1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 12:38:12 +00:00

LibHTML: Implement basic tiled background image support

It's now possible to set a page background image via <body background>.
Also, HtmlView now officially handles rendering the body element's
background (color, image or both.) LayoutBox is responsible for all
other background rendering.

Note that it's not yet possible to use CSS background-image properties
directly, since we can't parse them yet. :^)
This commit is contained in:
Andreas Kling 2019-10-19 11:49:46 +02:00
parent 96f10c8de2
commit 5a34225999
11 changed files with 101 additions and 7 deletions

View file

@ -119,6 +119,27 @@ Color Document::background_color() const
return background_color.value()->to_color(*this);
}
RefPtr<GraphicsBitmap> Document::background_image() const
{
auto* body_element = body();
if (!body_element)
return {};
auto* body_layout_node = body_element->layout_node();
if (!body_layout_node)
return {};
auto background_image = body_layout_node->style().property(CSS::PropertyID::BackgroundImage);
if (!background_image.has_value() || !background_image.value()->is_image())
return {};
auto& image_value = static_cast<const ImageStyleValue&>(*background_image.value());
if (!image_value.bitmap())
return {};
return *image_value.bitmap();
}
URL Document::complete_url(const String& string) const
{
URL url(string);