1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 18:27:35 +00:00

LibWeb: Respect min-width and max-width on position:absolute elements

This commit is contained in:
Andreas Kling 2020-06-18 21:30:19 +02:00
parent 55a3575a7c
commit dec0cd3755

View file

@ -270,6 +270,7 @@ void LayoutBlock::compute_width_for_absolutely_positioned_block()
auto& containing_block = *this->containing_block();
auto zero_value = Length(0, Length::Type::Px);
auto try_compute_width = [&](const auto& a_width) {
auto margin_left = style.length_or_fallback(CSS::PropertyID::MarginLeft, zero_value, containing_block.width());
auto margin_right = style.length_or_fallback(CSS::PropertyID::MarginRight, zero_value, containing_block.width());
auto border_left = style.length_or_fallback(CSS::PropertyID::BorderLeftWidth, zero_value);
@ -279,7 +280,7 @@ void LayoutBlock::compute_width_for_absolutely_positioned_block()
auto left = style.length_or_fallback(CSS::PropertyID::Left, {}, containing_block.width());
auto right = style.length_or_fallback(CSS::PropertyID::Right, {}, containing_block.width());
auto width = style.length_or_fallback(CSS::PropertyID::Width, {}, containing_block.width());
auto width = a_width;
auto solve_for_left = [&] {
return Length(containing_block.width() - margin_left.to_px(*this) - border_left.to_px(*this) - padding_left.to_px(*this) - width.to_px(*this) - padding_right.to_px(*this) - border_right.to_px(*this) - margin_right.to_px(*this) - right.to_px(*this), Length::Type::Px);
@ -310,8 +311,7 @@ void LayoutBlock::compute_width_for_absolutely_positioned_block()
if (!left.is_auto() && !width.is_auto() && !right.is_auto()) {
// FIXME: This should be solved in a more complicated way.
set_width(width.to_px(*this));
return;
return width;
}
if (margin_left.is_auto())
@ -365,7 +365,33 @@ void LayoutBlock::compute_width_for_absolutely_positioned_block()
right = solve_for_right();
}
set_width(width.to_px(*this));
return width;
};
auto specified_width = style.length_or_fallback(CSS::PropertyID::Width, {}, containing_block.width());
// 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 = style.length_or_fallback(CSS::PropertyID::MaxWidth, {}, containing_block.width());
if (!specified_max_width.is_auto()) {
if (used_width.to_px(*this) > specified_max_width.to_px(*this)) {
used_width = try_compute_width(specified_max_width);
}
}
// 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 = style.length_or_fallback(CSS::PropertyID::MinWidth, {}, containing_block.width());
if (!specified_min_width.is_auto()) {
if (used_width.to_px(*this) < specified_min_width.to_px(*this)) {
used_width = try_compute_width(specified_min_width);
}
}
set_width(used_width.to_px(*this));
}
void LayoutBlock::compute_width()