mirror of
https://github.com/servo/servo.git
synced 2025-08-08 23:15:33 +01:00
CSS Grid: percentage sizing fixes (#34948)
This applies some fixes for CSS Grid percentage sizing. These fixes are mostly within Taffy, but there are some changes in Servo to allow it to communicate whether an item is replaced to Taffy. It also updates Taffy to v0.8.0. Taffy has switched to a tagged pointer representation of length/size styles. Much of the diff here is updating Servo's type conversion code to use the new representation. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] There are tests for these changes OR --------- Signed-off-by: Nico Burns <nico@nicoburns.com>
This commit is contained in:
parent
bd6639aadb
commit
1b5a10a55f
10 changed files with 111 additions and 105 deletions
|
@ -10,33 +10,44 @@ use super::convert;
|
|||
|
||||
/// A wrapper struct for anything that Deref's to a [`ComputedValues`], which
|
||||
/// implements Taffy's layout traits and can used with Taffy's layout algorithms.
|
||||
pub struct TaffyStyloStyle<T: Deref<Target = ComputedValues>>(pub T);
|
||||
pub struct TaffyStyloStyle<T: Deref<Target = ComputedValues>> {
|
||||
pub style: T,
|
||||
pub is_compressible_replaced: bool,
|
||||
}
|
||||
|
||||
impl<T: Deref<Target = ComputedValues>> From<T> for TaffyStyloStyle<T> {
|
||||
fn from(value: T) -> Self {
|
||||
Self(value)
|
||||
impl<T: Deref<Target = ComputedValues>> TaffyStyloStyle<T> {
|
||||
pub fn new(style: T, is_compressible_replaced: bool) -> Self {
|
||||
Self {
|
||||
style,
|
||||
is_compressible_replaced,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Deref<Target = ComputedValues>> taffy::CoreStyle for TaffyStyloStyle<T> {
|
||||
#[inline]
|
||||
fn box_generation_mode(&self) -> taffy::BoxGenerationMode {
|
||||
convert::box_generation_mode(self.0.get_box().display)
|
||||
convert::box_generation_mode(self.style.get_box().display)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn is_block(&self) -> bool {
|
||||
convert::is_block(self.0.get_box().display)
|
||||
convert::is_block(self.style.get_box().display)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn is_compressible_replaced(&self) -> bool {
|
||||
self.is_compressible_replaced
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn box_sizing(&self) -> taffy::BoxSizing {
|
||||
convert::box_sizing(self.0.get_position().box_sizing)
|
||||
convert::box_sizing(self.style.get_position().box_sizing)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn overflow(&self) -> taffy::Point<taffy::Overflow> {
|
||||
let box_styles = self.0.get_box();
|
||||
let box_styles = self.style.get_box();
|
||||
taffy::Point {
|
||||
x: convert::overflow(box_styles.overflow_x),
|
||||
y: convert::overflow(box_styles.overflow_y),
|
||||
|
@ -50,12 +61,12 @@ impl<T: Deref<Target = ComputedValues>> taffy::CoreStyle for TaffyStyloStyle<T>
|
|||
|
||||
#[inline]
|
||||
fn position(&self) -> taffy::Position {
|
||||
convert::position(self.0.get_box().position)
|
||||
convert::position(self.style.get_box().position)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn inset(&self) -> taffy::Rect<taffy::LengthPercentageAuto> {
|
||||
let position_styles = self.0.get_position();
|
||||
let position_styles = self.style.get_position();
|
||||
taffy::Rect {
|
||||
left: convert::inset(&position_styles.left),
|
||||
right: convert::inset(&position_styles.right),
|
||||
|
@ -66,7 +77,7 @@ impl<T: Deref<Target = ComputedValues>> taffy::CoreStyle for TaffyStyloStyle<T>
|
|||
|
||||
#[inline]
|
||||
fn size(&self) -> taffy::Size<taffy::Dimension> {
|
||||
let position_styles = self.0.get_position();
|
||||
let position_styles = self.style.get_position();
|
||||
taffy::Size {
|
||||
width: convert::dimension(&position_styles.width),
|
||||
height: convert::dimension(&position_styles.height),
|
||||
|
@ -75,7 +86,7 @@ impl<T: Deref<Target = ComputedValues>> taffy::CoreStyle for TaffyStyloStyle<T>
|
|||
|
||||
#[inline]
|
||||
fn min_size(&self) -> taffy::Size<taffy::Dimension> {
|
||||
let position_styles = self.0.get_position();
|
||||
let position_styles = self.style.get_position();
|
||||
taffy::Size {
|
||||
width: convert::dimension(&position_styles.min_width),
|
||||
height: convert::dimension(&position_styles.min_height),
|
||||
|
@ -84,7 +95,7 @@ impl<T: Deref<Target = ComputedValues>> taffy::CoreStyle for TaffyStyloStyle<T>
|
|||
|
||||
#[inline]
|
||||
fn max_size(&self) -> taffy::Size<taffy::Dimension> {
|
||||
let position_styles = self.0.get_position();
|
||||
let position_styles = self.style.get_position();
|
||||
taffy::Size {
|
||||
width: convert::max_size_dimension(&position_styles.max_width),
|
||||
height: convert::max_size_dimension(&position_styles.max_height),
|
||||
|
@ -93,12 +104,12 @@ impl<T: Deref<Target = ComputedValues>> taffy::CoreStyle for TaffyStyloStyle<T>
|
|||
|
||||
#[inline]
|
||||
fn aspect_ratio(&self) -> Option<f32> {
|
||||
convert::aspect_ratio(self.0.get_position().aspect_ratio)
|
||||
convert::aspect_ratio(self.style.get_position().aspect_ratio)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn margin(&self) -> taffy::Rect<taffy::LengthPercentageAuto> {
|
||||
let margin_styles = self.0.get_margin();
|
||||
let margin_styles = self.style.get_margin();
|
||||
taffy::Rect {
|
||||
left: convert::margin(&margin_styles.margin_left),
|
||||
right: convert::margin(&margin_styles.margin_right),
|
||||
|
@ -109,7 +120,7 @@ impl<T: Deref<Target = ComputedValues>> taffy::CoreStyle for TaffyStyloStyle<T>
|
|||
|
||||
#[inline]
|
||||
fn padding(&self) -> taffy::Rect<taffy::LengthPercentage> {
|
||||
let padding_styles = self.0.get_padding();
|
||||
let padding_styles = self.style.get_padding();
|
||||
taffy::Rect {
|
||||
left: convert::length_percentage(&padding_styles.padding_left.0),
|
||||
right: convert::length_percentage(&padding_styles.padding_right.0),
|
||||
|
@ -120,12 +131,12 @@ impl<T: Deref<Target = ComputedValues>> taffy::CoreStyle for TaffyStyloStyle<T>
|
|||
|
||||
#[inline]
|
||||
fn border(&self) -> taffy::Rect<taffy::LengthPercentage> {
|
||||
let border_styles = self.0.get_border();
|
||||
let border_styles = self.style.get_border();
|
||||
taffy::Rect {
|
||||
left: taffy::LengthPercentage::Length(border_styles.border_left_width.to_f32_px()),
|
||||
right: taffy::LengthPercentage::Length(border_styles.border_right_width.to_f32_px()),
|
||||
top: taffy::LengthPercentage::Length(border_styles.border_top_width.to_f32_px()),
|
||||
bottom: taffy::LengthPercentage::Length(border_styles.border_bottom_width.to_f32_px()),
|
||||
left: taffy::LengthPercentage::length(border_styles.border_left_width.to_f32_px()),
|
||||
right: taffy::LengthPercentage::length(border_styles.border_right_width.to_f32_px()),
|
||||
top: taffy::LengthPercentage::length(border_styles.border_top_width.to_f32_px()),
|
||||
bottom: taffy::LengthPercentage::length(border_styles.border_bottom_width.to_f32_px()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -142,32 +153,32 @@ impl<T: Deref<Target = ComputedValues>> taffy::GridContainerStyle for TaffyStylo
|
|||
|
||||
#[inline]
|
||||
fn grid_template_rows(&self) -> Self::TemplateTrackList<'_> {
|
||||
convert::grid_template_tracks(&self.0.get_position().grid_template_rows)
|
||||
convert::grid_template_tracks(&self.style.get_position().grid_template_rows)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn grid_template_columns(&self) -> Self::TemplateTrackList<'_> {
|
||||
convert::grid_template_tracks(&self.0.get_position().grid_template_columns)
|
||||
convert::grid_template_tracks(&self.style.get_position().grid_template_columns)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn grid_auto_rows(&self) -> Self::AutoTrackList<'_> {
|
||||
convert::grid_auto_tracks(&self.0.get_position().grid_auto_rows)
|
||||
convert::grid_auto_tracks(&self.style.get_position().grid_auto_rows)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn grid_auto_columns(&self) -> Self::AutoTrackList<'_> {
|
||||
convert::grid_auto_tracks(&self.0.get_position().grid_auto_columns)
|
||||
convert::grid_auto_tracks(&self.style.get_position().grid_auto_columns)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn grid_auto_flow(&self) -> taffy::GridAutoFlow {
|
||||
convert::grid_auto_flow(self.0.get_position().grid_auto_flow)
|
||||
convert::grid_auto_flow(self.style.get_position().grid_auto_flow)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn gap(&self) -> taffy::Size<taffy::LengthPercentage> {
|
||||
let position_styles = self.0.get_position();
|
||||
let position_styles = self.style.get_position();
|
||||
taffy::Size {
|
||||
width: convert::gap(&position_styles.column_gap),
|
||||
height: convert::gap(&position_styles.row_gap),
|
||||
|
@ -176,29 +187,29 @@ impl<T: Deref<Target = ComputedValues>> taffy::GridContainerStyle for TaffyStylo
|
|||
|
||||
#[inline]
|
||||
fn align_content(&self) -> Option<taffy::AlignContent> {
|
||||
convert::content_alignment(self.0.get_position().align_content.0)
|
||||
convert::content_alignment(self.style.get_position().align_content.0)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn justify_content(&self) -> Option<taffy::JustifyContent> {
|
||||
convert::content_alignment(self.0.get_position().justify_content.0)
|
||||
convert::content_alignment(self.style.get_position().justify_content.0)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn align_items(&self) -> Option<taffy::AlignItems> {
|
||||
convert::item_alignment(self.0.get_position().align_items.0)
|
||||
convert::item_alignment(self.style.get_position().align_items.0)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn justify_items(&self) -> Option<taffy::AlignItems> {
|
||||
convert::item_alignment(self.0.get_position().justify_items.computed.0)
|
||||
convert::item_alignment(self.style.get_position().justify_items.computed.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Deref<Target = ComputedValues>> taffy::GridItemStyle for TaffyStyloStyle<T> {
|
||||
#[inline]
|
||||
fn grid_row(&self) -> taffy::Line<taffy::GridPlacement> {
|
||||
let position_styles = self.0.get_position();
|
||||
let position_styles = self.style.get_position();
|
||||
taffy::Line {
|
||||
start: convert::grid_line(&position_styles.grid_row_start),
|
||||
end: convert::grid_line(&position_styles.grid_row_end),
|
||||
|
@ -207,7 +218,7 @@ impl<T: Deref<Target = ComputedValues>> taffy::GridItemStyle for TaffyStyloStyle
|
|||
|
||||
#[inline]
|
||||
fn grid_column(&self) -> taffy::Line<taffy::GridPlacement> {
|
||||
let position_styles = self.0.get_position();
|
||||
let position_styles = self.style.get_position();
|
||||
taffy::Line {
|
||||
start: convert::grid_line(&position_styles.grid_column_start),
|
||||
end: convert::grid_line(&position_styles.grid_column_end),
|
||||
|
@ -216,11 +227,11 @@ impl<T: Deref<Target = ComputedValues>> taffy::GridItemStyle for TaffyStyloStyle
|
|||
|
||||
#[inline]
|
||||
fn align_self(&self) -> Option<taffy::AlignSelf> {
|
||||
convert::item_alignment(self.0.get_position().align_self.0.0)
|
||||
convert::item_alignment(self.style.get_position().align_self.0.0)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn justify_self(&self) -> Option<taffy::AlignSelf> {
|
||||
convert::item_alignment(self.0.get_position().justify_self.0.0)
|
||||
convert::item_alignment(self.style.get_position().justify_self.0.0)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue