mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Auto merge of #19957 - gootorov:move-counter-from-mako, r=emilio
style: Move content property out of mako. <!-- Please describe your changes on the following line: --> r? emilio --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach build-geckolib` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #19936 (github issue number if applicable). <!-- Either: --> - [x] These changes do not require tests <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/19957) <!-- Reviewable:end -->
This commit is contained in:
commit
804b4b3db6
11 changed files with 302 additions and 281 deletions
|
@ -4,11 +4,202 @@
|
|||
|
||||
//! Computed values for counter properties
|
||||
|
||||
#[cfg(feature = "servo")]
|
||||
use computed_values::list_style_type::T as ListStyleType;
|
||||
use cssparser::{self, Parser, Token};
|
||||
use parser::{Parse, ParserContext};
|
||||
use selectors::parser::SelectorParseErrorKind;
|
||||
use std::fmt::{self, Write};
|
||||
use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss};
|
||||
#[cfg(feature = "gecko")]
|
||||
use values::generics::CounterStyleOrNone;
|
||||
use values::generics::counters::CounterIncrement as GenericCounterIncrement;
|
||||
use values::generics::counters::CounterReset as GenericCounterReset;
|
||||
#[cfg(feature = "gecko")]
|
||||
use values::specified::Attr;
|
||||
#[cfg(feature = "gecko")]
|
||||
use values::specified::url::SpecifiedUrl;
|
||||
pub use values::specified::{Content, ContentItem};
|
||||
|
||||
/// A computed value for the `counter-increment` property.
|
||||
pub type CounterIncrement = GenericCounterIncrement<i32>;
|
||||
|
||||
/// A computed value for the `counter-increment` property.
|
||||
pub type CounterReset = GenericCounterReset<i32>;
|
||||
|
||||
impl Content {
|
||||
/// Set `content` property to `normal`.
|
||||
#[inline]
|
||||
pub fn normal() -> Self {
|
||||
Content::Normal
|
||||
}
|
||||
|
||||
#[cfg(feature = "servo")]
|
||||
fn parse_counter_style(
|
||||
input: &mut Parser
|
||||
) -> ListStyleType {
|
||||
input.try(|input| {
|
||||
input.expect_comma()?;
|
||||
ListStyleType::parse(input)
|
||||
}).unwrap_or(ListStyleType::Decimal)
|
||||
}
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
fn parse_counter_style(
|
||||
context: &ParserContext,
|
||||
input: &mut Parser
|
||||
) -> CounterStyleOrNone {
|
||||
input.try(|input| {
|
||||
input.expect_comma()?;
|
||||
CounterStyleOrNone::parse(context, input)
|
||||
}).unwrap_or(CounterStyleOrNone::decimal())
|
||||
}
|
||||
}
|
||||
|
||||
impl Parse for Content {
|
||||
// normal | none | [ <string> | <counter> | open-quote | close-quote | no-open-quote |
|
||||
// no-close-quote ]+
|
||||
// TODO: <uri>, attr(<identifier>)
|
||||
fn parse<'i, 't>(
|
||||
_context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
if input.try(|input| input.expect_ident_matching("normal")).is_ok() {
|
||||
return Ok(Content::Normal);
|
||||
}
|
||||
if input.try(|input| input.expect_ident_matching("none")).is_ok() {
|
||||
return Ok(Content::None);
|
||||
}
|
||||
#[cfg(feature = "gecko")] {
|
||||
if input.try(|input| input.expect_ident_matching("-moz-alt-content")).is_ok() {
|
||||
return Ok(Content::MozAltContent);
|
||||
}
|
||||
}
|
||||
|
||||
let mut content = vec![];
|
||||
loop {
|
||||
#[cfg(feature = "gecko")] {
|
||||
if let Ok(mut url) = input.try(|i| SpecifiedUrl::parse(_context, i)) {
|
||||
url.build_image_value();
|
||||
content.push(ContentItem::Url(url));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// FIXME: remove clone() when lifetimes are non-lexical
|
||||
match input.next().map(|t| t.clone()) {
|
||||
Ok(Token::QuotedString(ref value)) => {
|
||||
content.push(ContentItem::String(value.as_ref().to_owned().into_boxed_str()));
|
||||
}
|
||||
Ok(Token::Function(ref name)) => {
|
||||
let result = match_ignore_ascii_case! { &name,
|
||||
"counter" => Some(input.parse_nested_block(|input| {
|
||||
let name = input.expect_ident()?.as_ref().to_owned().into_boxed_str();
|
||||
#[cfg(feature = "servo")]
|
||||
let style = Content::parse_counter_style(input);
|
||||
#[cfg(feature = "gecko")]
|
||||
let style = Content::parse_counter_style(_context, input);
|
||||
Ok(ContentItem::Counter(name, style))
|
||||
})),
|
||||
"counters" => Some(input.parse_nested_block(|input| {
|
||||
let name = input.expect_ident()?.as_ref().to_owned().into_boxed_str();
|
||||
input.expect_comma()?;
|
||||
let separator = input.expect_string()?.as_ref().to_owned().into_boxed_str();
|
||||
#[cfg(feature = "servo")]
|
||||
let style = Content::parse_counter_style(input);
|
||||
#[cfg(feature = "gecko")]
|
||||
let style = Content::parse_counter_style(_context, input);
|
||||
Ok(ContentItem::Counters(name, separator, style))
|
||||
})),
|
||||
#[cfg(feature = "gecko")]
|
||||
"attr" => Some(input.parse_nested_block(|input| {
|
||||
Ok(ContentItem::Attr(Attr::parse_function(_context, input)?))
|
||||
})),
|
||||
_ => None
|
||||
};
|
||||
match result {
|
||||
Some(result) => content.push(result?),
|
||||
None => return Err(input.new_custom_error(
|
||||
StyleParseErrorKind::UnexpectedFunction(name.clone())
|
||||
))
|
||||
}
|
||||
}
|
||||
Ok(Token::Ident(ref ident)) => {
|
||||
content.push(
|
||||
match_ignore_ascii_case! { &ident,
|
||||
"open-quote" => ContentItem::OpenQuote,
|
||||
"close-quote" => ContentItem::CloseQuote,
|
||||
"no-open-quote" => ContentItem::NoOpenQuote,
|
||||
"no-close-quote" => ContentItem::NoCloseQuote,
|
||||
_ => return Err(input.new_custom_error(
|
||||
SelectorParseErrorKind::UnexpectedIdent(ident.clone())))
|
||||
}
|
||||
);
|
||||
}
|
||||
Err(_) => break,
|
||||
Ok(t) => return Err(input.new_unexpected_token_error(t))
|
||||
}
|
||||
}
|
||||
if content.is_empty() {
|
||||
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError));
|
||||
}
|
||||
Ok(Content::Items(content.into_boxed_slice()))
|
||||
}
|
||||
}
|
||||
|
||||
impl ToCss for Content {
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
||||
where W: Write,
|
||||
{
|
||||
match *self {
|
||||
Content::Normal => dest.write_str("normal"),
|
||||
Content::None => dest.write_str("none"),
|
||||
#[cfg(feature = "gecko")]
|
||||
Content::MozAltContent => dest.write_str("-moz-alt-content"),
|
||||
Content::Items(ref content) => {
|
||||
let mut iter = content.iter();
|
||||
iter.next().unwrap().to_css(dest)?;
|
||||
for c in iter {
|
||||
dest.write_str(" ")?;
|
||||
c.to_css(dest)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToCss for ContentItem {
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
||||
where W: Write,
|
||||
{
|
||||
match *self {
|
||||
ContentItem::String(ref s) => s.to_css(dest),
|
||||
ContentItem::Counter(ref s, ref counter_style) => {
|
||||
dest.write_str("counter(")?;
|
||||
cssparser::serialize_identifier(&**s, dest)?;
|
||||
dest.write_str(", ")?;
|
||||
counter_style.to_css(dest)?;
|
||||
dest.write_str(")")
|
||||
}
|
||||
ContentItem::Counters(ref s, ref separator, ref counter_style) => {
|
||||
dest.write_str("counters(")?;
|
||||
cssparser::serialize_identifier(&**s, dest)?;
|
||||
dest.write_str(", ")?;
|
||||
separator.to_css(dest)?;
|
||||
dest.write_str(", ")?;
|
||||
counter_style.to_css(dest)?;
|
||||
dest.write_str(")")
|
||||
}
|
||||
ContentItem::OpenQuote => dest.write_str("open-quote"),
|
||||
ContentItem::CloseQuote => dest.write_str("close-quote"),
|
||||
ContentItem::NoOpenQuote => dest.write_str("no-open-quote"),
|
||||
ContentItem::NoCloseQuote => dest.write_str("no-close-quote"),
|
||||
#[cfg(feature = "gecko")]
|
||||
ContentItem::Attr(ref attr) => {
|
||||
attr.to_css(dest)
|
||||
}
|
||||
#[cfg(feature = "gecko")]
|
||||
ContentItem::Url(ref url) => url.to_css(dest),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ pub use self::font::{MozScriptLevel, MozScriptMinSize, MozScriptSizeMultiplier,
|
|||
pub use self::box_::{AnimationIterationCount, AnimationName, Display, OverscrollBehavior, Contain};
|
||||
pub use self::box_::{OverflowClipBox, ScrollSnapType, TouchAction, VerticalAlign, WillChange};
|
||||
pub use self::color::{Color, ColorPropertyValue, RGBAColor};
|
||||
pub use self::counters::{CounterIncrement, CounterReset};
|
||||
pub use self::counters::{Content, ContentItem, CounterIncrement, CounterReset};
|
||||
pub use self::effects::{BoxShadow, Filter, SimpleShadow};
|
||||
pub use self::flex::FlexBasis;
|
||||
pub use self::image::{Gradient, GradientItem, Image, ImageLayer, LineDirection, MozImageRect};
|
||||
|
|
|
@ -4,13 +4,21 @@
|
|||
|
||||
//! Specified types for counter properties.
|
||||
|
||||
#[cfg(feature = "servo")]
|
||||
use computed_values::list_style_type::T as ListStyleType;
|
||||
use cssparser::{Token, Parser};
|
||||
use parser::{Parse, ParserContext};
|
||||
use style_traits::{ParseError, StyleParseErrorKind};
|
||||
use values::CustomIdent;
|
||||
#[cfg(feature = "gecko")]
|
||||
use values::generics::CounterStyleOrNone;
|
||||
use values::generics::counters::CounterIncrement as GenericCounterIncrement;
|
||||
use values::generics::counters::CounterReset as GenericCounterReset;
|
||||
#[cfg(feature = "gecko")]
|
||||
use values::specified::Attr;
|
||||
use values::specified::Integer;
|
||||
#[cfg(feature = "gecko")]
|
||||
use values::specified::url::SpecifiedUrl;
|
||||
|
||||
/// A specified value for the `counter-increment` property.
|
||||
pub type CounterIncrement = GenericCounterIncrement<Integer>;
|
||||
|
@ -65,3 +73,49 @@ fn parse_counters<'i, 't>(
|
|||
Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "servo")]
|
||||
type CounterStyleType = ListStyleType;
|
||||
#[cfg(feature = "gecko")]
|
||||
type CounterStyleType = CounterStyleOrNone;
|
||||
|
||||
/// The specified value for the `content` property.
|
||||
///
|
||||
/// https://drafts.csswg.org/css-content/#propdef-content
|
||||
#[derive(Clone, Debug, Eq, MallocSizeOf, PartialEq, ToComputedValue)]
|
||||
pub enum Content {
|
||||
/// `normal` reserved keyword.
|
||||
Normal,
|
||||
/// `none` reserved keyword.
|
||||
None,
|
||||
/// `-moz-alt-content`.
|
||||
#[cfg(feature = "gecko")]
|
||||
MozAltContent,
|
||||
/// Content items.
|
||||
Items(Box<[ContentItem]>),
|
||||
}
|
||||
|
||||
/// Items for the `content` property.
|
||||
#[derive(Clone, Debug, Eq, MallocSizeOf, PartialEq, ToComputedValue)]
|
||||
pub enum ContentItem {
|
||||
/// Literal string content.
|
||||
String(Box<str>),
|
||||
/// `counter(name, style)`.
|
||||
Counter(Box<str>, CounterStyleType),
|
||||
/// `counters(name, separator, style)`.
|
||||
Counters(Box<str>, Box<str>, CounterStyleType),
|
||||
/// `open-quote`.
|
||||
OpenQuote,
|
||||
/// `close-quote`.
|
||||
CloseQuote,
|
||||
/// `no-open-quote`.
|
||||
NoOpenQuote,
|
||||
/// `no-close-quote`.
|
||||
NoCloseQuote,
|
||||
/// `attr([namespace? `|`]? ident)`
|
||||
#[cfg(feature = "gecko")]
|
||||
Attr(Attr),
|
||||
/// `url(url)`
|
||||
#[cfg(feature = "gecko")]
|
||||
Url(SpecifiedUrl),
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ pub use self::font::{MozScriptLevel, MozScriptMinSize, MozScriptSizeMultiplier,
|
|||
pub use self::box_::{AnimationIterationCount, AnimationName, Display, OverscrollBehavior, Contain};
|
||||
pub use self::box_::{OverflowClipBox, ScrollSnapType, TouchAction, VerticalAlign, WillChange};
|
||||
pub use self::color::{Color, ColorPropertyValue, RGBAColor};
|
||||
pub use self::counters::{CounterIncrement, CounterReset};
|
||||
pub use self::counters::{Content, ContentItem, CounterIncrement, CounterReset};
|
||||
pub use self::effects::{BoxShadow, Filter, SimpleShadow};
|
||||
pub use self::flex::FlexBasis;
|
||||
#[cfg(feature = "gecko")]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue