LibWeb: Implement justify-*: left/right

This commit is contained in:
Gingeh 2024-09-09 10:42:16 +10:00 committed by Sam Atkins
commit 4a3a9e6ec4
Notes: github-actions[bot] 2024-09-10 09:41:09 +00:00
3 changed files with 41 additions and 4 deletions

View file

@ -235,7 +235,9 @@
"space-between", "space-between",
"space-around", "space-around",
"space-evenly", "space-evenly",
"stretch" "stretch",
"left",
"right"
], ],
"justify-items": [ "justify-items": [
"baseline", "baseline",
@ -250,7 +252,9 @@
"self-start", "self-start",
"start", "start",
"stretch", "stretch",
"unsafe" "unsafe",
"left",
"right"
], ],
"justify-self": [ "justify-self": [
"auto", "auto",
@ -265,7 +269,9 @@
"self-start", "self-start",
"start", "start",
"stretch", "stretch",
"unsafe" "unsafe",
"left",
"right"
], ],
"line-style": [ "line-style": [
"none", "none",

View file

@ -1262,6 +1262,7 @@ void FlexFormattingContext::distribute_any_remaining_free_space()
if (auto_margins == 0 && number_of_items > 0) { if (auto_margins == 0 && number_of_items > 0) {
switch (flex_container().computed_values().justify_content()) { switch (flex_container().computed_values().justify_content()) {
case CSS::JustifyContent::Start: case CSS::JustifyContent::Start:
case CSS::JustifyContent::Left:
initial_offset = 0; initial_offset = 0;
break; break;
case CSS::JustifyContent::Stretch: case CSS::JustifyContent::Stretch:
@ -1276,6 +1277,13 @@ void FlexFormattingContext::distribute_any_remaining_free_space()
case CSS::JustifyContent::End: case CSS::JustifyContent::End:
initial_offset = inner_main_size(m_flex_container_state); initial_offset = inner_main_size(m_flex_container_state);
break; break;
case CSS::JustifyContent::Right:
if (is_row_layout()) {
initial_offset = inner_main_size(m_flex_container_state);
} else {
initial_offset = 0;
}
break;
case CSS::JustifyContent::FlexEnd: case CSS::JustifyContent::FlexEnd:
if (is_direction_reverse()) { if (is_direction_reverse()) {
initial_offset = 0; initial_offset = 0;
@ -1330,6 +1338,10 @@ void FlexFormattingContext::distribute_any_remaining_free_space()
if (auto_margins == 0) { if (auto_margins == 0) {
switch (flex_container().computed_values().justify_content()) { switch (flex_container().computed_values().justify_content()) {
case CSS::JustifyContent::Start:
case CSS::JustifyContent::Left:
flex_region_render_cursor = FlexRegionRenderCursor::Left;
break;
case CSS::JustifyContent::Normal: case CSS::JustifyContent::Normal:
case CSS::JustifyContent::FlexStart: case CSS::JustifyContent::FlexStart:
case CSS::JustifyContent::Center: case CSS::JustifyContent::Center:
@ -1344,6 +1356,13 @@ void FlexFormattingContext::distribute_any_remaining_free_space()
case CSS::JustifyContent::End: case CSS::JustifyContent::End:
flex_region_render_cursor = FlexRegionRenderCursor::Right; flex_region_render_cursor = FlexRegionRenderCursor::Right;
break; break;
case CSS::JustifyContent::Right:
if (is_row_layout()) {
flex_region_render_cursor = FlexRegionRenderCursor::Right;
} else {
flex_region_render_cursor = FlexRegionRenderCursor::Left;
}
break;
case CSS::JustifyContent::FlexEnd: case CSS::JustifyContent::FlexEnd:
if (!is_direction_reverse()) { if (!is_direction_reverse()) {
flex_region_render_cursor = FlexRegionRenderCursor::Right; flex_region_render_cursor = FlexRegionRenderCursor::Right;
@ -2172,6 +2191,7 @@ CSSPixelPoint FlexFormattingContext::calculate_static_position(Box const& box) c
CSSPixels main_offset = 0; CSSPixels main_offset = 0;
switch (flex_container().computed_values().justify_content()) { switch (flex_container().computed_values().justify_content()) {
case CSS::JustifyContent::Start: case CSS::JustifyContent::Start:
case CSS::JustifyContent::Left:
pack_from_end = false; pack_from_end = false;
break; break;
case CSS::JustifyContent::Stretch: case CSS::JustifyContent::Stretch:
@ -2183,6 +2203,9 @@ CSSPixelPoint FlexFormattingContext::calculate_static_position(Box const& box) c
case CSS::JustifyContent::End: case CSS::JustifyContent::End:
pack_from_end = true; pack_from_end = true;
break; break;
case CSS::JustifyContent::Right:
pack_from_end = is_row_layout();
break;
case CSS::JustifyContent::FlexEnd: case CSS::JustifyContent::FlexEnd:
pack_from_end = !is_direction_reverse(); pack_from_end = !is_direction_reverse();
break; break;

View file

@ -1426,6 +1426,10 @@ CSS::JustifyItems GridFormattingContext::justification_for_item(Box const& box)
return CSS::JustifyItems::Safe; return CSS::JustifyItems::Safe;
case CSS::JustifySelf::Unsafe: case CSS::JustifySelf::Unsafe:
return CSS::JustifyItems::Unsafe; return CSS::JustifyItems::Unsafe;
case CSS::JustifySelf::Left:
return CSS::JustifyItems::Left;
case CSS::JustifySelf::Right:
return CSS::JustifyItems::Right;
default: default:
VERIFY_NOT_REACHED(); VERIFY_NOT_REACHED();
} }
@ -1516,11 +1520,13 @@ void GridFormattingContext::resolve_grid_item_widths()
break; break;
case CSS::JustifyItems::Start: case CSS::JustifyItems::Start:
case CSS::JustifyItems::FlexStart: case CSS::JustifyItems::FlexStart:
case CSS::JustifyItems::Left:
result.margin_right += free_space_left_for_alignment; result.margin_right += free_space_left_for_alignment;
result.width = a_width; result.width = a_width;
break; break;
case CSS::JustifyItems::End: case CSS::JustifyItems::End:
case CSS::JustifyItems::FlexEnd: case CSS::JustifyItems::FlexEnd:
case CSS::JustifyItems::Right:
result.margin_left += free_space_left_for_alignment; result.margin_left += free_space_left_for_alignment;
result.width = a_width; result.width = a_width;
break; break;
@ -1744,7 +1750,7 @@ CSSPixelRect GridFormattingContext::get_grid_area_rect(GridItem const& grid_item
auto free_space = grid_container_width - sum_base_size_of_columns; auto free_space = grid_container_width - sum_base_size_of_columns;
x_start = free_space / 2; x_start = free_space / 2;
x_end = free_space / 2; x_end = free_space / 2;
} else if (justify_content == CSS::JustifyContent::End) { } else if (justify_content == CSS::JustifyContent::End || justify_content == CSS::JustifyContent::Right) {
auto free_space = grid_container_width - sum_base_size_of_columns; auto free_space = grid_container_width - sum_base_size_of_columns;
x_start = free_space; x_start = free_space;
x_end = free_space; x_end = free_space;
@ -1938,10 +1944,12 @@ void GridFormattingContext::layout_absolutely_positioned_element(Box const& box,
break; break;
case CSS::JustifyItems::Start: case CSS::JustifyItems::Start:
case CSS::JustifyItems::FlexStart: case CSS::JustifyItems::FlexStart:
case CSS::JustifyItems::Left:
box_state.inset_right = width_left_for_alignment; box_state.inset_right = width_left_for_alignment;
break; break;
case CSS::JustifyItems::End: case CSS::JustifyItems::End:
case CSS::JustifyItems::FlexEnd: case CSS::JustifyItems::FlexEnd:
case CSS::JustifyItems::Right:
box_state.inset_left = width_left_for_alignment; box_state.inset_left = width_left_for_alignment;
break; break;
default: default: