Skip to content

Commit 1094654

Browse files
AtkinsSJawesomekling
authored andcommitted
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. :^)
1 parent f9367a5 commit 1094654

13 files changed

+101
-101
lines changed

Userland/Libraries/LibWeb/CSS/ComputedValues.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,13 @@ struct FlexBasisData {
8888
bool is_definite() const { return type == CSS::FlexBasis::LengthPercentage; }
8989
};
9090

91-
struct BoxShadowData {
91+
struct ShadowData {
9292
Color color {};
9393
CSS::Length offset_x { Length::make_px(0) };
9494
CSS::Length offset_y { Length::make_px(0) };
9595
CSS::Length blur_radius { Length::make_px(0) };
9696
CSS::Length spread_distance { Length::make_px(0) };
97-
CSS::BoxShadowPlacement placement { CSS::BoxShadowPlacement::Outer };
97+
CSS::ShadowPlacement placement { CSS::ShadowPlacement::Outer };
9898
};
9999

100100
struct ContentData {
@@ -137,7 +137,7 @@ class ComputedValues {
137137
CSS::Visibility visibility() const { return m_inherited.visibility; }
138138
CSS::ImageRendering image_rendering() const { return m_inherited.image_rendering; }
139139
CSS::JustifyContent justify_content() const { return m_noninherited.justify_content; }
140-
Vector<BoxShadowData> const& box_shadow() const { return m_noninherited.box_shadow; }
140+
Vector<ShadowData> const& box_shadow() const { return m_noninherited.box_shadow; }
141141
CSS::BoxSizing box_sizing() const { return m_noninherited.box_sizing; }
142142
Optional<CSS::LengthPercentage> const& width() const { return m_noninherited.width; }
143143
Optional<CSS::LengthPercentage> const& min_width() const { return m_noninherited.min_width; }
@@ -248,7 +248,7 @@ class ComputedValues {
248248
CSS::Overflow overflow_x { InitialValues::overflow() };
249249
CSS::Overflow overflow_y { InitialValues::overflow() };
250250
float opacity { InitialValues::opacity() };
251-
Vector<BoxShadowData> box_shadow {};
251+
Vector<ShadowData> box_shadow {};
252252
Vector<CSS::Transformation> transformations {};
253253
CSS::TransformOrigin transform_origin {};
254254
CSS::BoxSizing box_sizing { InitialValues::box_sizing() };
@@ -313,7 +313,7 @@ class MutableComputedValues final : public ComputedValues {
313313
void set_align_items(CSS::AlignItems value) { m_noninherited.align_items = value; }
314314
void set_opacity(float value) { m_noninherited.opacity = value; }
315315
void set_justify_content(CSS::JustifyContent value) { m_noninherited.justify_content = value; }
316-
void set_box_shadow(Vector<BoxShadowData>&& value) { m_noninherited.box_shadow = move(value); }
316+
void set_box_shadow(Vector<ShadowData>&& value) { m_noninherited.box_shadow = move(value); }
317317
void set_transformations(Vector<CSS::Transformation> value) { m_noninherited.transformations = move(value); }
318318
void set_transform_origin(CSS::TransformOrigin value) { m_noninherited.transform_origin = value; }
319319
void set_box_sizing(CSS::BoxSizing value) { m_noninherited.box_sizing = value; }

Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3318,7 +3318,7 @@ RefPtr<StyleValue> Parser::parse_border_radius_shorthand_value(Vector<StyleCompo
33183318
return StyleValueList::create(move(border_radii), StyleValueList::Separator::Space);
33193319
}
33203320

3321-
RefPtr<StyleValue> Parser::parse_box_shadow_value(Vector<StyleComponentValueRule> const& component_values)
3321+
RefPtr<StyleValue> Parser::parse_shadow_value(Vector<StyleComponentValueRule> const& component_values)
33223322
{
33233323
// "none"
33243324
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
33283328
}
33293329

33303330
return parse_comma_separated_value_list(component_values, [this](auto& tokens) {
3331-
return parse_single_box_shadow_value(tokens);
3331+
return parse_single_shadow_value(tokens);
33323332
});
33333333
}
33343334

3335-
RefPtr<StyleValue> Parser::parse_single_box_shadow_value(TokenStream<StyleComponentValueRule>& tokens)
3335+
RefPtr<StyleValue> Parser::parse_single_shadow_value(TokenStream<StyleComponentValueRule>& tokens)
33363336
{
33373337
auto start_position = tokens.position();
33383338
auto error = [&]() {
@@ -3345,7 +3345,7 @@ RefPtr<StyleValue> Parser::parse_single_box_shadow_value(TokenStream<StyleCompon
33453345
Optional<Length> offset_y;
33463346
Optional<Length> blur_radius;
33473347
Optional<Length> spread_distance;
3348-
Optional<BoxShadowPlacement> placement;
3348+
Optional<ShadowPlacement> placement;
33493349

33503350
while (tokens.has_next_token()) {
33513351
auto& token = tokens.peek_token();
@@ -3398,7 +3398,7 @@ RefPtr<StyleValue> Parser::parse_single_box_shadow_value(TokenStream<StyleCompon
33983398
if (token.is(Token::Type::Ident) && token.token().ident().equals_ignoring_case("inset"sv)) {
33993399
if (placement.has_value())
34003400
return error();
3401-
placement = BoxShadowPlacement::Inner;
3401+
placement = ShadowPlacement::Inner;
34023402
tokens.next_token();
34033403
continue;
34043404
}
@@ -3425,9 +3425,9 @@ RefPtr<StyleValue> Parser::parse_single_box_shadow_value(TokenStream<StyleCompon
34253425

34263426
// Placement is outer by default
34273427
if (!placement.has_value())
3428-
placement = BoxShadowPlacement::Outer;
3428+
placement = ShadowPlacement::Outer;
34293429

3430-
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());
3430+
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());
34313431
}
34323432

34333433
RefPtr<StyleValue> Parser::parse_content_value(Vector<StyleComponentValueRule> const& component_values)
@@ -4248,7 +4248,7 @@ Result<NonnullRefPtr<StyleValue>, Parser::ParsingResult> Parser::parse_css_value
42484248
return parsed_value.release_nonnull();
42494249
return ParsingResult::SyntaxError;
42504250
case PropertyID::BoxShadow:
4251-
if (auto parsed_value = parse_box_shadow_value(component_values))
4251+
if (auto parsed_value = parse_shadow_value(component_values))
42524252
return parsed_value.release_nonnull();
42534253
return ParsingResult::SyntaxError;
42544254
case PropertyID::Content:

Userland/Libraries/LibWeb/CSS/Parser/Parser.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,15 +287,15 @@ class Parser {
287287
RefPtr<StyleValue> parse_border_value(Vector<StyleComponentValueRule> const&);
288288
RefPtr<StyleValue> parse_border_radius_value(Vector<StyleComponentValueRule> const&);
289289
RefPtr<StyleValue> parse_border_radius_shorthand_value(Vector<StyleComponentValueRule> const&);
290-
RefPtr<StyleValue> parse_box_shadow_value(Vector<StyleComponentValueRule> const&);
291-
RefPtr<StyleValue> parse_single_box_shadow_value(TokenStream<StyleComponentValueRule>&);
292290
RefPtr<StyleValue> parse_content_value(Vector<StyleComponentValueRule> const&);
293291
RefPtr<StyleValue> parse_flex_value(Vector<StyleComponentValueRule> const&);
294292
RefPtr<StyleValue> parse_flex_flow_value(Vector<StyleComponentValueRule> const&);
295293
RefPtr<StyleValue> parse_font_value(Vector<StyleComponentValueRule> const&);
296294
RefPtr<StyleValue> parse_font_family_value(Vector<StyleComponentValueRule> const&, size_t start_index = 0);
297295
RefPtr<StyleValue> parse_list_style_value(Vector<StyleComponentValueRule> const&);
298296
RefPtr<StyleValue> parse_overflow_value(Vector<StyleComponentValueRule> const&);
297+
RefPtr<StyleValue> parse_shadow_value(Vector<StyleComponentValueRule> const&);
298+
RefPtr<StyleValue> parse_single_shadow_value(TokenStream<StyleComponentValueRule>&);
299299
RefPtr<StyleValue> parse_text_decoration_value(Vector<StyleComponentValueRule> const&);
300300
RefPtr<StyleValue> parse_transform_value(Vector<StyleComponentValueRule> const&);
301301
RefPtr<StyleValue> parse_transform_origin_value(Vector<StyleComponentValueRule> const&);

Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,8 +560,8 @@ RefPtr<StyleValue> ResolvedCSSStyleDeclaration::style_value_for_property(Layout:
560560
if (box_shadow_layers.is_empty())
561561
return {};
562562

563-
auto make_box_shadow_style_value = [](BoxShadowData const& data) {
564-
return BoxShadowStyleValue::create(data.color, data.offset_x, data.offset_y, data.blur_radius, data.spread_distance, data.placement);
563+
auto make_box_shadow_style_value = [](ShadowData const& data) {
564+
return ShadowStyleValue::create(data.color, data.offset_x, data.offset_y, data.blur_radius, data.spread_distance, data.placement);
565565
};
566566

567567
if (box_shadow_layers.size() == 1)

Userland/Libraries/LibWeb/CSS/StyleProperties.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -914,31 +914,31 @@ Optional<CSS::Overflow> StyleProperties::overflow(CSS::PropertyID property_id) c
914914
}
915915
}
916916

917-
Vector<BoxShadowData> StyleProperties::box_shadow() const
917+
Vector<ShadowData> StyleProperties::box_shadow() const
918918
{
919919
auto value_or_error = property(PropertyID::BoxShadow);
920920
if (!value_or_error.has_value())
921921
return {};
922922

923923
auto value = value_or_error.value();
924924

925-
auto make_box_shadow_data = [](BoxShadowStyleValue const& box) {
926-
return BoxShadowData { box.color(), box.offset_x(), box.offset_y(), box.blur_radius(), box.spread_distance(), box.placement() };
925+
auto make_box_shadow_data = [](ShadowStyleValue const& box) {
926+
return ShadowData { box.color(), box.offset_x(), box.offset_y(), box.blur_radius(), box.spread_distance(), box.placement() };
927927
};
928928

929929
if (value->is_value_list()) {
930930
auto& value_list = value->as_value_list();
931931

932-
Vector<BoxShadowData> box_shadow_data;
932+
Vector<ShadowData> box_shadow_data;
933933
box_shadow_data.ensure_capacity(value_list.size());
934934
for (auto const& layer_value : value_list.values())
935-
box_shadow_data.append(make_box_shadow_data(layer_value.as_box_shadow()));
935+
box_shadow_data.append(make_box_shadow_data(layer_value.as_shadow()));
936936

937937
return box_shadow_data;
938938
}
939939

940-
if (value->is_box_shadow()) {
941-
auto& box = value->as_box_shadow();
940+
if (value->is_shadow()) {
941+
auto& box = value->as_shadow();
942942
return { make_box_shadow_data(box) };
943943
}
944944

Userland/Libraries/LibWeb/CSS/StyleProperties.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class StyleProperties : public RefCounted<StyleProperties> {
7171
Optional<CSS::JustifyContent> justify_content() const;
7272
Optional<CSS::Overflow> overflow_x() const;
7373
Optional<CSS::Overflow> overflow_y() const;
74-
Vector<CSS::BoxShadowData> box_shadow() const;
74+
Vector<CSS::ShadowData> box_shadow() const;
7575
CSS::BoxSizing box_sizing() const;
7676
Optional<CSS::PointerEvents> pointer_events() const;
7777
Variant<CSS::VerticalAlign, CSS::LengthPercentage> vertical_align() const;

Userland/Libraries/LibWeb/CSS/StyleValue.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ BorderRadiusStyleValue const& StyleValue::as_border_radius() const
5959
return static_cast<BorderRadiusStyleValue const&>(*this);
6060
}
6161

62-
BoxShadowStyleValue const& StyleValue::as_box_shadow() const
62+
ShadowStyleValue const& StyleValue::as_shadow() const
6363
{
64-
VERIFY(is_box_shadow());
65-
return static_cast<BoxShadowStyleValue const&>(*this);
64+
VERIFY(is_shadow());
65+
return static_cast<ShadowStyleValue const&>(*this);
6666
}
6767

6868
CalculatedStyleValue const& StyleValue::as_calculated() const
@@ -295,11 +295,11 @@ String BorderRadiusStyleValue::to_string() const
295295
return String::formatted("{} / {}", m_horizontal_radius.to_string(), m_vertical_radius.to_string());
296296
}
297297

298-
String BoxShadowStyleValue::to_string() const
298+
String ShadowStyleValue::to_string() const
299299
{
300300
StringBuilder builder;
301301
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());
302-
if (m_placement == BoxShadowPlacement::Inner)
302+
if (m_placement == ShadowPlacement::Inner)
303303
builder.append(" inset");
304304
return builder.to_string();
305305
}
@@ -1446,13 +1446,13 @@ NonnullRefPtr<StyleValue> LengthStyleValue::absolutized(Gfx::IntRect const& view
14461446
return *this;
14471447
}
14481448

1449-
NonnullRefPtr<StyleValue> BoxShadowStyleValue::absolutized(Gfx::IntRect const& viewport_rect, Gfx::FontMetrics const& font_metrics, float font_size, float root_font_size) const
1449+
NonnullRefPtr<StyleValue> ShadowStyleValue::absolutized(Gfx::IntRect const& viewport_rect, Gfx::FontMetrics const& font_metrics, float font_size, float root_font_size) const
14501450
{
14511451
auto absolutized_offset_x = absolutized_length(m_offset_x, viewport_rect, font_metrics, font_size, root_font_size).value_or(m_offset_x);
14521452
auto absolutized_offset_y = absolutized_length(m_offset_y, viewport_rect, font_metrics, font_size, root_font_size).value_or(m_offset_y);
14531453
auto absolutized_blur_radius = absolutized_length(m_blur_radius, viewport_rect, font_metrics, font_size, root_font_size).value_or(m_blur_radius);
14541454
auto absolutized_spread_distance = absolutized_length(m_spread_distance, viewport_rect, font_metrics, font_size, root_font_size).value_or(m_spread_distance);
1455-
return BoxShadowStyleValue::create(m_color, absolutized_offset_x, absolutized_offset_y, absolutized_blur_radius, absolutized_spread_distance, m_placement);
1455+
return ShadowStyleValue::create(m_color, absolutized_offset_x, absolutized_offset_y, absolutized_blur_radius, absolutized_spread_distance, m_placement);
14561456
}
14571457

14581458
NonnullRefPtr<StyleValue> BorderRadiusStyleValue::absolutized(Gfx::IntRect const& viewport_rect, Gfx::FontMetrics const& font_metrics, float font_size, float root_font_size) const

0 commit comments

Comments
 (0)