Skip to content

Commit

Permalink
Update alignment translation for new Stylo alignment types from Gecko
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoburns committed Jun 20, 2024
1 parent 8b87869 commit c69959a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 79 deletions.
14 changes: 8 additions & 6 deletions packages/dom/src/stylo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,11 @@ impl crate::document::Document {
flex_wrap,
justify_content,
align_content,
justify_items,
align_items,
flex_grow,
flex_shrink,
justify_self,
align_self,
// order,
flex_basis,
Expand Down Expand Up @@ -124,10 +126,12 @@ impl crate::document::Document {
border: stylo_to_taffy::border(border),
flex_direction: stylo_to_taffy::flex_direction(*flex_direction),
flex_wrap: stylo_to_taffy::flex_wrap(*flex_wrap),
justify_content: stylo_to_taffy::justify_content(*justify_content),
align_content: stylo_to_taffy::align_content(*align_content),
align_items: stylo_to_taffy::align_items(*align_items),
align_self: stylo_to_taffy::align_self(*align_self),
justify_content: stylo_to_taffy::content_alignment(justify_content.0),
justify_items: stylo_to_taffy::item_alignment(justify_items.computed.0),
justify_self: stylo_to_taffy::item_alignment((justify_self.0).0),
align_content: stylo_to_taffy::content_alignment(align_content.0),
align_items: stylo_to_taffy::item_alignment(align_items.0),
align_self: stylo_to_taffy::item_alignment((align_self.0).0),
flex_grow: flex_grow.0,
flex_shrink: flex_shrink.0,
flex_basis: stylo_to_taffy::flex_basis(flex_basis),
Expand Down Expand Up @@ -166,8 +170,6 @@ impl crate::document::Document {

// TODO: Enable CSS Grid properties in servo configuration of stylo
//
// justify_items
// justify_self
// grid_template_rows
// grid_template_columns
// grid_auto_rows
Expand Down
106 changes: 33 additions & 73 deletions packages/dom/src/stylo_to_taffy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,8 @@
// Module of type aliases so we can refer to stylo types with nicer names
mod stylo {
pub(crate) use style::computed_values::align_content::T as AlignContent;
pub(crate) use style::computed_values::align_items::T as AlignItems;
pub(crate) use style::computed_values::align_self::T as AlignSelf;
pub(crate) use style::computed_values::flex_direction::T as FlexDirection;
pub(crate) use style::computed_values::flex_wrap::T as FlexWrap;
pub(crate) use style::computed_values::justify_content::T as JustifyContent;
// pub(crate) use style::computed_values::justify_items::T as JustifyItems;
// pub(crate) use style::computed_values::justify_self::T as JustifySelf;
pub(crate) use style::properties::longhands::aspect_ratio::computed_value::T as AspectRatio;
pub(crate) use style::properties::longhands::position::computed_value::T as Position;
pub(crate) use style::properties::style_structs::{Margin, Padding};
Expand All @@ -21,6 +15,8 @@ mod stylo {
pub(crate) use style::values::generics::length::GenericSize;
pub(crate) use style::values::generics::position::PreferredRatio;
pub(crate) use style::values::generics::NonNegative;
pub(crate) use style::values::specified::align::AlignFlags;
pub(crate) use style::values::specified::align::ContentDistribution;
pub(crate) use style::values::specified::box_::Display;
pub(crate) use style::values::specified::box_::DisplayInside;
pub(crate) use style::values::specified::box_::DisplayOutside;
Expand Down Expand Up @@ -194,72 +190,36 @@ pub(crate) fn flex_wrap(input: stylo::FlexWrap) -> taffy::FlexWrap {
}
}

pub(crate) fn justify_content(input: stylo::JustifyContent) -> Option<taffy::JustifyContent> {
match input {
stylo::JustifyContent::Start => Some(taffy::JustifyContent::Start),
stylo::JustifyContent::End => Some(taffy::JustifyContent::End),
stylo::JustifyContent::FlexStart => Some(taffy::JustifyContent::FlexStart),
stylo::JustifyContent::Stretch => Some(taffy::JustifyContent::Stretch),
stylo::JustifyContent::FlexEnd => Some(taffy::JustifyContent::FlexEnd),
stylo::JustifyContent::Center => Some(taffy::JustifyContent::Center),
stylo::JustifyContent::SpaceBetween => Some(taffy::JustifyContent::SpaceBetween),
stylo::JustifyContent::SpaceAround => Some(taffy::JustifyContent::SpaceAround),
stylo::JustifyContent::SpaceEvenly => Some(taffy::JustifyContent::SpaceEvenly),
}
}

pub(crate) fn align_content(input: stylo::AlignContent) -> Option<taffy::AlignContent> {
match input {
stylo::AlignContent::Start => Some(taffy::AlignContent::Start),
stylo::AlignContent::End => Some(taffy::AlignContent::End),
stylo::AlignContent::FlexStart => Some(taffy::AlignContent::FlexStart),
stylo::AlignContent::Stretch => Some(taffy::AlignContent::Stretch),
stylo::AlignContent::FlexEnd => Some(taffy::AlignContent::FlexEnd),
stylo::AlignContent::Center => Some(taffy::AlignContent::Center),
stylo::AlignContent::SpaceBetween => Some(taffy::AlignContent::SpaceBetween),
stylo::AlignContent::SpaceAround => Some(taffy::AlignContent::SpaceAround),
stylo::AlignContent::SpaceEvenly => Some(taffy::AlignContent::SpaceEvenly),
pub(crate) fn content_alignment(input: stylo::ContentDistribution) -> Option<taffy::AlignContent> {
match input.primary().value() {
stylo::AlignFlags::NORMAL => None,
stylo::AlignFlags::AUTO => None,
stylo::AlignFlags::START => Some(taffy::AlignContent::Start),
stylo::AlignFlags::END => Some(taffy::AlignContent::End),
stylo::AlignFlags::FLEX_START => Some(taffy::AlignContent::FlexStart),
stylo::AlignFlags::STRETCH => Some(taffy::AlignContent::Stretch),
stylo::AlignFlags::FLEX_END => Some(taffy::AlignContent::FlexEnd),
stylo::AlignFlags::CENTER => Some(taffy::AlignContent::Center),
stylo::AlignFlags::SPACE_BETWEEN => Some(taffy::AlignContent::SpaceBetween),
stylo::AlignFlags::SPACE_AROUND => Some(taffy::AlignContent::SpaceAround),
stylo::AlignFlags::SPACE_EVENLY => Some(taffy::AlignContent::SpaceEvenly),
// Should never be hit. But no real reason to panic here.
_ => None,
}
}

pub(crate) fn item_alignment(input: stylo::AlignFlags) -> Option<taffy::AlignItems> {
match input.value() {
stylo::AlignFlags::NORMAL => None,
stylo::AlignFlags::AUTO => None,
stylo::AlignFlags::STRETCH => Some(taffy::AlignItems::Stretch),
stylo::AlignFlags::FLEX_START => Some(taffy::AlignItems::FlexStart),
stylo::AlignFlags::FLEX_END => Some(taffy::AlignItems::FlexEnd),
stylo::AlignFlags::START => Some(taffy::AlignItems::Start),
stylo::AlignFlags::END => Some(taffy::AlignItems::End),
stylo::AlignFlags::CENTER => Some(taffy::AlignItems::Center),
stylo::AlignFlags::BASELINE => Some(taffy::AlignItems::Baseline),
// Should never be hit. But no real reason to panic here.
_ => None,
}
}

pub(crate) fn align_items(input: stylo::AlignItems) -> Option<taffy::AlignItems> {
match input {
stylo::AlignItems::Stretch => Some(taffy::AlignItems::Stretch),
stylo::AlignItems::FlexStart => Some(taffy::AlignItems::FlexStart),
stylo::AlignItems::FlexEnd => Some(taffy::AlignItems::FlexEnd),
stylo::AlignItems::Center => Some(taffy::AlignItems::Center),
stylo::AlignItems::Baseline => Some(taffy::AlignItems::Baseline),
}
}

pub(crate) fn align_self(input: stylo::AlignSelf) -> Option<taffy::AlignSelf> {
match input {
stylo::AlignSelf::Auto => None,
stylo::AlignSelf::Stretch => Some(taffy::AlignSelf::Stretch),
stylo::AlignSelf::FlexStart => Some(taffy::AlignSelf::FlexStart),
stylo::AlignSelf::FlexEnd => Some(taffy::AlignSelf::FlexEnd),
stylo::AlignSelf::Center => Some(taffy::AlignSelf::Center),
stylo::AlignSelf::Baseline => Some(taffy::AlignSelf::Baseline),
}
}

// pub(crate) fn justify_items(input: stylo::JustifyItems) -> Option<taffy::JustifyItems> {
// match input {
// stylo::JustifyItems::Stretch => Some(taffy::JustifyItems::Stretch),
// stylo::JustifyItems::FlexStart => Some(taffy::JustifyItems::FlexStart),
// stylo::JustifyItems::FlexEnd => Some(taffy::JustifyItems::FlexEnd),
// stylo::JustifyItems::Center => Some(taffy::JustifyItems::Center),
// stylo::JustifyItems::Baseline => Some(taffy::JustifyItems::Baseline),
// }
// }

// pub(crate) fn justify_self(input: stylo::JustifySelf) -> Option<taffy::JustifySelf> {
// match input {
// stylo::JustifySelf::Auto => None,
// stylo::JustifySelf::Stretch => Some(taffy::JustifySelf::Stretch),
// stylo::JustifySelf::FlexStart => Some(taffy::JustifySelf::FlexStart),
// stylo::JustifySelf::FlexEnd => Some(taffy::JustifySelf::FlexEnd),
// stylo::JustifySelf::Center => Some(taffy::JustifySelf::Center),
// stylo::JustifySelf::Baseline => Some(taffy::JustifySelf::Baseline),
// }
// }

0 comments on commit c69959a

Please sign in to comment.