Auto merge of #20210 - emilio:justify-items-kinda-sucks, r=Manishearth

style: Add a comment about the weird setup for justify-items.

And derive ToCss while at it.

<!-- 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/20210)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2018-03-06 05:29:17 -05:00 committed by GitHub
commit 226d9a5b0e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -6,8 +6,6 @@
//!
//! https://drafts.csswg.org/css-align/
use std::fmt;
use style_traits::{CssWriter, ToCss};
use values::computed::{Context, ToComputedValue};
use values::specified;
@ -17,23 +15,33 @@ pub use super::specified::{AlignSelf, JustifySelf};
/// The computed value for the `justify-items` property.
///
/// Need to carry around both the specified and computed value to handle the
/// special legacy keyword. Sigh.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
/// special legacy keyword without destroying style sharing.
///
/// 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
/// 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
/// `legacy` modifier.
///
/// So instead of computing `auto` "normally" looking at get_parent_position(),
/// marking it as uncacheable, we carry the specified value around and handle
/// the special case in `StyleAdjuster` instead, only when the result of the
/// computation would vary.
///
/// Note that we also need to special-case this property in matching.rs, in
/// order to properly handle changes to the legacy keyword... This all kinda
/// sucks :(.
///
/// See the discussion in https://bugzil.la/1384542.
#[derive(Clone, Copy, Debug, Eq, PartialEq, ToCss)]
pub struct JustifyItems {
/// The specified value for the property. Can contain `auto`.
#[css(skip)]
pub specified: specified::JustifyItems,
/// The computed value for the property. Cannot contain `auto`.
pub computed: specified::JustifyItems,
}
impl ToCss for JustifyItems {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
where W: fmt::Write,
{
self.computed.to_css(dest)
}
}
impl JustifyItems {
/// Returns the `auto` value.
pub fn auto() -> Self {