diff options
author | Sam Atkins <atkinssj@serenityos.org> | 2022-02-21 17:35:52 +0000 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-02-24 08:04:25 +0100 |
commit | a07fed4e5301b83e01aa304778b3cb105fdac450 (patch) | |
tree | bd25632fc1cc21b9609467636d18d6ac5a10dd4c /Userland/Libraries | |
parent | 64f112c4ea1b54274b8c80cd7e44cc7103fb02d4 (diff) | |
download | serenity-a07fed4e5301b83e01aa304778b3cb105fdac450.zip |
LibWeb: Account for `Calculated` in Length methods
We were ignoring this in a couple of places.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/Length.cpp | 11 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/Length.h | 9 |
2 files changed, 14 insertions, 6 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/Length.cpp b/Userland/Libraries/LibWeb/CSS/Length.cpp index 18b07935ea..badb21bbd8 100644 --- a/Userland/Libraries/LibWeb/CSS/Length.cpp +++ b/Userland/Libraries/LibWeb/CSS/Length.cpp @@ -48,6 +48,8 @@ Length Length::make_calculated(NonnullRefPtr<CalculatedStyleValue> calculated_st Length Length::percentage_of(Percentage const& percentage) const { + VERIFY(!is_calculated()); + if (is_auto()) { dbgln("Attempting to get percentage of an auto length, this seems wrong? But for now we just return the original length."); return *this; @@ -104,6 +106,15 @@ float Length::to_px(Layout::Node const& layout_node) const return to_px(viewport_rect, layout_node.font().metrics('M'), layout_node.computed_values().font_size(), root_element->layout_node()->computed_values().font_size()); } +String Length::to_string() const +{ + if (is_calculated()) + return m_calculated_style->to_string(); + if (is_auto()) + return "auto"; + return String::formatted("{}{}", m_value, unit_name()); +} + const char* Length::unit_name() const { switch (m_type) { diff --git a/Userland/Libraries/LibWeb/CSS/Length.h b/Userland/Libraries/LibWeb/CSS/Length.h index d0e48bcca8..4b979eba82 100644 --- a/Userland/Libraries/LibWeb/CSS/Length.h +++ b/Userland/Libraries/LibWeb/CSS/Length.h @@ -112,15 +112,12 @@ public: } } - String to_string() const - { - if (is_auto()) - return "auto"; - return String::formatted("{}{}", m_value, unit_name()); - } + String to_string() const; bool operator==(const Length& other) const { + if (is_calculated()) + return m_calculated_style == other.m_calculated_style; return m_type == other.m_type && m_value == other.m_value; } |