Prechádzať zdrojové kódy

LibWeb: Ensure PercentageOr<T>::resolved() returns a concrete T

Which is to say, a T where `is_calculated()` is false.

As is becoming a repeating theme with CSS types, we have two states for
a FooPercentage that is a `calc()` expression: Either the FooPercentage
holds the CalculatedStyleValue directly, or it holds a Foo which itself
holds the CalculatedStyleValue. The first case was already handled to
return Foo, and with this patch, the second is too. :^)
Sam Atkins 3 rokov pred
rodič
commit
7b4004d682

+ 6 - 0
Userland/Libraries/LibWeb/CSS/Angle.cpp

@@ -96,4 +96,10 @@ Optional<Angle::Type> Angle::unit_from_name(StringView name)
     return {};
 }
 
+NonnullRefPtr<CalculatedStyleValue> Angle::calculated_style_value() const
+{
+    VERIFY(!m_calculated_style.is_null());
+    return *m_calculated_style;
+}
+
 }

+ 1 - 0
Userland/Libraries/LibWeb/CSS/Angle.h

@@ -31,6 +31,7 @@ public:
     Angle percentage_of(Percentage const&) const;
 
     bool is_calculated() const { return m_type == Type::Calculated; }
+    NonnullRefPtr<CalculatedStyleValue> calculated_style_value() const;
 
     String to_string() const;
     float to_degrees() const;

+ 6 - 0
Userland/Libraries/LibWeb/CSS/Frequency.cpp

@@ -83,4 +83,10 @@ Optional<Frequency::Type> Frequency::unit_from_name(StringView name)
     return {};
 }
 
+NonnullRefPtr<CalculatedStyleValue> Frequency::calculated_style_value() const
+{
+    VERIFY(!m_calculated_style.is_null());
+    return *m_calculated_style;
+}
+
 }

+ 1 - 0
Userland/Libraries/LibWeb/CSS/Frequency.h

@@ -28,6 +28,7 @@ public:
     Frequency percentage_of(Percentage const&) const;
 
     bool is_calculated() const { return m_type == Type::Calculated; }
+    NonnullRefPtr<CalculatedStyleValue> calculated_style_value() const;
 
     String to_string() const;
     float to_hertz() const;

+ 6 - 0
Userland/Libraries/LibWeb/CSS/Length.cpp

@@ -198,4 +198,10 @@ Optional<Length::Type> Length::unit_from_name(StringView name)
     return {};
 }
 
+NonnullRefPtr<CalculatedStyleValue> Length::calculated_style_value() const
+{
+    VERIFY(!m_calculated_style.is_null());
+    return *m_calculated_style;
+}
+
 }

+ 1 - 0
Userland/Libraries/LibWeb/CSS/Length.h

@@ -76,6 +76,7 @@ public:
     }
 
     float raw_value() const { return m_value; }
+    NonnullRefPtr<CalculatedStyleValue> calculated_style_value() const;
 
     float to_px(Layout::Node const&) const;
 

+ 2 - 0
Userland/Libraries/LibWeb/CSS/Percentage.h

@@ -98,6 +98,8 @@ public:
     {
         return m_value.visit(
             [&](T const& t) {
+                if (t.is_calculated())
+                    return resolve_calculated(t.calculated_style_value(), layout_node, reference_value);
                 return t;
             },
             [&](Percentage const& percentage) {

+ 6 - 0
Userland/Libraries/LibWeb/CSS/Time.cpp

@@ -83,4 +83,10 @@ Optional<Time::Type> Time::unit_from_name(StringView name)
     return {};
 }
 
+NonnullRefPtr<CalculatedStyleValue> Time::calculated_style_value() const
+{
+    VERIFY(!m_calculated_style.is_null());
+    return *m_calculated_style;
+}
+
 }

+ 1 - 0
Userland/Libraries/LibWeb/CSS/Time.h

@@ -29,6 +29,7 @@ public:
     Time percentage_of(Percentage const&) const;
 
     bool is_calculated() const { return m_type == Type::Calculated; }
+    NonnullRefPtr<CalculatedStyleValue> calculated_style_value() const;
 
     String to_string() const;
     float to_seconds() const;