LibWeb: Remove Length::Type::Percentage :^)

All `<percentage>`s in the CSS grammar are now represented by the
`Percentage` class, and `<length-percentage>` by `LengthPercentage`.
This commit is contained in:
Sam Atkins 2022-01-19 16:40:01 +00:00 committed by Andreas Kling
parent 5e9a6302e5
commit cff44831a8
Notes: sideshowbarker 2024-07-17 20:36:12 +09:00
5 changed files with 3 additions and 19 deletions

View File

@ -307,13 +307,12 @@ bool property_accepts_value(PropertyID property_id, StyleValue& style_value)
)~~~");
} else if (type_name == "length") {
property_generator.append(R"~~~(
if ((style_value.has_length() && !style_value.to_length().is_percentage()) || style_value.is_calculated())
if (style_value.has_length() || style_value.is_calculated())
return true;
)~~~");
} else if (type_name == "percentage") {
// FIXME: Detecting lengths here is temporary until Length/Percentage are fully separated.
property_generator.append(R"~~~(
if (style_value.is_percentage() || style_value.is_calculated() || (style_value.has_length() && !style_value.to_length().is_percentage()))
if (style_value.is_percentage() || style_value.is_calculated())
return true;
)~~~");
} else if (type_name == "number" || type_name == "integer") {

View File

@ -55,8 +55,6 @@ Length Length::resolved(const Length& fallback_for_undefined, const Layout::Node
return fallback_for_undefined;
if (is_calculated())
return Length(resolve_calculated_value(layout_node, reference_for_percent), Type::Px);
if (is_percentage())
return make_px(raw_value() / 100.0f * reference_for_percent);
if (is_relative())
return make_px(to_px(layout_node));
return *this;
@ -257,8 +255,6 @@ const char* Length::unit_name() const
return "rem";
case Type::Auto:
return "auto";
case Type::Percentage:
return "%";
case Type::Undefined:
return "undefined";
case Type::Vh:

View File

@ -16,7 +16,6 @@ class Length {
public:
enum class Type {
Undefined,
Percentage,
Calculated,
Auto,
Cm,
@ -52,7 +51,6 @@ public:
bool is_undefined_or_auto() const { return m_type == Type::Undefined || m_type == Type::Auto; }
bool is_undefined() const { return m_type == Type::Undefined; }
bool is_percentage() const { return m_type == Type::Percentage || m_type == Type::Calculated; }
bool is_auto() const { return m_type == Type::Auto; }
bool is_calculated() const { return m_type == Type::Calculated; }

View File

@ -2184,12 +2184,7 @@ Optional<Length> Parser::parse_length(StyleComponentValueRule const& component_v
if (dimension->is_length())
return dimension->length();
// FIXME: This is a temporary hack until Length is split up fully.
if (dimension->is_percentage()) {
auto percentage = dimension->percentage();
return Length { (float)percentage.value(), Length::Type::Percentage };
}
// FIXME: auto isn't a length!
if (component_value.is(Token::Type::Ident) && component_value.token().ident().equals_ignoring_case("auto"))
return Length::make_auto();

View File

@ -1194,10 +1194,6 @@ public:
Percentage const& percentage() const { return m_percentage; }
Percentage& percentage() { return m_percentage; }
// FIXME: This is a temporary hack until we fully separate Length and Percentage.
bool has_length() const override { return true; }
Length to_length() const override { return { m_percentage.value(), Length::Type::Percentage }; }
virtual String to_string() const override
{
return m_percentage.to_string();