diff options
author | Tobias Christiansen <tobi@tobyase.de> | 2021-07-23 21:31:31 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-07-24 22:16:48 +0200 |
commit | 5471c872469b059a51d9d652853baa15de006fac (patch) | |
tree | 853d96407ec0a76eb507a70ec62f5c5d18d24a22 /Userland/Libraries/LibWeb | |
parent | 281689e1fa01586722efd0fa47ec1638cca190de (diff) | |
download | serenity-5471c872469b059a51d9d652853baa15de006fac.zip |
LibWeb: Add box-shadow rendering
This patch adds the box-shadow rendering to Boxes. We do parse the
blur-radius of a box-shadow but we don't use it for now as the Filter
in the system don't seem quite powerful enough yet to handle that.
Diffstat (limited to 'Userland/Libraries/LibWeb')
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/Box.cpp | 31 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/Box.h | 1 |
2 files changed, 31 insertions, 1 deletions
diff --git a/Userland/Libraries/LibWeb/Layout/Box.cpp b/Userland/Libraries/LibWeb/Layout/Box.cpp index 206746f161..132f724d05 100644 --- a/Userland/Libraries/LibWeb/Layout/Box.cpp +++ b/Userland/Libraries/LibWeb/Layout/Box.cpp @@ -4,6 +4,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include <LibGfx/DisjointRectSet.h> #include <LibGfx/Painter.h> #include <LibWeb/DOM/Document.h> #include <LibWeb/HTML/HTMLBodyElement.h> @@ -27,8 +28,8 @@ void Box::paint(PaintContext& context, PaintPhase phase) auto padded_rect = this->padded_rect(); if (phase == PaintPhase::Background) { - paint_background(context); + paint_box_shadow(context); } if (phase == PaintPhase::Border) { @@ -253,6 +254,33 @@ void Box::paint_background_image( context.painter().blit_tiled(background_rect, background_image, background_image.rect()); } +void Box::paint_box_shadow(PaintContext& context) +{ + // FIXME: Implement support for blurring the shadow. + auto box_shadow_data = computed_values().box_shadow(); + if (!box_shadow_data.has_value()) + return; + + auto offset_x_px = box_shadow_data->offset_x.resolved_or_zero(*this, width()).to_px(*this); + auto offset_y_px = box_shadow_data->offset_y.resolved_or_zero(*this, width()).to_px(*this); + + Gfx::IntRect shifted_box_rect = { + bordered_rect().x() + offset_x_px, + bordered_rect().y() + offset_y_px, + bordered_rect().width(), + bordered_rect().height() + }; + + Gfx::DisjointRectSet rect_set; + rect_set.add(shifted_box_rect); + auto shattered = rect_set.shatter(enclosing_int_rect(bordered_rect())); + + for (auto& rect : shattered.rects()) { + context.painter().fill_rect(rect, box_shadow_data->color); + (void)rect; + } +} + Box::BorderRadiusData Box::normalized_border_radius_data() { // FIXME: some values should be relative to the height() if specified, but which? For now, all relative values are relative to the width. @@ -376,4 +404,5 @@ float Box::width_of_logical_containing_block() const VERIFY(containing_block); return containing_block->width(); } + } diff --git a/Userland/Libraries/LibWeb/Layout/Box.h b/Userland/Libraries/LibWeb/Layout/Box.h index 8e1d88bba4..26060e1c2b 100644 --- a/Userland/Libraries/LibWeb/Layout/Box.h +++ b/Userland/Libraries/LibWeb/Layout/Box.h @@ -111,6 +111,7 @@ public: virtual void paint(PaintContext&, PaintPhase) override; virtual void paint_border(PaintContext& context); + virtual void paint_box_shadow(PaintContext& context); virtual void paint_background(PaintContext& context); Vector<LineBox>& line_boxes() { return m_line_boxes; } |