mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Review fixups
This commit is contained in:
parent
a98c0fc037
commit
466df01e71
4 changed files with 99 additions and 94 deletions
|
@ -516,31 +516,31 @@ impl FragmentDisplayListBuilding for Fragment {
|
||||||
// Use 'background-origin' to get the origin value.
|
// Use 'background-origin' to get the origin value.
|
||||||
let origin = get_cyclic(&background.background_origin.0, index);
|
let origin = get_cyclic(&background.background_origin.0, index);
|
||||||
let (mut origin_x, mut origin_y) = match *origin {
|
let (mut origin_x, mut origin_y) = match *origin {
|
||||||
background_origin::single_value::T::padding_box => {
|
background_origin::single_value::T::padding_box => {
|
||||||
(Au(0), Au(0))
|
(Au(0), Au(0))
|
||||||
}
|
}
|
||||||
background_origin::single_value::T::border_box => {
|
background_origin::single_value::T::border_box => {
|
||||||
(-border.left, -border.top)
|
(-border.left, -border.top)
|
||||||
}
|
}
|
||||||
background_origin::single_value::T::content_box => {
|
background_origin::single_value::T::content_box => {
|
||||||
let border_padding = self.border_padding.to_physical(self.style.writing_mode);
|
let border_padding = self.border_padding.to_physical(self.style.writing_mode);
|
||||||
(border_padding.left - border.left, border_padding.top - border.top)
|
(border_padding.left - border.left, border_padding.top - border.top)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Use `background-attachment` to get the initial virtual origin
|
// Use `background-attachment` to get the initial virtual origin
|
||||||
let attachment = get_cyclic(&background.background_attachment.0, index);
|
let attachment = get_cyclic(&background.background_attachment.0, index);
|
||||||
let (virtual_origin_x, virtual_origin_y) = match *attachment {
|
let (virtual_origin_x, virtual_origin_y) = match *attachment {
|
||||||
background_attachment::single_value::T::scroll => {
|
background_attachment::single_value::T::scroll => {
|
||||||
(absolute_bounds.origin.x, absolute_bounds.origin.y)
|
(absolute_bounds.origin.x, absolute_bounds.origin.y)
|
||||||
}
|
}
|
||||||
background_attachment::single_value::T::fixed => {
|
background_attachment::single_value::T::fixed => {
|
||||||
// If the ‘background-attachment’ value for this image is ‘fixed’, then
|
// If the ‘background-attachment’ value for this image is ‘fixed’, then
|
||||||
// 'background-origin' has no effect.
|
// 'background-origin' has no effect.
|
||||||
origin_x = Au(0);
|
origin_x = Au(0);
|
||||||
origin_y = Au(0);
|
origin_y = Au(0);
|
||||||
(Au(0), Au(0))
|
(Au(0), Au(0))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let position = *get_cyclic(&background.background_position.0, index);
|
let position = *get_cyclic(&background.background_position.0, index);
|
||||||
|
|
|
@ -162,16 +162,9 @@ impl<T: RepeatableListInterpolate> Interpolate for Vec<T> {
|
||||||
fn interpolate(&self, other: &Self, time: f64) -> Result<Self, ()> {
|
fn interpolate(&self, other: &Self, time: f64) -> Result<Self, ()> {
|
||||||
use num_integer::lcm;
|
use num_integer::lcm;
|
||||||
let len = lcm(self.len(), other.len());
|
let len = lcm(self.len(), other.len());
|
||||||
let ret = self.iter().cycle().zip(other.iter().cycle())
|
self.iter().cycle().zip(other.iter().cycle()).take(len).map(|(me, you)| {
|
||||||
.take(len)
|
me.interpolate(you, time)
|
||||||
.filter_map(|(ref me, ref you)| {
|
}).collect()
|
||||||
me.interpolate(you, time).ok()
|
|
||||||
}).collect::<Self>();
|
|
||||||
if ret.len() == len {
|
|
||||||
Ok(ret)
|
|
||||||
} else {
|
|
||||||
Err(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// https://drafts.csswg.org/css-transitions/#animtype-number
|
/// https://drafts.csswg.org/css-transitions/#animtype-number
|
||||||
|
|
|
@ -12,16 +12,15 @@
|
||||||
use properties::longhands::{background_image, background_size, background_origin, background_clip};
|
use properties::longhands::{background_image, background_size, background_origin, background_clip};
|
||||||
|
|
||||||
pub fn parse_value(context: &ParserContext, input: &mut Parser) -> Result<Longhands, ()> {
|
pub fn parse_value(context: &ParserContext, input: &mut Parser) -> Result<Longhands, ()> {
|
||||||
% for name in "image position repeat size attachment origin clip".split():
|
|
||||||
let mut any_${name} = false;
|
|
||||||
% endfor
|
|
||||||
|
|
||||||
let mut background_color = None;
|
let mut background_color = None;
|
||||||
let vec = try!(input.parse_comma_separated(|input| {
|
|
||||||
|
% for name in "image position repeat size attachment origin clip".split():
|
||||||
|
let mut background_${name} = background_${name}::SpecifiedValue(Vec::new());
|
||||||
|
% endfor
|
||||||
|
try!(input.parse_comma_separated(|input| {
|
||||||
% for name in "image position repeat size attachment origin clip".split():
|
% for name in "image position repeat size attachment origin clip".split():
|
||||||
let mut ${name} = None;
|
let mut ${name} = None;
|
||||||
% endfor
|
% endfor
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
if let Ok(value) = input.try(|input| background_color::parse(context, input)) {
|
if let Ok(value) = input.try(|input| background_color::parse(context, input)) {
|
||||||
if background_color.is_none() {
|
if background_color.is_none() {
|
||||||
|
@ -33,71 +32,59 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if position.is_none() {
|
if position.is_none() {
|
||||||
if let Ok(value) = input.try(|input| background_position::single_value::parse(context, input)) {
|
if let Ok(value) = input.try(|input| background_position::single_value
|
||||||
|
::parse(context, input)) {
|
||||||
position = Some(value);
|
position = Some(value);
|
||||||
any_position = true;
|
|
||||||
|
|
||||||
// Parse background size, if applicable.
|
// Parse background size, if applicable.
|
||||||
size = input.try(|input| {
|
size = input.try(|input| {
|
||||||
try!(input.expect_delim('/'));
|
try!(input.expect_delim('/'));
|
||||||
background_size::single_value::parse(context, input)
|
background_size::single_value::parse(context, input)
|
||||||
}).ok();
|
}).ok();
|
||||||
if let Some(_) = size {
|
|
||||||
any_size = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
% for name in "image repeat attachment origin clip".split():
|
% for name in "image repeat attachment origin clip".split():
|
||||||
if ${name}.is_none() {
|
if ${name}.is_none() {
|
||||||
if let Ok(value) = input.try(|input| background_${name}::single_value::parse(context, input)) {
|
if let Ok(value) = input.try(|input| background_${name}::single_value
|
||||||
|
::parse(context, input)) {
|
||||||
${name} = Some(value);
|
${name} = Some(value);
|
||||||
any_${name} = true;
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
% endfor
|
% endfor
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
Ok((image, position, repeat, size, attachment, origin, clip))
|
let mut any = false;
|
||||||
}));
|
% for name in "image position repeat size attachment origin clip".split():
|
||||||
|
any = any || ${name}.is_some();
|
||||||
if !(any_image || any_position || any_repeat || any_size ||
|
|
||||||
any_attachment || any_origin || any_clip ||
|
|
||||||
background_color.is_some()) {
|
|
||||||
return Err(())
|
|
||||||
}
|
|
||||||
|
|
||||||
% for name in "image position repeat size attachment origin clip".split():
|
|
||||||
let mut background_${name} = if any_${name} {
|
|
||||||
Some(background_${name}::SpecifiedValue(Vec::new()))
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
};
|
|
||||||
% endfor
|
|
||||||
|
|
||||||
for i in vec {
|
|
||||||
% for i,name in enumerate("image position repeat size attachment origin clip".split()):
|
|
||||||
if let Some(ref mut buf) = background_${name} {
|
|
||||||
if let Some(bg_${name}) = i.${i} {
|
|
||||||
buf.0.push(bg_${name})
|
|
||||||
} else {
|
|
||||||
buf.0.push(background_${name}::single_value::get_initial_specified_value())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
% endfor
|
% endfor
|
||||||
}
|
any = any || background_color.is_some();
|
||||||
|
if any {
|
||||||
|
% for name in "image position repeat size attachment origin clip".split():
|
||||||
|
if let Some(bg_${name}) = ${name} {
|
||||||
|
background_${name}.0.push(bg_${name});
|
||||||
|
} else {
|
||||||
|
background_${name}.0.push(background_${name}::single_value
|
||||||
|
::get_initial_specified_value());
|
||||||
|
}
|
||||||
|
% endfor
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
Err(())
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
Ok(Longhands {
|
Ok(Longhands {
|
||||||
background_color: background_color,
|
background_color: background_color,
|
||||||
background_image: background_image,
|
background_image: Some(background_image),
|
||||||
background_position: background_position,
|
background_position: Some(background_position),
|
||||||
background_repeat: background_repeat,
|
background_repeat: Some(background_repeat),
|
||||||
background_attachment: background_attachment,
|
background_attachment: Some(background_attachment),
|
||||||
background_size: background_size,
|
background_size: Some(background_size),
|
||||||
background_origin: background_origin,
|
background_origin: Some(background_origin),
|
||||||
background_clip: background_clip,
|
background_clip: Some(background_clip),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,7 +98,6 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
use std::iter::{once, repeat};
|
|
||||||
let mut len = 0;
|
let mut len = 0;
|
||||||
% for name in "image position repeat size attachment origin clip".split():
|
% for name in "image position repeat size attachment origin clip".split():
|
||||||
len = cmp::max(len, extract_value(self.background_${name}).map(|i| i.0.len())
|
len = cmp::max(len, extract_value(self.background_${name}).map(|i| i.0.len())
|
||||||
|
@ -123,15 +109,21 @@
|
||||||
return dest.write_str("")
|
return dest.write_str("")
|
||||||
}
|
}
|
||||||
|
|
||||||
let iter = repeat(None).take(len - 1).chain(once(Some(self.background_color)))
|
|
||||||
% for name in "image position repeat size attachment origin clip".split():
|
|
||||||
.zip(extract_value(self.background_${name}).into_iter()
|
|
||||||
.flat_map(|x| x.0.iter())
|
|
||||||
.map(Some).chain(repeat(None)))
|
|
||||||
% endfor
|
|
||||||
;
|
|
||||||
let mut first = true;
|
let mut first = true;
|
||||||
for (((((((color, image), position), repeat), size), attachment), origin), clip) in iter {
|
for i in 0..len {
|
||||||
|
% for name in "image position repeat size attachment origin clip".split():
|
||||||
|
let ${name} = if let DeclaredValue::Value(ref arr) = *self.background_${name} {
|
||||||
|
arr.0.get(i % arr.0.len())
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
% endfor
|
||||||
|
let color = if i == len - 1 {
|
||||||
|
Some(self.background_color)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
if first {
|
if first {
|
||||||
first = false;
|
first = false;
|
||||||
} else {
|
} else {
|
||||||
|
@ -144,7 +136,6 @@
|
||||||
},
|
},
|
||||||
Some(_) => {
|
Some(_) => {
|
||||||
try!(write!(dest, "transparent "));
|
try!(write!(dest, "transparent "));
|
||||||
try!(write!(dest, " "));
|
|
||||||
}
|
}
|
||||||
// Not yet the last one
|
// Not yet the last one
|
||||||
None => ()
|
None => ()
|
||||||
|
|
|
@ -191,19 +191,40 @@ fn test_parse_stylesheet() {
|
||||||
}
|
}
|
||||||
)),
|
)),
|
||||||
Importance::Normal),
|
Importance::Normal),
|
||||||
(PropertyDeclaration::BackgroundPosition(DeclaredValue::Initial),
|
(PropertyDeclaration::BackgroundPosition(DeclaredValue::Value(
|
||||||
|
longhands::background_position::SpecifiedValue(
|
||||||
|
vec![longhands::background_position::single_value
|
||||||
|
::get_initial_specified_value()]))),
|
||||||
Importance::Normal),
|
Importance::Normal),
|
||||||
(PropertyDeclaration::BackgroundRepeat(DeclaredValue::Initial),
|
(PropertyDeclaration::BackgroundRepeat(DeclaredValue::Value(
|
||||||
|
longhands::background_repeat::SpecifiedValue(
|
||||||
|
vec![longhands::background_repeat::single_value
|
||||||
|
::get_initial_specified_value()]))),
|
||||||
Importance::Normal),
|
Importance::Normal),
|
||||||
(PropertyDeclaration::BackgroundAttachment(DeclaredValue::Initial),
|
(PropertyDeclaration::BackgroundAttachment(DeclaredValue::Value(
|
||||||
|
longhands::background_attachment::SpecifiedValue(
|
||||||
|
vec![longhands::background_attachment::single_value
|
||||||
|
::get_initial_specified_value()]))),
|
||||||
Importance::Normal),
|
Importance::Normal),
|
||||||
(PropertyDeclaration::BackgroundImage(DeclaredValue::Initial),
|
(PropertyDeclaration::BackgroundImage(DeclaredValue::Value(
|
||||||
|
longhands::background_image::SpecifiedValue(
|
||||||
|
vec![longhands::background_image::single_value
|
||||||
|
::get_initial_specified_value()]))),
|
||||||
Importance::Normal),
|
Importance::Normal),
|
||||||
(PropertyDeclaration::BackgroundSize(DeclaredValue::Initial),
|
(PropertyDeclaration::BackgroundSize(DeclaredValue::Value(
|
||||||
|
longhands::background_size::SpecifiedValue(
|
||||||
|
vec![longhands::background_size::single_value
|
||||||
|
::get_initial_specified_value()]))),
|
||||||
Importance::Normal),
|
Importance::Normal),
|
||||||
(PropertyDeclaration::BackgroundOrigin(DeclaredValue::Initial),
|
(PropertyDeclaration::BackgroundOrigin(DeclaredValue::Value(
|
||||||
|
longhands::background_origin::SpecifiedValue(
|
||||||
|
vec![longhands::background_origin::single_value
|
||||||
|
::get_initial_specified_value()]))),
|
||||||
Importance::Normal),
|
Importance::Normal),
|
||||||
(PropertyDeclaration::BackgroundClip(DeclaredValue::Initial),
|
(PropertyDeclaration::BackgroundClip(DeclaredValue::Value(
|
||||||
|
longhands::background_clip::SpecifiedValue(
|
||||||
|
vec![longhands::background_clip::single_value
|
||||||
|
::get_initial_specified_value()]))),
|
||||||
Importance::Normal),
|
Importance::Normal),
|
||||||
]),
|
]),
|
||||||
important_count: 0,
|
important_count: 0,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue