mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-21 16:58:58 +00:00
LibWeb/CSS: Use Optional instead of auto lengths in Size
Any type of Size which has no LengthPercentage value now uses an empty optional instead of making an auto Length as before. We also now serialize a `fit-content` Size as `fit-content` instead of `fit-content(auto)`, though this doesn't affect test results and I didn't identify where it's actually used.
This commit is contained in:
parent
d10eaa996e
commit
60fc23e916
Notes:
github-actions[bot]
2025-09-04 12:33:22 +00:00
Author: https://github.com/AtkinsSJ
Commit: 60fc23e916
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6043
3 changed files with 28 additions and 22 deletions
|
@ -346,8 +346,11 @@ static NonnullRefPtr<StyleValue const> style_value_for_size(Size const& size)
|
|||
return KeywordStyleValue::create(Keyword::MinContent);
|
||||
if (size.is_max_content())
|
||||
return KeywordStyleValue::create(Keyword::MaxContent);
|
||||
if (size.is_fit_content())
|
||||
return FitContentStyleValue::create(size.fit_content_available_space());
|
||||
if (size.is_fit_content()) {
|
||||
if (auto available_space = size.fit_content_available_space(); available_space.has_value())
|
||||
return FitContentStyleValue::create(available_space.release_value());
|
||||
return FitContentStyleValue::create();
|
||||
}
|
||||
TODO();
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
namespace Web::CSS {
|
||||
|
||||
Size::Size(Type type, LengthPercentage length_percentage)
|
||||
Size::Size(Type type, Optional<LengthPercentage> length_percentage)
|
||||
: m_type(type)
|
||||
, m_length_percentage(move(length_percentage))
|
||||
{
|
||||
|
@ -16,17 +16,19 @@ Size::Size(Type type, LengthPercentage length_percentage)
|
|||
|
||||
CSSPixels Size::to_px(Layout::Node const& node, CSSPixels reference_value) const
|
||||
{
|
||||
return m_length_percentage.resolved(node, reference_value).to_px(node);
|
||||
if (!m_length_percentage.has_value())
|
||||
return 0;
|
||||
return m_length_percentage->resolved(node, reference_value).to_px(node);
|
||||
}
|
||||
|
||||
Size Size::make_auto()
|
||||
{
|
||||
return Size { Type::Auto, Length::make_auto() };
|
||||
return Size { Type::Auto };
|
||||
}
|
||||
|
||||
Size Size::make_px(CSSPixels px)
|
||||
{
|
||||
return make_length(CSS::Length::make_px(px));
|
||||
return make_length(Length::make_px(px));
|
||||
}
|
||||
|
||||
Size Size::make_length(Length length)
|
||||
|
@ -58,12 +60,12 @@ Size Size::make_length_percentage(LengthPercentage const& length_percentage)
|
|||
|
||||
Size Size::make_min_content()
|
||||
{
|
||||
return Size { Type::MinContent, Length::make_auto() };
|
||||
return Size { Type::MinContent };
|
||||
}
|
||||
|
||||
Size Size::make_max_content()
|
||||
{
|
||||
return Size { Type::MaxContent, Length::make_auto() };
|
||||
return Size { Type::MaxContent };
|
||||
}
|
||||
|
||||
Size Size::make_fit_content(LengthPercentage available_space)
|
||||
|
@ -73,13 +75,12 @@ Size Size::make_fit_content(LengthPercentage available_space)
|
|||
|
||||
Size Size::make_fit_content()
|
||||
{
|
||||
// NOTE: We use "auto" as a stand-in for "stretch" here.
|
||||
return Size { Type::FitContent, Length::make_auto() };
|
||||
return Size { Type::FitContent };
|
||||
}
|
||||
|
||||
Size Size::make_none()
|
||||
{
|
||||
return Size { Type::None, Length::make_auto() };
|
||||
return Size { Type::None };
|
||||
}
|
||||
|
||||
bool Size::contains_percentage() const
|
||||
|
@ -95,7 +96,7 @@ bool Size::contains_percentage() const
|
|||
// but we have to update a lot of code to handle this.
|
||||
return false;
|
||||
default:
|
||||
return m_length_percentage.contains_percentage();
|
||||
return m_length_percentage->contains_percentage();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -107,13 +108,15 @@ String Size::to_string(SerializationMode mode) const
|
|||
case Type::Calculated:
|
||||
case Type::Length:
|
||||
case Type::Percentage:
|
||||
return m_length_percentage.to_string(mode);
|
||||
return m_length_percentage->to_string(mode);
|
||||
case Type::MinContent:
|
||||
return "min-content"_string;
|
||||
case Type::MaxContent:
|
||||
return "max-content"_string;
|
||||
case Type::FitContent:
|
||||
return MUST(String::formatted("fit-content({})", m_length_percentage.to_string(mode)));
|
||||
if (!m_length_percentage.has_value())
|
||||
return "fit-content"_string;
|
||||
return MUST(String::formatted("fit-content({})", m_length_percentage->to_string(mode)));
|
||||
case Type::None:
|
||||
return "none"_string;
|
||||
}
|
||||
|
|
|
@ -55,22 +55,22 @@ public:
|
|||
CalculatedStyleValue const& calculated() const
|
||||
{
|
||||
VERIFY(is_calculated());
|
||||
return m_length_percentage.calculated();
|
||||
return m_length_percentage->calculated();
|
||||
}
|
||||
|
||||
CSS::Length const& length() const
|
||||
Length const& length() const
|
||||
{
|
||||
VERIFY(is_length());
|
||||
return m_length_percentage.length();
|
||||
return m_length_percentage->length();
|
||||
}
|
||||
|
||||
CSS::Percentage const& percentage() const
|
||||
Percentage const& percentage() const
|
||||
{
|
||||
VERIFY(is_percentage());
|
||||
return m_length_percentage.percentage();
|
||||
return m_length_percentage->percentage();
|
||||
}
|
||||
|
||||
CSS::LengthPercentage const& fit_content_available_space() const
|
||||
Optional<LengthPercentage> const& fit_content_available_space() const
|
||||
{
|
||||
VERIFY(is_fit_content());
|
||||
return m_length_percentage;
|
||||
|
@ -80,10 +80,10 @@ public:
|
|||
bool operator==(Size const&) const = default;
|
||||
|
||||
private:
|
||||
Size(Type type, LengthPercentage);
|
||||
explicit Size(Type type, Optional<LengthPercentage> = {});
|
||||
|
||||
Type m_type {};
|
||||
CSS::LengthPercentage m_length_percentage;
|
||||
Optional<LengthPercentage> m_length_percentage;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue