mirror of
https://github.com/servo/servo.git
synced 2025-07-25 08:10:21 +01:00
Simplify counter CSS properties
This commit is contained in:
parent
2f8cd0fe22
commit
df11a7fec7
7 changed files with 120 additions and 186 deletions
|
@ -1035,8 +1035,8 @@ impl BaseFlow {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !style.get_counters().counter_reset.get_values().is_empty() ||
|
if !style.get_counters().counter_reset.is_empty() ||
|
||||||
!style.get_counters().counter_increment.get_values().is_empty() {
|
!style.get_counters().counter_increment.is_empty() {
|
||||||
flags.insert(FlowFlags::AFFECTS_COUNTERS)
|
flags.insert(FlowFlags::AFFECTS_COUNTERS)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -272,7 +272,7 @@ impl<'a, 'b> ResolveGeneratedContentFragmentMutator<'a, 'b> {
|
||||||
}
|
}
|
||||||
self.traversal.list_item.truncate_to_level(self.level);
|
self.traversal.list_item.truncate_to_level(self.level);
|
||||||
|
|
||||||
for &(ref counter_name, value) in fragment.style().get_counters().counter_reset.get_values() {
|
for &(ref counter_name, value) in &*fragment.style().get_counters().counter_reset {
|
||||||
let counter_name = &*counter_name.0;
|
let counter_name = &*counter_name.0;
|
||||||
if let Some(ref mut counter) = self.traversal.counters.get_mut(counter_name) {
|
if let Some(ref mut counter) = self.traversal.counters.get_mut(counter_name) {
|
||||||
counter.reset(self.level, value);
|
counter.reset(self.level, value);
|
||||||
|
@ -284,7 +284,7 @@ impl<'a, 'b> ResolveGeneratedContentFragmentMutator<'a, 'b> {
|
||||||
self.traversal.counters.insert(counter_name.to_owned(), counter);
|
self.traversal.counters.insert(counter_name.to_owned(), counter);
|
||||||
}
|
}
|
||||||
|
|
||||||
for &(ref counter_name, value) in fragment.style().get_counters().counter_increment.get_values() {
|
for &(ref counter_name, value) in &*fragment.style().get_counters().counter_increment {
|
||||||
let counter_name = &*counter_name.0;
|
let counter_name = &*counter_name.0;
|
||||||
if let Some(ref mut counter) = self.traversal.counters.get_mut(counter_name) {
|
if let Some(ref mut counter) = self.traversal.counters.get_mut(counter_name) {
|
||||||
counter.increment(self.level, value);
|
counter.increment(self.level, value);
|
||||||
|
|
|
@ -5669,9 +5669,8 @@ clip-path
|
||||||
v: longhands::counter_${counter_property.lower()}::computed_value::T
|
v: longhands::counter_${counter_property.lower()}::computed_value::T
|
||||||
) {
|
) {
|
||||||
unsafe {
|
unsafe {
|
||||||
bindings::Gecko_ClearAndResizeCounter${counter_property}s(&mut self.gecko,
|
bindings::Gecko_ClearAndResizeCounter${counter_property}s(&mut self.gecko, v.len() as u32);
|
||||||
v.get_values().len() as u32);
|
for (i, &(ref name, value)) in v.iter().enumerate() {
|
||||||
for (i, &(ref name, value)) in v.get_values().into_iter().enumerate() {
|
|
||||||
self.gecko.m${counter_property}s[i].mCounter.assign(name.0.as_slice());
|
self.gecko.m${counter_property}s[i].mCounter.assign(name.0.as_slice());
|
||||||
self.gecko.m${counter_property}s[i].mValue = value;
|
self.gecko.m${counter_property}s[i].mValue = value;
|
||||||
}
|
}
|
||||||
|
|
|
@ -236,14 +236,18 @@
|
||||||
}
|
}
|
||||||
</%helpers:longhand>
|
</%helpers:longhand>
|
||||||
|
|
||||||
${helpers.predefined_type("counter-increment",
|
${helpers.predefined_type(
|
||||||
|
"counter-increment",
|
||||||
"CounterIncrement",
|
"CounterIncrement",
|
||||||
initial_value="computed::CounterIncrement::none()",
|
initial_value="Default::default()",
|
||||||
animation_value_type="discrete",
|
animation_value_type="discrete",
|
||||||
spec="https://drafts.csswg.org/css-lists/#propdef-counter-increment")}
|
spec="https://drafts.csswg.org/css-lists/#propdef-counter-increment",
|
||||||
|
)}
|
||||||
|
|
||||||
${helpers.predefined_type("counter-reset",
|
${helpers.predefined_type(
|
||||||
|
"counter-reset",
|
||||||
"CounterReset",
|
"CounterReset",
|
||||||
initial_value="computed::CounterReset::none()",
|
initial_value="Default::default()",
|
||||||
animation_value_type="discrete",
|
animation_value_type="discrete",
|
||||||
spec="https://drafts.csswg.org/css-lists-3/#propdef-counter-reset")}
|
spec="https://drafts.csswg.org/css-lists-3/#propdef-counter-reset",
|
||||||
|
)}
|
||||||
|
|
|
@ -4,77 +4,11 @@
|
||||||
|
|
||||||
//! Computed values for counter properties
|
//! Computed values for counter properties
|
||||||
|
|
||||||
use values::CustomIdent;
|
use values::generics::counters::CounterIncrement as GenericCounterIncrement;
|
||||||
use values::computed::{Context, ToComputedValue};
|
use values::generics::counters::CounterReset as GenericCounterReset;
|
||||||
use values::generics::counters::CounterIntegerList;
|
|
||||||
use values::specified::{CounterIncrement as SpecifiedCounterIncrement, CounterReset as SpecifiedCounterReset};
|
|
||||||
|
|
||||||
type ComputedIntegerList = CounterIntegerList<i32>;
|
|
||||||
|
|
||||||
/// A computed value for the `counter-increment` property.
|
/// A computed value for the `counter-increment` property.
|
||||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToCss)]
|
pub type CounterIncrement = GenericCounterIncrement<i32>;
|
||||||
pub struct CounterIncrement(pub ComputedIntegerList);
|
|
||||||
|
|
||||||
impl CounterIncrement {
|
/// A computed value for the `counter-increment` property.
|
||||||
/// Returns the `none` value.
|
pub type CounterReset = GenericCounterReset<i32>;
|
||||||
#[inline]
|
|
||||||
pub fn none() -> CounterIncrement {
|
|
||||||
CounterIncrement(ComputedIntegerList::new(Vec::new()))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns a new computed `counter-increment` object with the given values.
|
|
||||||
pub fn new(vec: Vec<(CustomIdent, i32)>) -> CounterIncrement {
|
|
||||||
CounterIncrement(ComputedIntegerList::new(vec))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the values of the computed `counter-increment` object.
|
|
||||||
pub fn get_values(&self) -> &[(CustomIdent, i32)] {
|
|
||||||
self.0.get_values()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ToComputedValue for SpecifiedCounterIncrement {
|
|
||||||
type ComputedValue = CounterIncrement;
|
|
||||||
|
|
||||||
fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
|
|
||||||
CounterIncrement(self.0.to_computed_value(context))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn from_computed_value(computed: &Self::ComputedValue) -> Self {
|
|
||||||
SpecifiedCounterIncrement(ToComputedValue::from_computed_value(&computed.0))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A computed value for the `counter-reset` property.
|
|
||||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToCss)]
|
|
||||||
pub struct CounterReset(pub ComputedIntegerList);
|
|
||||||
|
|
||||||
impl CounterReset {
|
|
||||||
/// Returns the `none` value.
|
|
||||||
#[inline]
|
|
||||||
pub fn none() -> CounterReset {
|
|
||||||
CounterReset(ComputedIntegerList::new(Vec::new()))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns a new computed `counter-reset` object with the given values.
|
|
||||||
pub fn new(vec: Vec<(CustomIdent, i32)>) -> CounterReset {
|
|
||||||
CounterReset(ComputedIntegerList::new(vec))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the values of the computed `counter-reset` object.
|
|
||||||
pub fn get_values(&self) -> &[(CustomIdent, i32)] {
|
|
||||||
self.0.get_values()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ToComputedValue for SpecifiedCounterReset {
|
|
||||||
type ComputedValue = CounterReset;
|
|
||||||
|
|
||||||
fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
|
|
||||||
CounterReset(self.0.to_computed_value(context))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn from_computed_value(computed: &Self::ComputedValue) -> Self {
|
|
||||||
SpecifiedCounterReset(ToComputedValue::from_computed_value(&computed.0))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -6,36 +6,68 @@
|
||||||
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
|
use std::ops::Deref;
|
||||||
use style_traits::{CssWriter, ToCss};
|
use style_traits::{CssWriter, ToCss};
|
||||||
use values::CustomIdent;
|
use values::CustomIdent;
|
||||||
|
|
||||||
/// A generic value for both the `counter-increment` and `counter-reset` property.
|
/// A generic value for the `counter-increment` property.
|
||||||
|
#[derive(Clone, Debug, Default, MallocSizeOf, PartialEq, ToComputedValue, ToCss)]
|
||||||
|
pub struct CounterIncrement<I>(Counters<I>);
|
||||||
|
|
||||||
|
impl<I> CounterIncrement<I> {
|
||||||
|
/// Returns a new value for `counter-increment`.
|
||||||
|
#[inline]
|
||||||
|
pub fn new(counters: Vec<(CustomIdent, I)>) -> Self {
|
||||||
|
CounterIncrement(Counters(counters.into_boxed_slice()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<I> Deref for CounterIncrement<I> {
|
||||||
|
type Target = [(CustomIdent, I)];
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
&(self.0).0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A generic value for the `counter-reset` property.
|
||||||
|
#[derive(Clone, Debug, Default, MallocSizeOf, PartialEq, ToComputedValue, ToCss)]
|
||||||
|
pub struct CounterReset<I>(Counters<I>);
|
||||||
|
|
||||||
|
impl<I> CounterReset<I> {
|
||||||
|
/// Returns a new value for `counter-reset`.
|
||||||
|
#[inline]
|
||||||
|
pub fn new(counters: Vec<(CustomIdent, I)>) -> Self {
|
||||||
|
CounterReset(Counters(counters.into_boxed_slice()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<I> Deref for CounterReset<I> {
|
||||||
|
type Target = [(CustomIdent, I)];
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
&(self.0).0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A generic value for lists of counters.
|
||||||
///
|
///
|
||||||
/// Keyword `none` is represented by an empty vector.
|
/// Keyword `none` is represented by an empty vector.
|
||||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToComputedValue)]
|
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToComputedValue)]
|
||||||
pub struct CounterIntegerList<I>(Box<[(CustomIdent, I)]>);
|
pub struct Counters<I>(Box<[(CustomIdent, I)]>);
|
||||||
|
|
||||||
impl<I> CounterIntegerList<I> {
|
impl<I> Default for Counters<I> {
|
||||||
/// Returns the `none` value.
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn none() -> CounterIntegerList<I> {
|
fn default() -> Self {
|
||||||
CounterIntegerList(vec![].into_boxed_slice())
|
Counters(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 CounterIntegerList<I>
|
impl<I> ToCss for Counters<I>
|
||||||
where
|
where
|
||||||
I: ToCss
|
I: ToCss,
|
||||||
{
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
||||||
|
@ -47,7 +79,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut first = true;
|
let mut first = true;
|
||||||
for &(ref name, ref value) in self.get_values() {
|
for &(ref name, ref value) in &*self.0 {
|
||||||
if !first {
|
if !first {
|
||||||
dest.write_str(" ")?;
|
dest.write_str(" ")?;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,30 +4,48 @@
|
||||||
|
|
||||||
//! Specified types for counter properties.
|
//! Specified types for counter properties.
|
||||||
|
|
||||||
use cssparser::Parser;
|
use cssparser::{Token, Parser};
|
||||||
use parser::{Parse, ParserContext};
|
use parser::{Parse, ParserContext};
|
||||||
use style_traits::ParseError;
|
use style_traits::{ParseError, StyleParseErrorKind};
|
||||||
use values::CustomIdent;
|
use values::CustomIdent;
|
||||||
use values::generics::counters::CounterIntegerList;
|
use values::generics::counters::CounterIncrement as GenericCounterIncrement;
|
||||||
|
use values::generics::counters::CounterReset as GenericCounterReset;
|
||||||
use values::specified::Integer;
|
use values::specified::Integer;
|
||||||
|
|
||||||
/// A specified value for the `counter-increment` and `counter-reset` property.
|
/// A specified value for the `counter-increment` property.
|
||||||
type SpecifiedIntegerList = CounterIntegerList<Integer>;
|
pub type CounterIncrement = GenericCounterIncrement<Integer>;
|
||||||
|
|
||||||
impl SpecifiedIntegerList {
|
impl Parse for CounterIncrement {
|
||||||
fn parse_with_default<'i, 't>(
|
fn parse<'i, 't>(
|
||||||
context: &ParserContext,
|
context: &ParserContext,
|
||||||
input: &mut Parser<'i, 't>,
|
input: &mut Parser<'i, 't>
|
||||||
default_value: i32
|
) -> Result<Self, ParseError<'i>> {
|
||||||
) -> Result<SpecifiedIntegerList, ParseError<'i>> {
|
Ok(Self::new(parse_counters(context, input, 1)?))
|
||||||
use cssparser::Token;
|
}
|
||||||
use style_traits::StyleParseErrorKind;
|
|
||||||
|
|
||||||
if input.try(|input| input.expect_ident_matching("none")).is_ok() {
|
|
||||||
return Ok(CounterIntegerList::new(Vec::new()))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut counters: Vec<(CustomIdent, Integer)> = Vec::new();
|
/// A specified value for the `counter-increment` property.
|
||||||
|
pub type CounterReset = GenericCounterReset<Integer>;
|
||||||
|
|
||||||
|
impl Parse for CounterReset {
|
||||||
|
fn parse<'i, 't>(
|
||||||
|
context: &ParserContext,
|
||||||
|
input: &mut Parser<'i, 't>
|
||||||
|
) -> Result<Self, ParseError<'i>> {
|
||||||
|
Ok(Self::new(parse_counters(context, input, 0)?))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_counters<'i, 't>(
|
||||||
|
context: &ParserContext,
|
||||||
|
input: &mut Parser<'i, 't>,
|
||||||
|
default_value: i32,
|
||||||
|
) -> Result<Vec<(CustomIdent, Integer)>, ParseError<'i>> {
|
||||||
|
if input.try(|input| input.expect_ident_matching("none")).is_ok() {
|
||||||
|
return Ok(vec![]);
|
||||||
|
}
|
||||||
|
|
||||||
|
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 counter_name = match input.next() {
|
||||||
|
@ -42,61 +60,8 @@ impl SpecifiedIntegerList {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !counters.is_empty() {
|
if !counters.is_empty() {
|
||||||
Ok(CounterIntegerList::new(counters))
|
Ok(counters)
|
||||||
} else {
|
} else {
|
||||||
Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
|
Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// A specified value for the `counter-increment` property.
|
|
||||||
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
|
|
||||||
#[derive(Clone, Debug, PartialEq, ToCss)]
|
|
||||||
pub struct CounterIncrement(pub SpecifiedIntegerList);
|
|
||||||
|
|
||||||
impl CounterIncrement {
|
|
||||||
/// Returns a new specified `counter-increment` object with the given values.
|
|
||||||
pub fn new(vec: Vec<(CustomIdent, Integer)>) -> CounterIncrement {
|
|
||||||
CounterIncrement(SpecifiedIntegerList::new(vec))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the values of the specified `counter-increment` object.
|
|
||||||
pub fn get_values(&self) -> &[(CustomIdent, Integer)] {
|
|
||||||
self.0.get_values()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Parse for CounterIncrement {
|
|
||||||
fn parse<'i, 't>(
|
|
||||||
context: &ParserContext,
|
|
||||||
input: &mut Parser<'i, 't>
|
|
||||||
) -> Result<CounterIncrement, ParseError<'i>> {
|
|
||||||
Ok(CounterIncrement(SpecifiedIntegerList::parse_with_default(context, input, 1)?))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A specified value for the `counter-reset` property.
|
|
||||||
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
|
|
||||||
#[derive(Clone, Debug, PartialEq, ToCss)]
|
|
||||||
pub struct CounterReset(pub SpecifiedIntegerList);
|
|
||||||
|
|
||||||
impl CounterReset {
|
|
||||||
/// Returns a new specified `counter-reset` object with the given values.
|
|
||||||
pub fn new(vec: Vec<(CustomIdent, Integer)>) -> CounterReset {
|
|
||||||
CounterReset(SpecifiedIntegerList::new(vec))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the values of the specified `counter-reset` object.
|
|
||||||
pub fn get_values(&self) -> &[(CustomIdent, Integer)] {
|
|
||||||
self.0.get_values()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Parse for CounterReset {
|
|
||||||
fn parse<'i, 't>(
|
|
||||||
context: &ParserContext,
|
|
||||||
input: &mut Parser<'i, 't>
|
|
||||||
) -> Result<CounterReset, ParseError<'i>> {
|
|
||||||
Ok(CounterReset(SpecifiedIntegerList::parse_with_default(context, input, 0)?))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue