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