mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
Change ToCss to take a CssWriter<W>
This more concrete wrapper type can write a prefix the very first time something is written to it. This allows removing plenty of useless monomorphisations caused by the former W/SequenceWriter<W> pair of types.
This commit is contained in:
parent
3672856efa
commit
cd8f96cc9e
89 changed files with 873 additions and 533 deletions
|
@ -16,11 +16,11 @@ use properties::animated_properties::AnimationValue;
|
|||
use shared_lock::Locked;
|
||||
use smallbitvec::{self, SmallBitVec};
|
||||
use smallvec::SmallVec;
|
||||
use std::fmt;
|
||||
use std::fmt::{self, Write};
|
||||
use std::iter::{DoubleEndedIterator, Zip};
|
||||
use std::slice::Iter;
|
||||
use str::{CssString, CssStringBorrow, CssStringWriter};
|
||||
use style_traits::{ToCss, ParseError, ParsingMode, StyleParseErrorKind};
|
||||
use style_traits::{CssWriter, ParseError, ParsingMode, StyleParseErrorKind, ToCss};
|
||||
use stylesheets::{CssRuleType, Origin, UrlExtraData};
|
||||
use super::*;
|
||||
use values::computed::Context;
|
||||
|
@ -664,7 +664,7 @@ impl PropertyDeclarationBlock {
|
|||
css.append_to(dest)
|
||||
},
|
||||
Some(AppendableValue::DeclarationsForShorthand(_, decls)) => {
|
||||
shorthand.longhands_to_css(decls, dest)
|
||||
shorthand.longhands_to_css(decls, &mut CssWriter::new(dest))
|
||||
}
|
||||
_ => Ok(())
|
||||
}
|
||||
|
@ -845,7 +845,7 @@ impl PropertyDeclarationBlock {
|
|||
}
|
||||
#[cfg(feature = "gecko")]
|
||||
(_, Some(sys)) => {
|
||||
sys.to_css(&mut v)?;
|
||||
sys.to_css(&mut CssWriter::new(&mut v))?;
|
||||
AppendableValue::Css {
|
||||
css: CssStringBorrow::from(&v),
|
||||
with_variables: false,
|
||||
|
@ -951,10 +951,12 @@ pub enum AppendableValue<'a, I>
|
|||
}
|
||||
|
||||
/// Potentially appends whitespace after the first (property: value;) pair.
|
||||
fn handle_first_serialization<W>(dest: &mut W,
|
||||
is_first_serialization: &mut bool)
|
||||
-> fmt::Result
|
||||
where W: fmt::Write,
|
||||
fn handle_first_serialization<W>(
|
||||
dest: &mut W,
|
||||
is_first_serialization: &mut bool,
|
||||
) -> fmt::Result
|
||||
where
|
||||
W: Write,
|
||||
{
|
||||
if !*is_first_serialization {
|
||||
dest.write_str(" ")
|
||||
|
@ -980,7 +982,7 @@ where
|
|||
decl.to_css(dest)
|
||||
},
|
||||
AppendableValue::DeclarationsForShorthand(shorthand, decls) => {
|
||||
shorthand.longhands_to_css(decls, dest)
|
||||
shorthand.longhands_to_css(decls, &mut CssWriter::new(dest))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -999,7 +1001,7 @@ where
|
|||
{
|
||||
handle_first_serialization(dest, is_first_serialization)?;
|
||||
|
||||
property_name.to_css(dest)?;
|
||||
property_name.to_css(&mut CssWriter::new(dest))?;
|
||||
dest.write_char(':')?;
|
||||
|
||||
// for normal parsed values, add a space between key: and value
|
||||
|
|
|
@ -82,8 +82,8 @@
|
|||
need_animatable=need_animatable, **kwargs)">
|
||||
#[allow(unused_imports)]
|
||||
use smallvec::SmallVec;
|
||||
use std::fmt;
|
||||
use style_traits::{Separator, ToCss};
|
||||
use std::fmt::{self, Write};
|
||||
use style_traits::{CssWriter, Separator, ToCss};
|
||||
|
||||
pub mod single_value {
|
||||
#[allow(unused_imports)]
|
||||
|
@ -154,8 +154,9 @@
|
|||
}
|
||||
|
||||
impl ToCss for computed_value::T {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
|
||||
where W: fmt::Write,
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
||||
where
|
||||
W: Write,
|
||||
{
|
||||
let mut iter = self.0.iter();
|
||||
if let Some(val) = iter.next() {
|
||||
|
@ -180,8 +181,9 @@
|
|||
pub struct SpecifiedValue(pub Vec<single_value::SpecifiedValue>);
|
||||
|
||||
impl ToCss for SpecifiedValue {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
|
||||
where W: fmt::Write,
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
||||
where
|
||||
W: Write,
|
||||
{
|
||||
let mut iter = self.0.iter();
|
||||
if let Some(val) = iter.next() {
|
||||
|
@ -682,11 +684,11 @@
|
|||
#[allow(unused_imports)]
|
||||
use selectors::parser::SelectorParseErrorKind;
|
||||
#[allow(unused_imports)]
|
||||
use std::fmt;
|
||||
use std::fmt::{self, Write};
|
||||
#[allow(unused_imports)]
|
||||
use style_traits::{ParseError, StyleParseErrorKind};
|
||||
#[allow(unused_imports)]
|
||||
use style_traits::ToCss;
|
||||
use style_traits::{CssWriter, ToCss};
|
||||
|
||||
pub struct Longhands {
|
||||
% for sub_property in shorthand.sub_properties:
|
||||
|
@ -806,7 +808,10 @@
|
|||
}
|
||||
|
||||
impl<'a> ToCss for LonghandsToSerialize<'a> {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
||||
where
|
||||
W: Write,
|
||||
{
|
||||
let rect = Rect::new(
|
||||
% for side in ["top", "right", "bottom", "left"]:
|
||||
&self.${to_rust_ident(sub_property_pattern % side)},
|
||||
|
|
|
@ -27,9 +27,9 @@ use selectors::parser::SelectorParseErrorKind;
|
|||
use servo_arc::Arc;
|
||||
use smallvec::SmallVec;
|
||||
use std::cmp;
|
||||
use std::fmt;
|
||||
use std::fmt::{self, Write};
|
||||
#[cfg(feature = "gecko")] use hash::FnvHashMap;
|
||||
use style_traits::{ParseError, ToCss};
|
||||
use style_traits::{CssWriter, ParseError, ToCss};
|
||||
use super::ComputedValues;
|
||||
use values::{CSSFloat, CustomIdent, Either};
|
||||
use values::animated::{Animate, Procedure, ToAnimatedValue, ToAnimatedZero};
|
||||
|
@ -94,7 +94,10 @@ pub enum TransitionProperty {
|
|||
}
|
||||
|
||||
impl ToCss for TransitionProperty {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
||||
where
|
||||
W: Write,
|
||||
{
|
||||
match *self {
|
||||
TransitionProperty::All => dest.write_str("all"),
|
||||
TransitionProperty::Shorthand(ref id) => dest.write_str(id.name()),
|
||||
|
|
|
@ -66,8 +66,8 @@ pub mod system_colors {
|
|||
use cssparser::Parser;
|
||||
use gecko_bindings::bindings::Gecko_GetLookAndFeelSystemColor;
|
||||
use gecko_bindings::structs::root::mozilla::LookAndFeel_ColorID;
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
use std::fmt::{self, Write};
|
||||
use style_traits::{CssWriter, ToCss};
|
||||
use values::computed::{Context, ToComputedValue};
|
||||
|
||||
pub type SystemColor = LookAndFeel_ColorID;
|
||||
|
@ -77,7 +77,10 @@ pub mod system_colors {
|
|||
malloc_size_of_is_0!(SystemColor);
|
||||
|
||||
impl ToCss for SystemColor {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
||||
where
|
||||
W: Write,
|
||||
{
|
||||
let s = match *self {
|
||||
% for color in system_colors + extra_colors:
|
||||
LookAndFeel_ColorID::eColorID_${to_rust_ident(color)} => "${color}",
|
||||
|
|
|
@ -23,8 +23,8 @@
|
|||
|
||||
pub mod computed_value {
|
||||
use cssparser;
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
use std::fmt::{self, Write};
|
||||
use style_traits::{CssWriter, ToCss};
|
||||
#[cfg(feature = "gecko")]
|
||||
use values::specified::url::SpecifiedUrl;
|
||||
|
||||
|
@ -62,7 +62,10 @@
|
|||
}
|
||||
|
||||
impl ToCss for ContentItem {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
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) => {
|
||||
|
@ -106,7 +109,10 @@
|
|||
}
|
||||
|
||||
impl ToCss for T {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
||||
where
|
||||
W: Write,
|
||||
{
|
||||
match *self {
|
||||
T::Normal => dest.write_str("normal"),
|
||||
T::None => dest.write_str("none"),
|
||||
|
@ -232,8 +238,8 @@
|
|||
|
||||
<%helpers:longhand name="counter-increment" animation_value_type="discrete"
|
||||
spec="https://drafts.csswg.org/css-lists/#propdef-counter-increment">
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
use std::fmt::{self, Write};
|
||||
use style_traits::{CssWriter, ToCss};
|
||||
use values::CustomIdent;
|
||||
|
||||
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
|
||||
|
@ -241,16 +247,17 @@
|
|||
pub struct SpecifiedValue(pub Vec<(CustomIdent, specified::Integer)>);
|
||||
|
||||
pub mod computed_value {
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
use std::fmt::{self, Write};
|
||||
use style_traits::{CssWriter, ToCss};
|
||||
use values::CustomIdent;
|
||||
|
||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq)]
|
||||
pub struct T(pub Vec<(CustomIdent, i32)>);
|
||||
|
||||
impl ToCss for T {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
|
||||
where W: fmt::Write,
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
||||
where
|
||||
W: Write,
|
||||
{
|
||||
if self.0.is_empty() {
|
||||
return dest.write_str("none")
|
||||
|
@ -292,10 +299,10 @@
|
|||
computed_value::T(Vec::new())
|
||||
}
|
||||
|
||||
|
||||
impl ToCss for SpecifiedValue {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
|
||||
where W: fmt::Write,
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
||||
where
|
||||
W: Write,
|
||||
{
|
||||
if self.0.is_empty() {
|
||||
return dest.write_str("none");
|
||||
|
|
|
@ -193,8 +193,8 @@ ${helpers.predefined_type(
|
|||
animation_value_type="discrete"
|
||||
spec="https://drafts.csswg.org/css-text-decor/#propdef-text-emphasis-style">
|
||||
use computed_values::writing_mode::T as WritingMode;
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
use std::fmt::{self, Write};
|
||||
use style_traits::{CssWriter, ToCss};
|
||||
use unicode_segmentation::UnicodeSegmentation;
|
||||
|
||||
|
||||
|
@ -229,7 +229,7 @@ ${helpers.predefined_type(
|
|||
}
|
||||
|
||||
impl ToCss for KeywordValue {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
|
||||
if let Some(fill) = self.fill() {
|
||||
if fill {
|
||||
dest.write_str("filled")?;
|
||||
|
@ -246,8 +246,12 @@ ${helpers.predefined_type(
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl ToCss for computed_value::KeywordValue {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
||||
where
|
||||
W: Write,
|
||||
{
|
||||
if self.fill {
|
||||
dest.write_str("filled")?;
|
||||
} else {
|
||||
|
|
|
@ -16,10 +16,9 @@ use custom_properties::CustomPropertiesBuilder;
|
|||
use servo_arc::{Arc, UniqueArc};
|
||||
use smallbitvec::SmallBitVec;
|
||||
use std::borrow::Cow;
|
||||
use std::{mem, ops};
|
||||
use std::cell::RefCell;
|
||||
use std::fmt::{self, Write};
|
||||
use std::mem;
|
||||
use std::ops;
|
||||
|
||||
#[cfg(feature = "servo")] use cssparser::RGBA;
|
||||
use cssparser::{CowRcStr, Parser, TokenSerializationType, serialize_identifier};
|
||||
|
@ -40,7 +39,7 @@ use selector_parser::PseudoElement;
|
|||
use selectors::parser::SelectorParseErrorKind;
|
||||
#[cfg(feature = "servo")] use servo_config::prefs::PREFS;
|
||||
use shared_lock::StylesheetGuards;
|
||||
use style_traits::{ParsingMode, ToCss, ParseError, StyleParseErrorKind};
|
||||
use style_traits::{CssWriter, ParseError, ParsingMode, StyleParseErrorKind, ToCss};
|
||||
use stylesheets::{CssRuleType, Origin, UrlExtraData};
|
||||
#[cfg(feature = "servo")] use values::Either;
|
||||
use values::generics::text::LineHeight;
|
||||
|
@ -855,9 +854,14 @@ impl ShorthandId {
|
|||
///
|
||||
/// Returns an error if writing to the stream fails, or if the declarations
|
||||
/// do not map to a shorthand.
|
||||
pub fn longhands_to_css<'a, W, I>(&self, declarations: I, dest: &mut W) -> fmt::Result
|
||||
where W: fmt::Write,
|
||||
I: Iterator<Item=&'a PropertyDeclaration>,
|
||||
pub fn longhands_to_css<'a, W, I>(
|
||||
&self,
|
||||
declarations: I,
|
||||
dest: &mut CssWriter<W>,
|
||||
) -> fmt::Result
|
||||
where
|
||||
W: Write,
|
||||
I: Iterator<Item=&'a PropertyDeclaration>,
|
||||
{
|
||||
match *self {
|
||||
ShorthandId::All => {
|
||||
|
@ -1075,8 +1079,9 @@ impl UnparsedValue {
|
|||
}
|
||||
|
||||
impl<'a, T: ToCss> ToCss for DeclaredValue<'a, T> {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
|
||||
where W: fmt::Write,
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
||||
where
|
||||
W: Write,
|
||||
{
|
||||
match *self {
|
||||
DeclaredValue::Value(ref inner) => inner.to_css(dest),
|
||||
|
@ -1104,8 +1109,9 @@ pub enum PropertyDeclarationId<'a> {
|
|||
}
|
||||
|
||||
impl<'a> ToCss for PropertyDeclarationId<'a> {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
|
||||
where W: fmt::Write,
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
||||
where
|
||||
W: Write,
|
||||
{
|
||||
match *self {
|
||||
PropertyDeclarationId::Longhand(id) => dest.write_str(id.name()),
|
||||
|
@ -1150,7 +1156,6 @@ impl<'a> PropertyDeclarationId<'a> {
|
|||
match *self {
|
||||
PropertyDeclarationId::Longhand(id) => id.name().into(),
|
||||
PropertyDeclarationId::Custom(name) => {
|
||||
use std::fmt::Write;
|
||||
let mut s = String::new();
|
||||
write!(&mut s, "--{}", name).unwrap();
|
||||
s.into()
|
||||
|
@ -1177,13 +1182,14 @@ pub enum PropertyId {
|
|||
|
||||
impl fmt::Debug for PropertyId {
|
||||
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
self.to_css(formatter)
|
||||
self.to_css(&mut CssWriter::new(formatter))
|
||||
}
|
||||
}
|
||||
|
||||
impl ToCss for PropertyId {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
|
||||
where W: fmt::Write,
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
||||
where
|
||||
W: Write,
|
||||
{
|
||||
match *self {
|
||||
PropertyId::Longhand(id) => dest.write_str(id.name()),
|
||||
|
@ -1331,7 +1337,6 @@ impl PropertyId {
|
|||
PropertyId::LonghandAlias(id, _) |
|
||||
PropertyId::Longhand(id) => id.name().into(),
|
||||
PropertyId::Custom(ref name) => {
|
||||
use std::fmt::Write;
|
||||
let mut s = String::new();
|
||||
write!(&mut s, "--{}", name).unwrap();
|
||||
s.into()
|
||||
|
@ -1464,7 +1469,7 @@ pub enum PropertyDeclaration {
|
|||
|
||||
impl fmt::Debug for PropertyDeclaration {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
self.id().to_css(f)?;
|
||||
self.id().to_css(&mut CssWriter::new(f))?;
|
||||
f.write_str(": ")?;
|
||||
|
||||
// Because PropertyDeclaration::to_css requires CssStringWriter, we can't write
|
||||
|
@ -1483,10 +1488,13 @@ impl PropertyDeclaration {
|
|||
pub fn to_css(&self, dest: &mut CssStringWriter) -> fmt::Result {
|
||||
match *self {
|
||||
% for property in data.longhands:
|
||||
PropertyDeclaration::${property.camel_case}(ref value) =>
|
||||
value.to_css(dest),
|
||||
PropertyDeclaration::${property.camel_case}(ref value) => {
|
||||
value.to_css(&mut CssWriter::new(dest))
|
||||
}
|
||||
% endfor
|
||||
PropertyDeclaration::CSSWideKeyword(_, keyword) => keyword.to_css(dest),
|
||||
PropertyDeclaration::CSSWideKeyword(_, keyword) => {
|
||||
keyword.to_css(&mut CssWriter::new(dest))
|
||||
},
|
||||
PropertyDeclaration::WithVariables(_, ref with_variables) => {
|
||||
// https://drafts.csswg.org/css-variables/#variables-in-shorthands
|
||||
match with_variables.from_shorthand {
|
||||
|
@ -1500,7 +1508,9 @@ impl PropertyDeclaration {
|
|||
}
|
||||
Ok(())
|
||||
},
|
||||
PropertyDeclaration::Custom(_, ref value) => value.borrow().to_css(dest),
|
||||
PropertyDeclaration::Custom(_, ref value) => {
|
||||
value.borrow().to_css(&mut CssWriter::new(dest))
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -131,7 +131,7 @@
|
|||
}
|
||||
|
||||
impl<'a> ToCss for LonghandsToSerialize<'a> {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
|
||||
let len = self.background_image.0.len();
|
||||
// There should be at least one declared value
|
||||
if len == 0 {
|
||||
|
@ -228,7 +228,7 @@
|
|||
}
|
||||
|
||||
impl<'a> ToCss for LonghandsToSerialize<'a> {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
|
||||
let len = self.background_position_x.0.len();
|
||||
if len == 0 || len != self.background_position_y.0.len() {
|
||||
return Ok(());
|
||||
|
|
|
@ -34,7 +34,7 @@ ${helpers.four_sides_shorthand("border-style", "border-%s-style",
|
|||
}
|
||||
|
||||
impl<'a> ToCss for LonghandsToSerialize<'a> {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
|
||||
% for side in PHYSICAL_SIDES:
|
||||
let ${side} = &self.border_${side}_width;
|
||||
% endfor
|
||||
|
@ -113,7 +113,7 @@ pub fn parse_border<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
|
|||
}
|
||||
|
||||
impl<'a> ToCss for LonghandsToSerialize<'a> {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
|
||||
super::serialize_directional_border(
|
||||
dest,
|
||||
self.border_${to_rust_ident(side)}_width,
|
||||
|
@ -156,7 +156,7 @@ pub fn parse_border<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
|
|||
}
|
||||
|
||||
impl<'a> ToCss for LonghandsToSerialize<'a> {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
|
||||
let all_equal = {
|
||||
% for side in PHYSICAL_SIDES:
|
||||
let border_${side}_width = self.border_${side}_width;
|
||||
|
@ -215,7 +215,7 @@ pub fn parse_border<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
|
|||
}
|
||||
|
||||
impl<'a> ToCss for LonghandsToSerialize<'a> {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
|
||||
let LonghandsToSerialize {
|
||||
border_top_left_radius: &BorderCornerRadius(ref tl),
|
||||
border_top_right_radius: &BorderCornerRadius(ref tr),
|
||||
|
@ -315,7 +315,7 @@ pub fn parse_border<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
|
|||
}
|
||||
|
||||
impl<'a> ToCss for LonghandsToSerialize<'a> {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
|
||||
self.border_image_source.to_css(dest)?;
|
||||
dest.write_str(" ")?;
|
||||
self.border_image_slice.to_css(dest)?;
|
||||
|
|
|
@ -48,7 +48,7 @@
|
|||
}
|
||||
|
||||
impl<'a> ToCss for LonghandsToSerialize<'a> {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
|
||||
if self.overflow_x == self.overflow_y {
|
||||
self.overflow_x.to_css(dest)
|
||||
} else {
|
||||
|
@ -83,7 +83,7 @@
|
|||
}
|
||||
|
||||
impl<'a> ToCss for LonghandsToSerialize<'a> {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
|
||||
self.overflow_clip_box_block.to_css(dest)?;
|
||||
|
||||
if self.overflow_clip_box_block != self.overflow_clip_box_inline {
|
||||
|
@ -203,7 +203,7 @@ macro_rules! try_parse_one {
|
|||
}
|
||||
|
||||
impl<'a> ToCss for LonghandsToSerialize<'a> {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
|
||||
let property_len = self.transition_property.0.len();
|
||||
|
||||
// There are two cases that we can do shorthand serialization:
|
||||
|
@ -327,7 +327,7 @@ macro_rules! try_parse_one {
|
|||
}
|
||||
|
||||
impl<'a> ToCss for LonghandsToSerialize<'a> {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
|
||||
let len = self.animation_name.0.len();
|
||||
// There should be at least one declared value
|
||||
if len == 0 {
|
||||
|
@ -376,7 +376,7 @@ macro_rules! try_parse_one {
|
|||
impl<'a> ToCss for LonghandsToSerialize<'a> {
|
||||
// Serializes into the single keyword value if both scroll-snap-type-x and scroll-snap-type-y are same.
|
||||
// Otherwise into an empty string. This is done to match Gecko's behaviour.
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
|
||||
if self.scroll_snap_type_x == self.scroll_snap_type_y {
|
||||
self.scroll_snap_type_x.to_css(dest)
|
||||
} else {
|
||||
|
@ -406,7 +406,7 @@ macro_rules! try_parse_one {
|
|||
impl<'a> ToCss for LonghandsToSerialize<'a> {
|
||||
// Serializes into the single keyword value if both overscroll-behavior-x and overscroll-behavior-y are same.
|
||||
// Otherwise into two values separated by a space.
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
|
||||
self.overscroll_behavior_x.to_css(dest)?;
|
||||
if self.overscroll_behavior_y != self.overscroll_behavior_x {
|
||||
dest.write_str(" ")?;
|
||||
|
|
|
@ -151,9 +151,14 @@
|
|||
}
|
||||
|
||||
impl<'a> LonghandsToSerialize<'a> {
|
||||
fn to_css_for<W>(&self,
|
||||
serialize_for: SerializeFor,
|
||||
dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
fn to_css_for<W>(
|
||||
&self,
|
||||
serialize_for: SerializeFor,
|
||||
dest: &mut CssWriter<W>,
|
||||
) -> fmt::Result
|
||||
where
|
||||
W: Write,
|
||||
{
|
||||
% if product == "gecko":
|
||||
match self.check_system() {
|
||||
CheckSystemResult::AllSystem(sys) => return sys.to_css(dest),
|
||||
|
@ -226,7 +231,7 @@
|
|||
}
|
||||
|
||||
/// Serialize the shorthand value for canvas font attribute.
|
||||
pub fn to_css_for_canvas<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
pub fn to_css_for_canvas<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
|
||||
self.to_css_for(SerializeFor::Canvas, dest)
|
||||
}
|
||||
% endif
|
||||
|
@ -234,7 +239,7 @@
|
|||
|
||||
// This may be a bit off, unsure, possibly needs changes
|
||||
impl<'a> ToCss for LonghandsToSerialize<'a> {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
|
||||
self.to_css_for(SerializeFor::Normal, dest)
|
||||
}
|
||||
}
|
||||
|
@ -309,7 +314,7 @@
|
|||
|
||||
impl<'a> ToCss for LonghandsToSerialize<'a> {
|
||||
#[allow(unused_assignments)]
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
|
||||
|
||||
let has_none_ligatures =
|
||||
% if product == "gecko":
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
}
|
||||
|
||||
impl<'a> ToCss for LonghandsToSerialize<'a> {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
|
||||
if self.marker_start == self.marker_mid && self.marker_mid == self.marker_end {
|
||||
self.marker_start.to_css(dest)
|
||||
} else {
|
||||
|
|
|
@ -121,7 +121,7 @@
|
|||
}
|
||||
|
||||
impl<'a> ToCss for LonghandsToSerialize<'a> {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
|
||||
use properties::longhands::mask_origin::single_value::computed_value::T as Origin;
|
||||
use properties::longhands::mask_clip::single_value::computed_value::T as Clip;
|
||||
|
||||
|
@ -214,7 +214,7 @@
|
|||
}
|
||||
|
||||
impl<'a> ToCss for LonghandsToSerialize<'a> {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
|
||||
let len = self.mask_position_x.0.len();
|
||||
if len == 0 || self.mask_position_y.0.len() != len {
|
||||
return Ok(());
|
||||
|
|
|
@ -76,7 +76,7 @@
|
|||
}
|
||||
|
||||
impl<'a> ToCss for LonghandsToSerialize<'a> {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
|
||||
use values::generics::border::BorderCornerRadius;
|
||||
|
||||
let LonghandsToSerialize {
|
||||
|
|
|
@ -119,7 +119,7 @@
|
|||
}
|
||||
|
||||
impl<'a> ToCss for LonghandsToSerialize<'a> {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
|
||||
if self.grid_row_gap == self.grid_column_gap {
|
||||
self.grid_row_gap.to_css(dest)
|
||||
} else {
|
||||
|
@ -163,7 +163,7 @@
|
|||
}
|
||||
|
||||
impl<'a> ToCss for LonghandsToSerialize<'a> {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
|
||||
self.grid_${kind}_start.to_css(dest)?;
|
||||
dest.write_str(" / ")?;
|
||||
self.grid_${kind}_end.to_css(dest)
|
||||
|
@ -224,7 +224,7 @@
|
|||
}
|
||||
|
||||
impl<'a> ToCss for LonghandsToSerialize<'a> {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
|
||||
self.grid_row_start.to_css(dest)?;
|
||||
let values = [&self.grid_column_start, &self.grid_row_end, &self.grid_column_end];
|
||||
for value in &values {
|
||||
|
@ -362,10 +362,14 @@
|
|||
}
|
||||
|
||||
/// Serialization for `<grid-template>` shorthand (also used by `grid` shorthand).
|
||||
pub fn serialize_grid_template<W>(template_rows: &GridTemplateComponent,
|
||||
template_columns: &GridTemplateComponent,
|
||||
template_areas: &Either<TemplateAreas, None_>,
|
||||
dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
pub fn serialize_grid_template<W>(
|
||||
template_rows: &GridTemplateComponent,
|
||||
template_columns: &GridTemplateComponent,
|
||||
template_areas: &Either<TemplateAreas, None_>,
|
||||
dest: &mut CssWriter<W>,
|
||||
) -> fmt::Result
|
||||
where
|
||||
W: Write {
|
||||
match *template_areas {
|
||||
Either::Second(_none) => {
|
||||
template_rows.to_css(dest)?;
|
||||
|
@ -451,7 +455,7 @@
|
|||
|
||||
impl<'a> ToCss for LonghandsToSerialize<'a> {
|
||||
#[inline]
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
|
||||
serialize_grid_template(self.grid_template_rows, self.grid_template_columns,
|
||||
self.grid_template_areas, dest)
|
||||
}
|
||||
|
@ -542,7 +546,7 @@
|
|||
}
|
||||
|
||||
impl<'a> ToCss for LonghandsToSerialize<'a> {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
|
||||
if *self.grid_template_areas != Either::Second(None_) ||
|
||||
(*self.grid_template_rows != GridTemplateComponent::None &&
|
||||
*self.grid_template_columns != GridTemplateComponent::None) ||
|
||||
|
@ -635,7 +639,7 @@
|
|||
}
|
||||
|
||||
impl<'a> ToCss for LonghandsToSerialize<'a> {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
|
||||
self.align_content.to_css(dest)?;
|
||||
if self.align_content != self.justify_content {
|
||||
dest.write_str(" ")?;
|
||||
|
@ -670,7 +674,7 @@
|
|||
}
|
||||
|
||||
impl<'a> ToCss for LonghandsToSerialize<'a> {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
|
||||
if self.align_self == self.justify_self {
|
||||
self.align_self.to_css(dest)
|
||||
} else {
|
||||
|
@ -713,7 +717,7 @@
|
|||
}
|
||||
|
||||
impl<'a> ToCss for LonghandsToSerialize<'a> {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
|
||||
if self.align_items.0 == self.justify_items.0 {
|
||||
self.align_items.to_css(dest)
|
||||
} else {
|
||||
|
|
|
@ -2,15 +2,20 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use style_traits::ToCss;
|
||||
use style_traits::{CssWriter, ToCss};
|
||||
use values::specified::{BorderStyle, Color};
|
||||
use std::fmt;
|
||||
use std::fmt::{self, Write};
|
||||
|
||||
fn serialize_directional_border<W, I,>(dest: &mut W,
|
||||
width: &I,
|
||||
style: &BorderStyle,
|
||||
color: &Color)
|
||||
-> fmt::Result where W: fmt::Write, I: ToCss {
|
||||
fn serialize_directional_border<W, I,>(
|
||||
dest: &mut CssWriter<W>,
|
||||
width: &I,
|
||||
style: &BorderStyle,
|
||||
color: &Color,
|
||||
) -> fmt::Result
|
||||
where
|
||||
W: Write,
|
||||
I: ToCss,
|
||||
{
|
||||
width.to_css(dest)?;
|
||||
dest.write_str(" ")?;
|
||||
style.to_css(dest)?;
|
||||
|
|
|
@ -62,7 +62,7 @@
|
|||
}
|
||||
|
||||
impl<'a> ToCss for LonghandsToSerialize<'a> {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
|
||||
self.text_decoration_line.to_css(dest)?;
|
||||
|
||||
% if product == "gecko":
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue