diff options
author | Sam Atkins <atkinssj@serenityos.org> | 2023-03-30 10:50:40 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-03-30 21:29:50 +0200 |
commit | 62a8cf2bb8c595a9a4ebef930094cb3f570f45bf (patch) | |
tree | 3a9e6c09635ed3b97976794ecbe31eaa14634798 /Userland | |
parent | ac4350748eb05cd11dffc090a752bfc702366567 (diff) | |
download | serenity-62a8cf2bb8c595a9a4ebef930094cb3f570f45bf.zip |
LibWeb: Let CSS::Size contain a CalculatedStyleValue
Technically this was already true, but now we explicitly allow it
instead of that calc value being hidden inside a Length or Percentage.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/Size.cpp | 6 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/Size.h | 10 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/StyleProperties.cpp | 2 |
4 files changed, 19 insertions, 1 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp index 900384f994..4b5b149582 100644 --- a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp +++ b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp @@ -168,6 +168,8 @@ static NonnullRefPtr<StyleValue const> style_value_for_size(CSS::Size const& siz return LengthStyleValue::create(size.length()); if (size.is_auto()) return IdentifierStyleValue::create(ValueID::Auto); + if (size.is_calculated()) + return size.calculated(); if (size.is_min_content()) return IdentifierStyleValue::create(ValueID::MinContent); if (size.is_max_content()) diff --git a/Userland/Libraries/LibWeb/CSS/Size.cpp b/Userland/Libraries/LibWeb/CSS/Size.cpp index 9b6ea918eb..fa4e8f8fe9 100644 --- a/Userland/Libraries/LibWeb/CSS/Size.cpp +++ b/Userland/Libraries/LibWeb/CSS/Size.cpp @@ -41,6 +41,11 @@ Size Size::make_percentage(Percentage percentage) return Size { Type::Percentage, move(percentage) }; } +Size Size::make_calculated(NonnullRefPtr<Web::CSS::CalculatedStyleValue> calculated) +{ + return Size { Type::Calculated, move(calculated) }; +} + Size Size::make_min_content() { return Size { Type::MinContent, Length::make_auto() }; @@ -79,6 +84,7 @@ ErrorOr<String> Size::to_string() const switch (m_type) { case Type::Auto: return "auto"_string; + case Type::Calculated: case Type::Length: case Type::Percentage: return m_length_percentage.to_string(); diff --git a/Userland/Libraries/LibWeb/CSS/Size.h b/Userland/Libraries/LibWeb/CSS/Size.h index d8cad444a1..8e2a8ac952 100644 --- a/Userland/Libraries/LibWeb/CSS/Size.h +++ b/Userland/Libraries/LibWeb/CSS/Size.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2022, Andreas Kling <kling@serenityos.org> + * Copyright (c) 2023, Sam Atkins <atkinssj@serenityos.org> * * SPDX-License-Identifier: BSD-2-Clause */ @@ -15,6 +16,7 @@ class Size { public: enum class Type { Auto, + Calculated, Length, Percentage, MinContent, @@ -27,12 +29,14 @@ public: static Size make_px(CSSPixels); static Size make_length(Length); static Size make_percentage(Percentage); + static Size make_calculated(NonnullRefPtr<CalculatedStyleValue>); static Size make_min_content(); static Size make_max_content(); static Size make_fit_content(Length available_space); static Size make_none(); bool is_auto() const { return m_type == Type::Auto; } + bool is_calculated() const { return m_type == Type::Calculated; } bool is_length() const { return m_type == Type::Length; } bool is_percentage() const { return m_type == Type::Percentage; } bool is_min_content() const { return m_type == Type::MinContent; } @@ -45,6 +49,12 @@ public: bool contains_percentage() const; + CalculatedStyleValue const& calculated() const + { + VERIFY(is_calculated()); + return m_length_percentage.calculated(); + } + CSS::Length const& length() const { VERIFY(is_length()); diff --git a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp index ded4425ebb..eadfa46b1a 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp @@ -79,7 +79,7 @@ CSS::Size StyleProperties::size_value(CSS::PropertyID id) const } if (value->is_calculated()) - return CSS::Size::make_length(CSS::Length::make_calculated(const_cast<CalculatedStyleValue&>(value->as_calculated()))); + return CSS::Size::make_calculated(const_cast<CalculatedStyleValue&>(value->as_calculated())); if (value->is_percentage()) return CSS::Size::make_percentage(value->as_percentage().percentage()); |