mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Derive ToCss for MediaList
This uncovered the fancy snowflake `use fmt::Write` in the impl of ToCss for NonTSPseudoClass.
This commit is contained in:
parent
fb8b6fc0a5
commit
31036d6510
3 changed files with 3 additions and 39 deletions
|
@ -66,7 +66,7 @@ apply_non_ts_list!(pseudo_class_name);
|
|||
impl ToCss for NonTSPseudoClass {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
use cssparser::CssStringWriter;
|
||||
use fmt::Write;
|
||||
use std::fmt::Write;
|
||||
macro_rules! pseudo_class_serialize {
|
||||
(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),)*]) => {
|
||||
|
|
|
@ -133,9 +133,6 @@ pub mod traversal_flags;
|
|||
#[allow(non_camel_case_types)]
|
||||
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::Atom;
|
||||
#[cfg(feature = "gecko")] pub use gecko_string_cache::Namespace;
|
||||
|
@ -181,30 +178,6 @@ macro_rules! 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 = "servo")] use servo_atoms::Atom as WeakAtom;
|
||||
|
||||
|
|
|
@ -13,7 +13,6 @@ use cssparser::{Token, ParserInput};
|
|||
use error_reporting::{ContextualParseError, ParseErrorReporter};
|
||||
use parser::{ParserContext, ParserErrorContext};
|
||||
use selectors::parser::SelectorParseErrorKind;
|
||||
use serialize_comma_separated_list;
|
||||
use std::fmt::{self, Write};
|
||||
use str::string_as_ascii_lowercase;
|
||||
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};
|
||||
|
||||
/// A type that encapsulates a media query list.
|
||||
#[derive(Clone, Debug)]
|
||||
#[cfg_attr(feature = "servo", derive(MallocSizeOf))]
|
||||
#[css(comma, iterable)]
|
||||
#[derive(Clone, Debug, ToCss)]
|
||||
pub struct MediaList {
|
||||
/// The list of media queries.
|
||||
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 {
|
||||
/// Create an empty MediaList.
|
||||
pub fn empty() -> Self {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue