mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
style: Derive ToCss for Counters.
Bug: 1457332 Reviewed-by: xidorn MozReview-Commit-ID: 1jOglcqt1Dd
This commit is contained in:
parent
8c322b9c1e
commit
a375baf84b
3 changed files with 29 additions and 44 deletions
|
@ -5697,9 +5697,9 @@ clip-path
|
||||||
) {
|
) {
|
||||||
unsafe {
|
unsafe {
|
||||||
bindings::Gecko_ClearAndResizeCounter${counter_property}s(&mut self.gecko, v.len() as u32);
|
bindings::Gecko_ClearAndResizeCounter${counter_property}s(&mut self.gecko, v.len() as u32);
|
||||||
for (i, &(ref name, value)) in v.iter().enumerate() {
|
for (i, ref pair) in v.iter().enumerate() {
|
||||||
self.gecko.m${counter_property}s[i].mCounter.assign(name.0.as_slice());
|
self.gecko.m${counter_property}s[i].mCounter.assign(pair.name.0.as_slice());
|
||||||
self.gecko.m${counter_property}s[i].mValue = value;
|
self.gecko.m${counter_property}s[i].mValue = pair.value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5717,12 +5717,16 @@ clip-path
|
||||||
pub fn clone_counter_${counter_property.lower()}(
|
pub fn clone_counter_${counter_property.lower()}(
|
||||||
&self
|
&self
|
||||||
) -> longhands::counter_${counter_property.lower()}::computed_value::T {
|
) -> longhands::counter_${counter_property.lower()}::computed_value::T {
|
||||||
|
use values::generics::counters::CounterPair;
|
||||||
use values::CustomIdent;
|
use values::CustomIdent;
|
||||||
use gecko_string_cache::Atom;
|
use gecko_string_cache::Atom;
|
||||||
|
|
||||||
longhands::counter_${counter_property.lower()}::computed_value::T::new(
|
longhands::counter_${counter_property.lower()}::computed_value::T::new(
|
||||||
self.gecko.m${counter_property}s.iter().map(|ref gecko_counter| {
|
self.gecko.m${counter_property}s.iter().map(|ref gecko_counter| {
|
||||||
(CustomIdent(Atom::from(gecko_counter.mCounter.to_string())), gecko_counter.mValue)
|
CounterPair {
|
||||||
|
name: CustomIdent(Atom::from(gecko_counter.mCounter.to_string())),
|
||||||
|
value: gecko_counter.mValue,
|
||||||
|
}
|
||||||
}).collect()
|
}).collect()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,12 +4,19 @@
|
||||||
|
|
||||||
//! Generic types for counters-related CSS values.
|
//! Generic types for counters-related CSS values.
|
||||||
|
|
||||||
use std::fmt;
|
|
||||||
use std::fmt::Write;
|
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
use style_traits::{CssWriter, ToCss};
|
|
||||||
use values::CustomIdent;
|
use values::CustomIdent;
|
||||||
|
|
||||||
|
/// A name / value pair for counters.
|
||||||
|
#[derive(Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo,
|
||||||
|
ToComputedValue, ToCss)]
|
||||||
|
pub struct CounterPair<Integer> {
|
||||||
|
/// The name of the counter.
|
||||||
|
pub name: CustomIdent,
|
||||||
|
/// The value of the counter / increment / etc.
|
||||||
|
pub value: Integer,
|
||||||
|
}
|
||||||
|
|
||||||
/// A generic value for the `counter-increment` property.
|
/// A generic value for the `counter-increment` property.
|
||||||
#[derive(Clone, Debug, Default, MallocSizeOf, PartialEq, SpecifiedValueInfo,
|
#[derive(Clone, Debug, Default, MallocSizeOf, PartialEq, SpecifiedValueInfo,
|
||||||
ToComputedValue, ToCss)]
|
ToComputedValue, ToCss)]
|
||||||
|
@ -18,13 +25,13 @@ pub struct CounterIncrement<I>(Counters<I>);
|
||||||
impl<I> CounterIncrement<I> {
|
impl<I> CounterIncrement<I> {
|
||||||
/// Returns a new value for `counter-increment`.
|
/// Returns a new value for `counter-increment`.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new(counters: Vec<(CustomIdent, I)>) -> Self {
|
pub fn new(counters: Vec<CounterPair<I>>) -> Self {
|
||||||
CounterIncrement(Counters(counters.into_boxed_slice()))
|
CounterIncrement(Counters(counters.into_boxed_slice()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<I> Deref for CounterIncrement<I> {
|
impl<I> Deref for CounterIncrement<I> {
|
||||||
type Target = [(CustomIdent, I)];
|
type Target = [CounterPair<I>];
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target {
|
||||||
|
@ -40,13 +47,13 @@ pub struct CounterReset<I>(Counters<I>);
|
||||||
impl<I> CounterReset<I> {
|
impl<I> CounterReset<I> {
|
||||||
/// Returns a new value for `counter-reset`.
|
/// Returns a new value for `counter-reset`.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new(counters: Vec<(CustomIdent, I)>) -> Self {
|
pub fn new(counters: Vec<CounterPair<I>>) -> Self {
|
||||||
CounterReset(Counters(counters.into_boxed_slice()))
|
CounterReset(Counters(counters.into_boxed_slice()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<I> Deref for CounterReset<I> {
|
impl<I> Deref for CounterReset<I> {
|
||||||
type Target = [(CustomIdent, I)];
|
type Target = [CounterPair<I>];
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target {
|
||||||
|
@ -58,8 +65,8 @@ impl<I> Deref for CounterReset<I> {
|
||||||
///
|
///
|
||||||
/// Keyword `none` is represented by an empty vector.
|
/// Keyword `none` is represented by an empty vector.
|
||||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo,
|
#[derive(Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo,
|
||||||
ToComputedValue)]
|
ToComputedValue, ToCss)]
|
||||||
pub struct Counters<I>(#[css(if_empty = "none")] Box<[(CustomIdent, I)]>);
|
pub struct Counters<I>(#[css(iterable, if_empty = "none")] Box<[CounterPair<I>]>);
|
||||||
|
|
||||||
impl<I> Default for Counters<I> {
|
impl<I> Default for Counters<I> {
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -67,30 +74,3 @@ impl<I> Default for Counters<I> {
|
||||||
Counters(vec![].into_boxed_slice())
|
Counters(vec![].into_boxed_slice())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<I> ToCss for Counters<I>
|
|
||||||
where
|
|
||||||
I: ToCss,
|
|
||||||
{
|
|
||||||
#[inline]
|
|
||||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
|
||||||
where
|
|
||||||
W: fmt::Write,
|
|
||||||
{
|
|
||||||
if self.0.is_empty() {
|
|
||||||
return dest.write_str("none");
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut first = true;
|
|
||||||
for &(ref name, ref value) in &*self.0 {
|
|
||||||
if !first {
|
|
||||||
dest.write_str(" ")?;
|
|
||||||
}
|
|
||||||
first = false;
|
|
||||||
name.to_css(dest)?;
|
|
||||||
dest.write_str(" ")?;
|
|
||||||
value.to_css(dest)?;
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ use style_traits::{ParseError, StyleParseErrorKind};
|
||||||
use values::CustomIdent;
|
use values::CustomIdent;
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
use values::generics::CounterStyleOrNone;
|
use values::generics::CounterStyleOrNone;
|
||||||
|
use values::generics::counters::CounterPair;
|
||||||
use values::generics::counters::CounterIncrement as GenericCounterIncrement;
|
use values::generics::counters::CounterIncrement as GenericCounterIncrement;
|
||||||
use values::generics::counters::CounterReset as GenericCounterReset;
|
use values::generics::counters::CounterReset as GenericCounterReset;
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
|
@ -48,7 +49,7 @@ fn parse_counters<'i, 't>(
|
||||||
context: &ParserContext,
|
context: &ParserContext,
|
||||||
input: &mut Parser<'i, 't>,
|
input: &mut Parser<'i, 't>,
|
||||||
default_value: i32,
|
default_value: i32,
|
||||||
) -> Result<Vec<(CustomIdent, Integer)>, ParseError<'i>> {
|
) -> Result<Vec<CounterPair<Integer>>, ParseError<'i>> {
|
||||||
if input
|
if input
|
||||||
.try(|input| input.expect_ident_matching("none"))
|
.try(|input| input.expect_ident_matching("none"))
|
||||||
.is_ok()
|
.is_ok()
|
||||||
|
@ -59,16 +60,16 @@ fn parse_counters<'i, 't>(
|
||||||
let mut counters = Vec::new();
|
let mut counters = Vec::new();
|
||||||
loop {
|
loop {
|
||||||
let location = input.current_source_location();
|
let location = input.current_source_location();
|
||||||
let counter_name = match input.next() {
|
let name = match input.next() {
|
||||||
Ok(&Token::Ident(ref ident)) => CustomIdent::from_ident(location, ident, &["none"])?,
|
Ok(&Token::Ident(ref ident)) => CustomIdent::from_ident(location, ident, &["none"])?,
|
||||||
Ok(t) => return Err(location.new_unexpected_token_error(t.clone())),
|
Ok(t) => return Err(location.new_unexpected_token_error(t.clone())),
|
||||||
Err(_) => break,
|
Err(_) => break,
|
||||||
};
|
};
|
||||||
|
|
||||||
let counter_delta = input
|
let value = input
|
||||||
.try(|input| Integer::parse(context, input))
|
.try(|input| Integer::parse(context, input))
|
||||||
.unwrap_or(Integer::new(default_value));
|
.unwrap_or(Integer::new(default_value));
|
||||||
counters.push((counter_name, counter_delta))
|
counters.push(CounterPair { name, value });
|
||||||
}
|
}
|
||||||
|
|
||||||
if !counters.is_empty() {
|
if !counters.is_empty() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue