style: Rename justify-items: auto to legacy.

Bug: 1363875
Reviewed-by: mats,xidorn
MozReview-Commit-ID: Jfwib2XDmSw
This commit is contained in:
Emilio Cobos Álvarez 2018-04-19 17:50:32 +02:00
parent 625634a027
commit 593e4e4c9e
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
5 changed files with 74 additions and 71 deletions

View file

@ -1806,7 +1806,7 @@ fn static_assert() {
} }
pub fn set_computed_justify_items(&mut self, v: values::specified::JustifyItems) { pub fn set_computed_justify_items(&mut self, v: values::specified::JustifyItems) {
debug_assert_ne!(v.0, ::values::specified::align::AlignFlags::AUTO); debug_assert_ne!(v.0, ::values::specified::align::AlignFlags::LEGACY);
self.gecko.mJustifyItems = v.into(); self.gecko.mJustifyItems = v.into();
} }

View file

@ -118,11 +118,13 @@ ${helpers.single_keyword("flex-wrap", "nowrap wrap wrap-reverse",
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
impl_align_conversions!(::values::specified::align::AlignItems); impl_align_conversions!(::values::specified::align::AlignItems);
${helpers.predefined_type(name="justify-items", ${helpers.predefined_type(
type="JustifyItems", name="justify-items",
initial_value="computed::JustifyItems::auto()", type="JustifyItems",
spec="https://drafts.csswg.org/css-align/#propdef-justify-items", initial_value="computed::JustifyItems::legacy()",
animation_value_type="discrete")} spec="https://drafts.csswg.org/css-align/#propdef-justify-items",
animation_value_type="discrete",
)}
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
impl_align_conversions!(::values::specified::align::JustifyItems); impl_align_conversions!(::values::specified::align::JustifyItems);

View file

@ -673,17 +673,15 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> {
} }
} }
/// Resolves "justify-items: auto" based on the inherited style if needed to /// Resolves "justify-items: legacy" based on the inherited style if needed
/// comply with: /// to comply with:
/// ///
/// <https://drafts.csswg.org/css-align/#valdef-justify-items-legacy> /// <https://drafts.csswg.org/css-align/#valdef-justify-items-legacy>
///
/// (Note that "auto" is being renamed to "legacy")
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
fn adjust_for_justify_items(&mut self) { fn adjust_for_justify_items(&mut self) {
use values::specified::align; use values::specified::align;
let justify_items = self.style.get_position().clone_justify_items(); let justify_items = self.style.get_position().clone_justify_items();
if justify_items.specified.0 != align::AlignFlags::AUTO { if justify_items.specified.0 != align::AlignFlags::LEGACY {
return; return;
} }

View file

@ -20,10 +20,10 @@ pub use super::specified::{AlignSelf, JustifySelf};
/// In particular, `justify-items` is a reset property, so we ought to be able /// In particular, `justify-items` is a reset property, so we ought to be able
/// to share its computed representation across elements as long as they match /// to share its computed representation across elements as long as they match
/// the same rules. Except that it's not true if the specified value for /// the same rules. Except that it's not true if the specified value for
/// `justify-items` is `auto` and the computed value of the parent has the /// `justify-items` is `legacy` and the computed value of the parent has the
/// `legacy` modifier. /// `legacy` modifier.
/// ///
/// So instead of computing `auto` "normally" looking at get_parent_position(), /// So instead of computing `legacy` "normally" looking at get_parent_position(),
/// marking it as uncacheable, we carry the specified value around and handle /// marking it as uncacheable, we carry the specified value around and handle
/// the special case in `StyleAdjuster` instead, only when the result of the /// the special case in `StyleAdjuster` instead, only when the result of the
/// computation would vary. /// computation would vary.
@ -35,18 +35,21 @@ pub use super::specified::{AlignSelf, JustifySelf};
/// See the discussion in https://bugzil.la/1384542. /// See the discussion in https://bugzil.la/1384542.
#[derive(Clone, Copy, Debug, Eq, PartialEq, ToCss)] #[derive(Clone, Copy, Debug, Eq, PartialEq, ToCss)]
pub struct JustifyItems { pub struct JustifyItems {
/// The specified value for the property. Can contain `auto`. /// The specified value for the property. Can contain the bare `legacy`
/// keyword.
#[css(skip)] #[css(skip)]
pub specified: specified::JustifyItems, pub specified: specified::JustifyItems,
/// The computed value for the property. Cannot contain `auto`. /// The computed value for the property. Cannot contain the bare `legacy`
/// keyword, but note that it could contain it in combination with other
/// keywords like `left`, `right` or `center`.
pub computed: specified::JustifyItems, pub computed: specified::JustifyItems,
} }
impl JustifyItems { impl JustifyItems {
/// Returns the `auto` value. /// Returns the `legacy` value.
pub fn auto() -> Self { pub fn legacy() -> Self {
Self { Self {
specified: specified::JustifyItems::auto(), specified: specified::JustifyItems::legacy(),
computed: specified::JustifyItems::normal(), computed: specified::JustifyItems::normal(),
} }
} }
@ -59,13 +62,13 @@ impl ToComputedValue for specified::JustifyItems {
fn to_computed_value(&self, _context: &Context) -> JustifyItems { fn to_computed_value(&self, _context: &Context) -> JustifyItems {
use values::specified::align; use values::specified::align;
let specified = *self; let specified = *self;
let computed = if self.0 != align::AlignFlags::AUTO { let computed = if self.0 != align::AlignFlags::LEGACY {
*self *self
} else { } else {
// If the inherited value of `justify-items` includes the // If the inherited value of `justify-items` includes the
// `legacy` keyword, `auto` computes to the inherited value, // `legacy` keyword, `legacy` computes to the inherited value, but
// but we assume it computes to `normal`, and handle that // we assume it computes to `normal`, and handle that special-case
// special-case in StyleAdjuster. // in StyleAdjuster.
Self::normal() Self::normal()
}; };

View file

@ -9,9 +9,8 @@
use cssparser::Parser; use cssparser::Parser;
use gecko_bindings::structs; use gecko_bindings::structs;
use parser::{Parse, ParserContext}; use parser::{Parse, ParserContext};
use selectors::parser::SelectorParseErrorKind;
use std::fmt::{self, Write}; use std::fmt::{self, Write};
use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss}; use style_traits::{CssWriter, ParseError, ToCss};
bitflags! { bitflags! {
/// Constants shared by multiple CSS Box Alignment properties /// Constants shared by multiple CSS Box Alignment properties
@ -81,14 +80,26 @@ impl ToCss for AlignFlags {
where where
W: Write, W: Write,
{ {
match *self & AlignFlags::FLAG_BITS { let extra_flags = *self & AlignFlags::FLAG_BITS;
AlignFlags::LEGACY => dest.write_str("legacy ")?, let value = self.value();
match extra_flags {
AlignFlags::LEGACY => {
dest.write_str("legacy")?;
if value.is_empty() {
return Ok(());
}
dest.write_char(' ')?;
},
AlignFlags::SAFE => dest.write_str("safe ")?, AlignFlags::SAFE => dest.write_str("safe ")?,
// Don't serialize "unsafe", since it's the default. // Don't serialize "unsafe", since it's the default.
_ => {}, AlignFlags::UNSAFE => {},
_ => {
debug_assert_eq!(extra_flags, AlignFlags::empty());
},
} }
dest.write_str(match self.value() { dest.write_str(match value {
AlignFlags::AUTO => "auto", AlignFlags::AUTO => "auto",
AlignFlags::NORMAL => "normal", AlignFlags::NORMAL => "normal",
AlignFlags::START => "start", AlignFlags::START => "start",
@ -436,10 +447,10 @@ impl Parse for AlignItems {
pub struct JustifyItems(pub AlignFlags); pub struct JustifyItems(pub AlignFlags);
impl JustifyItems { impl JustifyItems {
/// The initial value 'auto' /// The initial value 'legacy'
#[inline] #[inline]
pub fn auto() -> Self { pub fn legacy() -> Self {
JustifyItems(AlignFlags::AUTO) JustifyItems(AlignFlags::LEGACY)
} }
/// The value 'normal' /// The value 'normal'
@ -462,24 +473,12 @@ impl Parse for JustifyItems {
return Ok(JustifyItems(baseline)); return Ok(JustifyItems(baseline));
} }
// auto | normal | stretch // normal | stretch
// if let Ok(value) = input.try(parse_normal_stretch) {
// FIXME(emilio): auto is no longer a keyword in the current spec, and
// has been renamed to legacy, but that needs different changes because
// right now it's the initial value for both style systems, and has that
// weird behavior of "inheriting" into descendants.
//
// Fix this in both.
//
// See also:
// https://bugs.webkit.org/show_bug.cgi?id=172711
// https://bugs.chromium.org/p/chromium/issues/detail?id=726148
//
if let Ok(value) = input.try(parse_auto_normal_stretch) {
return Ok(JustifyItems(value)); return Ok(JustifyItems(value));
} }
// [ legacy || [ left | right | center ] ] // legacy | [ legacy && [ left | right | center ] ]
if let Ok(value) = input.try(parse_legacy) { if let Ok(value) = input.try(parse_legacy) {
return Ok(JustifyItems(value)); return Ok(JustifyItems(value));
} }
@ -567,29 +566,30 @@ fn parse_self_position<'i, 't>(
}) })
} }
// [ legacy && [ left | right | center ] ] fn parse_left_right_center<'i, 't>(
fn parse_legacy<'i, 't>(input: &mut Parser<'i, 't>) -> Result<AlignFlags, ParseError<'i>> { input: &mut Parser<'i, 't>,
let a_location = input.current_source_location(); ) -> Result<AlignFlags, ParseError<'i>> {
let a = input.expect_ident()?.clone(); Ok(try_match_ident_ignore_ascii_case! { input,
let b_location = input.current_source_location(); "left" => AlignFlags::LEFT,
let b = input.expect_ident()?; "right" => AlignFlags::RIGHT,
if a.eq_ignore_ascii_case("legacy") { "center" => AlignFlags::CENTER,
(match_ignore_ascii_case! { &b, })
"left" => Ok(AlignFlags::LEGACY | AlignFlags::LEFT), }
"right" => Ok(AlignFlags::LEGACY | AlignFlags::RIGHT),
"center" => Ok(AlignFlags::LEGACY | AlignFlags::CENTER), // legacy | [ legacy && [ left | right | center ] ]
_ => Err(()) fn parse_legacy<'i, 't>(input: &mut Parser<'i, 't>) -> Result<AlignFlags, ParseError<'i>> {
}).map_err(|()| { let flags = try_match_ident_ignore_ascii_case! { input,
b_location.new_custom_error(SelectorParseErrorKind::UnexpectedIdent(b.clone())) "legacy" => {
}) let flags = input.try(parse_left_right_center)
} else if b.eq_ignore_ascii_case("legacy") { .unwrap_or(AlignFlags::empty());
(match_ignore_ascii_case! { &a,
"left" => Ok(AlignFlags::LEGACY | AlignFlags::LEFT), return Ok(AlignFlags::LEGACY | flags)
"right" => Ok(AlignFlags::LEGACY | AlignFlags::RIGHT), }
"center" => Ok(AlignFlags::LEGACY | AlignFlags::CENTER), "left" => AlignFlags::LEFT,
_ => Err(()) "right" => AlignFlags::RIGHT,
}).map_err(|()| a_location.new_custom_error(SelectorParseErrorKind::UnexpectedIdent(a))) "center" => AlignFlags::CENTER,
} else { };
Err(a_location.new_custom_error(StyleParseErrorKind::UnspecifiedError))
} input.expect_ident_matching("legacy")?;
Ok(AlignFlags::LEGACY | flags)
} }