diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-10-19 11:49:46 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-10-19 11:49:46 +0200 |
commit | 5a3422599976f20801828f79d8bad7dcc8d84272 (patch) | |
tree | 84bbf5aaaf87fe187e64ffa900b2c11bf19a76a2 /Libraries/LibHTML/Layout | |
parent | 96f10c8de2a519db92e087fd660f27c1aaa5563f (diff) | |
download | serenity-5a3422599976f20801828f79d8bad7dcc8d84272.zip |
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. :^)
Diffstat (limited to 'Libraries/LibHTML/Layout')
-rw-r--r-- | Libraries/LibHTML/Layout/LayoutBox.cpp | 22 | ||||
-rw-r--r-- | Libraries/LibHTML/Layout/LayoutBox.h | 2 |
2 files changed, 21 insertions, 3 deletions
diff --git a/Libraries/LibHTML/Layout/LayoutBox.cpp b/Libraries/LibHTML/Layout/LayoutBox.cpp index 39d7c494e8..44ab81fe03 100644 --- a/Libraries/LibHTML/Layout/LayoutBox.cpp +++ b/Libraries/LibHTML/Layout/LayoutBox.cpp @@ -1,5 +1,6 @@ #include <LibGUI/GPainter.h> #include <LibHTML/DOM/Document.h> +#include <LibHTML/DOM/HTMLBodyElement.h> #include <LibHTML/Frame.h> #include <LibHTML/Layout/LayoutBlock.h> #include <LibHTML/Layout/LayoutBox.h> @@ -26,9 +27,19 @@ void LayoutBox::render(RenderingContext& context) padded_rect.set_y(y() - box_model().padding().top.to_px()); padded_rect.set_height(height() + box_model().padding().top.to_px() + box_model().padding().bottom.to_px()); - auto bgcolor = style().property(CSS::PropertyID::BackgroundColor); - if (bgcolor.has_value() && bgcolor.value()->is_color()) { - context.painter().fill_rect(padded_rect, bgcolor.value()->to_color(document())); + if (!is_body()) { + auto bgcolor = style().property(CSS::PropertyID::BackgroundColor); + if (bgcolor.has_value() && bgcolor.value()->is_color()) { + context.painter().fill_rect(padded_rect, bgcolor.value()->to_color(document())); + } + + auto bgimage = style().property(CSS::PropertyID::BackgroundImage); + if (bgimage.has_value() && bgimage.value()->is_image()) { + auto& image_value = static_cast<const ImageStyleValue&>(*bgimage.value()); + if (image_value.bitmap()) { + context.painter().draw_tiled_bitmap(padded_rect, *image_value.bitmap()); + } + } } // FIXME: Respect all individual border sides @@ -93,3 +104,8 @@ void LayoutBox::set_needs_display() LayoutNode::set_needs_display(); } + +bool LayoutBox::is_body() const +{ + return node() && node() == document().body(); +} diff --git a/Libraries/LibHTML/Layout/LayoutBox.h b/Libraries/LibHTML/Layout/LayoutBox.h index f66be67571..3fa0c294bf 100644 --- a/Libraries/LibHTML/Layout/LayoutBox.h +++ b/Libraries/LibHTML/Layout/LayoutBox.h @@ -18,6 +18,8 @@ public: virtual HitTestResult hit_test(const Point& position) const override; virtual void set_needs_display() override; + bool is_body() const; + protected: LayoutBox(const Node* node, NonnullRefPtr<StyleProperties> style) : LayoutNodeWithStyleAndBoxModelMetrics(node, move(style)) |