diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2017-02-16 13:51:15 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-16 13:51:15 -0800 |
commit | 11396b4dd3834d6794bd4e32f30c1df96fc6a01d (patch) | |
tree | 77ee6a376a22cc767af0369208f3c02d22ffea49 | |
parent | 2b254863d0b4ed482942ca11238c661bf487cad5 (diff) | |
parent | 4de480ec9b27740f5e7aa1f7dd63de41bd634bd3 (diff) | |
download | servo-11396b4dd3834d6794bd4e32f30c1df96fc6a01d.tar.gz servo-11396b4dd3834d6794bd4e32f30c1df96fc6a01d.zip |
Auto merge of #15576 - mbrubeck:align, r=Manishearth
stylo: Implement 'align-self' and 'justify-self'
Stylo-only patch to match Gecko property support. Part of #15001. r? @Manishearth
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/15576)
<!-- Reviewable:end -->
-rw-r--r-- | components/style/properties/gecko.mako.rs | 14 | ||||
-rw-r--r-- | components/style/properties/longhand/position.mako.rs | 29 | ||||
-rw-r--r-- | components/style/values/computed/mod.rs | 4 | ||||
-rw-r--r-- | components/style/values/specified/align.rs | 86 | ||||
-rw-r--r-- | components/style/values/specified/mod.rs | 2 |
5 files changed, 124 insertions, 11 deletions
diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index 822646bae7e..722faf11326 100644 --- a/components/style/properties/gecko.mako.rs +++ b/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/components/style/properties/longhand/position.mako.rs b/components/style/properties/longhand/position.mako.rs index 59edcd92672..b169f74c396 100644 --- a/components/style/properties/longhand/position.mako.rs +++ b/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/components/style/values/computed/mod.rs b/components/style/values/computed/mod.rs index b648e50c3c5..3c22ab1a8bb 100644 --- a/components/style/values/computed/mod.rs +++ b/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/components/style/values/specified/align.rs b/components/style/values/specified/align.rs index fe7c779552b..26291f219e6 100644 --- a/components/style/values/specified/align.rs +++ b/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<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + self.0.to_css(dest) + } +} + +impl Parse for AlignJustifySelf { + // auto | normal | stretch | <baseline-position> | + // [ <overflow-position>? && <self-position> ] + fn parse(_: &ParserContext, input: &mut Parser) -> Result<Self, ()> { + // auto | normal | stretch | <baseline-position> + if let Ok(value) = input.try(parse_auto_normal_stretch_baseline) { + return Ok(AlignJustifySelf(value)) + } + // [ <overflow-position>? && <self-position> ] + if let Ok(value) = input.try(parse_overflow_self_position) { + return Ok(AlignJustifySelf(value)) + } + Err(()) + } +} + + +// auto | normal | stretch | <baseline-position> +fn parse_auto_normal_stretch_baseline(input: &mut Parser) -> Result<AlignFlags, ()> { + 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 | <baseline-position> fn parse_normal_or_baseline(input: &mut Parser) -> Result<AlignFlags, ()> { let ident = input.expect_ident()?; @@ -264,3 +315,38 @@ fn parse_overflow_position(input: &mut Parser) -> Result<AlignFlags, ()> { _ => Err(()) } } + +// [ <overflow-position>? && <self-position> ] +fn parse_overflow_self_position(input: &mut Parser) -> Result<AlignFlags, ()> { + // <self-position> followed by optional <overflow-position> + 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) + } + // <overflow-position> followed by required <self-position> + 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(()) +} + +// <self-position> +fn parse_self_position(input: &mut Parser) -> Result<AlignFlags, ()> { + 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/components/style/values/specified/mod.rs b/components/style/values/specified/mod.rs index b9f645e669e..e79d68b7777 100644 --- a/components/style/values/specified/mod.rs +++ b/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}; |