Bug 1906395 - Switch Servo to use Gecko's alignment style implementations. (r=emilio)

Differential Revision: https://phabricator.services.mozilla.com/D216126
This commit is contained in:
Nico Burns 2024-07-12 11:36:16 +00:00
Родитель 6b8e9a64a3
Коммит 12942bcef2
5 изменённых файлов: 122 добавлений и 132 удалений

Просмотреть файл

@ -75,95 +75,55 @@ ${helpers.single_keyword(
affects="layout",
)}
% if engine in "servo":
// FIXME: Update Servo to support the same Syntax as Gecko.
${helpers.single_keyword(
"justify-content",
"flex-start stretch flex-end center space-between space-around",
engines="servo",
servo_pref="layout.flexbox.enabled",
extra_prefixes="webkit",
spec="https://drafts.csswg.org/css-align/#propdef-justify-content",
animation_value_type="discrete",
servo_restyle_damage = "reflow",
affects="layout",
)}
% endif
% if engine == "gecko":
${helpers.predefined_type(
"justify-content",
"JustifyContent",
"specified::JustifyContent(specified::ContentDistribution::normal())",
engines="gecko",
spec="https://drafts.csswg.org/css-align/#propdef-justify-content",
extra_prefixes="webkit",
animation_value_type="discrete",
servo_restyle_damage="reflow",
affects="layout",
)}
% endif
${helpers.predefined_type(
"justify-content",
"JustifyContent",
"specified::JustifyContent(specified::ContentDistribution::normal())",
engines="gecko servo",
servo_pref="layout.flexbox.enabled",
spec="https://drafts.csswg.org/css-align/#propdef-justify-content",
extra_prefixes="webkit",
animation_value_type="discrete",
servo_restyle_damage="reflow",
affects="layout",
)}
% if engine == "servo":
// FIXME: Update Servo to support the same Syntax as Gecko.
${helpers.single_keyword(
"align-content",
"stretch flex-start flex-end center space-between space-around",
engines="servo",
servo_pref="layout.flexbox.enabled",
extra_prefixes="webkit",
spec="https://drafts.csswg.org/css-align/#propdef-align-content",
animation_value_type="discrete",
servo_restyle_damage="reflow",
affects="layout",
)}
${helpers.predefined_type(
"align-content",
"AlignContent",
"specified::AlignContent(specified::ContentDistribution::normal())",
engines="gecko servo",
servo_pref="layout.flexbox.enabled",
spec="https://drafts.csswg.org/css-align/#propdef-align-content",
extra_prefixes="webkit",
animation_value_type="discrete",
servo_restyle_damage="reflow",
affects="layout",
)}
${helpers.single_keyword(
"align-items",
"stretch flex-start flex-end center baseline",
engines="servo",
servo_pref="layout.flexbox.enabled",
extra_prefixes="webkit",
spec="https://drafts.csswg.org/css-flexbox/#align-items-property",
animation_value_type="discrete",
servo_restyle_damage="reflow",
affects="layout",
)}
% endif
% if engine == "gecko":
${helpers.predefined_type(
"align-content",
"AlignContent",
"specified::AlignContent(specified::ContentDistribution::normal())",
engines="gecko",
spec="https://drafts.csswg.org/css-align/#propdef-align-content",
extra_prefixes="webkit",
animation_value_type="discrete",
servo_restyle_damage="reflow",
affects="layout",
)}
${helpers.predefined_type(
"align-items",
"AlignItems",
"specified::AlignItems::normal()",
engines="gecko servo",
servo_pref="layout.flexbox.enabled",
spec="https://drafts.csswg.org/css-align/#propdef-align-items",
extra_prefixes="webkit",
animation_value_type="discrete",
servo_restyle_damage="reflow",
affects="layout",
)}
${helpers.predefined_type(
"align-items",
"AlignItems",
"specified::AlignItems::normal()",
engines="gecko",
spec="https://drafts.csswg.org/css-align/#propdef-align-items",
extra_prefixes="webkit",
animation_value_type="discrete",
servo_restyle_damage="reflow",
affects="layout",
)}
${helpers.predefined_type(
"justify-items",
"JustifyItems",
"computed::JustifyItems::legacy()",
engines="gecko",
spec="https://drafts.csswg.org/css-align/#propdef-justify-items",
animation_value_type="discrete",
affects="layout",
)}
% endif
${helpers.predefined_type(
"justify-items",
"JustifyItems",
"computed::JustifyItems::legacy()",
engines="gecko servo",
servo_pref="layout.grid.enabled",
spec="https://drafts.csswg.org/css-align/#propdef-justify-items",
animation_value_type="discrete",
affects="layout",
)}
// Flex item properties
${helpers.predefined_type(
@ -193,42 +153,27 @@ ${helpers.predefined_type(
)}
// https://drafts.csswg.org/css-align/#align-self-property
% if engine == "servo":
// FIXME: Update Servo to support the same syntax as Gecko.
${helpers.single_keyword(
"align-self",
"auto stretch flex-start flex-end center baseline",
engines="servo",
servo_pref="layout.flexbox.enabled",
extra_prefixes="webkit",
spec="https://drafts.csswg.org/css-flexbox/#propdef-align-self",
animation_value_type="discrete",
servo_restyle_damage = "reflow",
affects="layout",
)}
% endif
% if engine == "gecko":
${helpers.predefined_type(
"align-self",
"AlignSelf",
"specified::AlignSelf(specified::SelfAlignment::auto())",
engines="gecko",
spec="https://drafts.csswg.org/css-align/#align-self-property",
extra_prefixes="webkit",
animation_value_type="discrete",
affects="layout",
)}
${helpers.predefined_type(
"justify-self",
"JustifySelf",
"specified::JustifySelf(specified::SelfAlignment::auto())",
engines="gecko",
spec="https://drafts.csswg.org/css-align/#justify-self-property",
animation_value_type="discrete",
affects="layout",
)}
% endif
${helpers.predefined_type(
"align-self",
"AlignSelf",
"specified::AlignSelf(specified::SelfAlignment::auto())",
engines="gecko servo",
servo_pref="layout.flexbox.enabled",
spec="https://drafts.csswg.org/css-align/#align-self-property",
extra_prefixes="webkit",
animation_value_type="discrete",
affects="layout",
)}
${helpers.predefined_type(
"justify-self",
"JustifySelf",
"specified::JustifySelf(specified::SelfAlignment::auto())",
engines="gecko servo",
servo_pref="layout.grid.enabled",
spec="https://drafts.csswg.org/css-align/#justify-self-property",
animation_value_type="discrete",
affects="layout",
)}
// https://drafts.csswg.org/css-flexbox/#propdef-order
${helpers.predefined_type(

Просмотреть файл

@ -716,7 +716,8 @@
<%helpers:shorthand
name="place-content"
engines="gecko"
engines="gecko servo"
servo_pref="layout.flexbox.enabled",
sub_properties="align-content justify-content"
spec="https://drafts.csswg.org/css-align/#propdef-place-content"
>
@ -771,7 +772,7 @@
<%helpers:shorthand
name="place-self"
engines="gecko"
engines="gecko servo"
sub_properties="align-self justify-self"
spec="https://drafts.csswg.org/css-align/#place-self-property"
>
@ -798,6 +799,7 @@
})
}
#[cfg(feature = "gecko")]
impl<'a> ToCss for LonghandsToSerialize<'a> {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
self.align_self.to_css(dest)?;
@ -808,11 +810,35 @@
Ok(())
}
}
#[cfg(feature = "servo")]
impl<'a> ToCss for LonghandsToSerialize<'a> {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
match (self.align_self, self.justify_self) {
(Some(align_self), Some(justify_self)) => {
align_self.to_css(dest)?;
if align_self.0 != justify_self.0 {
dest.write_char(' ')?;
justify_self.to_css(dest)?;
}
}
(Some(align_self), None) => {
align_self.to_css(dest)?;
}
(None, Some(justify_self)) => {
justify_self.to_css(dest)?;
}
(None, None) => {}
}
Ok(())
}
}
</%helpers:shorthand>
<%helpers:shorthand
name="place-items"
engines="gecko"
engines="gecko servo"
servo_pref="layout.flexbox.enabled",
sub_properties="align-items justify-items"
spec="https://drafts.csswg.org/css-align/#place-items-property"
>
@ -840,6 +866,7 @@
})
}
#[cfg(feature = "gecko")]
impl<'a> ToCss for LonghandsToSerialize<'a> {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
self.align_items.to_css(dest)?;
@ -851,6 +878,22 @@
Ok(())
}
}
#[cfg(feature = "servo")]
impl<'a> ToCss for LonghandsToSerialize<'a> {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
self.align_items.to_css(dest)?;
if let Some(justify_items) = self.justify_items {
if self.align_items.0 != justify_items.0 {
dest.write_char(' ')?;
self.justify_items.to_css(dest)?;
}
}
Ok(())
}
}
</%helpers:shorthand>
// See https://github.com/w3c/csswg-drafts/issues/3525 for the quirks stuff.

