mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Auto merge of #20196 - servo:derive-all-the-things, r=emilio
Derive some more ToCss implementations <!-- 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/20196) <!-- Reviewable:end -->
This commit is contained in:
commit
266258331e
7 changed files with 58 additions and 74 deletions
|
@ -444,7 +444,18 @@ impl Parse for Negative {
|
||||||
///
|
///
|
||||||
/// Empty Vec represents 'auto'
|
/// Empty Vec represents 'auto'
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Ranges(pub Vec<Range<Option<i32>>>);
|
pub struct Ranges(pub Vec<Range<CounterBound>>);
|
||||||
|
|
||||||
|
/// A bound found in `Ranges`.
|
||||||
|
#[derive(Clone, Copy, Debug, ToCss)]
|
||||||
|
pub enum CounterBound {
|
||||||
|
/// An integer bound.
|
||||||
|
///
|
||||||
|
/// FIXME(https://github.com/servo/servo/issues/20197)
|
||||||
|
Integer(i32),
|
||||||
|
/// The infinite bound.
|
||||||
|
Infinite,
|
||||||
|
}
|
||||||
|
|
||||||
impl Parse for Ranges {
|
impl Parse for Ranges {
|
||||||
fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
|
fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
|
||||||
|
@ -454,7 +465,7 @@ impl Parse for Ranges {
|
||||||
input.parse_comma_separated(|input| {
|
input.parse_comma_separated(|input| {
|
||||||
let opt_start = parse_bound(input)?;
|
let opt_start = parse_bound(input)?;
|
||||||
let opt_end = parse_bound(input)?;
|
let opt_end = parse_bound(input)?;
|
||||||
if let (Some(start), Some(end)) = (opt_start, opt_end) {
|
if let (CounterBound::Integer(start), CounterBound::Integer(end)) = (opt_start, opt_end) {
|
||||||
if start > end {
|
if start > end {
|
||||||
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
|
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
|
||||||
}
|
}
|
||||||
|
@ -465,11 +476,17 @@ impl Parse for Ranges {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_bound<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Option<i32>, ParseError<'i>> {
|
fn parse_bound<'i, 't>(
|
||||||
|
input: &mut Parser<'i, 't>,
|
||||||
|
) -> Result<CounterBound, ParseError<'i>> {
|
||||||
let location = input.current_source_location();
|
let location = input.current_source_location();
|
||||||
match *input.next()? {
|
match *input.next()? {
|
||||||
Token::Number { int_value: Some(v), .. } => Ok(Some(v)),
|
Token::Number { int_value: Some(v), .. } => {
|
||||||
Token::Ident(ref ident) if ident.eq_ignore_ascii_case("infinite") => Ok(None),
|
Ok(CounterBound::Integer(v))
|
||||||
|
}
|
||||||
|
Token::Ident(ref ident) if ident.eq_ignore_ascii_case("infinite") => {
|
||||||
|
Ok(CounterBound::Infinite)
|
||||||
|
}
|
||||||
ref t => Err(location.new_unexpected_token_error(t.clone())),
|
ref t => Err(location.new_unexpected_token_error(t.clone())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -493,24 +510,13 @@ impl ToCss for Ranges {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn range_to_css<W>(range: &Range<Option<i32>>, dest: &mut CssWriter<W>) -> fmt::Result
|
fn range_to_css<W>(range: &Range<CounterBound>, dest: &mut CssWriter<W>) -> fmt::Result
|
||||||
where
|
where
|
||||||
W: Write,
|
W: Write,
|
||||||
{
|
{
|
||||||
bound_to_css(range.start, dest)?;
|
range.start.to_css(dest)?;
|
||||||
dest.write_char(' ')?;
|
dest.write_char(' ')?;
|
||||||
bound_to_css(range.end, dest)
|
range.end.to_css(dest)
|
||||||
}
|
|
||||||
|
|
||||||
fn bound_to_css<W>(range: Option<i32>, dest: &mut CssWriter<W>) -> fmt::Result
|
|
||||||
where
|
|
||||||
W: Write,
|
|
||||||
{
|
|
||||||
if let Some(finite) = range {
|
|
||||||
finite.to_css(dest)
|
|
||||||
} else {
|
|
||||||
dest.write_str("infinite")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <https://drafts.csswg.org/css-counter-styles/#counter-style-pad>
|
/// <https://drafts.csswg.org/css-counter-styles/#counter-style-pad>
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
use byteorder::{BigEndian, WriteBytesExt};
|
use byteorder::{BigEndian, WriteBytesExt};
|
||||||
use computed_values::{font_stretch, font_style, font_weight};
|
use computed_values::{font_stretch, font_style, font_weight};
|
||||||
use counter_style;
|
use counter_style::{self, CounterBound};
|
||||||
use cssparser::UnicodeRange;
|
use cssparser::UnicodeRange;
|
||||||
use font_face::{FontFaceRuleData, Source, FontDisplay, FontWeight};
|
use font_face::{FontFaceRuleData, Source, FontDisplay, FontWeight};
|
||||||
use gecko_bindings::bindings;
|
use gecko_bindings::bindings;
|
||||||
|
@ -324,8 +324,8 @@ impl ToNsCssValue for counter_style::Ranges {
|
||||||
nscssvalue.set_auto();
|
nscssvalue.set_auto();
|
||||||
} else {
|
} else {
|
||||||
nscssvalue.set_pair_list(self.0.into_iter().map(|range| {
|
nscssvalue.set_pair_list(self.0.into_iter().map(|range| {
|
||||||
fn set_bound(bound: Option<i32>, nscssvalue: &mut nsCSSValue) {
|
fn set_bound(bound: CounterBound, nscssvalue: &mut nsCSSValue) {
|
||||||
if let Some(finite) = bound {
|
if let CounterBound::Integer(finite) = bound {
|
||||||
nscssvalue.set_integer(finite)
|
nscssvalue.set_integer(finite)
|
||||||
} else {
|
} else {
|
||||||
nscssvalue.set_enum(structs::NS_STYLE_COUNTER_RANGE_INFINITE as i32)
|
nscssvalue.set_enum(structs::NS_STYLE_COUNTER_RANGE_INFINITE as i32)
|
||||||
|
|
|
@ -66,7 +66,7 @@ apply_non_ts_list!(pseudo_class_name);
|
||||||
impl ToCss for NonTSPseudoClass {
|
impl ToCss for NonTSPseudoClass {
|
||||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||||
use cssparser::CssStringWriter;
|
use cssparser::CssStringWriter;
|
||||||
use fmt::Write;
|
use std::fmt::Write;
|
||||||
macro_rules! pseudo_class_serialize {
|
macro_rules! pseudo_class_serialize {
|
||||||
(bare: [$(($css:expr, $name:ident, $gecko_type:tt, $state:tt, $flags:tt),)*],
|
(bare: [$(($css:expr, $name:ident, $gecko_type:tt, $state:tt, $flags:tt),)*],
|
||||||
string: [$(($s_css:expr, $s_name:ident, $s_gecko_type:tt, $s_state:tt, $s_flags:tt),)*]) => {
|
string: [$(($s_css:expr, $s_name:ident, $s_gecko_type:tt, $s_state:tt, $s_flags:tt),)*]) => {
|
||||||
|
|
|
@ -133,9 +133,6 @@ pub mod traversal_flags;
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
pub mod values;
|
pub mod values;
|
||||||
|
|
||||||
use std::fmt::{self, Write};
|
|
||||||
use style_traits::{CssWriter, ToCss};
|
|
||||||
|
|
||||||
#[cfg(feature = "gecko")] pub use gecko_string_cache as string_cache;
|
#[cfg(feature = "gecko")] pub use gecko_string_cache as string_cache;
|
||||||
#[cfg(feature = "gecko")] pub use gecko_string_cache::Atom;
|
#[cfg(feature = "gecko")] pub use gecko_string_cache::Atom;
|
||||||
#[cfg(feature = "gecko")] pub use gecko_string_cache::Namespace;
|
#[cfg(feature = "gecko")] pub use gecko_string_cache::Namespace;
|
||||||
|
@ -181,30 +178,6 @@ macro_rules! reexport_computed_values {
|
||||||
}
|
}
|
||||||
longhand_properties_idents!(reexport_computed_values);
|
longhand_properties_idents!(reexport_computed_values);
|
||||||
|
|
||||||
/// Serializes as CSS a comma-separated list of any `T` that supports being
|
|
||||||
/// serialized as CSS.
|
|
||||||
pub fn serialize_comma_separated_list<W, T>(
|
|
||||||
dest: &mut CssWriter<W>,
|
|
||||||
list: &[T],
|
|
||||||
) -> fmt::Result
|
|
||||||
where
|
|
||||||
W: Write,
|
|
||||||
T: ToCss,
|
|
||||||
{
|
|
||||||
if list.is_empty() {
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
|
|
||||||
list[0].to_css(dest)?;
|
|
||||||
|
|
||||||
for item in list.iter().skip(1) {
|
|
||||||
dest.write_str(", ")?;
|
|
||||||
item.to_css(dest)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "gecko")] use gecko_string_cache::WeakAtom;
|
#[cfg(feature = "gecko")] use gecko_string_cache::WeakAtom;
|
||||||
#[cfg(feature = "servo")] use servo_atoms::Atom as WeakAtom;
|
#[cfg(feature = "servo")] use servo_atoms::Atom as WeakAtom;
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,6 @@ use cssparser::{Token, ParserInput};
|
||||||
use error_reporting::{ContextualParseError, ParseErrorReporter};
|
use error_reporting::{ContextualParseError, ParseErrorReporter};
|
||||||
use parser::{ParserContext, ParserErrorContext};
|
use parser::{ParserContext, ParserErrorContext};
|
||||||
use selectors::parser::SelectorParseErrorKind;
|
use selectors::parser::SelectorParseErrorKind;
|
||||||
use serialize_comma_separated_list;
|
|
||||||
use std::fmt::{self, Write};
|
use std::fmt::{self, Write};
|
||||||
use str::string_as_ascii_lowercase;
|
use str::string_as_ascii_lowercase;
|
||||||
use style_traits::{CssWriter, ToCss, ParseError, StyleParseErrorKind};
|
use style_traits::{CssWriter, ToCss, ParseError, StyleParseErrorKind};
|
||||||
|
@ -25,22 +24,14 @@ pub use servo::media_queries::{Device, Expression};
|
||||||
pub use gecko::media_queries::{Device, Expression};
|
pub use gecko::media_queries::{Device, Expression};
|
||||||
|
|
||||||
/// A type that encapsulates a media query list.
|
/// A type that encapsulates a media query list.
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
#[cfg_attr(feature = "servo", derive(MallocSizeOf))]
|
#[cfg_attr(feature = "servo", derive(MallocSizeOf))]
|
||||||
|
#[css(comma, iterable)]
|
||||||
|
#[derive(Clone, Debug, ToCss)]
|
||||||
pub struct MediaList {
|
pub struct MediaList {
|
||||||
/// The list of media queries.
|
/// The list of media queries.
|
||||||
pub media_queries: Vec<MediaQuery>,
|
pub media_queries: Vec<MediaQuery>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToCss for MediaList {
|
|
||||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
|
||||||
where
|
|
||||||
W: Write,
|
|
||||||
{
|
|
||||||
serialize_comma_separated_list(dest, &self.media_queries)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl MediaList {
|
impl MediaList {
|
||||||
/// Create an empty MediaList.
|
/// Create an empty MediaList.
|
||||||
pub fn empty() -> Self {
|
pub fn empty() -> Self {
|
||||||
|
|
|
@ -83,8 +83,10 @@
|
||||||
need_animatable=need_animatable, **kwargs)">
|
need_animatable=need_animatable, **kwargs)">
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
|
% if allow_empty:
|
||||||
use std::fmt::{self, Write};
|
use std::fmt::{self, Write};
|
||||||
use style_traits::{CssWriter, Separator, ToCss};
|
use style_traits::{CssWriter, Separator, ToCss};
|
||||||
|
% endif
|
||||||
|
|
||||||
pub mod single_value {
|
pub mod single_value {
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
|
@ -122,6 +124,14 @@
|
||||||
% if need_animatable or animation_value_type == "ComputedValue":
|
% if need_animatable or animation_value_type == "ComputedValue":
|
||||||
#[derive(Animate, ComputeSquaredDistance)]
|
#[derive(Animate, ComputeSquaredDistance)]
|
||||||
% endif
|
% endif
|
||||||
|
% if not allow_empty:
|
||||||
|
% if separator == "Comma":
|
||||||
|
#[css(comma, iterable)]
|
||||||
|
% else:
|
||||||
|
#[css(iterable)]
|
||||||
|
% endif
|
||||||
|
#[derive(ToCss)]
|
||||||
|
% endif
|
||||||
pub struct T(
|
pub struct T(
|
||||||
% if allow_empty and allow_empty != "NotInitial":
|
% if allow_empty and allow_empty != "NotInitial":
|
||||||
pub Vec<single_value::T>,
|
pub Vec<single_value::T>,
|
||||||
|
@ -154,6 +164,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
% if allow_empty:
|
||||||
impl ToCss for computed_value::T {
|
impl ToCss for computed_value::T {
|
||||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
||||||
where
|
where
|
||||||
|
@ -163,11 +174,7 @@
|
||||||
if let Some(val) = iter.next() {
|
if let Some(val) = iter.next() {
|
||||||
val.to_css(dest)?;
|
val.to_css(dest)?;
|
||||||
} else {
|
} else {
|
||||||
% if allow_empty:
|
return dest.write_str("none");
|
||||||
dest.write_str("none")?;
|
|
||||||
% else:
|
|
||||||
warn!("Found empty value for property ${name}");
|
|
||||||
% endif
|
|
||||||
}
|
}
|
||||||
for i in iter {
|
for i in iter {
|
||||||
dest.write_str(::style_traits::${separator}::separator())?;
|
dest.write_str(::style_traits::${separator}::separator())?;
|
||||||
|
@ -176,11 +183,21 @@
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
% endif
|
||||||
|
|
||||||
/// The specified value of ${name}.
|
/// The specified value of ${name}.
|
||||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq)]
|
#[derive(Clone, Debug, MallocSizeOf, PartialEq)]
|
||||||
|
% if not allow_empty:
|
||||||
|
% if separator == "Comma":
|
||||||
|
#[css(comma, iterable)]
|
||||||
|
% else:
|
||||||
|
#[css(iterable)]
|
||||||
|
% endif
|
||||||
|
#[derive(ToCss)]
|
||||||
|
% endif
|
||||||
pub struct SpecifiedValue(pub Vec<single_value::SpecifiedValue>);
|
pub struct SpecifiedValue(pub Vec<single_value::SpecifiedValue>);
|
||||||
|
|
||||||
|
% if allow_empty:
|
||||||
impl ToCss for SpecifiedValue {
|
impl ToCss for SpecifiedValue {
|
||||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
||||||
where
|
where
|
||||||
|
@ -190,11 +207,7 @@
|
||||||
if let Some(val) = iter.next() {
|
if let Some(val) = iter.next() {
|
||||||
val.to_css(dest)?;
|
val.to_css(dest)?;
|
||||||
} else {
|
} else {
|
||||||
% if allow_empty:
|
return dest.write_str("none");
|
||||||
dest.write_str("none")?;
|
|
||||||
% else:
|
|
||||||
warn!("Found empty value for property ${name}");
|
|
||||||
% endif
|
|
||||||
}
|
}
|
||||||
for i in iter {
|
for i in iter {
|
||||||
dest.write_str(::style_traits::${separator}::separator())?;
|
dest.write_str(::style_traits::${separator}::separator())?;
|
||||||
|
@ -203,6 +216,7 @@
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
% endif
|
||||||
|
|
||||||
pub fn get_initial_value() -> computed_value::T {
|
pub fn get_initial_value() -> computed_value::T {
|
||||||
% if allow_empty and allow_empty != "NotInitial":
|
% if allow_empty and allow_empty != "NotInitial":
|
||||||
|
|
|
@ -1308,7 +1308,7 @@ impl ShorthandId {
|
||||||
|
|
||||||
/// Servo's representation of a declared value for a given `T`, which is the
|
/// Servo's representation of a declared value for a given `T`, which is the
|
||||||
/// declared value for that property.
|
/// declared value for that property.
|
||||||
#[derive(Clone, Debug, Eq, PartialEq, ToCss)]
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||||
pub enum DeclaredValue<'a, T: 'a> {
|
pub enum DeclaredValue<'a, T: 'a> {
|
||||||
/// A known specified value from the stylesheet.
|
/// A known specified value from the stylesheet.
|
||||||
Value(&'a T),
|
Value(&'a T),
|
||||||
|
@ -1323,7 +1323,7 @@ pub enum DeclaredValue<'a, T: 'a> {
|
||||||
/// extra discriminant word) and synthesize dependent DeclaredValues for
|
/// extra discriminant word) and synthesize dependent DeclaredValues for
|
||||||
/// PropertyDeclaration instances as needed.
|
/// PropertyDeclaration instances as needed.
|
||||||
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
|
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
|
||||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
#[derive(Clone, Debug, Eq, PartialEq, ToCss)]
|
||||||
pub enum DeclaredValueOwned<T> {
|
pub enum DeclaredValueOwned<T> {
|
||||||
/// A known specified value from the stylesheet.
|
/// A known specified value from the stylesheet.
|
||||||
Value(T),
|
Value(T),
|
||||||
|
@ -1756,7 +1756,7 @@ impl ToCss for CustomDeclaration {
|
||||||
where
|
where
|
||||||
W: fmt::Write,
|
W: fmt::Write,
|
||||||
{
|
{
|
||||||
self.value.borrow().to_css(dest)
|
self.value.to_css(dest)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue