mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 23:07:36 +00:00
LibWeb: Support calc(...) in box-shadow's values of type Length
The CSS box-shadow property takes 2-4 properties that are `<length>`s, those being: - offset-x - offset-y - blur-radius - spread-radius Previously these were resolved directly to concrete Lengths at parse time, but now they will be parsed as LengthStyleValues and/or CalculatedStyleValues and be stored that way until styles are later resolved.
This commit is contained in:
parent
8873bf5016
commit
110eeb8591
9 changed files with 143 additions and 58 deletions
|
@ -14,7 +14,7 @@ namespace Web::CSS {
|
|||
ErrorOr<String> ShadowStyleValue::to_string() const
|
||||
{
|
||||
StringBuilder builder;
|
||||
TRY(builder.try_appendff("{} {} {} {} {}", m_properties.color.to_deprecated_string(), TRY(m_properties.offset_x.to_string()), TRY(m_properties.offset_y.to_string()), TRY(m_properties.blur_radius.to_string()), TRY(m_properties.spread_distance.to_string())));
|
||||
TRY(builder.try_appendff("{} {} {} {} {}", m_properties.color.to_deprecated_string(), TRY(m_properties.offset_x->to_string()), TRY(m_properties.offset_y->to_string()), TRY(m_properties.blur_radius->to_string()), TRY(m_properties.spread_distance->to_string())));
|
||||
if (m_properties.placement == ShadowPlacement::Inner)
|
||||
TRY(builder.try_append(" inset"sv));
|
||||
return builder.to_string();
|
||||
|
@ -22,10 +22,10 @@ ErrorOr<String> ShadowStyleValue::to_string() const
|
|||
|
||||
ErrorOr<ValueComparingNonnullRefPtr<StyleValue const>> ShadowStyleValue::absolutized(CSSPixelRect const& viewport_rect, Length::FontMetrics const& font_metrics, Length::FontMetrics const& root_font_metrics) const
|
||||
{
|
||||
auto absolutized_offset_x = m_properties.offset_x.absolutized(viewport_rect, font_metrics, root_font_metrics);
|
||||
auto absolutized_offset_y = m_properties.offset_y.absolutized(viewport_rect, font_metrics, root_font_metrics);
|
||||
auto absolutized_blur_radius = m_properties.blur_radius.absolutized(viewport_rect, font_metrics, root_font_metrics);
|
||||
auto absolutized_spread_distance = m_properties.spread_distance.absolutized(viewport_rect, font_metrics, root_font_metrics);
|
||||
auto absolutized_offset_x = TRY(m_properties.offset_x->absolutized(viewport_rect, font_metrics, root_font_metrics));
|
||||
auto absolutized_offset_y = TRY(m_properties.offset_y->absolutized(viewport_rect, font_metrics, root_font_metrics));
|
||||
auto absolutized_blur_radius = TRY(m_properties.blur_radius->absolutized(viewport_rect, font_metrics, root_font_metrics));
|
||||
auto absolutized_spread_distance = TRY(m_properties.spread_distance->absolutized(viewport_rect, font_metrics, root_font_metrics));
|
||||
return ShadowStyleValue::create(m_properties.color, absolutized_offset_x, absolutized_offset_y, absolutized_blur_radius, absolutized_spread_distance, m_properties.placement);
|
||||
}
|
||||
|
||||
|
|
|
@ -22,17 +22,23 @@ enum class ShadowPlacement {
|
|||
|
||||
class ShadowStyleValue final : public StyleValueWithDefaultOperators<ShadowStyleValue> {
|
||||
public:
|
||||
static ErrorOr<ValueComparingNonnullRefPtr<ShadowStyleValue>> create(Color color, Length const& offset_x, Length const& offset_y, Length const& blur_radius, Length const& spread_distance, ShadowPlacement placement)
|
||||
static ErrorOr<ValueComparingNonnullRefPtr<ShadowStyleValue>> create(
|
||||
Color color,
|
||||
ValueComparingNonnullRefPtr<StyleValue const> offset_x,
|
||||
ValueComparingNonnullRefPtr<StyleValue const> offset_y,
|
||||
ValueComparingNonnullRefPtr<StyleValue const> blur_radius,
|
||||
ValueComparingNonnullRefPtr<StyleValue const> spread_distance,
|
||||
ShadowPlacement placement)
|
||||
{
|
||||
return adopt_nonnull_ref_or_enomem(new (nothrow) ShadowStyleValue(color, offset_x, offset_y, blur_radius, spread_distance, placement));
|
||||
return adopt_nonnull_ref_or_enomem(new (nothrow) ShadowStyleValue(color, move(offset_x), move(offset_y), move(blur_radius), move(spread_distance), placement));
|
||||
}
|
||||
virtual ~ShadowStyleValue() override = default;
|
||||
|
||||
Color color() const { return m_properties.color; }
|
||||
Length const& offset_x() const { return m_properties.offset_x; }
|
||||
Length const& offset_y() const { return m_properties.offset_y; }
|
||||
Length const& blur_radius() const { return m_properties.blur_radius; }
|
||||
Length const& spread_distance() const { return m_properties.spread_distance; }
|
||||
ValueComparingNonnullRefPtr<StyleValue const> const& offset_x() const { return m_properties.offset_x; }
|
||||
ValueComparingNonnullRefPtr<StyleValue const> const& offset_y() const { return m_properties.offset_y; }
|
||||
ValueComparingNonnullRefPtr<StyleValue const> const& blur_radius() const { return m_properties.blur_radius; }
|
||||
ValueComparingNonnullRefPtr<StyleValue const> const& spread_distance() const { return m_properties.spread_distance; }
|
||||
ShadowPlacement placement() const { return m_properties.placement; }
|
||||
|
||||
virtual ErrorOr<String> to_string() const override;
|
||||
|
@ -40,9 +46,22 @@ public:
|
|||
bool properties_equal(ShadowStyleValue const& other) const { return m_properties == other.m_properties; }
|
||||
|
||||
private:
|
||||
explicit ShadowStyleValue(Color color, Length const& offset_x, Length const& offset_y, Length const& blur_radius, Length const& spread_distance, ShadowPlacement placement)
|
||||
ShadowStyleValue(
|
||||
Color color,
|
||||
ValueComparingNonnullRefPtr<StyleValue const> offset_x,
|
||||
ValueComparingNonnullRefPtr<StyleValue const> offset_y,
|
||||
ValueComparingNonnullRefPtr<StyleValue const> blur_radius,
|
||||
ValueComparingNonnullRefPtr<StyleValue const> spread_distance,
|
||||
ShadowPlacement placement)
|
||||
: StyleValueWithDefaultOperators(Type::Shadow)
|
||||
, m_properties { .color = color, .offset_x = offset_x, .offset_y = offset_y, .blur_radius = blur_radius, .spread_distance = spread_distance, .placement = placement }
|
||||
, m_properties {
|
||||
.color = color,
|
||||
.offset_x = move(offset_x),
|
||||
.offset_y = move(offset_y),
|
||||
.blur_radius = move(blur_radius),
|
||||
.spread_distance = move(spread_distance),
|
||||
.placement = placement
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -50,10 +69,10 @@ private:
|
|||
|
||||
struct Properties {
|
||||
Color color;
|
||||
Length offset_x;
|
||||
Length offset_y;
|
||||
Length blur_radius;
|
||||
Length spread_distance;
|
||||
ValueComparingNonnullRefPtr<StyleValue const> offset_x;
|
||||
ValueComparingNonnullRefPtr<StyleValue const> offset_y;
|
||||
ValueComparingNonnullRefPtr<StyleValue const> blur_radius;
|
||||
ValueComparingNonnullRefPtr<StyleValue const> spread_distance;
|
||||
ShadowPlacement placement;
|
||||
bool operator==(Properties const&) const = default;
|
||||
} m_properties;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue