style: Fix the position of the <overflow-position> in content distribution shorthands, and remove fallback.

MozReview-Commit-ID: 4rPICzZ5gMn
This commit is contained in:
Emilio Cobos Álvarez 2018-01-24 17:02:08 +01:00
parent fd47a93b9c
commit 4c773a1424
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
2 changed files with 34 additions and 99 deletions

View file

@ -615,25 +615,17 @@
<%helpers:shorthand name="place-content" sub_properties="align-content justify-content" <%helpers:shorthand name="place-content" sub_properties="align-content justify-content"
spec="https://drafts.csswg.org/css-align/#propdef-place-content" spec="https://drafts.csswg.org/css-align/#propdef-place-content"
products="gecko"> products="gecko">
use values::specified::align::{AlignContent, JustifyContent, ContentDistribution, FallbackAllowed, AxisDirection}; use values::specified::align::{AlignContent, JustifyContent, ContentDistribution, AxisDirection};
pub fn parse_value<'i, 't>( pub fn parse_value<'i, 't>(
_: &ParserContext, _: &ParserContext,
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Longhands, ParseError<'i>> { ) -> Result<Longhands, ParseError<'i>> {
let align_content = let align_content =
ContentDistribution::parse( ContentDistribution::parse(input, AxisDirection::Block)?;
input,
FallbackAllowed::No,
AxisDirection::Inline,
)?;
let justify_content = input.try(|input| { let justify_content = input.try(|input| {
ContentDistribution::parse( ContentDistribution::parse(input, AxisDirection::Inline)
input,
FallbackAllowed::No,
AxisDirection::Block,
)
}); });
let justify_content = match justify_content { let justify_content = match justify_content {

View file

@ -105,11 +105,6 @@ impl ToCss for AlignFlags {
} }
} }
/// Mask for a single AlignFlags value.
const ALIGN_ALL_BITS: u16 = structs::NS_STYLE_ALIGN_ALL_BITS as u16;
/// Number of bits to shift a fallback alignment.
const ALIGN_ALL_SHIFT: u32 = structs::NS_STYLE_ALIGN_ALL_SHIFT;
/// An axis direction, either inline (for the `justify` properties) or block, /// An axis direction, either inline (for the `justify` properties) or block,
/// (for the `align` properties). /// (for the `align` properties).
#[derive(Clone, Copy, PartialEq)] #[derive(Clone, Copy, PartialEq)]
@ -120,28 +115,15 @@ pub enum AxisDirection {
Inline, Inline,
} }
/// Whether fallback is allowed in align-content / justify-content parsing.
///
/// This is used for the place-content shorthand, until the resolutions from [1]
/// are specified.
///
/// [1]: https://github.com/w3c/csswg-drafts/issues/1002
#[derive(Clone, Copy, PartialEq)]
pub enum FallbackAllowed {
/// Allow fallback alignment.
Yes,
/// Don't allow fallback alignment.
No,
}
/// Shared value for the `align-content` and `justify-content` properties. /// Shared value for the `align-content` and `justify-content` properties.
/// ///
/// <https://drafts.csswg.org/css-align/#content-distribution> /// <https://drafts.csswg.org/css-align/#content-distribution>
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq, ToComputedValue)] #[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq, ToComputedValue, ToCss)]
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))] #[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
pub struct ContentDistribution { pub struct ContentDistribution {
primary: AlignFlags, primary: AlignFlags,
fallback: AlignFlags, // FIXME(https://github.com/w3c/csswg-drafts/issues/1002): This will need to
// accept fallback alignment, eventually.
} }
impl ContentDistribution { impl ContentDistribution {
@ -151,43 +133,30 @@ impl ContentDistribution {
Self::new(AlignFlags::NORMAL) Self::new(AlignFlags::NORMAL)
} }
/// Construct a value with no fallback. /// The initial value 'normal'
#[inline] #[inline]
pub fn new(flags: AlignFlags) -> Self { pub fn new(primary: AlignFlags) -> Self {
Self::with_fallback(flags, AlignFlags::empty()) Self { primary }
}
/// Construct a value including a fallback alignment.
///
/// <https://drafts.csswg.org/css-align/#fallback-alignment>
#[inline]
pub fn with_fallback(primary: AlignFlags, fallback: AlignFlags) -> Self {
Self { primary, fallback }
} }
fn from_bits(bits: u16) -> Self { fn from_bits(bits: u16) -> Self {
let primary = Self {
AlignFlags::from_bits_truncate((bits & ALIGN_ALL_BITS) as u8); primary: AlignFlags::from_bits_truncate(bits as u8)
let fallback = }
AlignFlags::from_bits_truncate((bits >> ALIGN_ALL_SHIFT) as u8);
Self::with_fallback(primary, fallback)
} }
fn as_bits(&self) -> u16 { fn as_bits(&self) -> u16 {
self.primary.bits() as u16 | self.primary.bits() as u16
((self.fallback.bits() as u16) << ALIGN_ALL_SHIFT)
} }
/// Returns whether this value is valid for both axis directions. /// Returns whether this value is valid for both axis directions.
pub fn is_valid_on_both_axes(&self) -> bool { pub fn is_valid_on_both_axes(&self) -> bool {
if self.primary.intersects(AlignFlags::BASELINE | AlignFlags::LAST_BASELINE) || if self.primary.intersects(AlignFlags::BASELINE | AlignFlags::LAST_BASELINE) {
self.fallback.intersects(AlignFlags::BASELINE | AlignFlags::LAST_BASELINE) {
// <baseline-position> is only allowed on the block axis. // <baseline-position> is only allowed on the block axis.
return false; return false;
} }
if self.primary.intersects(AlignFlags::LEFT | AlignFlags::RIGHT) || if self.primary.intersects(AlignFlags::LEFT | AlignFlags::RIGHT) {
self.fallback.intersects(AlignFlags::LEFT | AlignFlags::RIGHT) {
// left | right are only allowed on the inline axis. // left | right are only allowed on the inline axis.
return false; return false;
} }
@ -201,24 +170,15 @@ impl ContentDistribution {
self.primary self.primary
} }
/// The fallback alignment
#[inline]
pub fn fallback(self) -> AlignFlags {
self.fallback
}
/// Whether this value has extra flags. /// Whether this value has extra flags.
#[inline] #[inline]
pub fn has_extra_flags(self) -> bool { pub fn has_extra_flags(self) -> bool {
self.primary().intersects(AlignFlags::FLAG_BITS) || self.primary().intersects(AlignFlags::FLAG_BITS)
self.fallback().intersects(AlignFlags::FLAG_BITS)
} }
/// Parse a value for align-content / justify-content, optionally allowing /// Parse a value for align-content / justify-content.
/// fallback.
pub fn parse<'i, 't>( pub fn parse<'i, 't>(
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
fallback_allowed: FallbackAllowed,
axis: AxisDirection, axis: AxisDirection,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
// Try to parse normal first // Try to parse normal first
@ -233,42 +193,27 @@ impl ContentDistribution {
} }
} }
// <content-distribution> followed by optional <*-position> // <content-distribution>
if let Ok(value) = input.try(|input| parse_content_distribution(input)) { if let Ok(value) = input.try(parse_content_distribution) {
if fallback_allowed == FallbackAllowed::Yes { return Ok(ContentDistribution::new(value));
if let Ok(fallback) = input.try(|input| parse_overflow_content_position(input, axis)) {
return Ok(ContentDistribution::with_fallback(value, fallback))
}
}
return Ok(ContentDistribution::new(value))
} }
// <*-position> followed by optional <content-distribution> // <overflow-position>? <content-position>
let fallback = parse_overflow_content_position(input, axis)?; let overflow_position =
if fallback_allowed == FallbackAllowed::Yes { input.try(parse_overflow_position)
if let Ok(value) = input.try(|input| parse_content_distribution(input)) { .unwrap_or(AlignFlags::empty());
return Ok(ContentDistribution::with_fallback(value, fallback))
}
}
Ok(ContentDistribution::new(fallback)) let content_position = try_match_ident_ignore_ascii_case! { input,
} "start" => AlignFlags::START,
} "end" => AlignFlags::END,
"flex-start" => AlignFlags::FLEX_START,
"flex-end" => AlignFlags::FLEX_END,
"center" => AlignFlags::CENTER,
"left" if axis == AxisDirection::Inline => AlignFlags::LEFT,
"right" if axis == AxisDirection::Inline => AlignFlags::RIGHT,
};
impl ToCss for ContentDistribution { Ok(ContentDistribution::new(content_position | overflow_position))
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
where
W: Write,
{
self.primary().to_css(dest)?;
match self.fallback() {
AlignFlags::AUTO => {}
fallback => {
dest.write_str(" ")?;
fallback.to_css(dest)?;
}
}
Ok(())
} }
} }
@ -285,7 +230,6 @@ impl Parse for AlignContent {
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
Ok(AlignContent(ContentDistribution::parse( Ok(AlignContent(ContentDistribution::parse(
input, input,
FallbackAllowed::Yes,
AxisDirection::Block, AxisDirection::Block,
)?)) )?))
} }
@ -318,7 +262,6 @@ impl Parse for JustifyContent {
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
Ok(JustifyContent(ContentDistribution::parse( Ok(JustifyContent(ContentDistribution::parse(
input, input,
FallbackAllowed::Yes,
AxisDirection::Inline, AxisDirection::Inline,
)?)) )?))
} }