Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stylo: Add support for grid-template-{rows,columns} #16067

Merged
merged 12 commits into from May 18, 2017

Apply track repetitions and merge grid <line-names> in ToComputedValue

  • Loading branch information
wafflespeanut committed May 18, 2017
commit 7d1505a1883495067019fa6a7cbea30a95955326
@@ -8,6 +8,7 @@ use cssparser::{Parser, Token, serialize_identifier};
use parser::{Parse, ParserContext};
use std::ascii::AsciiExt;
use std::fmt;
use std::mem;
use style_traits::ToCss;
use values::{CSSFloat, CustomIdent, HasViewportPercentage};
use values::computed::{ComputedValueAsSpecified, Context, ToComputedValue};
@@ -548,3 +549,57 @@ impl HasViewportPercentage for TrackRepeat<LengthOrPercentage> {
self.track_sizes.iter().any(|ref v| v.has_viewport_percentage())
}
}

impl<L: ToComputedValue> ToComputedValue for TrackRepeat<L> {
type ComputedValue = TrackRepeat<L::ComputedValue>;

#[inline]
fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
// If the repeat count is numeric, then expand the values and merge accordingly.
if let RepeatCount::Number(num) = self.count {
let mut line_names = vec![];
let mut track_sizes = vec![];
let mut prev_names = vec![];

for _ in 0..num.value {
let mut names_iter = self.line_names.iter();
for (size, names) in self.track_sizes.iter().zip(&mut names_iter) {
prev_names.extend_from_slice(&names);
line_names.push(mem::replace(&mut prev_names, vec![]));
track_sizes.push(size.to_computed_value(context));
}

if let Some(names) = names_iter.next() {
prev_names.extend_from_slice(&names);
}
}

line_names.push(prev_names);
TrackRepeat {
count: self.count,
track_sizes: track_sizes,
line_names: line_names,
}

} else { // if it's auto-fit/auto-fill, then it's left to the layout.
TrackRepeat {
count: self.count,
track_sizes: self.track_sizes.iter()
.map(|l| l.to_computed_value(context))
.collect(),
line_names: self.line_names.clone(),
}
}
}

#[inline]
fn from_computed_value(computed: &Self::ComputedValue) -> Self {
TrackRepeat {
count: computed.count,
track_sizes: computed.track_sizes.iter()
.map(ToComputedValue::from_computed_value)
.collect(),
line_names: computed.line_names.clone(),
}
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.