LibWeb: Add helpers to convert CSS::ShadowData to Painting::ShadowData
This commit is contained in:
parent
726fe8284c
commit
1dd5409630
2 changed files with 26 additions and 10 deletions
|
|
@ -1160,16 +1160,8 @@ void PaintableBox::resolve_paint_properties()
|
|||
auto const& box_shadow_data = computed_values.box_shadow();
|
||||
Vector<Painting::ShadowData> resolved_box_shadow_data;
|
||||
resolved_box_shadow_data.ensure_capacity(box_shadow_data.size());
|
||||
for (auto const& layer : box_shadow_data) {
|
||||
resolved_box_shadow_data.empend(
|
||||
layer.color,
|
||||
layer.offset_x.to_px(layout_node),
|
||||
layer.offset_y.to_px(layout_node),
|
||||
layer.blur_radius.to_px(layout_node),
|
||||
layer.spread_distance.to_px(layout_node),
|
||||
layer.placement == CSS::ShadowPlacement::Outer ? Painting::ShadowPlacement::Outer
|
||||
: Painting::ShadowPlacement::Inner);
|
||||
}
|
||||
for (auto const& layer : box_shadow_data)
|
||||
resolved_box_shadow_data.unchecked_append(ShadowData::from_css(layer, layout_node));
|
||||
set_box_shadow_data(move(resolved_box_shadow_data));
|
||||
|
||||
// Outlines
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
* Copyright (c) 2018-2020, Andreas Kling <andreas@ladybird.org>
|
||||
* Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org>
|
||||
* Copyright (c) 2022, MacDue <macdue@dueutil.tech>
|
||||
* Copyright (c) 2026, Jelle Raaijmakers <jelle@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
|
@ -18,6 +19,17 @@ enum class ShadowPlacement {
|
|||
Inner,
|
||||
};
|
||||
|
||||
inline ShadowPlacement shadow_placement_from_css(CSS::ShadowPlacement placement)
|
||||
{
|
||||
switch (placement) {
|
||||
case CSS::ShadowPlacement::Outer:
|
||||
return ShadowPlacement::Outer;
|
||||
case CSS::ShadowPlacement::Inner:
|
||||
return ShadowPlacement::Inner;
|
||||
}
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
struct ShadowData {
|
||||
Gfx::Color color;
|
||||
CSSPixels offset_x;
|
||||
|
|
@ -25,6 +37,18 @@ struct ShadowData {
|
|||
CSSPixels blur_radius;
|
||||
CSSPixels spread_distance;
|
||||
ShadowPlacement placement;
|
||||
|
||||
static ShadowData from_css(CSS::ShadowData const& shadow, Layout::Node const& layout_node)
|
||||
{
|
||||
return {
|
||||
shadow.color,
|
||||
shadow.offset_x.to_px(layout_node),
|
||||
shadow.offset_y.to_px(layout_node),
|
||||
shadow.blur_radius.to_px(layout_node),
|
||||
shadow.spread_distance.to_px(layout_node),
|
||||
shadow_placement_from_css(shadow.placement),
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue