mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
moved css longhand counter-reset out of mako
This commit is contained in:
parent
dcd13b857c
commit
d24301b7a0
11 changed files with 240 additions and 151 deletions
|
@ -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)?;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue