mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:17:45 +00:00
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:
parent
5e9a6302e5
commit
cff44831a8
5 changed files with 3 additions and 19 deletions
|
@ -307,13 +307,12 @@ bool property_accepts_value(PropertyID property_id, StyleValue& style_value)
|
||||||
)~~~");
|
)~~~");
|
||||||
} else if (type_name == "length") {
|
} else if (type_name == "length") {
|
||||||
property_generator.append(R"~~~(
|
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;
|
return true;
|
||||||
)~~~");
|
)~~~");
|
||||||
} else if (type_name == "percentage") {
|
} else if (type_name == "percentage") {
|
||||||
// FIXME: Detecting lengths here is temporary until Length/Percentage are fully separated.
|
|
||||||
property_generator.append(R"~~~(
|
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;
|
return true;
|
||||||
)~~~");
|
)~~~");
|
||||||
} else if (type_name == "number" || type_name == "integer") {
|
} else if (type_name == "number" || type_name == "integer") {
|
||||||
|
|
|
@ -55,8 +55,6 @@ Length Length::resolved(const Length& fallback_for_undefined, const Layout::Node
|
||||||
return fallback_for_undefined;
|
return fallback_for_undefined;
|
||||||
if (is_calculated())
|
if (is_calculated())
|
||||||
return Length(resolve_calculated_value(layout_node, reference_for_percent), Type::Px);
|
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())
|
if (is_relative())
|
||||||
return make_px(to_px(layout_node));
|
return make_px(to_px(layout_node));
|
||||||
return *this;
|
return *this;
|
||||||
|
@ -257,8 +255,6 @@ const char* Length::unit_name() const
|
||||||
return "rem";
|
return "rem";
|
||||||
case Type::Auto:
|
case Type::Auto:
|
||||||
return "auto";
|
return "auto";
|
||||||
case Type::Percentage:
|
|
||||||
return "%";
|
|
||||||
case Type::Undefined:
|
case Type::Undefined:
|
||||||
return "undefined";
|
return "undefined";
|
||||||
case Type::Vh:
|
case Type::Vh:
|
||||||
|
|
|
@ -16,7 +16,6 @@ class Length {
|
||||||
public:
|
public:
|
||||||
enum class Type {
|
enum class Type {
|
||||||
Undefined,
|
Undefined,
|
||||||
Percentage,
|
|
||||||
Calculated,
|
Calculated,
|
||||||
Auto,
|
Auto,
|
||||||
Cm,
|
Cm,
|
||||||
|
@ -52,7 +51,6 @@ public:
|
||||||
|
|
||||||
bool is_undefined_or_auto() const { return m_type == Type::Undefined || m_type == Type::Auto; }
|
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_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_auto() const { return m_type == Type::Auto; }
|
||||||
bool is_calculated() const { return m_type == Type::Calculated; }
|
bool is_calculated() const { return m_type == Type::Calculated; }
|
||||||
|
|
||||||
|
|
|
@ -2184,12 +2184,7 @@ Optional<Length> Parser::parse_length(StyleComponentValueRule const& component_v
|
||||||
if (dimension->is_length())
|
if (dimension->is_length())
|
||||||
return dimension->length();
|
return dimension->length();
|
||||||
|
|
||||||
// FIXME: This is a temporary hack until Length is split up fully.
|
// FIXME: auto isn't a length!
|
||||||
if (dimension->is_percentage()) {
|
|
||||||
auto percentage = dimension->percentage();
|
|
||||||
return Length { (float)percentage.value(), Length::Type::Percentage };
|
|
||||||
}
|
|
||||||
|
|
||||||
if (component_value.is(Token::Type::Ident) && component_value.token().ident().equals_ignoring_case("auto"))
|
if (component_value.is(Token::Type::Ident) && component_value.token().ident().equals_ignoring_case("auto"))
|
||||||
return Length::make_auto();
|
return Length::make_auto();
|
||||||
|
|
||||||
|
|
|
@ -1194,10 +1194,6 @@ public:
|
||||||
Percentage const& percentage() const { return m_percentage; }
|
Percentage const& percentage() const { return m_percentage; }
|
||||||
Percentage& percentage() { 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
|
virtual String to_string() const override
|
||||||
{
|
{
|
||||||
return m_percentage.to_string();
|
return m_percentage.to_string();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue