mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 05:37:43 +00:00
LibWeb: Use Optional instead of undefined-lengths for widths/heights
This commit is contained in:
parent
699b48ccc8
commit
5b2482a939
10 changed files with 126 additions and 92 deletions
|
@ -17,17 +17,19 @@
|
|||
|
||||
namespace Web::Layout {
|
||||
|
||||
static float get_pixel_size(Box const& box, CSS::LengthPercentage const& length_percentage)
|
||||
static float get_pixel_size(Box const& box, Optional<CSS::LengthPercentage> const& length_percentage)
|
||||
{
|
||||
if (!length_percentage.has_value())
|
||||
return 0;
|
||||
auto inner_main_size = CSS::Length::make_px(box.containing_block()->content_width());
|
||||
return length_percentage.resolved(box, inner_main_size)
|
||||
.resolved(CSS::Length::make_px(0), box)
|
||||
.to_px(box);
|
||||
return length_percentage->resolved(box, inner_main_size).resolved(CSS::Length::make_px(0), box).to_px(box);
|
||||
}
|
||||
|
||||
static bool is_undefined_or_auto(CSS::LengthPercentage const& length_percentage)
|
||||
static bool is_undefined_or_auto(Optional<CSS::LengthPercentage> const& length_percentage)
|
||||
{
|
||||
return length_percentage.is_length() && length_percentage.length().is_undefined_or_auto();
|
||||
if (!length_percentage.has_value())
|
||||
return true;
|
||||
return length_percentage->is_length() && length_percentage->length().is_undefined_or_auto();
|
||||
}
|
||||
|
||||
FlexFormattingContext::FlexFormattingContext(Box& flex_container, FormattingContext* parent)
|
||||
|
@ -143,16 +145,27 @@ void FlexFormattingContext::generate_anonymous_flex_items()
|
|||
flex_container().set_content_width(flex_container().containing_block()->content_width());
|
||||
} else {
|
||||
auto container_width = flex_container().containing_block()->content_width();
|
||||
auto width = flex_container().computed_values().width().resolved(flex_container(), CSS::Length::make_px(container_width)).resolved_or_zero(flex_container()).to_px(flex_container());
|
||||
flex_container().set_content_width(width);
|
||||
|
||||
auto& maybe_width = flex_container().computed_values().width();
|
||||
if (maybe_width.has_value()) {
|
||||
auto width = maybe_width->resolved(flex_container(), CSS::Length::make_px(container_width)).resolved_or_zero(flex_container()).to_px(flex_container());
|
||||
flex_container().set_content_width(width);
|
||||
} else {
|
||||
flex_container().set_content_width(0);
|
||||
}
|
||||
}
|
||||
|
||||
if (!flex_container().has_definite_height()) {
|
||||
flex_container().set_content_height(flex_container().containing_block()->content_height());
|
||||
} else {
|
||||
auto container_height = flex_container().containing_block()->content_height();
|
||||
auto height = flex_container().computed_values().height().resolved(flex_container(), CSS::Length::make_px(container_height)).resolved_or_zero(flex_container()).to_px(flex_container());
|
||||
flex_container().set_content_height(height);
|
||||
auto& maybe_height = flex_container().computed_values().height();
|
||||
if (maybe_height.has_value()) {
|
||||
auto height = maybe_height->resolved(flex_container(), CSS::Length::make_px(container_height)).resolved_or_zero(flex_container()).to_px(flex_container());
|
||||
flex_container().set_content_height(height);
|
||||
} else {
|
||||
flex_container().set_content_height(0);
|
||||
}
|
||||
}
|
||||
|
||||
flex_container().for_each_child_of_type<Box>([&](Box& child_box) {
|
||||
|
@ -219,8 +232,11 @@ bool FlexFormattingContext::cross_size_is_absolute_or_resolved_nicely(NodeWithSt
|
|||
{
|
||||
auto length_percentage = is_row_layout() ? box.computed_values().height() : box.computed_values().width();
|
||||
|
||||
if (length_percentage.is_length()) {
|
||||
auto& length = length_percentage.length();
|
||||
if (!length_percentage.has_value())
|
||||
return false;
|
||||
|
||||
if (length_percentage->is_length()) {
|
||||
auto& length = length_percentage->length();
|
||||
if (length.is_absolute() || length.is_relative())
|
||||
return true;
|
||||
if (length.is_undefined_or_auto())
|
||||
|
@ -229,7 +245,7 @@ bool FlexFormattingContext::cross_size_is_absolute_or_resolved_nicely(NodeWithSt
|
|||
|
||||
if (!box.parent())
|
||||
return false;
|
||||
if (length_percentage.is_percentage() && cross_size_is_absolute_or_resolved_nicely(*box.parent()))
|
||||
if (length_percentage->is_percentage() && cross_size_is_absolute_or_resolved_nicely(*box.parent()))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
@ -237,8 +253,10 @@ bool FlexFormattingContext::cross_size_is_absolute_or_resolved_nicely(NodeWithSt
|
|||
float FlexFormattingContext::specified_main_size_of_child_box(Box const& child_box) const
|
||||
{
|
||||
auto main_size_of_parent = specified_main_size(flex_container());
|
||||
auto value = is_row_layout() ? child_box.computed_values().width() : child_box.computed_values().height();
|
||||
return value.resolved(child_box, CSS::Length::make_px(main_size_of_parent)).resolved_or_zero(child_box).to_px(child_box);
|
||||
auto& value = is_row_layout() ? child_box.computed_values().width() : child_box.computed_values().height();
|
||||
if (!value.has_value())
|
||||
return 0;
|
||||
return value->resolved(child_box, CSS::Length::make_px(main_size_of_parent)).resolved_or_zero(child_box).to_px(child_box);
|
||||
}
|
||||
|
||||
float FlexFormattingContext::specified_main_min_size(Box const& box) const
|
||||
|
@ -290,9 +308,8 @@ float FlexFormattingContext::calculated_main_size(Box const& box) const
|
|||
|
||||
bool FlexFormattingContext::is_cross_auto(Box const& box) const
|
||||
{
|
||||
if (is_row_layout())
|
||||
return box.computed_values().height().is_length() && box.computed_values().height().length().is_auto();
|
||||
return box.computed_values().width().is_length() && box.computed_values().width().length().is_auto();
|
||||
auto& cross_length = is_row_layout() ? box.computed_values().height() : box.computed_values().width();
|
||||
return cross_length.has_value() && cross_length->length().is_auto();
|
||||
}
|
||||
|
||||
bool FlexFormattingContext::is_main_axis_margin_first_auto(Box const& box) const
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue