LibWeb: Oops, not all length boxes should default to 'auto' values

Only the offset box (left/top/right/bottom) box defaults to 'auto'.
Both the padding and margin boxes default to '0' for all values.
This commit is contained in:
Andreas Kling 2020-12-15 20:01:00 +01:00
parent 30685a7714
commit 92d8e559ba
Notes: sideshowbarker 2024-07-19 00:48:38 +09:00
3 changed files with 9 additions and 9 deletions

View file

@ -77,13 +77,13 @@ Length StyleProperties::length_or_fallback(CSS::PropertyID id, const Length& fal
return value.value()->to_length();
}
LengthBox StyleProperties::length_box(CSS::PropertyID left_id, CSS::PropertyID top_id, CSS::PropertyID right_id, CSS::PropertyID bottom_id) const
LengthBox StyleProperties::length_box(CSS::PropertyID left_id, CSS::PropertyID top_id, CSS::PropertyID right_id, CSS::PropertyID bottom_id, const CSS::Length& default_value) const
{
LengthBox box;
box.left = length_or_fallback(left_id, CSS::Length::make_auto());
box.top = length_or_fallback(top_id, CSS::Length::make_auto());
box.right = length_or_fallback(right_id, CSS::Length::make_auto());
box.bottom = length_or_fallback(bottom_id, CSS::Length::make_auto());
box.left = length_or_fallback(left_id, default_value);
box.top = length_or_fallback(top_id, default_value);
box.right = length_or_fallback(right_id, default_value);
box.bottom = length_or_fallback(bottom_id, default_value);
return box;
}

View file

@ -57,7 +57,7 @@ public:
Optional<NonnullRefPtr<StyleValue>> property(CSS::PropertyID) const;
Length length_or_fallback(CSS::PropertyID, const Length& fallback) const;
LengthBox length_box(CSS::PropertyID left_id, CSS::PropertyID top_id, CSS::PropertyID right_id, CSS::PropertyID bottom_id) const;
LengthBox length_box(CSS::PropertyID left_id, CSS::PropertyID top_id, CSS::PropertyID right_id, CSS::PropertyID bottom_id, const CSS::Length& default_value) const;
String string_or_fallback(CSS::PropertyID, const StringView& fallback) const;
Color color_or_fallback(CSS::PropertyID, const DOM::Document&, Color fallback) const;
Optional<CSS::TextAlign> text_align() const;

View file

@ -261,9 +261,9 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& specified_style)
style.set_min_height(specified_style.length_or_fallback(CSS::PropertyID::MinHeight, {}));
style.set_max_height(specified_style.length_or_fallback(CSS::PropertyID::MaxHeight, {}));
style.set_offset(specified_style.length_box(CSS::PropertyID::Left, CSS::PropertyID::Top, CSS::PropertyID::Right, CSS::PropertyID::Bottom));
style.set_margin(specified_style.length_box(CSS::PropertyID::MarginLeft, CSS::PropertyID::MarginTop, CSS::PropertyID::MarginRight, CSS::PropertyID::MarginBottom));
style.set_padding(specified_style.length_box(CSS::PropertyID::PaddingLeft, CSS::PropertyID::PaddingTop, CSS::PropertyID::PaddingRight, CSS::PropertyID::PaddingBottom));
style.set_offset(specified_style.length_box(CSS::PropertyID::Left, CSS::PropertyID::Top, CSS::PropertyID::Right, CSS::PropertyID::Bottom, CSS::Length::make_auto()));
style.set_margin(specified_style.length_box(CSS::PropertyID::MarginLeft, CSS::PropertyID::MarginTop, CSS::PropertyID::MarginRight, CSS::PropertyID::MarginBottom, CSS::Length::make_px(0)));
style.set_padding(specified_style.length_box(CSS::PropertyID::PaddingLeft, CSS::PropertyID::PaddingTop, CSS::PropertyID::PaddingRight, CSS::PropertyID::PaddingBottom, CSS::Length::make_px(0)));
auto do_border_style = [&](BorderData& border, CSS::PropertyID width_property, CSS::PropertyID color_property, CSS::PropertyID style_property) {
border.width = specified_style.length_or_fallback(width_property, {}).resolved_or_zero(*this, 0).to_px(*this);