mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
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 -->
This commit is contained in:
commit
11396b4dd3
5 changed files with 124 additions and 11 deletions
|
@ -864,7 +864,7 @@ fn static_assert() {
|
||||||
<% skip_position_longhands = " ".join(x.ident for x in SIDES + GRID_LINES) %>
|
<% skip_position_longhands = " ".join(x.ident for x in SIDES + GRID_LINES) %>
|
||||||
<%self:impl_trait style_struct_name="Position"
|
<%self:impl_trait style_struct_name="Position"
|
||||||
skip_longhands="${skip_position_longhands} z-index box-sizing order align-content
|
skip_longhands="${skip_position_longhands} z-index box-sizing order align-content
|
||||||
justify-content">
|
justify-content align-self justify-self">
|
||||||
% for side in SIDES:
|
% for side in SIDES:
|
||||||
<% impl_split_style_coord("%s" % side.ident,
|
<% impl_split_style_coord("%s" % side.ident,
|
||||||
"mOffset",
|
"mOffset",
|
||||||
|
@ -914,6 +914,18 @@ fn static_assert() {
|
||||||
|
|
||||||
${impl_simple_copy('justify_content', 'mJustifyContent')}
|
${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) {
|
pub fn set_box_sizing(&mut self, v: longhands::box_sizing::computed_value::T) {
|
||||||
use computed_values::box_sizing::T;
|
use computed_values::box_sizing::T;
|
||||||
use gecko_bindings::structs::StyleBoxSizing;
|
use gecko_bindings::structs::StyleBoxSizing;
|
||||||
|
|
|
@ -140,14 +140,27 @@ ${helpers.predefined_type("flex-shrink", "Number",
|
||||||
animatable=True)}
|
animatable=True)}
|
||||||
|
|
||||||
// https://drafts.csswg.org/css-align/#align-self-property
|
// https://drafts.csswg.org/css-align/#align-self-property
|
||||||
// FIXME: We don't support the Gecko value 'normal' yet.
|
% if product == "servo":
|
||||||
${helpers.single_keyword("align-self", "auto stretch flex-start flex-end center baseline",
|
// FIXME: Update Servo to support the same syntax as Gecko.
|
||||||
need_clone=True,
|
${helpers.single_keyword("align-self", "auto stretch flex-start flex-end center baseline",
|
||||||
extra_prefixes="webkit",
|
need_clone=True,
|
||||||
extra_gecko_values="normal",
|
extra_prefixes="webkit",
|
||||||
gecko_constant_prefix="NS_STYLE_ALIGN",
|
spec="https://drafts.csswg.org/css-flexbox/#propdef-align-self",
|
||||||
spec="https://drafts.csswg.org/css-flexbox/#propdef-align-self",
|
animatable=False)}
|
||||||
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
|
// https://drafts.csswg.org/css-flexbox/#propdef-order
|
||||||
<%helpers:longhand name="order" animatable="True" extra_prefixes="webkit"
|
<%helpers:longhand name="order" animatable="True" extra_prefixes="webkit"
|
||||||
|
|
|
@ -17,7 +17,7 @@ pub use self::image::{AngleOrCorner, EndingShape as GradientShape, Gradient, Gra
|
||||||
pub use self::image::{LengthOrKeyword, LengthOrPercentageOrKeyword};
|
pub use self::image::{LengthOrKeyword, LengthOrPercentageOrKeyword};
|
||||||
pub use super::{Auto, Either, None_};
|
pub use super::{Auto, Either, None_};
|
||||||
#[cfg(feature = "gecko")]
|
#[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::{Angle, BorderStyle, GridLine, Time, UrlOrNone};
|
||||||
pub use super::specified::url::UrlExtraData;
|
pub use super::specified::url::UrlExtraData;
|
||||||
pub use self::length::{CalcLengthOrPercentage, Length, LengthOrNumber, LengthOrPercentage, LengthOrPercentageOrAuto};
|
pub use self::length::{CalcLengthOrPercentage, Length, LengthOrNumber, LengthOrPercentage, LengthOrPercentageOrAuto};
|
||||||
|
@ -124,6 +124,8 @@ impl ToComputedValue for specified::CSSColor {
|
||||||
|
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
impl ComputedValueAsSpecified for specified::AlignJustifyContent {}
|
impl ComputedValueAsSpecified for specified::AlignJustifyContent {}
|
||||||
|
#[cfg(feature = "gecko")]
|
||||||
|
impl ComputedValueAsSpecified for specified::AlignJustifySelf {}
|
||||||
impl ComputedValueAsSpecified for specified::BorderStyle {}
|
impl ComputedValueAsSpecified for specified::BorderStyle {}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone, Copy)]
|
#[derive(Debug, PartialEq, Clone, Copy)]
|
||||||
|
|
|
@ -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>
|
// normal | <baseline-position>
|
||||||
fn parse_normal_or_baseline(input: &mut Parser) -> Result<AlignFlags, ()> {
|
fn parse_normal_or_baseline(input: &mut Parser) -> Result<AlignFlags, ()> {
|
||||||
let ident = input.expect_ident()?;
|
let ident = input.expect_ident()?;
|
||||||
|
@ -264,3 +315,38 @@ fn parse_overflow_position(input: &mut Parser) -> Result<AlignFlags, ()> {
|
||||||
_ => Err(())
|
_ => 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(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ use super::computed::{ComputedValueAsSpecified, Context, ToComputedValue};
|
||||||
use super::computed::Shadow as ComputedShadow;
|
use super::computed::Shadow as ComputedShadow;
|
||||||
|
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
pub use self::align::AlignJustifyContent;
|
pub use self::align::{AlignJustifyContent, AlignJustifySelf};
|
||||||
pub use self::grid::GridLine;
|
pub use self::grid::GridLine;
|
||||||
pub use self::image::{AngleOrCorner, ColorStop, EndingShape as GradientEndingShape, Gradient};
|
pub use self::image::{AngleOrCorner, ColorStop, EndingShape as GradientEndingShape, Gradient};
|
||||||
pub use self::image::{GradientKind, HorizontalDirection, Image, LengthOrKeyword, LengthOrPercentageOrKeyword};
|
pub use self::image::{GradientKind, HorizontalDirection, Image, LengthOrKeyword, LengthOrPercentageOrKeyword};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue