diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index a7653f18b9..66a1771a60 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -2168,6 +2168,18 @@ Optional Parser::parse_dimension(StyleComponentValueRule cons if (auto length_type = Length::unit_from_name(unit_string); length_type.has_value()) return Length { numeric_value, length_type.release_value() }; + + if (auto angle_type = Angle::unit_from_name(unit_string); angle_type.has_value()) + return Angle { numeric_value, angle_type.release_value() }; + + if (auto frequency_type = Frequency::unit_from_name(unit_string); frequency_type.has_value()) + return Frequency { numeric_value, frequency_type.release_value() }; + + if (auto resolution_type = Resolution::unit_from_name(unit_string); resolution_type.has_value()) + return Resolution { numeric_value, resolution_type.release_value() }; + + if (auto time_type = Time::unit_from_name(unit_string); time_type.has_value()) + return Time { numeric_value, time_type.release_value() }; } if (component_value.is(Token::Type::Percentage)) @@ -2222,10 +2234,18 @@ RefPtr Parser::parse_dimension_value(StyleComponentValueRule const& if (!dimension.has_value()) return {}; + if (dimension->is_angle()) + return AngleStyleValue::create(dimension->angle()); + if (dimension->is_frequency()) + return FrequencyStyleValue::create(dimension->frequency()); if (dimension->is_length()) return LengthStyleValue::create(dimension->length()); if (dimension->is_percentage()) return PercentageStyleValue::create(dimension->percentage()); + if (dimension->is_resolution()) + return ResolutionStyleValue::create(dimension->resolution()); + if (dimension->is_time()) + return TimeStyleValue::create(dimension->time()); VERIFY_NOT_REACHED(); } @@ -4535,6 +4555,54 @@ RefPtr Parser::parse_css_value(Badge, ParsingContext return result.release_value(); } +bool Parser::Dimension::is_angle() const +{ + return m_value.has(); +} + +Angle Parser::Dimension::angle() const +{ + return m_value.get(); +} + +bool Parser::Dimension::is_angle_percentage() const +{ + return is_angle() || is_percentage(); +} + +AnglePercentage Parser::Dimension::angle_percentage() const +{ + if (is_angle()) + return angle(); + if (is_percentage()) + return percentage(); + VERIFY_NOT_REACHED(); +} + +bool Parser::Dimension::is_frequency() const +{ + return m_value.has(); +} + +Frequency Parser::Dimension::frequency() const +{ + return m_value.get(); +} + +bool Parser::Dimension::is_frequency_percentage() const +{ + return is_frequency() || is_percentage(); +} + +FrequencyPercentage Parser::Dimension::frequency_percentage() const +{ + if (is_frequency()) + return frequency(); + if (is_percentage()) + return percentage(); + VERIFY_NOT_REACHED(); +} + bool Parser::Dimension::is_length() const { return m_value.has(); @@ -4545,6 +4613,20 @@ Length Parser::Dimension::length() const return m_value.get(); } +bool Parser::Dimension::is_length_percentage() const +{ + return is_length() || is_percentage(); +} + +LengthPercentage Parser::Dimension::length_percentage() const +{ + if (is_length()) + return length(); + if (is_percentage()) + return percentage(); + VERIFY_NOT_REACHED(); +} + bool Parser::Dimension::is_percentage() const { return m_value.has(); @@ -4555,15 +4637,35 @@ Percentage Parser::Dimension::percentage() const return m_value.get(); } -bool Parser::Dimension::is_length_percentage() const +bool Parser::Dimension::is_resolution() const { - return is_length() || is_percentage(); + return m_value.has(); } -LengthPercentage Parser::Dimension::length_percentage() const +Resolution Parser::Dimension::resolution() const { - if (is_length()) - return length(); + return m_value.get(); +} + +bool Parser::Dimension::is_time() const +{ + return m_value.has