mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 16:18:12 +00:00
LibWeb: Use CSS::Size for computed size and max-size values
This patch changes the *computed* representation of the following CSS properties to use CSS::Size: - width, min-width, max-width - height, min-height, max-height A few things had to change in order for things to keep working, but I tried to keep the diff to a minimum. The main trouble was that `min-width` and `max-width` can't actually be `auto`, but they *can* be `none`. We previously treated `auto` as a valid value (and it behaved mostly like `none`).
This commit is contained in:
parent
844321d89f
commit
0843960235
9 changed files with 144 additions and 109 deletions
|
@ -212,19 +212,19 @@ void BlockFormattingContext::compute_width(Box const& box, LayoutMode layout_mod
|
|||
|
||||
// 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().resolved(box, width_of_containing_block_as_length).resolved(box);
|
||||
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);
|
||||
if (!computed_values.max_width().is_none()) {
|
||||
auto max_width = computed_values.max_width().resolved(box, width_of_containing_block_as_length).resolved(box);
|
||||
if (used_width.to_px(box) > max_width.to_px(box)) {
|
||||
used_width = try_compute_width(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 = computed_values.min_width().resolved(box, width_of_containing_block_as_length).resolved(box);
|
||||
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);
|
||||
if (!computed_values.min_width().is_auto()) {
|
||||
auto min_width = computed_values.min_width().resolved(box, width_of_containing_block_as_length).resolved(box);
|
||||
if (used_width.to_px(box) < min_width.to_px(box)) {
|
||||
used_width = try_compute_width(min_width);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -292,18 +292,18 @@ void BlockFormattingContext::compute_width_for_floating_box(Box const& box, Layo
|
|||
|
||||
// 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().resolved(box, width_of_containing_block_as_length).resolved(box);
|
||||
if (!specified_max_width.is_auto()) {
|
||||
if (width.to_px(box) > specified_max_width.to_px(box))
|
||||
width = compute_width(specified_max_width);
|
||||
if (!computed_values.max_width().is_none()) {
|
||||
auto max_width = computed_values.max_width().resolved(box, width_of_containing_block_as_length).resolved(box);
|
||||
if (width.to_px(box) > max_width.to_px(box))
|
||||
width = compute_width(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 = computed_values.min_width().resolved(box, width_of_containing_block_as_length).resolved(box);
|
||||
if (!specified_min_width.is_auto()) {
|
||||
if (width.to_px(box) < specified_min_width.to_px(box))
|
||||
width = compute_width(specified_min_width);
|
||||
if (!computed_values.min_width().is_auto()) {
|
||||
auto min_width = computed_values.min_width().resolved(box, width_of_containing_block_as_length).resolved(box);
|
||||
if (width.to_px(box) < min_width.to_px(box))
|
||||
width = compute_width(min_width);
|
||||
}
|
||||
|
||||
auto& box_state = m_state.get_mutable(box);
|
||||
|
@ -340,9 +340,11 @@ void BlockFormattingContext::compute_height(Box const& box, LayoutState& state)
|
|||
}
|
||||
}
|
||||
|
||||
auto specified_max_height = computed_values.max_height().resolved(box, containing_block_height).resolved(box);
|
||||
if (!specified_max_height.is_auto())
|
||||
height = min(height, specified_max_height.to_px(box));
|
||||
if (!computed_values.max_height().is_none()) {
|
||||
auto max_height = computed_values.max_height().resolved(box, containing_block_height).resolved(box);
|
||||
if (!max_height.is_auto())
|
||||
height = min(height, max_height.to_px(box));
|
||||
}
|
||||
auto specified_min_height = computed_values.min_height().resolved(box, containing_block_height).resolved(box);
|
||||
if (!specified_min_height.is_auto())
|
||||
height = max(height, specified_min_height.to_px(box));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue