moved css longhand counter-reset out of mako

This commit is contained in:
Jonas Reinwald 2017-12-08 19:08:22 +01:00 committed by Emilio Cobos Álvarez
parent dcd13b857c
commit d24301b7a0
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
11 changed files with 240 additions and 151 deletions

View file

@ -5,26 +5,37 @@
//! Generic types for counters-related CSS values.
use std::fmt;
use std::fmt::Write;
use style_traits::{CssWriter, ToCss};
use values::CustomIdent;
/// A generic value for the `counter-increment` property.
/// A generic value for both the `counter-increment` and `counter-reset` property.
///
/// Keyword `none` is represented by an empty slice.
#[derive(Clone, Debug, PartialEq, ToComputedValue)]
pub struct CounterIncrement<Integer>(Box<[(CustomIdent, Integer)]);
/// Keyword `none` is represented by an empty vector.
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToComputedValue)]
pub struct CounterIntegerList<I>(Box<[(CustomIdent, I)]>);
impl<I> CounterIncrement<I> {
/// Returns `none`.
impl<I> CounterIntegerList<I> {
/// Returns the `none` value.
#[inline]
pub fn none() -> Self {
CounterIncrement(vec![].into_boxed_slice())
pub fn none() -> CounterIntegerList<I> {
CounterIntegerList(vec![].into_boxed_slice())
}
/// Returns a new CounterIntegerList object.
pub fn new(vec: Vec<(CustomIdent, I)>) -> CounterIntegerList<I> {
CounterIntegerList(vec.into_boxed_slice())
}
/// Returns the values of the CounterIntegerList object.
pub fn get_values(&self) -> &[(CustomIdent, I)] {
self.0.as_ref()
}
}
impl<I> ToCss for CounterIncrement<I>
impl<I> ToCss for CounterIntegerList<I>
where
I: ToCss,
I: ToCss
{
#[inline]
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
@ -32,12 +43,15 @@ where
W: fmt::Write,
{
if self.0.is_empty() {
return dest.write_str("none");
return dest.write_str("none")
}
for (&(ref name, ref value), i) in self.0.iter().enumerate() {
if i != 0 {
let mut first = true;
for &(ref name, ref value) in self.get_values() {
if !first {
dest.write_str(" ")?;
}
first = false;
name.to_css(dest)?;
dest.write_str(" ")?;
value.to_css(dest)?;