mirror of
https://github.com/servo/servo.git
synced 2025-08-27 08:08:19 +01:00
Adding support for correct shorthand serialization
This commit is contained in:
parent
49431be44a
commit
3831c0650c
23 changed files with 1186 additions and 643 deletions
97
components/style/properties/shorthand/serialize.mako.rs
Normal file
97
components/style/properties/shorthand/serialize.mako.rs
Normal file
|
@ -0,0 +1,97 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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 cssparser::ToCss;
|
||||
use properties::{AppendableValue, DeclaredValue, PropertyDeclaration, Shorthand};
|
||||
use values::specified::{BorderStyle, CSSColor};
|
||||
use std::fmt;
|
||||
|
||||
pub fn serialize_four_sides<W, I>(dest: &mut W, top: &I, right: &I, bottom: &I, left: &I)
|
||||
-> fmt::Result where W: fmt::Write, I: ToCss + PartialEq {
|
||||
|
||||
if left == right {
|
||||
let horizontal_value = left;
|
||||
|
||||
if top == bottom {
|
||||
let vertical_value = top;
|
||||
|
||||
if horizontal_value == vertical_value {
|
||||
let single_value = horizontal_value;
|
||||
try!(single_value.to_css(dest));
|
||||
} else {
|
||||
try!(vertical_value.to_css(dest));
|
||||
try!(write!(dest, " "));
|
||||
|
||||
try!(horizontal_value.to_css(dest));
|
||||
}
|
||||
} else {
|
||||
try!(top.to_css(dest));
|
||||
try!(write!(dest, " "));
|
||||
|
||||
try!(horizontal_value.to_css(dest));
|
||||
try!(write!(dest, " "));
|
||||
|
||||
try!(bottom.to_css(dest));
|
||||
}
|
||||
} else {
|
||||
try!(top.to_css(dest));
|
||||
try!(write!(dest, " "));
|
||||
|
||||
try!(right.to_css(dest));
|
||||
try!(write!(dest, " "));
|
||||
|
||||
try!(bottom.to_css(dest));
|
||||
try!(write!(dest, " "));
|
||||
|
||||
try!(left.to_css(dest));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn serialize_directional_border<W, I>(dest: &mut W,
|
||||
width: &DeclaredValue<I>,
|
||||
style: &DeclaredValue<BorderStyle>,
|
||||
color: &DeclaredValue<CSSColor>)
|
||||
-> fmt::Result where W: fmt::Write, I: ToCss {
|
||||
match *width {
|
||||
DeclaredValue::Value(ref width) => {
|
||||
try!(width.to_css(dest));
|
||||
},
|
||||
_ => {
|
||||
try!(write!(dest, "medium"));
|
||||
}
|
||||
};
|
||||
|
||||
try!(write!(dest, " "));
|
||||
|
||||
match *style {
|
||||
DeclaredValue::Value(ref style) => {
|
||||
try!(style.to_css(dest));
|
||||
},
|
||||
_ => {
|
||||
try!(write!(dest, "none"));
|
||||
}
|
||||
};
|
||||
|
||||
match *color {
|
||||
DeclaredValue::Value(ref color) => {
|
||||
try!(write!(dest, " "));
|
||||
color.to_css(dest)
|
||||
},
|
||||
_ => Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn is_overflow_shorthand<'a, I>(appendable_value: &AppendableValue<'a, I>) -> bool
|
||||
where I: Iterator<Item=&'a PropertyDeclaration> {
|
||||
if let AppendableValue::DeclarationsForShorthand(shorthand, _) = *appendable_value {
|
||||
if let Shorthand::Overflow = shorthand {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
false
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue