LibWeb: Construct resolved shorthands from resolved longhands

Recursively call `style_value_for_property()` for the longhands, instead
of duplicating the logic to construct them.
This commit is contained in:
Sam Atkins 2023-09-29 13:02:11 +01:00 committed by Sam Atkins
parent 737cccec70
commit 30e31d83b6
Notes: sideshowbarker 2024-07-17 18:08:55 +09:00

View file

@ -199,7 +199,7 @@ RefPtr<StyleValue const> ResolvedCSSStyleDeclaration::style_value_for_property(L
// -> padding-left // -> padding-left
// -> padding-right // -> padding-right
// -> padding-top // -> padding-top
// FIXME: -> width // -> width
// -> A resolved value special case property like height defined in another specification // -> A resolved value special case property like height defined in another specification
// FIXME: If the property applies to the element or pseudo-element and the resolved value of the // FIXME: If the property applies to the element or pseudo-element and the resolved value of the
// display property is not none or contents, then the resolved value is the used value. // display property is not none or contents, then the resolved value is the used value.
@ -305,56 +305,50 @@ RefPtr<StyleValue const> ResolvedCSSStyleDeclaration::style_value_for_property(L
EdgeStyleValue::create(PositionEdge::Top, Percentage(0))); EdgeStyleValue::create(PositionEdge::Top, Percentage(0)));
}); });
case PropertyID::Border: { case PropertyID::Border: {
auto top = layout_node.computed_values().border_top(); auto width = style_value_for_property(layout_node, PropertyID::BorderWidth);
auto right = layout_node.computed_values().border_right(); auto style = style_value_for_property(layout_node, PropertyID::BorderStyle);
auto bottom = layout_node.computed_values().border_bottom(); auto color = style_value_for_property(layout_node, PropertyID::BorderColor);
auto left = layout_node.computed_values().border_left();
// `border` only has a reasonable value if all four sides are the same. // `border` only has a reasonable value if all four sides are the same.
if (top != right || top != bottom || top != left) if (width->is_value_list() || style->is_value_list() || color->is_value_list())
return nullptr; return nullptr;
auto width = LengthStyleValue::create(Length::make_px(top.width));
auto style = IdentifierStyleValue::create(to_value_id(top.line_style));
auto color = ColorStyleValue::create(top.color);
return ShorthandStyleValue::create(property_id, return ShorthandStyleValue::create(property_id,
{ PropertyID::BorderWidth, PropertyID::BorderStyle, PropertyID::BorderColor }, { PropertyID::BorderWidth, PropertyID::BorderStyle, PropertyID::BorderColor },
{ width, style, color }); { width.release_nonnull(), style.release_nonnull(), color.release_nonnull() });
} }
case PropertyID::BorderColor: { case PropertyID::BorderColor: {
auto top = ColorStyleValue::create(layout_node.computed_values().border_top().color); auto top = style_value_for_property(layout_node, PropertyID::BorderTopColor);
auto right = ColorStyleValue::create(layout_node.computed_values().border_right().color); auto right = style_value_for_property(layout_node, PropertyID::BorderRightColor);
auto bottom = ColorStyleValue::create(layout_node.computed_values().border_bottom().color); auto bottom = style_value_for_property(layout_node, PropertyID::BorderBottomColor);
auto left = ColorStyleValue::create(layout_node.computed_values().border_left().color); auto left = style_value_for_property(layout_node, PropertyID::BorderLeftColor);
return style_value_for_sided_shorthand(top, right, bottom, left); return style_value_for_sided_shorthand(top.release_nonnull(), right.release_nonnull(), bottom.release_nonnull(), left.release_nonnull());
} }
case PropertyID::BorderStyle: { case PropertyID::BorderStyle: {
auto top = IdentifierStyleValue::create(to_value_id(layout_node.computed_values().border_top().line_style)); auto top = style_value_for_property(layout_node, PropertyID::BorderTopStyle);
auto right = IdentifierStyleValue::create(to_value_id(layout_node.computed_values().border_right().line_style)); auto right = style_value_for_property(layout_node, PropertyID::BorderRightStyle);
auto bottom = IdentifierStyleValue::create(to_value_id(layout_node.computed_values().border_bottom().line_style)); auto bottom = style_value_for_property(layout_node, PropertyID::BorderBottomStyle);
auto left = IdentifierStyleValue::create(to_value_id(layout_node.computed_values().border_left().line_style)); auto left = style_value_for_property(layout_node, PropertyID::BorderLeftStyle);
return style_value_for_sided_shorthand(top, right, bottom, left); return style_value_for_sided_shorthand(top.release_nonnull(), right.release_nonnull(), bottom.release_nonnull(), left.release_nonnull());
} }
case PropertyID::BorderWidth: { case PropertyID::BorderWidth: {
auto top = LengthStyleValue::create(Length::make_px(layout_node.computed_values().border_top().width)); auto top = style_value_for_property(layout_node, PropertyID::BorderTopWidth);
auto right = LengthStyleValue::create(Length::make_px(layout_node.computed_values().border_right().width)); auto right = style_value_for_property(layout_node, PropertyID::BorderRightWidth);
auto bottom = LengthStyleValue::create(Length::make_px(layout_node.computed_values().border_bottom().width)); auto bottom = style_value_for_property(layout_node, PropertyID::BorderBottomWidth);
auto left = LengthStyleValue::create(Length::make_px(layout_node.computed_values().border_left().width)); auto left = style_value_for_property(layout_node, PropertyID::BorderLeftWidth);
return style_value_for_sided_shorthand(top, right, bottom, left); return style_value_for_sided_shorthand(top.release_nonnull(), right.release_nonnull(), bottom.release_nonnull(), left.release_nonnull());
} }
case PropertyID::Margin: { case PropertyID::Margin: {
auto margin = layout_node.computed_values().margin(); auto top = style_value_for_property(layout_node, PropertyID::MarginTop);
auto top = style_value_for_length_percentage(margin.top()); auto right = style_value_for_property(layout_node, PropertyID::MarginRight);
auto right = style_value_for_length_percentage(margin.right()); auto bottom = style_value_for_property(layout_node, PropertyID::MarginBottom);
auto bottom = style_value_for_length_percentage(margin.bottom()); auto left = style_value_for_property(layout_node, PropertyID::MarginLeft);
auto left = style_value_for_length_percentage(margin.left()); return style_value_for_sided_shorthand(top.release_nonnull(), right.release_nonnull(), bottom.release_nonnull(), left.release_nonnull());
return style_value_for_sided_shorthand(move(top), move(right), move(bottom), move(left));
} }
case PropertyID::Padding: { case PropertyID::Padding: {
auto padding = layout_node.computed_values().padding(); auto top = style_value_for_property(layout_node, PropertyID::PaddingTop);
auto top = style_value_for_length_percentage(padding.top()); auto right = style_value_for_property(layout_node, PropertyID::PaddingRight);
auto right = style_value_for_length_percentage(padding.right()); auto bottom = style_value_for_property(layout_node, PropertyID::PaddingBottom);
auto bottom = style_value_for_length_percentage(padding.bottom()); auto left = style_value_for_property(layout_node, PropertyID::PaddingLeft);
auto left = style_value_for_length_percentage(padding.left()); return style_value_for_sided_shorthand(top.release_nonnull(), right.release_nonnull(), bottom.release_nonnull(), left.release_nonnull());
return style_value_for_sided_shorthand(move(top), move(right), move(bottom), move(left));
} }
case PropertyID::Invalid: case PropertyID::Invalid:
return IdentifierStyleValue::create(ValueID::Invalid); return IdentifierStyleValue::create(ValueID::Invalid);