Convert layout to use Gecko's alignment style representation (#32790)

Signed-off-by: Nico Burns <nico@nicoburns.com>
Co-authored-by: Nico Burns <nico@nicoburns.com>
This commit is contained in:
Martin Robinson 2024-07-17 16:18:55 +02:00 committed by GitHub
parent a0d2b36ad8
commit 882a855b8c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
80 changed files with 177 additions and 6482 deletions

View file

@ -11,16 +11,14 @@ use app_units::{Au, MAX_AU};
use euclid::default::Point2D;
use log::debug;
use serde::Serialize;
use style::computed_values::align_content::T as AlignContent;
use style::computed_values::align_self::T as AlignSelf;
use style::computed_values::flex_direction::T as FlexDirection;
use style::computed_values::flex_wrap::T as FlexWrap;
use style::computed_values::justify_content::T as JustifyContent;
use style::logical_geometry::{Direction, LogicalSize};
use style::properties::ComputedValues;
use style::servo::restyle_damage::ServoRestyleDamage;
use style::values::computed::flex::FlexBasis;
use style::values::computed::{MaxSize, Size};
use style::values::specified::align::AlignFlags;
use crate::block::{AbsoluteAssignBSizesTraversal, BlockFlow, MarginsMayCollapseFlag};
use crate::context::LayoutContext;
@ -612,42 +610,47 @@ impl FlexFlow {
// TODO(stshine): if this flex line contain children that have
// property visibility:collapse, exclude them and resolve again.
let item_count = items.len() as i32;
let mut cur_i = inline_start_content_edge;
let item_interval = if line.free_space >= Au(0) && line.auto_margin_count == 0 {
match self
let justify_content = {
let justify_content = self
.block_flow
.fragment
.style()
.get_position()
.justify_content
{
JustifyContent::SpaceBetween => {
.0
.primary()
.value();
match justify_content {
AlignFlags::AUTO | AlignFlags::NORMAL => AlignFlags::STRETCH,
_ => justify_content,
}
};
let item_count = items.len() as i32;
let mut cur_i = inline_start_content_edge;
let item_interval = if line.free_space >= Au(0) && line.auto_margin_count == 0 {
match justify_content {
AlignFlags::SPACE_BETWEEN => {
if item_count == 1 {
Au(0)
} else {
line.free_space / (item_count - 1)
}
},
JustifyContent::SpaceAround => line.free_space / item_count,
AlignFlags::SPACE_AROUND => line.free_space / item_count,
_ => Au(0),
}
} else {
Au(0)
};
match self
.block_flow
.fragment
.style()
.get_position()
.justify_content
{
match justify_content {
// Overflow equally in both ends of line.
JustifyContent::Center | JustifyContent::SpaceAround => {
AlignFlags::CENTER | AlignFlags::SPACE_AROUND => {
cur_i += (line.free_space - item_interval * (item_count - 1)) / 2;
},
JustifyContent::FlexEnd => {
AlignFlags::FLEX_END => {
cur_i += line.free_space;
},
_ => {},
@ -721,12 +724,22 @@ impl FlexFlow {
let _scope = layout_debug_scope!("flex::inline_mode_assign_block_size");
let line_count = self.lines.len() as i32;
let line_align = self
.block_flow
.fragment
.style()
.get_position()
.align_content;
let line_align = {
let line_align = self
.block_flow
.fragment
.style()
.get_position()
.align_content
.0
.primary()
.value();
match line_align {
AlignFlags::AUTO | AlignFlags::NORMAL => AlignFlags::STRETCH,
_ => line_align,
}
};
let mut cur_b = self.block_flow.fragment.border_padding.block_start;
let mut total_cross_size = Au(0);
let mut line_interval = Au(0);
@ -762,21 +775,21 @@ impl FlexFlow {
let free_space = container_block_size - total_cross_size;
total_cross_size = container_block_size;
if line_align == AlignContent::Stretch && free_space > Au(0) {
if line_align == AlignFlags::STRETCH && free_space > Au(0) {
for line in self.lines.iter_mut() {
line.cross_size += free_space / line_count;
}
}
line_interval = match line_align {
AlignContent::SpaceBetween => {
AlignFlags::SPACE_BETWEEN => {
if line_count <= 1 {
Au(0)
} else {
free_space / (line_count - 1)
}
},
AlignContent::SpaceAround => {
AlignFlags::SPACE_AROUND => {
if line_count == 0 {
Au(0)
} else {
@ -787,16 +800,31 @@ impl FlexFlow {
};
match line_align {
AlignContent::Center | AlignContent::SpaceAround => {
AlignFlags::CENTER | AlignFlags::SPACE_AROUND => {
cur_b += (free_space - line_interval * (line_count - 1)) / 2;
},
AlignContent::FlexEnd => {
AlignFlags::FLEX_END => {
cur_b += free_space;
},
_ => {},
}
}
let align_items = {
let align_items = self
.block_flow
.fragment
.style()
.clone_align_items()
.0
.value();
match align_items {
AlignFlags::AUTO | AlignFlags::NORMAL => AlignFlags::STRETCH,
_ => align_items,
}
};
let mut children = self.block_flow.base.children.random_access_mut();
for line in &self.lines {
for item in self.items[line.range.clone()].iter_mut() {
@ -826,8 +854,23 @@ impl FlexFlow {
free_space = Au(0);
}
let self_align = block.fragment.style().get_position().align_self;
if self_align == AlignSelf::Stretch &&
let self_align = {
let self_align = block
.fragment
.style()
.get_position()
.align_self
.0
.0
.value();
match self_align {
AlignFlags::AUTO | AlignFlags::NORMAL => align_items,
_ => self_align,
}
};
if self_align == AlignFlags::STRETCH &&
block.fragment.style().content_block_size().is_auto()
{
free_space = Au(0);
@ -850,8 +893,8 @@ impl FlexFlow {
// TODO(stshine): support baseline alignment.
if free_space != Au(0) {
let flex_cross = match self_align {
AlignSelf::FlexEnd => free_space,
AlignSelf::Center => free_space / 2,
AlignFlags::FLEX_END => free_space,
AlignFlags::CENTER => free_space / 2,
_ => Au(0),
};
block.base.position.start.b += if !self.cross_reverse {