1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 18:58:12 +00:00

LibWeb: Remove fallback value from Length::resolved()

Nobody makes undefined Lengths now, (although actually removing
Undefined will come in a later commit) so we can remove this parameter,
and `resolved_or_auto()`/`resolved_or_zero()`.
This commit is contained in:
Sam Atkins 2022-02-18 16:17:27 +00:00 committed by Andreas Kling
parent 5b2482a939
commit 67066c5140
11 changed files with 106 additions and 120 deletions

View file

@ -67,7 +67,7 @@ void BlockFormattingContext::apply_transformations_to_children(Box& box)
continue;
transformation.values.first().visit(
[&](CSS::Length& value) {
transform_y_offset += value.resolved_or_zero(child_box).to_px(child_box);
transform_y_offset += value.resolved(child_box).to_px(child_box);
},
[&](float value) {
transform_y_offset += value;
@ -115,13 +115,13 @@ void BlockFormattingContext::compute_width(Box& box)
auto margin_left = CSS::Length::make_auto();
auto margin_right = CSS::Length::make_auto();
const auto padding_left = computed_values.padding().left.resolved(box, width_of_containing_block_as_length).resolved_or_zero(box);
const auto padding_right = computed_values.padding().right.resolved(box, width_of_containing_block_as_length).resolved_or_zero(box);
const auto padding_left = computed_values.padding().left.resolved(box, width_of_containing_block_as_length).resolved(box);
const auto padding_right = computed_values.padding().right.resolved(box, width_of_containing_block_as_length).resolved(box);
auto try_compute_width = [&](const auto& a_width) {
CSS::Length width = a_width;
margin_left = computed_values.margin().left.resolved(box, width_of_containing_block_as_length).resolved_or_zero(box);
margin_right = computed_values.margin().right.resolved(box, width_of_containing_block_as_length).resolved_or_zero(box);
margin_left = computed_values.margin().left.resolved(box, width_of_containing_block_as_length).resolved(box);
margin_right = computed_values.margin().right.resolved(box, width_of_containing_block_as_length).resolved(box);
float total_px = computed_values.border_left().width + computed_values.border_right().width;
for (auto& value : { margin_left, padding_left, width, padding_right, margin_right }) {
@ -195,14 +195,14 @@ void BlockFormattingContext::compute_width(Box& box)
return width;
};
auto specified_width = computed_values.width().has_value() ? computed_values.width()->resolved(box, width_of_containing_block_as_length).resolved_or_auto(box) : CSS::Length::make_auto();
auto specified_width = computed_values.width().has_value() ? computed_values.width()->resolved(box, width_of_containing_block_as_length).resolved(box) : CSS::Length::make_auto();
// 1. The tentative used width is calculated (without 'min-width' and 'max-width')
auto used_width = try_compute_width(specified_width);
// 2. The tentative used width is greater than 'max-width', the rules above are applied again,
// but this time using the computed value of 'max-width' as the computed value for 'width'.
auto specified_max_width = computed_values.max_width().has_value() ? computed_values.max_width()->resolved(box, width_of_containing_block_as_length).resolved_or_auto(box) : CSS::Length::make_auto();
auto specified_max_width = computed_values.max_width().has_value() ? computed_values.max_width()->resolved(box, width_of_containing_block_as_length).resolved(box) : CSS::Length::make_auto();
if (!specified_max_width.is_auto()) {
if (used_width.to_px(box) > specified_max_width.to_px(box)) {
used_width = try_compute_width(specified_max_width);
@ -211,7 +211,7 @@ void BlockFormattingContext::compute_width(Box& box)
// 3. If the resulting width is smaller than 'min-width', the rules above are applied again,
// but this time using the value of 'min-width' as the computed value for 'width'.
auto specified_min_width = computed_values.min_width().has_value() ? computed_values.min_width()->resolved(box, width_of_containing_block_as_length).resolved_or_auto(box) : CSS::Length::make_auto();
auto specified_min_width = computed_values.min_width().has_value() ? computed_values.min_width()->resolved(box, width_of_containing_block_as_length).resolved(box) : CSS::Length::make_auto();
if (!specified_min_width.is_auto()) {
if (used_width.to_px(box) < specified_min_width.to_px(box)) {
used_width = try_compute_width(specified_min_width);
@ -235,10 +235,10 @@ void BlockFormattingContext::compute_width_for_floating_box(Box& box)
auto width_of_containing_block_as_length = CSS::Length::make_px(width_of_containing_block);
auto zero_value = CSS::Length::make_px(0);
auto margin_left = computed_values.margin().left.resolved(box, width_of_containing_block_as_length).resolved_or_zero(box);
auto margin_right = computed_values.margin().right.resolved(box, width_of_containing_block_as_length).resolved_or_zero(box);
const auto padding_left = computed_values.padding().left.resolved(box, width_of_containing_block_as_length).resolved_or_zero(box);
const auto padding_right = computed_values.padding().right.resolved(box, width_of_containing_block_as_length).resolved_or_zero(box);
auto margin_left = computed_values.margin().left.resolved(box, width_of_containing_block_as_length).resolved(box);
auto margin_right = computed_values.margin().right.resolved(box, width_of_containing_block_as_length).resolved(box);
const auto padding_left = computed_values.padding().left.resolved(box, width_of_containing_block_as_length).resolved(box);
const auto padding_right = computed_values.padding().right.resolved(box, width_of_containing_block_as_length).resolved(box);
// If 'margin-left', or 'margin-right' are computed as 'auto', their used value is '0'.
if (margin_left.is_auto())
@ -246,7 +246,7 @@ void BlockFormattingContext::compute_width_for_floating_box(Box& box)
if (margin_right.is_auto())
margin_right = zero_value;
auto width = computed_values.width().has_value() ? computed_values.width()->resolved(box, width_of_containing_block_as_length).resolved_or_auto(box) : CSS::Length::make_auto();
auto width = computed_values.width().has_value() ? computed_values.width()->resolved(box, width_of_containing_block_as_length).resolved(box) : CSS::Length::make_auto();
// If 'width' is computed as 'auto', the used value is the "shrink-to-fit" width.
if (width.is_auto()) {
@ -264,7 +264,7 @@ void BlockFormattingContext::compute_width_for_floating_box(Box& box)
width = CSS::Length(min(max(result.preferred_minimum_width, available_width), result.preferred_width), CSS::Length::Type::Px);
}
float final_width = width.resolved_or_zero(box).to_px(box);
float final_width = width.resolved(box).to_px(box);
box.set_content_width(final_width);
box.box_model().margin.left = margin_left.to_px(box);
box.box_model().margin.right = margin_right.to_px(box);
@ -299,15 +299,15 @@ float BlockFormattingContext::compute_theoretical_height(Box const& box)
|| (computed_values.height().has_value() && computed_values.height()->is_percentage() && !is_absolute(containing_block.computed_values().height()))) {
height = compute_auto_height_for_block_level_element(box, ConsiderFloats::No);
} else {
height = computed_values.height().has_value() ? computed_values.height()->resolved(box, containing_block_height).resolved_or_auto(box).to_px(box) : 0;
height = computed_values.height().has_value() ? computed_values.height()->resolved(box, containing_block_height).resolved(box).to_px(box) : 0;
}
}
auto specified_max_height = computed_values.max_height().has_value() ? computed_values.max_height()->resolved(box, containing_block_height).resolved_or_auto(box) : CSS::Length::make_auto();
auto specified_max_height = computed_values.max_height().has_value() ? computed_values.max_height()->resolved(box, containing_block_height).resolved(box) : CSS::Length::make_auto();
if (!specified_max_height.is_auto()
&& !(computed_values.max_height().has_value() && computed_values.max_height()->is_percentage() && !is_absolute(containing_block.computed_values().height())))
height = min(height, specified_max_height.to_px(box));
auto specified_min_height = computed_values.min_height().has_value() ? computed_values.min_height()->resolved(box, containing_block_height).resolved_or_auto(box) : CSS::Length::make_auto();
auto specified_min_height = computed_values.min_height().has_value() ? computed_values.min_height()->resolved(box, containing_block_height).resolved(box) : CSS::Length::make_auto();
if (!specified_min_height.is_auto()
&& !(computed_values.min_height().has_value() && computed_values.min_height()->is_percentage() && !is_absolute(containing_block.computed_values().height())))
height = max(height, specified_min_height.to_px(box));
@ -323,13 +323,13 @@ void BlockFormattingContext::compute_height(Box& box)
// First, resolve the top/bottom parts of the surrounding box model.
// FIXME: While negative values are generally allowed for margins, for now just ignore those for height calculation
box.box_model().margin.top = max(computed_values.margin().top.resolved(box, width_of_containing_block_as_length).resolved_or_zero(box).to_px(box), 0);
box.box_model().margin.bottom = max(computed_values.margin().bottom.resolved(box, width_of_containing_block_as_length).resolved_or_zero(box).to_px(box), 0);
box.box_model().margin.top = max(computed_values.margin().top.resolved(box, width_of_containing_block_as_length).resolved(box).to_px(box), 0);
box.box_model().margin.bottom = max(computed_values.margin().bottom.resolved(box, width_of_containing_block_as_length).resolved(box).to_px(box), 0);
box.box_model().border.top = computed_values.border_top().width;
box.box_model().border.bottom = computed_values.border_bottom().width;
box.box_model().padding.top = computed_values.padding().top.resolved(box, width_of_containing_block_as_length).resolved_or_zero(box).to_px(box);
box.box_model().padding.bottom = computed_values.padding().bottom.resolved(box, width_of_containing_block_as_length).resolved_or_zero(box).to_px(box);
box.box_model().padding.top = computed_values.padding().top.resolved(box, width_of_containing_block_as_length).resolved(box).to_px(box);
box.box_model().padding.bottom = computed_values.padding().bottom.resolved(box, width_of_containing_block_as_length).resolved(box).to_px(box);
auto height = compute_theoretical_height(box);
box.set_content_height(height);
@ -345,8 +345,8 @@ void BlockFormattingContext::compute_position(Box& box)
float width_of_containing_block = box.containing_block()->content_width();
auto width_of_containing_block_as_length = CSS::Length::make_px(width_of_containing_block);
auto specified_left = computed_values.offset().left.resolved(box, width_of_containing_block_as_length).resolved_or_zero(box);
auto specified_right = computed_values.offset().right.resolved(box, width_of_containing_block_as_length).resolved_or_zero(box);
auto specified_left = computed_values.offset().left.resolved(box, width_of_containing_block_as_length).resolved(box);
auto specified_right = computed_values.offset().right.resolved(box, width_of_containing_block_as_length).resolved(box);
if (specified_left.is_auto() && specified_right.is_auto()) {
// If both 'left' and 'right' are 'auto' (their initial values), the used values are '0' (i.e., the boxes stay in their original position).
@ -452,12 +452,12 @@ void BlockFormattingContext::compute_vertical_box_model_metrics(Box& child_box,
auto const& computed_values = child_box.computed_values();
auto width_of_containing_block = CSS::Length::make_px(containing_block.content_width());
box_model.margin.top = computed_values.margin().top.resolved(child_box, width_of_containing_block).resolved_or_zero(containing_block).to_px(child_box);
box_model.margin.bottom = computed_values.margin().bottom.resolved(child_box, width_of_containing_block).resolved_or_zero(containing_block).to_px(child_box);
box_model.margin.top = computed_values.margin().top.resolved(child_box, width_of_containing_block).resolved(containing_block).to_px(child_box);
box_model.margin.bottom = computed_values.margin().bottom.resolved(child_box, width_of_containing_block).resolved(containing_block).to_px(child_box);
box_model.border.top = computed_values.border_top().width;
box_model.border.bottom = computed_values.border_bottom().width;
box_model.padding.top = computed_values.padding().top.resolved(child_box, width_of_containing_block).resolved_or_zero(containing_block).to_px(child_box);
box_model.padding.bottom = computed_values.padding().bottom.resolved(child_box, width_of_containing_block).resolved_or_zero(containing_block).to_px(child_box);
box_model.padding.top = computed_values.padding().top.resolved(child_box, width_of_containing_block).resolved(containing_block).to_px(child_box);
box_model.padding.bottom = computed_values.padding().bottom.resolved(child_box, width_of_containing_block).resolved(containing_block).to_px(child_box);
}
void BlockFormattingContext::place_block_level_element_in_normal_flow_vertically(Box& child_box, BlockContainer const& containing_block)