mirror of
https://github.com/servo/servo.git
synced 2025-06-24 09:04:33 +01:00
Add allow_empty to vector_longhand
This commit is contained in:
parent
34c82d6e78
commit
b6edae2f5e
1 changed files with 38 additions and 14 deletions
|
@ -41,11 +41,11 @@
|
|||
to True for cases where Servo takes a single value
|
||||
and Stylo supports vector values.
|
||||
|
||||
If the computed value is the same as the specified value,
|
||||
setting computed_is_specified to True will introduce additional
|
||||
optimizations
|
||||
Setting allow_empty to False allows for cases where the vector
|
||||
is empty. The grammar for these is usually "none | <thing> [ , <thing> ]*".
|
||||
We assume that the default/initial value is an empty vector for these.
|
||||
</%doc>
|
||||
<%def name="vector_longhand(name, gecko_only=False, **kwargs)">
|
||||
<%def name="vector_longhand(name, gecko_only=False, allow_empty=False, **kwargs)">
|
||||
<%call expr="longhand(name, **kwargs)">
|
||||
% if product == "gecko" or not gecko_only:
|
||||
use cssparser::ToCss;
|
||||
|
@ -68,10 +68,15 @@
|
|||
|
||||
impl ToCss for computed_value::T {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
if !self.0.is_empty() {
|
||||
try!(self.0[0].to_css(dest));
|
||||
let mut iter = self.0.iter();
|
||||
if let Some(val) = iter.next() {
|
||||
try!(val.to_css(dest));
|
||||
} else {
|
||||
% if allow_empty:
|
||||
try!(dest.write_str("none"));
|
||||
% endif
|
||||
}
|
||||
for i in self.0.iter().skip(1) {
|
||||
for i in iter {
|
||||
try!(dest.write_str(", "));
|
||||
try!(i.to_css(dest));
|
||||
}
|
||||
|
@ -85,10 +90,15 @@
|
|||
|
||||
impl ToCss for SpecifiedValue {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
if !self.0.is_empty() {
|
||||
try!(self.0[0].to_css(dest))
|
||||
let mut iter = self.0.iter();
|
||||
if let Some(val) = iter.next() {
|
||||
try!(val.to_css(dest));
|
||||
} else {
|
||||
% if allow_empty:
|
||||
try!(dest.write_str("none"));
|
||||
% endif
|
||||
}
|
||||
for i in self.0.iter().skip(1) {
|
||||
for i in iter {
|
||||
try!(dest.write_str(", "));
|
||||
try!(i.to_css(dest));
|
||||
}
|
||||
|
@ -96,12 +106,26 @@
|
|||
}
|
||||
}
|
||||
pub fn get_initial_value() -> computed_value::T {
|
||||
computed_value::T(vec![single_value::get_initial_value()])
|
||||
% if allow_empty:
|
||||
computed_value::T(vec![])
|
||||
% else:
|
||||
computed_value::T(vec![single_value::get_initial_value()])
|
||||
% endif
|
||||
}
|
||||
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
|
||||
input.parse_comma_separated(|parser| {
|
||||
single_value::parse(context, parser)
|
||||
}).map(|ok| SpecifiedValue(ok))
|
||||
% if allow_empty:
|
||||
if input.try(|input| input.expect_ident_matching("none")).is_ok() {
|
||||
Ok(SpecifiedValue(Vec::new()))
|
||||
} else {
|
||||
input.parse_comma_separated(|parser| {
|
||||
single_value::parse(context, parser)
|
||||
}).map(SpecifiedValue)
|
||||
}
|
||||
% else:
|
||||
input.parse_comma_separated(|parser| {
|
||||
single_value::parse(context, parser)
|
||||
}).map(SpecifiedValue)
|
||||
% endif
|
||||
}
|
||||
impl ToComputedValue for SpecifiedValue {
|
||||
type ComputedValue = computed_value::T;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue