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

LibWeb: Simplify more code with CSS::LengthPercentage::is_auto()

This commit is contained in:
Andreas Kling 2022-07-25 23:55:20 +02:00
parent 16c173de43
commit bd48d9521a
3 changed files with 15 additions and 19 deletions

View file

@ -393,15 +393,15 @@ bool FlexFormattingContext::is_cross_auto(Box const& box) const
bool FlexFormattingContext::is_main_axis_margin_first_auto(Box const& box) const bool FlexFormattingContext::is_main_axis_margin_first_auto(Box const& box) const
{ {
if (is_row_layout()) if (is_row_layout())
return box.computed_values().margin().left.length().is_auto(); return box.computed_values().margin().left.is_auto();
return box.computed_values().margin().top.length().is_auto(); return box.computed_values().margin().top.is_auto();
} }
bool FlexFormattingContext::is_main_axis_margin_second_auto(Box const& box) const bool FlexFormattingContext::is_main_axis_margin_second_auto(Box const& box) const
{ {
if (is_row_layout()) if (is_row_layout())
return box.computed_values().margin().right.length().is_auto(); return box.computed_values().margin().right.is_auto();
return box.computed_values().margin().bottom.length().is_auto(); return box.computed_values().margin().bottom.is_auto();
} }
void FlexFormattingContext::set_main_size(Box const& box, float size) void FlexFormattingContext::set_main_size(Box const& box, float size)

View file

@ -724,24 +724,20 @@ void FormattingContext::layout_absolutely_positioned_element(Box const& box)
box_state.inset_right = box.computed_values().inset().right.resolved(box, width_of_containing_block_as_length).to_px(box); box_state.inset_right = box.computed_values().inset().right.resolved(box, width_of_containing_block_as_length).to_px(box);
box_state.inset_bottom = box.computed_values().inset().bottom.resolved(box, height_of_containing_block_as_length).to_px(box); box_state.inset_bottom = box.computed_values().inset().bottom.resolved(box, height_of_containing_block_as_length).to_px(box);
auto is_auto = [](auto const& length_percentage) { if (box.computed_values().inset().left.is_auto() && specified_width.is_auto() && box.computed_values().inset().right.is_auto()) {
return length_percentage.is_length() && length_percentage.length().is_auto(); if (box.computed_values().margin().left.is_auto())
};
if (is_auto(box.computed_values().inset().left) && specified_width.is_auto() && is_auto(box.computed_values().inset().right)) {
if (is_auto(box.computed_values().margin().left))
box_state.margin_left = 0; box_state.margin_left = 0;
if (is_auto(box.computed_values().margin().right)) if (box.computed_values().margin().right.is_auto())
box_state.margin_right = 0; box_state.margin_right = 0;
} }
Gfx::FloatPoint used_offset; Gfx::FloatPoint used_offset;
if (!is_auto(box.computed_values().inset().left)) { if (!box.computed_values().inset().left.is_auto()) {
float x_offset = box_state.inset_left float x_offset = box_state.inset_left
+ box_state.border_box_left(); + box_state.border_box_left();
used_offset.set_x(x_offset + box_state.margin_left); used_offset.set_x(x_offset + box_state.margin_left);
} else if (!is_auto(box.computed_values().inset().right)) { } else if (!box.computed_values().inset().right.is_auto()) {
float x_offset = 0 float x_offset = 0
- box_state.inset_right - box_state.inset_right
- box_state.border_box_right(); - box_state.border_box_right();
@ -751,11 +747,11 @@ void FormattingContext::layout_absolutely_positioned_element(Box const& box)
used_offset.set_x(x_offset); used_offset.set_x(x_offset);
} }
if (!is_auto(box.computed_values().inset().top)) { if (!box.computed_values().inset().top.is_auto()) {
float y_offset = box_state.inset_top float y_offset = box_state.inset_top
+ box_state.border_box_top(); + box_state.border_box_top();
used_offset.set_y(y_offset + box_state.margin_top); used_offset.set_y(y_offset + box_state.margin_top);
} else if (!is_auto(box.computed_values().inset().bottom)) { } else if (!box.computed_values().inset().bottom.is_auto()) {
float y_offset = 0 float y_offset = 0
- box_state.inset_bottom - box_state.inset_bottom
- box_state.border_box_bottom(); - box_state.border_box_bottom();

View file

@ -139,8 +139,8 @@ void paint_background(PaintContext& context, Layout::NodeWithStyleAndBoxModelMet
case CSS::BackgroundSize::LengthPercentage: { case CSS::BackgroundSize::LengthPercentage: {
float width; float width;
float height; float height;
bool x_is_auto = layer.size_x.is_length() && layer.size_x.length().is_auto(); bool x_is_auto = layer.size_x.is_auto();
bool y_is_auto = layer.size_y.is_length() && layer.size_y.length().is_auto(); bool y_is_auto = layer.size_y.is_auto();
if (x_is_auto && y_is_auto) { if (x_is_auto && y_is_auto) {
width = image.width(); width = image.width();
height = image.height(); height = image.height();
@ -179,10 +179,10 @@ void paint_background(PaintContext& context, Layout::NodeWithStyleAndBoxModelMet
// for the other dimension, then there is a third step: that other dimension is scaled // for the other dimension, then there is a third step: that other dimension is scaled
// so that the original aspect ratio is restored. // so that the original aspect ratio is restored.
if (layer.repeat_x != layer.repeat_y) { if (layer.repeat_x != layer.repeat_y) {
if (layer.size_x.is_length() && layer.size_x.length().is_auto()) { if (layer.size_x.is_auto()) {
image_rect.set_width(image.width() * (image_rect.height() / image.height())); image_rect.set_width(image.width() * (image_rect.height() / image.height()));
} }
if (layer.size_y.is_length() && layer.size_y.length().is_auto()) { if (layer.size_y.is_auto()) {
image_rect.set_height(image.height() * (image_rect.width() / image.width())); image_rect.set_height(image.height() * (image_rect.width() / image.width()));
} }
} }