mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 01:18:12 +00:00
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.
This commit is contained in:
parent
ac4350748e
commit
62a8cf2bb8
4 changed files with 19 additions and 1 deletions
|
@ -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())
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue