1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 22:07:34 +00:00

LbWeb: Rename BoxShadowFoo => ShadowFoo

The `text-shadow` property is almost identical to `box-shadow`:
> Values are interpreted as for box-shadow [CSS-BACKGROUNDS-3].
> (But note that the inset keyword are not allowed.)

So, let's use the same data structures and parsing code for both. :^)
This commit is contained in:
Sam Atkins 2022-03-23 16:55:22 +00:00 committed by Andreas Kling
parent f9367a5fdb
commit 1094654adc
13 changed files with 101 additions and 101 deletions

View file

@ -88,13 +88,13 @@ struct FlexBasisData {
bool is_definite() const { return type == CSS::FlexBasis::LengthPercentage; } bool is_definite() const { return type == CSS::FlexBasis::LengthPercentage; }
}; };
struct BoxShadowData { struct ShadowData {
Color color {}; Color color {};
CSS::Length offset_x { Length::make_px(0) }; CSS::Length offset_x { Length::make_px(0) };
CSS::Length offset_y { Length::make_px(0) }; CSS::Length offset_y { Length::make_px(0) };
CSS::Length blur_radius { Length::make_px(0) }; CSS::Length blur_radius { Length::make_px(0) };
CSS::Length spread_distance { Length::make_px(0) }; CSS::Length spread_distance { Length::make_px(0) };
CSS::BoxShadowPlacement placement { CSS::BoxShadowPlacement::Outer }; CSS::ShadowPlacement placement { CSS::ShadowPlacement::Outer };
}; };
struct ContentData { struct ContentData {
@ -137,7 +137,7 @@ public:
CSS::Visibility visibility() const { return m_inherited.visibility; } CSS::Visibility visibility() const { return m_inherited.visibility; }
CSS::ImageRendering image_rendering() const { return m_inherited.image_rendering; } CSS::ImageRendering image_rendering() const { return m_inherited.image_rendering; }
CSS::JustifyContent justify_content() const { return m_noninherited.justify_content; } CSS::JustifyContent justify_content() const { return m_noninherited.justify_content; }
Vector<BoxShadowData> const& box_shadow() const { return m_noninherited.box_shadow; } Vector<ShadowData> const& box_shadow() const { return m_noninherited.box_shadow; }
CSS::BoxSizing box_sizing() const { return m_noninherited.box_sizing; } CSS::BoxSizing box_sizing() const { return m_noninherited.box_sizing; }
Optional<CSS::LengthPercentage> const& width() const { return m_noninherited.width; } Optional<CSS::LengthPercentage> const& width() const { return m_noninherited.width; }
Optional<CSS::LengthPercentage> const& min_width() const { return m_noninherited.min_width; } Optional<CSS::LengthPercentage> const& min_width() const { return m_noninherited.min_width; }
@ -248,7 +248,7 @@ protected:
CSS::Overflow overflow_x { InitialValues::overflow() }; CSS::Overflow overflow_x { InitialValues::overflow() };
CSS::Overflow overflow_y { InitialValues::overflow() }; CSS::Overflow overflow_y { InitialValues::overflow() };
float opacity { InitialValues::opacity() }; float opacity { InitialValues::opacity() };
Vector<BoxShadowData> box_shadow {}; Vector<ShadowData> box_shadow {};
Vector<CSS::Transformation> transformations {}; Vector<CSS::Transformation> transformations {};
CSS::TransformOrigin transform_origin {}; CSS::TransformOrigin transform_origin {};
CSS::BoxSizing box_sizing { InitialValues::box_sizing() }; CSS::BoxSizing box_sizing { InitialValues::box_sizing() };
@ -313,7 +313,7 @@ public:
void set_align_items(CSS::AlignItems value) { m_noninherited.align_items = value; } void set_align_items(CSS::AlignItems value) { m_noninherited.align_items = value; }
void set_opacity(float value) { m_noninherited.opacity = value; } void set_opacity(float value) { m_noninherited.opacity = value; }
void set_justify_content(CSS::JustifyContent value) { m_noninherited.justify_content = value; } void set_justify_content(CSS::JustifyContent value) { m_noninherited.justify_content = value; }
void set_box_shadow(Vector<BoxShadowData>&& value) { m_noninherited.box_shadow = move(value); } void set_box_shadow(Vector<ShadowData>&& value) { m_noninherited.box_shadow = move(value); }
void set_transformations(Vector<CSS::Transformation> value) { m_noninherited.transformations = move(value); } void set_transformations(Vector<CSS::Transformation> value) { m_noninherited.transformations = move(value); }
void set_transform_origin(CSS::TransformOrigin value) { m_noninherited.transform_origin = value; } void set_transform_origin(CSS::TransformOrigin value) { m_noninherited.transform_origin = value; }
void set_box_sizing(CSS::BoxSizing value) { m_noninherited.box_sizing = value; } void set_box_sizing(CSS::BoxSizing value) { m_noninherited.box_sizing = value; }

View file

@ -3318,7 +3318,7 @@ RefPtr<StyleValue> Parser::parse_border_radius_shorthand_value(Vector<StyleCompo
return StyleValueList::create(move(border_radii), StyleValueList::Separator::Space); return StyleValueList::create(move(border_radii), StyleValueList::Separator::Space);
} }
RefPtr<StyleValue> Parser::parse_box_shadow_value(Vector<StyleComponentValueRule> const& component_values) RefPtr<StyleValue> Parser::parse_shadow_value(Vector<StyleComponentValueRule> const& component_values)
{ {
// "none" // "none"
if (component_values.size() == 1 && component_values.first().is(Token::Type::Ident)) { if (component_values.size() == 1 && component_values.first().is(Token::Type::Ident)) {
@ -3328,11 +3328,11 @@ RefPtr<StyleValue> Parser::parse_box_shadow_value(Vector<StyleComponentValueRule
} }
return parse_comma_separated_value_list(component_values, [this](auto& tokens) { return parse_comma_separated_value_list(component_values, [this](auto& tokens) {
return parse_single_box_shadow_value(tokens); return parse_single_shadow_value(tokens);
}); });
} }
RefPtr<StyleValue> Parser::parse_single_box_shadow_value(TokenStream<StyleComponentValueRule>& tokens) RefPtr<StyleValue> Parser::parse_single_shadow_value(TokenStream<StyleComponentValueRule>& tokens)
{ {
auto start_position = tokens.position(); auto start_position = tokens.position();
auto error = [&]() { auto error = [&]() {
@ -3345,7 +3345,7 @@ RefPtr<StyleValue> Parser::parse_single_box_shadow_value(TokenStream<StyleCompon
Optional<Length> offset_y; Optional<Length> offset_y;
Optional<Length> blur_radius; Optional<Length> blur_radius;
Optional<Length> spread_distance; Optional<Length> spread_distance;
Optional<BoxShadowPlacement> placement; Optional<ShadowPlacement> placement;
while (tokens.has_next_token()) { while (tokens.has_next_token()) {
auto& token = tokens.peek_token(); auto& token = tokens.peek_token();
@ -3398,7 +3398,7 @@ RefPtr<StyleValue> Parser::parse_single_box_shadow_value(TokenStream<StyleCompon
if (token.is(Token::Type::Ident) && token.token().ident().equals_ignoring_case("inset"sv)) { if (token.is(Token::Type::Ident) && token.token().ident().equals_ignoring_case("inset"sv)) {
if (placement.has_value()) if (placement.has_value())
return error(); return error();
placement = BoxShadowPlacement::Inner; placement = ShadowPlacement::Inner;
tokens.next_token(); tokens.next_token();
continue; continue;
} }
@ -3425,9 +3425,9 @@ RefPtr<StyleValue> Parser::parse_single_box_shadow_value(TokenStream<StyleCompon
// Placement is outer by default // Placement is outer by default
if (!placement.has_value()) if (!placement.has_value())
placement = BoxShadowPlacement::Outer; placement = ShadowPlacement::Outer;
return BoxShadowStyleValue::create(color.release_value(), offset_x.release_value(), offset_y.release_value(), blur_radius.release_value(), spread_distance.release_value(), placement.release_value()); return ShadowStyleValue::create(color.release_value(), offset_x.release_value(), offset_y.release_value(), blur_radius.release_value(), spread_distance.release_value(), placement.release_value());
} }
RefPtr<StyleValue> Parser::parse_content_value(Vector<StyleComponentValueRule> const& component_values) RefPtr<StyleValue> Parser::parse_content_value(Vector<StyleComponentValueRule> const& component_values)
@ -4248,7 +4248,7 @@ Result<NonnullRefPtr<StyleValue>, Parser::ParsingResult> Parser::parse_css_value
return parsed_value.release_nonnull(); return parsed_value.release_nonnull();
return ParsingResult::SyntaxError; return ParsingResult::SyntaxError;
case PropertyID::BoxShadow: case PropertyID::BoxShadow:
if (auto parsed_value = parse_box_shadow_value(component_values)) if (auto parsed_value = parse_shadow_value(component_values))
return parsed_value.release_nonnull(); return parsed_value.release_nonnull();
return ParsingResult::SyntaxError; return ParsingResult::SyntaxError;
case PropertyID::Content: case PropertyID::Content:

View file

@ -287,8 +287,6 @@ private:
RefPtr<StyleValue> parse_border_value(Vector<StyleComponentValueRule> const&); RefPtr<StyleValue> parse_border_value(Vector<StyleComponentValueRule> const&);
RefPtr<StyleValue> parse_border_radius_value(Vector<StyleComponentValueRule> const&); RefPtr<StyleValue> parse_border_radius_value(Vector<StyleComponentValueRule> const&);
RefPtr<StyleValue> parse_border_radius_shorthand_value(Vector<StyleComponentValueRule> const&); RefPtr<StyleValue> parse_border_radius_shorthand_value(Vector<StyleComponentValueRule> const&);
RefPtr<StyleValue> parse_box_shadow_value(Vector<StyleComponentValueRule> const&);
RefPtr<StyleValue> parse_single_box_shadow_value(TokenStream<StyleComponentValueRule>&);
RefPtr<StyleValue> parse_content_value(Vector<StyleComponentValueRule> const&); RefPtr<StyleValue> parse_content_value(Vector<StyleComponentValueRule> const&);
RefPtr<StyleValue> parse_flex_value(Vector<StyleComponentValueRule> const&); RefPtr<StyleValue> parse_flex_value(Vector<StyleComponentValueRule> const&);
RefPtr<StyleValue> parse_flex_flow_value(Vector<StyleComponentValueRule> const&); RefPtr<StyleValue> parse_flex_flow_value(Vector<StyleComponentValueRule> const&);
@ -296,6 +294,8 @@ private:
RefPtr<StyleValue> parse_font_family_value(Vector<StyleComponentValueRule> const&, size_t start_index = 0); RefPtr<StyleValue> parse_font_family_value(Vector<StyleComponentValueRule> const&, size_t start_index = 0);
RefPtr<StyleValue> parse_list_style_value(Vector<StyleComponentValueRule> const&); RefPtr<StyleValue> parse_list_style_value(Vector<StyleComponentValueRule> const&);
RefPtr<StyleValue> parse_overflow_value(Vector<StyleComponentValueRule> const&); RefPtr<StyleValue> parse_overflow_value(Vector<StyleComponentValueRule> const&);
RefPtr<StyleValue> parse_shadow_value(Vector<StyleComponentValueRule> const&);
RefPtr<StyleValue> parse_single_shadow_value(TokenStream<StyleComponentValueRule>&);
RefPtr<StyleValue> parse_text_decoration_value(Vector<StyleComponentValueRule> const&); RefPtr<StyleValue> parse_text_decoration_value(Vector<StyleComponentValueRule> const&);
RefPtr<StyleValue> parse_transform_value(Vector<StyleComponentValueRule> const&); RefPtr<StyleValue> parse_transform_value(Vector<StyleComponentValueRule> const&);
RefPtr<StyleValue> parse_transform_origin_value(Vector<StyleComponentValueRule> const&); RefPtr<StyleValue> parse_transform_origin_value(Vector<StyleComponentValueRule> const&);

View file

@ -560,8 +560,8 @@ RefPtr<StyleValue> ResolvedCSSStyleDeclaration::style_value_for_property(Layout:
if (box_shadow_layers.is_empty()) if (box_shadow_layers.is_empty())
return {}; return {};
auto make_box_shadow_style_value = [](BoxShadowData const& data) { auto make_box_shadow_style_value = [](ShadowData const& data) {
return BoxShadowStyleValue::create(data.color, data.offset_x, data.offset_y, data.blur_radius, data.spread_distance, data.placement); return ShadowStyleValue::create(data.color, data.offset_x, data.offset_y, data.blur_radius, data.spread_distance, data.placement);
}; };
if (box_shadow_layers.size() == 1) if (box_shadow_layers.size() == 1)

View file

@ -914,7 +914,7 @@ Optional<CSS::Overflow> StyleProperties::overflow(CSS::PropertyID property_id) c
} }
} }
Vector<BoxShadowData> StyleProperties::box_shadow() const Vector<ShadowData> StyleProperties::box_shadow() const
{ {
auto value_or_error = property(PropertyID::BoxShadow); auto value_or_error = property(PropertyID::BoxShadow);
if (!value_or_error.has_value()) if (!value_or_error.has_value())
@ -922,23 +922,23 @@ Vector<BoxShadowData> StyleProperties::box_shadow() const
auto value = value_or_error.value(); auto value = value_or_error.value();
auto make_box_shadow_data = [](BoxShadowStyleValue const& box) { auto make_box_shadow_data = [](ShadowStyleValue const& box) {
return BoxShadowData { box.color(), box.offset_x(), box.offset_y(), box.blur_radius(), box.spread_distance(), box.placement() }; return ShadowData { box.color(), box.offset_x(), box.offset_y(), box.blur_radius(), box.spread_distance(), box.placement() };
}; };
if (value->is_value_list()) { if (value->is_value_list()) {
auto& value_list = value->as_value_list(); auto& value_list = value->as_value_list();
Vector<BoxShadowData> box_shadow_data; Vector<ShadowData> box_shadow_data;
box_shadow_data.ensure_capacity(value_list.size()); box_shadow_data.ensure_capacity(value_list.size());
for (auto const& layer_value : value_list.values()) for (auto const& layer_value : value_list.values())
box_shadow_data.append(make_box_shadow_data(layer_value.as_box_shadow())); box_shadow_data.append(make_box_shadow_data(layer_value.as_shadow()));
return box_shadow_data; return box_shadow_data;
} }
if (value->is_box_shadow()) { if (value->is_shadow()) {
auto& box = value->as_box_shadow(); auto& box = value->as_shadow();
return { make_box_shadow_data(box) }; return { make_box_shadow_data(box) };
} }

View file

@ -71,7 +71,7 @@ public:
Optional<CSS::JustifyContent> justify_content() const; Optional<CSS::JustifyContent> justify_content() const;
Optional<CSS::Overflow> overflow_x() const; Optional<CSS::Overflow> overflow_x() const;
Optional<CSS::Overflow> overflow_y() const; Optional<CSS::Overflow> overflow_y() const;
Vector<CSS::BoxShadowData> box_shadow() const; Vector<CSS::ShadowData> box_shadow() const;
CSS::BoxSizing box_sizing() const; CSS::BoxSizing box_sizing() const;
Optional<CSS::PointerEvents> pointer_events() const; Optional<CSS::PointerEvents> pointer_events() const;
Variant<CSS::VerticalAlign, CSS::LengthPercentage> vertical_align() const; Variant<CSS::VerticalAlign, CSS::LengthPercentage> vertical_align() const;

View file

@ -59,10 +59,10 @@ BorderRadiusStyleValue const& StyleValue::as_border_radius() const
return static_cast<BorderRadiusStyleValue const&>(*this); return static_cast<BorderRadiusStyleValue const&>(*this);
} }
BoxShadowStyleValue const& StyleValue::as_box_shadow() const ShadowStyleValue const& StyleValue::as_shadow() const
{ {
VERIFY(is_box_shadow()); VERIFY(is_shadow());
return static_cast<BoxShadowStyleValue const&>(*this); return static_cast<ShadowStyleValue const&>(*this);
} }
CalculatedStyleValue const& StyleValue::as_calculated() const CalculatedStyleValue const& StyleValue::as_calculated() const
@ -295,11 +295,11 @@ String BorderRadiusStyleValue::to_string() const
return String::formatted("{} / {}", m_horizontal_radius.to_string(), m_vertical_radius.to_string()); return String::formatted("{} / {}", m_horizontal_radius.to_string(), m_vertical_radius.to_string());
} }
String BoxShadowStyleValue::to_string() const String ShadowStyleValue::to_string() const
{ {
StringBuilder builder; StringBuilder builder;
builder.appendff("{} {} {} {} {}", m_color.to_string(), m_offset_x.to_string(), m_offset_y.to_string(), m_blur_radius.to_string(), m_spread_distance.to_string()); builder.appendff("{} {} {} {} {}", m_color.to_string(), m_offset_x.to_string(), m_offset_y.to_string(), m_blur_radius.to_string(), m_spread_distance.to_string());
if (m_placement == BoxShadowPlacement::Inner) if (m_placement == ShadowPlacement::Inner)
builder.append(" inset"); builder.append(" inset");
return builder.to_string(); return builder.to_string();
} }
@ -1446,13 +1446,13 @@ NonnullRefPtr<StyleValue> LengthStyleValue::absolutized(Gfx::IntRect const& view
return *this; return *this;
} }
NonnullRefPtr<StyleValue> BoxShadowStyleValue::absolutized(Gfx::IntRect const& viewport_rect, Gfx::FontMetrics const& font_metrics, float font_size, float root_font_size) const NonnullRefPtr<StyleValue> ShadowStyleValue::absolutized(Gfx::IntRect const& viewport_rect, Gfx::FontMetrics const& font_metrics, float font_size, float root_font_size) const
{ {
auto absolutized_offset_x = absolutized_length(m_offset_x, viewport_rect, font_metrics, font_size, root_font_size).value_or(m_offset_x); auto absolutized_offset_x = absolutized_length(m_offset_x, viewport_rect, font_metrics, font_size, root_font_size).value_or(m_offset_x);
auto absolutized_offset_y = absolutized_length(m_offset_y, viewport_rect, font_metrics, font_size, root_font_size).value_or(m_offset_y); auto absolutized_offset_y = absolutized_length(m_offset_y, viewport_rect, font_metrics, font_size, root_font_size).value_or(m_offset_y);
auto absolutized_blur_radius = absolutized_length(m_blur_radius, viewport_rect, font_metrics, font_size, root_font_size).value_or(m_blur_radius); auto absolutized_blur_radius = absolutized_length(m_blur_radius, viewport_rect, font_metrics, font_size, root_font_size).value_or(m_blur_radius);
auto absolutized_spread_distance = absolutized_length(m_spread_distance, viewport_rect, font_metrics, font_size, root_font_size).value_or(m_spread_distance); auto absolutized_spread_distance = absolutized_length(m_spread_distance, viewport_rect, font_metrics, font_size, root_font_size).value_or(m_spread_distance);
return BoxShadowStyleValue::create(m_color, absolutized_offset_x, absolutized_offset_y, absolutized_blur_radius, absolutized_spread_distance, m_placement); return ShadowStyleValue::create(m_color, absolutized_offset_x, absolutized_offset_y, absolutized_blur_radius, absolutized_spread_distance, m_placement);
} }
NonnullRefPtr<StyleValue> BorderRadiusStyleValue::absolutized(Gfx::IntRect const& viewport_rect, Gfx::FontMetrics const& font_metrics, float font_size, float root_font_size) const NonnullRefPtr<StyleValue> BorderRadiusStyleValue::absolutized(Gfx::IntRect const& viewport_rect, Gfx::FontMetrics const& font_metrics, float font_size, float root_font_size) const

View file

@ -70,7 +70,7 @@ enum class BoxSizing {
ContentBox, ContentBox,
}; };
enum class BoxShadowPlacement { enum class ShadowPlacement {
Outer, Outer,
Inner, Inner,
}; };
@ -352,7 +352,6 @@ public:
BackgroundSize, BackgroundSize,
Border, Border,
BorderRadius, BorderRadius,
BoxShadow,
Calculated, Calculated,
Color, Color,
CombinedBorderRadius, CombinedBorderRadius,
@ -373,6 +372,7 @@ public:
Percentage, Percentage,
Position, Position,
Resolution, Resolution,
Shadow,
String, String,
TextDecoration, TextDecoration,
Time, Time,
@ -390,7 +390,6 @@ public:
bool is_background_size() const { return type() == Type::BackgroundSize; } bool is_background_size() const { return type() == Type::BackgroundSize; }
bool is_border() const { return type() == Type::Border; } bool is_border() const { return type() == Type::Border; }
bool is_border_radius() const { return type() == Type::BorderRadius; } bool is_border_radius() const { return type() == Type::BorderRadius; }
bool is_box_shadow() const { return type() == Type::BoxShadow; }
bool is_calculated() const { return type() == Type::Calculated; } bool is_calculated() const { return type() == Type::Calculated; }
bool is_color() const { return type() == Type::Color; } bool is_color() const { return type() == Type::Color; }
bool is_content() const { return type() == Type::Content; } bool is_content() const { return type() == Type::Content; }
@ -409,6 +408,7 @@ public:
bool is_percentage() const { return type() == Type::Percentage; } bool is_percentage() const { return type() == Type::Percentage; }
bool is_position() const { return type() == Type::Position; } bool is_position() const { return type() == Type::Position; }
bool is_resolution() const { return type() == Type::Resolution; } bool is_resolution() const { return type() == Type::Resolution; }
bool is_shadow() const { return type() == Type::Shadow; }
bool is_string() const { return type() == Type::String; } bool is_string() const { return type() == Type::String; }
bool is_text_decoration() const { return type() == Type::TextDecoration; } bool is_text_decoration() const { return type() == Type::TextDecoration; }
bool is_time() const { return type() == Type::Time; } bool is_time() const { return type() == Type::Time; }
@ -425,7 +425,6 @@ public:
BackgroundSizeStyleValue const& as_background_size() const; BackgroundSizeStyleValue const& as_background_size() const;
BorderRadiusStyleValue const& as_border_radius() const; BorderRadiusStyleValue const& as_border_radius() const;
BorderStyleValue const& as_border() const; BorderStyleValue const& as_border() const;
BoxShadowStyleValue const& as_box_shadow() const;
CalculatedStyleValue const& as_calculated() const; CalculatedStyleValue const& as_calculated() const;
ColorStyleValue const& as_color() const; ColorStyleValue const& as_color() const;
ContentStyleValue const& as_content() const; ContentStyleValue const& as_content() const;
@ -444,6 +443,7 @@ public:
PercentageStyleValue const& as_percentage() const; PercentageStyleValue const& as_percentage() const;
PositionStyleValue const& as_position() const; PositionStyleValue const& as_position() const;
ResolutionStyleValue const& as_resolution() const; ResolutionStyleValue const& as_resolution() const;
ShadowStyleValue const& as_shadow() const;
StringStyleValue const& as_string() const; StringStyleValue const& as_string() const;
TextDecorationStyleValue const& as_text_decoration() const; TextDecorationStyleValue const& as_text_decoration() const;
TimeStyleValue const& as_time() const; TimeStyleValue const& as_time() const;
@ -458,7 +458,6 @@ public:
BackgroundSizeStyleValue& as_background_size() { return const_cast<BackgroundSizeStyleValue&>(const_cast<StyleValue const&>(*this).as_background_size()); } BackgroundSizeStyleValue& as_background_size() { return const_cast<BackgroundSizeStyleValue&>(const_cast<StyleValue const&>(*this).as_background_size()); }
BorderRadiusStyleValue& as_border_radius() { return const_cast<BorderRadiusStyleValue&>(const_cast<StyleValue const&>(*this).as_border_radius()); } BorderRadiusStyleValue& as_border_radius() { return const_cast<BorderRadiusStyleValue&>(const_cast<StyleValue const&>(*this).as_border_radius()); }
BorderStyleValue& as_border() { return const_cast<BorderStyleValue&>(const_cast<StyleValue const&>(*this).as_border()); } BorderStyleValue& as_border() { return const_cast<BorderStyleValue&>(const_cast<StyleValue const&>(*this).as_border()); }
BoxShadowStyleValue& as_box_shadow() { return const_cast<BoxShadowStyleValue&>(const_cast<StyleValue const&>(*this).as_box_shadow()); }
CalculatedStyleValue& as_calculated() { return const_cast<CalculatedStyleValue&>(const_cast<StyleValue const&>(*this).as_calculated()); } CalculatedStyleValue& as_calculated() { return const_cast<CalculatedStyleValue&>(const_cast<StyleValue const&>(*this).as_calculated()); }
ColorStyleValue& as_color() { return const_cast<ColorStyleValue&>(const_cast<StyleValue const&>(*this).as_color()); } ColorStyleValue& as_color() { return const_cast<ColorStyleValue&>(const_cast<StyleValue const&>(*this).as_color()); }
ContentStyleValue& as_content() { return const_cast<ContentStyleValue&>(const_cast<StyleValue const&>(*this).as_content()); } ContentStyleValue& as_content() { return const_cast<ContentStyleValue&>(const_cast<StyleValue const&>(*this).as_content()); }
@ -477,6 +476,7 @@ public:
PercentageStyleValue& as_percentage() { return const_cast<PercentageStyleValue&>(const_cast<StyleValue const&>(*this).as_percentage()); } PercentageStyleValue& as_percentage() { return const_cast<PercentageStyleValue&>(const_cast<StyleValue const&>(*this).as_percentage()); }
PositionStyleValue& as_position() { return const_cast<PositionStyleValue&>(const_cast<StyleValue const&>(*this).as_position()); } PositionStyleValue& as_position() { return const_cast<PositionStyleValue&>(const_cast<StyleValue const&>(*this).as_position()); }
ResolutionStyleValue& as_resolution() { return const_cast<ResolutionStyleValue&>(const_cast<StyleValue const&>(*this).as_resolution()); } ResolutionStyleValue& as_resolution() { return const_cast<ResolutionStyleValue&>(const_cast<StyleValue const&>(*this).as_resolution()); }
ShadowStyleValue& as_shadow() { return const_cast<ShadowStyleValue&>(const_cast<StyleValue const&>(*this).as_shadow()); }
StringStyleValue& as_string() { return const_cast<StringStyleValue&>(const_cast<StyleValue const&>(*this).as_string()); } StringStyleValue& as_string() { return const_cast<StringStyleValue&>(const_cast<StyleValue const&>(*this).as_string()); }
TextDecorationStyleValue& as_text_decoration() { return const_cast<TextDecorationStyleValue&>(const_cast<StyleValue const&>(*this).as_text_decoration()); } TextDecorationStyleValue& as_text_decoration() { return const_cast<TextDecorationStyleValue&>(const_cast<StyleValue const&>(*this).as_text_decoration()); }
TimeStyleValue& as_time() { return const_cast<TimeStyleValue&>(const_cast<StyleValue const&>(*this).as_time()); } TimeStyleValue& as_time() { return const_cast<TimeStyleValue&>(const_cast<StyleValue const&>(*this).as_time()); }
@ -740,59 +740,6 @@ private:
LengthPercentage m_vertical_radius; LengthPercentage m_vertical_radius;
}; };
class BoxShadowStyleValue final : public StyleValue {
public:
static NonnullRefPtr<BoxShadowStyleValue>
create(Color const& color, Length const& offset_x, Length const& offset_y, Length const& blur_radius, Length const& spread_distance, BoxShadowPlacement placement)
{
return adopt_ref(*new BoxShadowStyleValue(color, offset_x, offset_y, blur_radius, spread_distance, placement));
}
virtual ~BoxShadowStyleValue() override = default;
Color const& color() const { return m_color; }
Length const& offset_x() const { return m_offset_x; }
Length const& offset_y() const { return m_offset_y; }
Length const& blur_radius() const { return m_blur_radius; }
Length const& spread_distance() const { return m_spread_distance; }
BoxShadowPlacement placement() const { return m_placement; }
virtual String to_string() const override;
virtual bool equals(StyleValue const& other) const override
{
if (type() != other.type())
return false;
auto& other_value = static_cast<BoxShadowStyleValue const&>(other);
return m_color == other_value.m_color
&& m_offset_x == other_value.m_offset_x
&& m_offset_y == other_value.m_offset_y
&& m_blur_radius == other_value.m_blur_radius
&& m_spread_distance == other_value.m_spread_distance
&& m_placement == other_value.m_placement;
}
private:
explicit BoxShadowStyleValue(Color const& color, Length const& offset_x, Length const& offset_y, Length const& blur_radius, Length const& spread_distance, BoxShadowPlacement placement)
: StyleValue(Type::BoxShadow)
, m_color(color)
, m_offset_x(offset_x)
, m_offset_y(offset_y)
, m_blur_radius(blur_radius)
, m_spread_distance(spread_distance)
, m_placement(placement)
{
}
virtual NonnullRefPtr<StyleValue> absolutized(Gfx::IntRect const& viewport_rect, Gfx::FontMetrics const& font_metrics, float font_size, float root_font_size) const override;
Color m_color;
Length m_offset_x;
Length m_offset_y;
Length m_blur_radius;
Length m_spread_distance;
BoxShadowPlacement m_placement;
};
class CalculatedStyleValue : public StyleValue { class CalculatedStyleValue : public StyleValue {
public: public:
enum class ResolvedType { enum class ResolvedType {
@ -1510,6 +1457,59 @@ private:
Resolution m_resolution; Resolution m_resolution;
}; };
class ShadowStyleValue final : public StyleValue {
public:
static NonnullRefPtr<ShadowStyleValue>
create(Color const& color, Length const& offset_x, Length const& offset_y, Length const& blur_radius, Length const& spread_distance, ShadowPlacement placement)
{
return adopt_ref(*new ShadowStyleValue(color, offset_x, offset_y, blur_radius, spread_distance, placement));
}
virtual ~ShadowStyleValue() override = default;
Color const& color() const { return m_color; }
Length const& offset_x() const { return m_offset_x; }
Length const& offset_y() const { return m_offset_y; }
Length const& blur_radius() const { return m_blur_radius; }
Length const& spread_distance() const { return m_spread_distance; }
ShadowPlacement placement() const { return m_placement; }
virtual String to_string() const override;
virtual bool equals(StyleValue const& other) const override
{
if (type() != other.type())
return false;
auto& other_value = static_cast<ShadowStyleValue const&>(other);
return m_color == other_value.m_color
&& m_offset_x == other_value.m_offset_x
&& m_offset_y == other_value.m_offset_y
&& m_blur_radius == other_value.m_blur_radius
&& m_spread_distance == other_value.m_spread_distance
&& m_placement == other_value.m_placement;
}
private:
explicit ShadowStyleValue(Color const& color, Length const& offset_x, Length const& offset_y, Length const& blur_radius, Length const& spread_distance, ShadowPlacement placement)
: StyleValue(Type::Shadow)
, m_color(color)
, m_offset_x(offset_x)
, m_offset_y(offset_y)
, m_blur_radius(blur_radius)
, m_spread_distance(spread_distance)
, m_placement(placement)
{
}
virtual NonnullRefPtr<StyleValue> absolutized(Gfx::IntRect const& viewport_rect, Gfx::FontMetrics const& font_metrics, float font_size, float root_font_size) const override;
Color m_color;
Length m_offset_x;
Length m_offset_y;
Length m_blur_radius;
Length m_spread_distance;
ShadowPlacement m_placement;
};
class StringStyleValue : public StyleValue { class StringStyleValue : public StyleValue {
public: public:
static NonnullRefPtr<StringStyleValue> create(String const& string) static NonnullRefPtr<StringStyleValue> create(String const& string)

View file

@ -27,7 +27,6 @@ class BackgroundSizeStyleValue;
class BackgroundStyleValue; class BackgroundStyleValue;
class BorderRadiusStyleValue; class BorderRadiusStyleValue;
class BorderStyleValue; class BorderStyleValue;
class BoxShadowStyleValue;
class CalculatedStyleValue; class CalculatedStyleValue;
class ColorStyleValue; class ColorStyleValue;
class ContentStyleValue; class ContentStyleValue;
@ -70,6 +69,7 @@ class Resolution;
class ResolutionStyleValue; class ResolutionStyleValue;
class Screen; class Screen;
class Selector; class Selector;
class ShadowStyleValue;
class StringStyleValue; class StringStyleValue;
class StyleComputer; class StyleComputer;
class StyleProperties; class StyleProperties;

View file

@ -58,7 +58,7 @@ void InlinePaintable::paint(PaintContext& context, Painting::PaintPhase phase) c
Painting::paint_background(context, layout_node(), enclosing_int_rect(absolute_fragment_rect), computed_values().background_color(), &computed_values().background_layers(), border_radius_data); Painting::paint_background(context, layout_node(), enclosing_int_rect(absolute_fragment_rect), computed_values().background_color(), &computed_values().background_layers(), border_radius_data);
if (auto computed_box_shadow = computed_values().box_shadow(); !computed_box_shadow.is_empty()) { if (auto computed_box_shadow = computed_values().box_shadow(); !computed_box_shadow.is_empty()) {
Vector<Painting::BoxShadowData> resolved_box_shadow_data; Vector<Painting::ShadowData> resolved_box_shadow_data;
resolved_box_shadow_data.ensure_capacity(computed_box_shadow.size()); resolved_box_shadow_data.ensure_capacity(computed_box_shadow.size());
for (auto const& layer : computed_box_shadow) { for (auto const& layer : computed_box_shadow) {
resolved_box_shadow_data.empend( resolved_box_shadow_data.empend(
@ -67,7 +67,7 @@ void InlinePaintable::paint(PaintContext& context, Painting::PaintPhase phase) c
static_cast<int>(layer.offset_y.to_px(layout_node())), static_cast<int>(layer.offset_y.to_px(layout_node())),
static_cast<int>(layer.blur_radius.to_px(layout_node())), static_cast<int>(layer.blur_radius.to_px(layout_node())),
static_cast<int>(layer.spread_distance.to_px(layout_node())), static_cast<int>(layer.spread_distance.to_px(layout_node())),
layer.placement == CSS::BoxShadowPlacement::Outer ? Painting::BoxShadowPlacement::Outer : Painting::BoxShadowPlacement::Inner); layer.placement == CSS::ShadowPlacement::Outer ? Painting::ShadowPlacement::Outer : Painting::ShadowPlacement::Inner);
} }
Painting::paint_box_shadow(context, enclosing_int_rect(absolute_fragment_rect), resolved_box_shadow_data); Painting::paint_box_shadow(context, enclosing_int_rect(absolute_fragment_rect), resolved_box_shadow_data);
} }

View file

@ -203,7 +203,7 @@ void PaintableBox::paint_box_shadow(PaintContext& context) const
if (box_shadow_data.is_empty()) if (box_shadow_data.is_empty())
return; return;
Vector<BoxShadowData> resolved_box_shadow_data; Vector<ShadowData> resolved_box_shadow_data;
resolved_box_shadow_data.ensure_capacity(box_shadow_data.size()); resolved_box_shadow_data.ensure_capacity(box_shadow_data.size());
for (auto const& layer : box_shadow_data) { for (auto const& layer : box_shadow_data) {
resolved_box_shadow_data.empend( resolved_box_shadow_data.empend(
@ -212,7 +212,7 @@ void PaintableBox::paint_box_shadow(PaintContext& context) const
static_cast<int>(layer.offset_y.to_px(layout_box())), static_cast<int>(layer.offset_y.to_px(layout_box())),
static_cast<int>(layer.blur_radius.to_px(layout_box())), static_cast<int>(layer.blur_radius.to_px(layout_box())),
static_cast<int>(layer.spread_distance.to_px(layout_box())), static_cast<int>(layer.spread_distance.to_px(layout_box())),
layer.placement == CSS::BoxShadowPlacement::Outer ? BoxShadowPlacement::Outer : BoxShadowPlacement::Inner); layer.placement == CSS::ShadowPlacement::Outer ? ShadowPlacement::Outer : ShadowPlacement::Inner);
} }
Painting::paint_box_shadow(context, enclosing_int_rect(absolute_border_box_rect()), resolved_box_shadow_data); Painting::paint_box_shadow(context, enclosing_int_rect(absolute_border_box_rect()), resolved_box_shadow_data);
} }

View file

@ -13,7 +13,7 @@
namespace Web::Painting { namespace Web::Painting {
void paint_box_shadow(PaintContext& context, Gfx::IntRect const& content_rect, Vector<BoxShadowData> const& box_shadow_layers) void paint_box_shadow(PaintContext& context, Gfx::IntRect const& content_rect, Vector<ShadowData> const& box_shadow_layers)
{ {
if (box_shadow_layers.is_empty()) if (box_shadow_layers.is_empty())
return; return;
@ -24,7 +24,7 @@ void paint_box_shadow(PaintContext& context, Gfx::IntRect const& content_rect, V
for (int layer_index = box_shadow_layers.size() - 1; layer_index >= 0; layer_index--) { for (int layer_index = box_shadow_layers.size() - 1; layer_index >= 0; layer_index--) {
auto& box_shadow_data = box_shadow_layers[layer_index]; auto& box_shadow_data = box_shadow_layers[layer_index];
// FIXME: Paint inset shadows. // FIXME: Paint inset shadows.
if (box_shadow_data.placement != BoxShadowPlacement::Outer) if (box_shadow_data.placement != ShadowPlacement::Outer)
continue; continue;
// FIXME: Account for rounded corners. // FIXME: Account for rounded corners.

View file

@ -11,20 +11,20 @@
namespace Web::Painting { namespace Web::Painting {
enum class BoxShadowPlacement { enum class ShadowPlacement {
Outer, Outer,
Inner, Inner,
}; };
struct BoxShadowData { struct ShadowData {
Gfx::Color color; Gfx::Color color;
int offset_x; int offset_x;
int offset_y; int offset_y;
int blur_radius; int blur_radius;
int spread_distance; int spread_distance;
BoxShadowPlacement placement; ShadowPlacement placement;
}; };
void paint_box_shadow(PaintContext&, Gfx::IntRect const&, Vector<BoxShadowData> const&); void paint_box_shadow(PaintContext&, Gfx::IntRect const&, Vector<ShadowData> const&);
} }