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
This commit is contained in:
Matt Brubeck 2017-02-16 13:51:15 -08:00
parent 385b306f91
commit 3a75ed1ba5
5 changed files with 124 additions and 11 deletions

View File

@ -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;

View File

@ -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"

View File

@ -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)]

View File

@ -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(())
}
}

View File

@ -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};