mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 19:27:35 +00:00
LibWeb: Convert background-size from Length to LengthPercentage
Checking these for `auto` is awkward, but separating that will come later. :^)
This commit is contained in:
parent
f75e796909
commit
f602249ae9
4 changed files with 46 additions and 21 deletions
|
@ -49,8 +49,8 @@ struct BackgroundLayerData {
|
|||
CSS::PositionEdge position_edge_y { CSS::PositionEdge::Top };
|
||||
CSS::Length position_offset_y { CSS::Length::make_px(0) };
|
||||
CSS::BackgroundSize size_type { CSS::BackgroundSize::LengthPercentage };
|
||||
CSS::Length size_x { CSS::Length::make_auto() };
|
||||
CSS::Length size_y { CSS::Length::make_auto() };
|
||||
CSS::LengthPercentage size_x { CSS::Length::make_auto() };
|
||||
CSS::LengthPercentage size_y { CSS::Length::make_auto() };
|
||||
CSS::Repeat repeat_x { CSS::Repeat::Repeat };
|
||||
CSS::Repeat repeat_y { CSS::Repeat::Repeat };
|
||||
};
|
||||
|
|
|
@ -2940,6 +2940,14 @@ RefPtr<StyleValue> Parser::parse_single_background_size_value(TokenStream<StyleC
|
|||
return nullptr;
|
||||
};
|
||||
|
||||
auto get_length_percentage = [](StyleValue& style_value) -> Optional<LengthPercentage> {
|
||||
if (style_value.is_percentage())
|
||||
return LengthPercentage { style_value.as_percentage().percentage() };
|
||||
if (style_value.has_length())
|
||||
return LengthPercentage { style_value.to_length() };
|
||||
return {};
|
||||
};
|
||||
|
||||
auto maybe_x_value = parse_css_value(tokens.next_token());
|
||||
if (!maybe_x_value || !property_accepts_value(PropertyID::BackgroundSize, *maybe_x_value))
|
||||
return error();
|
||||
|
@ -2949,13 +2957,20 @@ RefPtr<StyleValue> Parser::parse_single_background_size_value(TokenStream<StyleC
|
|||
return x_value;
|
||||
|
||||
auto maybe_y_value = parse_css_value(tokens.peek_token());
|
||||
if (!maybe_y_value || !property_accepts_value(PropertyID::BackgroundSize, *maybe_y_value))
|
||||
return BackgroundSizeStyleValue::create(x_value->to_length(), x_value->to_length());
|
||||
if (!maybe_y_value || !property_accepts_value(PropertyID::BackgroundSize, *maybe_y_value)) {
|
||||
auto x_size = get_length_percentage(*x_value);
|
||||
if (!x_size.has_value())
|
||||
return error();
|
||||
return BackgroundSizeStyleValue::create(x_size.value(), x_size.value());
|
||||
}
|
||||
|
||||
tokens.next_token();
|
||||
auto y_value = maybe_y_value.release_nonnull();
|
||||
auto x_size = get_length_percentage(*x_value);
|
||||
auto y_size = get_length_percentage(*y_value);
|
||||
|
||||
if (x_value->has_length() && y_value->has_length())
|
||||
return BackgroundSizeStyleValue::create(x_value->to_length(), y_value->to_length());
|
||||
if (x_size.has_value() && y_size.has_value())
|
||||
return BackgroundSizeStyleValue::create(x_size.release_value(), y_size.release_value());
|
||||
|
||||
return error();
|
||||
}
|
||||
|
|
|
@ -499,14 +499,14 @@ private:
|
|||
// NOTE: This is not used for identifier sizes, like `cover` and `contain`.
|
||||
class BackgroundSizeStyleValue final : public StyleValue {
|
||||
public:
|
||||
static NonnullRefPtr<BackgroundSizeStyleValue> create(Length size_x, Length size_y)
|
||||
static NonnullRefPtr<BackgroundSizeStyleValue> create(LengthPercentage size_x, LengthPercentage size_y)
|
||||
{
|
||||
return adopt_ref(*new BackgroundSizeStyleValue(size_x, size_y));
|
||||
}
|
||||
virtual ~BackgroundSizeStyleValue() override { }
|
||||
|
||||
Length size_x() const { return m_size_x; }
|
||||
Length size_y() const { return m_size_y; }
|
||||
LengthPercentage size_x() const { return m_size_x; }
|
||||
LengthPercentage size_y() const { return m_size_y; }
|
||||
|
||||
virtual String to_string() const override
|
||||
{
|
||||
|
@ -514,15 +514,15 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
BackgroundSizeStyleValue(Length size_x, Length size_y)
|
||||
BackgroundSizeStyleValue(LengthPercentage size_x, LengthPercentage size_y)
|
||||
: StyleValue(Type::BackgroundSize)
|
||||
, m_size_x(size_x)
|
||||
, m_size_y(size_y)
|
||||
{
|
||||
}
|
||||
|
||||
Length m_size_x;
|
||||
Length m_size_y;
|
||||
LengthPercentage m_size_x;
|
||||
LengthPercentage m_size_y;
|
||||
};
|
||||
|
||||
class BorderStyleValue final : public StyleValue {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue