From 3a75ed1ba5f812fec21dfed812188f0bf605f8b1 Mon Sep 17 00:00:00 2001 From: Matt Brubeck Date: Thu, 16 Feb 2017 13:51:15 -0800 Subject: [PATCH] servo: Merge #15576 - stylo: Implement 'align-self' and 'justify-self' (from mbrubeck:align); r=Manishearth Stylo-only patch to match Gecko property support. Part of #15001. r? @Manishearth Source-Repo: https://github.com/servo/servo Source-Revision: 11396b4dd3834d6794bd4e32f30c1df96fc6a01d --HG-- extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear extra : subtree_revision : 2b17ff4d7a75d9fcd60f84a14f1178a102f0c13d --- .../components/style/properties/gecko.mako.rs | 14 ++- .../properties/longhand/position.mako.rs | 29 +++++-- servo/components/style/values/computed/mod.rs | 4 +- .../style/values/specified/align.rs | 86 +++++++++++++++++++ .../components/style/values/specified/mod.rs | 2 +- 5 files changed, 124 insertions(+), 11 deletions(-) diff --git a/servo/components/style/properties/gecko.mako.rs b/servo/components/style/properties/gecko.mako.rs index 822646bae7ee..722faf11326e 100644 --- a/servo/components/style/properties/gecko.mako.rs +++ b/servo/components/style/properties/gecko.mako.rs @@ -864,7 +864,7 @@ fn static_assert() { <% skip_position_longhands = " ".join(x.ident for x in SIDES + GRID_LINES) %> <%self:impl_trait style_struct_name="Position" skip_longhands="${skip_position_longhands} z-index box-sizing order align-content - justify-content"> + justify-content align-self justify-self"> % for side in SIDES: <% impl_split_style_coord("%s" % side.ident, "mOffset", @@ -914,6 +914,18 @@ fn static_assert() { ${impl_simple_copy('justify_content', 'mJustifyContent')} + pub fn set_align_self(&mut self, v: longhands::align_self::computed_value::T) { + self.gecko.mAlignSelf = v.0.bits() + } + + ${impl_simple_copy('align_self', 'mAlignSelf')} + + pub fn set_justify_self(&mut self, v: longhands::justify_self::computed_value::T) { + self.gecko.mJustifySelf = v.0.bits() + } + + ${impl_simple_copy('justify_self', 'mJustifySelf')} + pub fn set_box_sizing(&mut self, v: longhands::box_sizing::computed_value::T) { use computed_values::box_sizing::T; use gecko_bindings::structs::StyleBoxSizing; diff --git a/servo/components/style/properties/longhand/position.mako.rs b/servo/components/style/properties/longhand/position.mako.rs index 59edcd926729..b169f74c3965 100644 --- a/servo/components/style/properties/longhand/position.mako.rs +++ b/servo/components/style/properties/longhand/position.mako.rs @@ -140,14 +140,27 @@ ${helpers.predefined_type("flex-shrink", "Number", animatable=True)} // https://drafts.csswg.org/css-align/#align-self-property -// FIXME: We don't support the Gecko value 'normal' yet. -${helpers.single_keyword("align-self", "auto stretch flex-start flex-end center baseline", - need_clone=True, - extra_prefixes="webkit", - extra_gecko_values="normal", - gecko_constant_prefix="NS_STYLE_ALIGN", - spec="https://drafts.csswg.org/css-flexbox/#propdef-align-self", - animatable=False)} +% if product == "servo": + // FIXME: Update Servo to support the same syntax as Gecko. + ${helpers.single_keyword("align-self", "auto stretch flex-start flex-end center baseline", + need_clone=True, + extra_prefixes="webkit", + spec="https://drafts.csswg.org/css-flexbox/#propdef-align-self", + animatable=False)} +% else: + ${helpers.predefined_type(name="align-self", + type="AlignJustifySelf", + initial_value="specified::AlignJustifySelf::auto()", + spec="https://drafts.csswg.org/css-align/#align-self-property", + extra_prefixes="webkit", + animatable=False)} + + ${helpers.predefined_type(name="justify-self", + type="AlignJustifySelf", + initial_value="specified::AlignJustifySelf::auto()", + spec="https://drafts.csswg.org/css-align/#justify-self-property", + animatable=False)} +% endif // https://drafts.csswg.org/css-flexbox/#propdef-order <%helpers:longhand name="order" animatable="True" extra_prefixes="webkit" diff --git a/servo/components/style/values/computed/mod.rs b/servo/components/style/values/computed/mod.rs index b648e50c3c55..3c22ab1a8bb0 100644 --- a/servo/components/style/values/computed/mod.rs +++ b/servo/components/style/values/computed/mod.rs @@ -17,7 +17,7 @@ pub use self::image::{AngleOrCorner, EndingShape as GradientShape, Gradient, Gra pub use self::image::{LengthOrKeyword, LengthOrPercentageOrKeyword}; pub use super::{Auto, Either, None_}; #[cfg(feature = "gecko")] -pub use super::specified::AlignJustifyContent; +pub use super::specified::{AlignJustifyContent, AlignJustifySelf}; pub use super::specified::{Angle, BorderStyle, GridLine, Time, UrlOrNone}; pub use super::specified::url::UrlExtraData; pub use self::length::{CalcLengthOrPercentage, Length, LengthOrNumber, LengthOrPercentage, LengthOrPercentageOrAuto}; @@ -124,6 +124,8 @@ impl ToComputedValue for specified::CSSColor { #[cfg(feature = "gecko")] impl ComputedValueAsSpecified for specified::AlignJustifyContent {} +#[cfg(feature = "gecko")] +impl ComputedValueAsSpecified for specified::AlignJustifySelf {} impl ComputedValueAsSpecified for specified::BorderStyle {} #[derive(Debug, PartialEq, Clone, Copy)] diff --git a/servo/components/style/values/specified/align.rs b/servo/components/style/values/specified/align.rs index fe7c779552b0..26291f219e68 100644 --- a/servo/components/style/values/specified/align.rs +++ b/servo/components/style/values/specified/align.rs @@ -200,6 +200,57 @@ impl Parse for AlignJustifyContent { } } +/// Value of the `align-self` or `justify-self` property. +/// +/// https://drafts.csswg.org/css-align/#self-alignment +#[derive(Copy, Clone, Debug, Eq, PartialEq)] +pub struct AlignJustifySelf(pub AlignFlags); + +impl AlignJustifySelf { + /// The initial value 'auto' + #[inline] + pub fn auto() -> Self { + AlignJustifySelf(ALIGN_AUTO) + } +} + +no_viewport_percentage!(AlignJustifySelf); + +impl ToCss for AlignJustifySelf { + fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + self.0.to_css(dest) + } +} + +impl Parse for AlignJustifySelf { + // auto | normal | stretch | | + // [ ? && ] + fn parse(_: &ParserContext, input: &mut Parser) -> Result { + // auto | normal | stretch | + if let Ok(value) = input.try(parse_auto_normal_stretch_baseline) { + return Ok(AlignJustifySelf(value)) + } + // [ ? && ] + if let Ok(value) = input.try(parse_overflow_self_position) { + return Ok(AlignJustifySelf(value)) + } + Err(()) + } +} + + +// auto | normal | stretch | +fn parse_auto_normal_stretch_baseline(input: &mut Parser) -> Result { + let ident = input.expect_ident()?; + match_ignore_ascii_case! { ident, + "auto" => Ok(ALIGN_AUTO), + "normal" => Ok(ALIGN_NORMAL), + "stretch" => Ok(ALIGN_STRETCH), + "baseline" => Ok(ALIGN_BASELINE), + _ => Err(()) + } +} + // normal | fn parse_normal_or_baseline(input: &mut Parser) -> Result { let ident = input.expect_ident()?; @@ -264,3 +315,38 @@ fn parse_overflow_position(input: &mut Parser) -> Result { _ => Err(()) } } + +// [ ? && ] +fn parse_overflow_self_position(input: &mut Parser) -> Result { + // followed by optional + if let Ok(mut self_position) = input.try(|input| parse_self_position(input)) { + if let Ok(overflow) = input.try(|input| parse_overflow_position(input)) { + self_position |= overflow; + } + return Ok(self_position) + } + // followed by required + if let Ok(overflow) = input.try(|input| parse_overflow_position(input)) { + if let Ok(self_position) = input.try(|input| parse_self_position(input)) { + return Ok(overflow | self_position) + } + } + return Err(()) +} + +// +fn parse_self_position(input: &mut Parser) -> Result { + let ident = input.expect_ident()?; + match_ignore_ascii_case! { ident, + "start" => Ok(ALIGN_START), + "end" => Ok(ALIGN_END), + "flex-start" => Ok(ALIGN_FLEX_START), + "flex-end" => Ok(ALIGN_FLEX_END), + "center" => Ok(ALIGN_CENTER), + "left" => Ok(ALIGN_LEFT), + "right" => Ok(ALIGN_RIGHT), + "self-start" => Ok(ALIGN_SELF_START), + "self-end" => Ok(ALIGN_SELF_END), + _ => Err(()) + } +} diff --git a/servo/components/style/values/specified/mod.rs b/servo/components/style/values/specified/mod.rs index b9f645e669e7..e79d68b77774 100644 --- a/servo/components/style/values/specified/mod.rs +++ b/servo/components/style/values/specified/mod.rs @@ -21,7 +21,7 @@ use super::computed::{ComputedValueAsSpecified, Context, ToComputedValue}; use super::computed::Shadow as ComputedShadow; #[cfg(feature = "gecko")] -pub use self::align::AlignJustifyContent; +pub use self::align::{AlignJustifyContent, AlignJustifySelf}; pub use self::grid::GridLine; pub use self::image::{AngleOrCorner, ColorStop, EndingShape as GradientEndingShape, Gradient}; pub use self::image::{GradientKind, HorizontalDirection, Image, LengthOrKeyword, LengthOrPercentageOrKeyword};