|
@@ -290,10 +290,7 @@ void BlockFormattingContext::compute_width_for_floating_box(Box const& box, Avai
|
|
|
auto& computed_values = box.computed_values();
|
|
|
|
|
|
auto zero_value = CSS::Length::make_px(0);
|
|
|
- auto width_of_containing_block = available_space.width.to_px_or_zero();
|
|
|
- auto width_of_containing_block_as_length_for_resolve = CSS::Length::make_px(width_of_containing_block);
|
|
|
- if (!available_space.width.is_definite())
|
|
|
- width_of_containing_block_as_length_for_resolve = CSS::Length::make_px(0);
|
|
|
+ auto width_of_containing_block_as_length_for_resolve = CSS::Length::make_px(available_space.width.to_px_or_zero());
|
|
|
|
|
|
auto margin_left = computed_values.margin().left().resolved(box, width_of_containing_block_as_length_for_resolve);
|
|
|
auto margin_right = computed_values.margin().right().resolved(box, width_of_containing_block_as_length_for_resolve);
|
|
@@ -309,18 +306,24 @@ void BlockFormattingContext::compute_width_for_floating_box(Box const& box, Avai
|
|
|
auto compute_width = [&](auto width) {
|
|
|
// If 'width' is computed as 'auto', the used value is the "shrink-to-fit" width.
|
|
|
if (width.is_auto()) {
|
|
|
-
|
|
|
- // Find the available width: in this case, this is the width of the containing
|
|
|
- // block minus the used values of 'margin-left', 'border-left-width', 'padding-left',
|
|
|
- // 'padding-right', 'border-right-width', 'margin-right', and the widths of any relevant scroll bars.
|
|
|
- auto available_width = width_of_containing_block
|
|
|
- - margin_left.to_px(box) - computed_values.border_left().width - padding_left
|
|
|
- - padding_right - computed_values.border_right().width - margin_right.to_px(box);
|
|
|
-
|
|
|
auto result = calculate_shrink_to_fit_widths(box);
|
|
|
|
|
|
- // Then the shrink-to-fit width is: min(max(preferred minimum width, available width), preferred width).
|
|
|
- width = CSS::Length::make_px(min(max(result.preferred_minimum_width, available_width), result.preferred_width));
|
|
|
+ if (available_space.width.is_definite()) {
|
|
|
+ // Find the available width: in this case, this is the width of the containing
|
|
|
+ // block minus the used values of 'margin-left', 'border-left-width', 'padding-left',
|
|
|
+ // 'padding-right', 'border-right-width', 'margin-right', and the widths of any relevant scroll bars.
|
|
|
+ auto available_width = available_space.width.to_px_or_zero()
|
|
|
+ - margin_left.to_px(box) - computed_values.border_left().width - padding_left
|
|
|
+ - padding_right - computed_values.border_right().width - margin_right.to_px(box);
|
|
|
+ // Then the shrink-to-fit width is: min(max(preferred minimum width, available width), preferred width).
|
|
|
+ width = CSS::Length::make_px(min(max(result.preferred_minimum_width, available_width), result.preferred_width));
|
|
|
+ } else if (available_space.width.is_indefinite() || available_space.width.is_max_content()) {
|
|
|
+ // Fold the formula for shrink-to-fit width for indefinite and max-content available width.
|
|
|
+ width = CSS::Length::make_px(result.preferred_width);
|
|
|
+ } else {
|
|
|
+ // Fold the formula for shrink-to-fit width for min-content available width.
|
|
|
+ width = CSS::Length::make_px(min(result.preferred_minimum_width, result.preferred_width));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return width;
|
|
@@ -898,7 +901,6 @@ void BlockFormattingContext::layout_floating_box(Box const& box, BlockContainer
|
|
|
VERIFY(box.is_floating());
|
|
|
|
|
|
auto& box_state = m_state.get_mutable(box);
|
|
|
- CSSPixels width_of_containing_block = available_space.width.to_px_or_zero();
|
|
|
|
|
|
resolve_vertical_box_model_metrics(box);
|
|
|
|
|
@@ -957,7 +959,11 @@ void BlockFormattingContext::layout_floating_box(Box const& box, BlockContainer
|
|
|
bool fits_next_to_preceding_float = false;
|
|
|
if (side == FloatSide::Left) {
|
|
|
tentative_offset_from_edge = preceding_float.offset_from_edge + preceding_float_state.content_width() + preceding_float_state.margin_box_right() + box_state.margin_box_left();
|
|
|
- fits_next_to_preceding_float = (tentative_offset_from_edge + box_state.content_width() + box_state.margin_box_right()) <= width_of_containing_block;
|
|
|
+ if (available_space.width.is_definite()) {
|
|
|
+ fits_next_to_preceding_float = (tentative_offset_from_edge + box_state.content_width() + box_state.margin_box_right()) <= available_space.width.to_px_or_zero();
|
|
|
+ } else if (available_space.width.is_max_content() || available_space.width.is_indefinite()) {
|
|
|
+ fits_next_to_preceding_float = true;
|
|
|
+ }
|
|
|
} else {
|
|
|
tentative_offset_from_edge = preceding_float.offset_from_edge + preceding_float_state.margin_box_left() + box_state.margin_box_right() + box_state.content_width();
|
|
|
fits_next_to_preceding_float = tentative_offset_from_edge >= 0;
|