Просмотреть файл

@ -36,11 +36,9 @@ use std::cmp;
use std::f32;
use std::ops::{Add, Sub};
#[cfg(feature = "gecko")]
pub use self::align::{
AlignContent, AlignItems, JustifyContent, JustifyItems, SelfAlignment,
};
#[cfg(feature = "gecko")]
pub use self::align::{AlignSelf, JustifySelf};
pub use self::angle::Angle;
pub use self::animation::{
@ -122,7 +120,6 @@ pub use super::specified::ViewportVariant;
pub use super::specified::{BorderStyle, TextDecorationLine};
pub use app_units::Au;
#[cfg(feature = "gecko")]
pub mod align;
pub mod angle;
pub mod animation;

Просмотреть файл

@ -15,6 +15,7 @@ use style_traits::{CssWriter, KeywordsCollectFn, ParseError, SpecifiedValueInfo,
#[derive(
Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq, ToComputedValue, ToResolvedValue, ToShmem,
)]
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
#[repr(C)]
pub struct AlignFlags(u8);
bitflags! {
@ -153,8 +154,8 @@ pub enum AxisDirection {
ToResolvedValue,
ToShmem,
)]
#[repr(C)]
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
#[repr(C)]
pub struct ContentDistribution {
primary: AlignFlags,
// FIXME(https://github.com/w3c/csswg-drafts/issues/1002): This will need to
@ -271,6 +272,7 @@ impl ContentDistribution {
ToResolvedValue,
ToShmem,
)]
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
#[repr(transparent)]
pub struct AlignContent(pub ContentDistribution);
@ -309,6 +311,7 @@ impl SpecifiedValueInfo for AlignContent {
ToResolvedValue,
ToShmem,
)]
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
#[repr(transparent)]
pub struct JustifyContent(pub ContentDistribution);
@ -345,6 +348,7 @@ impl SpecifiedValueInfo for JustifyContent {
ToResolvedValue,
ToShmem,
)]
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
#[repr(transparent)]
pub struct SelfAlignment(pub AlignFlags);
@ -417,6 +421,7 @@ impl SelfAlignment {
ToResolvedValue,
ToShmem,
)]
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
#[repr(C)]
pub struct AlignSelf(pub SelfAlignment);
@ -455,6 +460,7 @@ impl SpecifiedValueInfo for AlignSelf {
ToResolvedValue,
ToShmem,
)]
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
#[repr(C)]
pub struct JustifySelf(pub SelfAlignment);
@ -493,6 +499,7 @@ impl SpecifiedValueInfo for JustifySelf {
ToResolvedValue,
ToShmem,
)]
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
#[repr(C)]
pub struct AlignItems(pub AlignFlags);
@ -545,6 +552,7 @@ impl SpecifiedValueInfo for AlignItems {
///
/// <https://drafts.csswg.org/css-align/#justify-items-property>
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq, ToCss, ToResolvedValue, ToShmem)]
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
#[repr(C)]
pub struct JustifyItems(pub AlignFlags);

Просмотреть файл

@ -25,9 +25,7 @@ use std::ops::Add;
use style_traits::values::specified::AllowedNumericType;
use style_traits::{CssWriter, ParseError, SpecifiedValueInfo, StyleParseErrorKind, ToCss};
#[cfg(feature = "gecko")]
pub use self::align::{AlignContent, AlignItems, AlignSelf, ContentDistribution};
#[cfg(feature = "gecko")]
pub use self::align::{JustifyContent, JustifyItems, JustifySelf, SelfAlignment};
pub use self::angle::{AllowUnitlessZeroAngle, Angle};
pub use self::animation::{
@ -114,7 +112,6 @@ pub use self::ui::CursorImage;
pub use self::ui::{BoolInteger, Cursor, UserSelect};
pub use super::generics::grid::GridTemplateComponent as GenericGridTemplateComponent;
#[cfg(feature = "gecko")]
pub mod align;
pub mod angle;
pub mod animation;