Skip to content

Commit 0595d52

Browse files
Calme1709AtkinsSJ
authored andcommitted
LibWeb: Simplify handling of {text,box}-shadow
We know that shadow values are always parsed as a `KeywordStyleValue` with `Keyword::None` or a `StyleValueList`
1 parent 4c4fa5c commit 0595d52

File tree

2 files changed

+14
-30
lines changed

2 files changed

+14
-30
lines changed

Libraries/LibWeb/CSS/ComputedProperties.cpp

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,29 +1381,21 @@ Vector<ShadowData> ComputedProperties::shadow(PropertyID property_id, Layout::No
13811381
};
13821382
};
13831383

1384-
if (value.is_value_list()) {
1385-
auto const& value_list = value.as_value_list();
1386-
1387-
Vector<ShadowData> shadow_data;
1388-
shadow_data.ensure_capacity(value_list.size());
1389-
for (auto const& layer_value : value_list.values()) {
1390-
auto maybe_shadow_data = make_shadow_data(layer_value->as_shadow());
1391-
if (!maybe_shadow_data.has_value())
1392-
return {};
1393-
shadow_data.append(maybe_shadow_data.release_value());
1394-
}
1384+
if (value.to_keyword() == Keyword::None)
1385+
return {};
13951386

1396-
return shadow_data;
1397-
}
1387+
auto const& value_list = value.as_value_list();
13981388

1399-
if (value.is_shadow()) {
1400-
auto maybe_shadow_data = make_shadow_data(value.as_shadow());
1389+
Vector<ShadowData> shadow_data;
1390+
shadow_data.ensure_capacity(value_list.size());
1391+
for (auto const& layer_value : value_list.values()) {
1392+
auto maybe_shadow_data = make_shadow_data(layer_value->as_shadow());
14011393
if (!maybe_shadow_data.has_value())
14021394
return {};
1403-
return { maybe_shadow_data.release_value() };
1395+
shadow_data.append(maybe_shadow_data.release_value());
14041396
}
14051397

1406-
return {};
1398+
return shadow_data;
14071399
}
14081400

14091401
Vector<ShadowData> ComputedProperties::box_shadow(Layout::Node const& layout_node) const

Libraries/LibWeb/CSS/Interpolation.cpp

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,19 +1341,11 @@ RefPtr<StyleValue const> interpolate_box_shadow(DOM::Element& element, Calculati
13411341
// (transparent 0 0 0 0) with a corresponding inset keyword as needed to match the longer list if
13421342
// the shorter list is otherwise compatible with the longer one
13431343

1344-
static constexpr auto process_list = [](StyleValue const& value) {
1345-
StyleValueVector shadows;
1346-
if (value.is_value_list()) {
1347-
for (auto const& element : value.as_value_list().values()) {
1348-
if (element->is_shadow())
1349-
shadows.append(element);
1350-
}
1351-
} else if (value.is_shadow()) {
1352-
shadows.append(value);
1353-
} else if (!value.is_keyword() || value.as_keyword().keyword() != Keyword::None) {
1354-
VERIFY_NOT_REACHED();
1355-
}
1356-
return shadows;
1344+
static constexpr auto process_list = [](StyleValue const& value) -> StyleValueVector {
1345+
if (value.to_keyword() == Keyword::None)
1346+
return {};
1347+
1348+
return value.as_value_list().values();
13571349
};
13581350

13591351
static constexpr auto extend_list_if_necessary = [](StyleValueVector& values, StyleValueVector const& other) {

0 commit comments

Comments
 (0)