Skip to content

Commit

Permalink
layout: Implement computation of table column widths (#31165)
Browse files Browse the repository at this point in the history
* layout: Implement computation of table column widths

This change implements the various steps of table column width
computation, ignoring features that don't exist yet (such as separated
borders, column elements, and colgroups).

Co-authored-by: Oriol Brufau <obrufau@igalia.com>

* Fix an issue with the assignment of column percent width

* Respond to review comments

---------

Co-authored-by: Oriol Brufau <obrufau@igalia.com>
  • Loading branch information
mrobinson and Loirooriol committed Jan 25, 2024
1 parent dc34eec commit d68c7e7
Show file tree
Hide file tree
Showing 16 changed files with 707 additions and 121 deletions.
9 changes: 5 additions & 4 deletions components/layout_2020/flow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,8 @@ fn calculate_inline_content_size_for_block_level_boxes(

impl AccumulatedData {
fn max_size_including_uncleared_floats(&self) -> ContentSizes {
self.max_size.max(self.left_floats.add(&self.right_floats))
self.max_size
.max(self.left_floats.union(&self.right_floats))
}
fn clear_floats(&mut self, clear: Clear) {
match clear {
Expand All @@ -333,12 +334,12 @@ fn calculate_inline_content_size_for_block_level_boxes(
let accumulate = |mut data: AccumulatedData, (size, float, clear)| {
data.clear_floats(clear);
match float {
Float::Left => data.left_floats = data.left_floats.add(&size),
Float::Right => data.right_floats = data.right_floats.add(&size),
Float::Left => data.left_floats = data.left_floats.union(&size),
Float::Right => data.right_floats = data.right_floats.union(&size),
Float::None => {
data.max_size = data
.max_size
.max(data.left_floats.add(&data.right_floats).add(&size));
.max(data.left_floats.union(&data.right_floats).union(&size));
data.left_floats = ContentSizes::zero();
data.right_floats = ContentSizes::zero();
},
Expand Down
27 changes: 25 additions & 2 deletions components/layout_2020/sizing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

//! <https://drafts.csswg.org/css-sizing/>

use std::ops::{Add, AddAssign};

use app_units::Au;
use serde::Serialize;
use style::logical_geometry::WritingMode;
Expand All @@ -14,7 +16,7 @@ use style::Zero;

use crate::style_ext::{Clamp, ComputedValuesExt};

#[derive(Clone, Debug, Serialize)]
#[derive(Clone, Copy, Debug, Serialize)]
pub(crate) struct ContentSizes {
pub min_content: Au,
pub max_content: Au,
Expand Down Expand Up @@ -43,14 +45,35 @@ impl ContentSizes {
}
}

pub fn add(&self, other: &Self) -> Self {
pub fn max_assign(&mut self, other: Self) {
*self = self.max(other);
}

pub fn union(&self, other: &Self) -> Self {
Self {
min_content: self.min_content.max(other.min_content),
max_content: self.max_content + other.max_content,
}
}
}

impl Add for ContentSizes {
type Output = Self;

fn add(self, rhs: Self) -> Self {
Self {
min_content: self.min_content + rhs.min_content,
max_content: self.max_content + rhs.max_content,
}
}
}

impl AddAssign for ContentSizes {
fn add_assign(&mut self, rhs: Self) {
*self = self.add(rhs)
}
}

impl ContentSizes {
/// <https://drafts.csswg.org/css2/visudet.html#shrink-to-fit-float>
pub fn shrink_to_fit(&self, available_size: Au) -> Au {
Expand Down

0 comments on commit d68c7e7

Please sign in to comment.