Преглед на файлове

LibWeb: Allow percentage tokens again when parsing calc()

I unintentionally broke this in my LengthPercentage PR, but it was not
convenient to fix until now.
Sam Atkins преди 3 години
родител
ревизия
b54cd17c1e
променени са 3 файла, в които са добавени 15 реда и са изтрити 5 реда
  1. 10 4
      Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
  2. 4 0
      Userland/Libraries/LibWeb/CSS/StyleValue.cpp
  3. 1 1
      Userland/Libraries/LibWeb/CSS/StyleValue.h

+ 10 - 4
Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp

@@ -4210,10 +4210,16 @@ Optional<CalculatedStyleValue::CalcValue> Parser::parse_calc_value(TokenStream<S
         return CalculatedStyleValue::CalcValue { static_cast<float>(current_token.token().number_value()) };
 
     if (current_token.is(Token::Type::Dimension) || current_token.is(Token::Type::Percentage)) {
-        auto maybe_length = parse_length(current_token);
-        if (maybe_length.has_value() && !maybe_length.value().is_undefined())
-            return CalculatedStyleValue::CalcValue { maybe_length.value() };
-        return {};
+        auto maybe_dimension = parse_dimension(current_token);
+        if (!maybe_dimension.has_value())
+            return {};
+        auto& dimension = maybe_dimension.value();
+
+        if (dimension.is_length())
+            return CalculatedStyleValue::CalcValue { dimension.length() };
+        if (dimension.is_percentage())
+            return CalculatedStyleValue::CalcValue { dimension.percentage() };
+        VERIFY_NOT_REACHED();
     }
 
     return {};

+ 4 - 0
Userland/Libraries/LibWeb/CSS/StyleValue.cpp

@@ -574,6 +574,7 @@ Optional<CalculatedStyleValue::ResolvedType> CalculatedStyleValue::CalcValue::re
     return value.visit(
         [](float) -> Optional<CalculatedStyleValue::ResolvedType> { return { ResolvedType::Number }; },
         [](Length const&) -> Optional<CalculatedStyleValue::ResolvedType> { return { ResolvedType::Length }; },
+        [](Percentage const&) -> Optional<CalculatedStyleValue::ResolvedType> { return { ResolvedType::Percentage }; },
         [](NonnullOwnPtr<CalcSum> const& sum) { return sum->resolved_type(); });
 }
 
@@ -604,6 +605,9 @@ CalculatedStyleValue::CalculationResult CalculatedStyleValue::CalcValue::resolve
         [&](Length const& length) -> CalculatedStyleValue::CalculationResult {
             return CalculatedStyleValue::CalculationResult { length };
         },
+        [&](Percentage const& percentage) -> CalculatedStyleValue::CalculationResult {
+            return CalculatedStyleValue::CalculationResult { percentage };
+        },
         [&](NonnullOwnPtr<CalcSum> const& sum) -> CalculatedStyleValue::CalculationResult {
             return sum->resolve(layout_node, percentage_basis);
         });

+ 1 - 1
Userland/Libraries/LibWeb/CSS/StyleValue.h

@@ -707,7 +707,7 @@ public:
     };
 
     struct CalcValue {
-        Variant<float, CSS::Length, NonnullOwnPtr<CalcSum>> value;
+        Variant<float, Length, Percentage, NonnullOwnPtr<CalcSum>> value;
         Optional<ResolvedType> resolved_type() const;
         CalculationResult resolve(Layout::Node const*, Length const& percentage_basis) const;
     };