mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-08 06:09:58 +00:00
LibWeb/CSS: Absolutize grid-related StyleValues
This commit is contained in:
parent
597fe8288c
commit
7de17dce9d
Notes:
github-actions[bot]
2025-11-19 23:47:02 +00:00
Author: https://github.com/AtkinsSJ
Commit: 7de17dce9d
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6857
Reviewed-by: https://github.com/tcl3 ✅
12 changed files with 161 additions and 26 deletions
|
|
@ -1,6 +1,7 @@
|
|||
/*
|
||||
* Copyright (c) 2022, Martin Falisse <mfalisse@outlook.com>
|
||||
* Copyright (c) 2025, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
|
||||
* Copyright (c) 2025, Sam Atkins <sam@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
|
@ -110,6 +111,41 @@ String GridSize::to_string(SerializationMode mode) const
|
|||
return m_value.visit([mode](auto const& it) { return it.to_string(mode); });
|
||||
}
|
||||
|
||||
GridSize GridSize::absolutized(ComputationContext const& context) const
|
||||
{
|
||||
auto absolutize_length_percentage = [&context](LengthPercentage const& length_percentage) -> Optional<LengthPercentage> {
|
||||
if (length_percentage.is_length()) {
|
||||
auto length = length_percentage.length().absolutize(context.length_resolution_context.viewport_rect, context.length_resolution_context.font_metrics, context.length_resolution_context.root_font_metrics);
|
||||
if (length.has_value())
|
||||
return length.release_value();
|
||||
return {};
|
||||
}
|
||||
|
||||
if (length_percentage.is_calculated())
|
||||
return LengthPercentage::from_style_value(length_percentage.calculated()->absolutized(context));
|
||||
|
||||
return {};
|
||||
};
|
||||
return m_value.visit(
|
||||
[&](Size const& size) -> GridSize {
|
||||
if (size.is_length_percentage()) {
|
||||
if (auto result = absolutize_length_percentage(size.length_percentage()); result.has_value())
|
||||
return Size::make_length_percentage(result.release_value());
|
||||
}
|
||||
|
||||
if (size.is_fit_content() && size.fit_content_available_space().has_value()) {
|
||||
if (auto result = absolutize_length_percentage(size.fit_content_available_space().value()); result.has_value()) {
|
||||
return Size::make_fit_content(result.release_value());
|
||||
}
|
||||
}
|
||||
|
||||
return GridSize { size };
|
||||
},
|
||||
[](Flex const& flex) {
|
||||
return GridSize { flex };
|
||||
});
|
||||
}
|
||||
|
||||
GridMinMax::GridMinMax(GridSize min_grid_size, GridSize max_grid_size)
|
||||
: m_min_grid_size(move(min_grid_size))
|
||||
, m_max_grid_size(move(max_grid_size))
|
||||
|
|
@ -127,6 +163,14 @@ String GridMinMax::to_string(SerializationMode mode) const
|
|||
return MUST(builder.to_string());
|
||||
}
|
||||
|
||||
GridMinMax GridMinMax::absolutized(ComputationContext const& context) const
|
||||
{
|
||||
return GridMinMax {
|
||||
m_min_grid_size.absolutized(context),
|
||||
m_max_grid_size.absolutized(context),
|
||||
};
|
||||
}
|
||||
|
||||
GridRepeat::GridRepeat(GridRepeatType grid_repeat_type, GridTrackSizeList&& grid_track_size_list, size_t repeat_count)
|
||||
: m_type(grid_repeat_type)
|
||||
, m_grid_track_size_list(move(grid_track_size_list))
|
||||
|
|
@ -162,6 +206,15 @@ String GridRepeat::to_string(SerializationMode mode) const
|
|||
return MUST(builder.to_string());
|
||||
}
|
||||
|
||||
GridRepeat GridRepeat::absolutized(ComputationContext const& context) const
|
||||
{
|
||||
return GridRepeat {
|
||||
m_type,
|
||||
m_grid_track_size_list.absolutized(context),
|
||||
m_repeat_count,
|
||||
};
|
||||
}
|
||||
|
||||
ExplicitGridTrack::ExplicitGridTrack(Variant<GridRepeat, GridMinMax, GridSize>&& value)
|
||||
: m_value(move(value))
|
||||
{
|
||||
|
|
@ -174,6 +227,13 @@ String ExplicitGridTrack::to_string(SerializationMode mode) const
|
|||
});
|
||||
}
|
||||
|
||||
ExplicitGridTrack ExplicitGridTrack::absolutized(ComputationContext const& context) const
|
||||
{
|
||||
return m_value.visit([&](auto const& it) {
|
||||
return ExplicitGridTrack { it.absolutized(context) };
|
||||
});
|
||||
}
|
||||
|
||||
String GridLineNames::to_string() const
|
||||
{
|
||||
StringBuilder builder;
|
||||
|
|
@ -239,4 +299,19 @@ void GridTrackSizeList::append(ExplicitGridTrack&& explicit_track)
|
|||
m_list.append(move(explicit_track));
|
||||
}
|
||||
|
||||
GridTrackSizeList GridTrackSizeList::absolutized(ComputationContext const& context) const
|
||||
{
|
||||
GridTrackSizeList result;
|
||||
for (auto const& item : m_list) {
|
||||
item.visit(
|
||||
[&result, &context](ExplicitGridTrack const& track) {
|
||||
result.append(track.absolutized(context));
|
||||
},
|
||||
[&result](GridLineNames names) {
|
||||
result.append(move(names));
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue