mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 22:17:43 +00:00
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.
This commit is contained in:
parent
281689e1fa
commit
5471c87246
2 changed files with 31 additions and 1 deletions
|
@ -4,6 +4,7 @@
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <LibGfx/DisjointRectSet.h>
|
||||||
#include <LibGfx/Painter.h>
|
#include <LibGfx/Painter.h>
|
||||||
#include <LibWeb/DOM/Document.h>
|
#include <LibWeb/DOM/Document.h>
|
||||||
#include <LibWeb/HTML/HTMLBodyElement.h>
|
#include <LibWeb/HTML/HTMLBodyElement.h>
|
||||||
|
@ -27,8 +28,8 @@ void Box::paint(PaintContext& context, PaintPhase phase)
|
||||||
auto padded_rect = this->padded_rect();
|
auto padded_rect = this->padded_rect();
|
||||||
|
|
||||||
if (phase == PaintPhase::Background) {
|
if (phase == PaintPhase::Background) {
|
||||||
|
|
||||||
paint_background(context);
|
paint_background(context);
|
||||||
|
paint_box_shadow(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (phase == PaintPhase::Border) {
|
if (phase == PaintPhase::Border) {
|
||||||
|
@ -253,6 +254,33 @@ void Box::paint_background_image(
|
||||||
context.painter().blit_tiled(background_rect, background_image, background_image.rect());
|
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()
|
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.
|
// 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);
|
VERIFY(containing_block);
|
||||||
return containing_block->width();
|
return containing_block->width();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -111,6 +111,7 @@ public:
|
||||||
|
|
||||||
virtual void paint(PaintContext&, PaintPhase) override;
|
virtual void paint(PaintContext&, PaintPhase) override;
|
||||||
virtual void paint_border(PaintContext& context);
|
virtual void paint_border(PaintContext& context);
|
||||||
|
virtual void paint_box_shadow(PaintContext& context);
|
||||||
virtual void paint_background(PaintContext& context);
|
virtual void paint_background(PaintContext& context);
|
||||||
|
|
||||||
Vector<LineBox>& line_boxes() { return m_line_boxes; }
|
Vector<LineBox>& line_boxes() { return m_line_boxes; }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue