mirror of
https://github.com/servo/servo.git
synced 2025-06-22 08:08:59 +01:00
Add background-image property
This commit is contained in:
parent
20bbf6a859
commit
3b55a5fca0
1 changed files with 47 additions and 6 deletions
|
@ -5,8 +5,10 @@
|
||||||
// This file is a Mako template: http://www.makotemplates.org/
|
// This file is a Mako template: http://www.makotemplates.org/
|
||||||
|
|
||||||
use std::ascii::StrAsciiExt;
|
use std::ascii::StrAsciiExt;
|
||||||
|
pub use servo_util::url::parse_url;
|
||||||
pub use extra::arc::Arc;
|
pub use extra::arc::Arc;
|
||||||
use servo_util::cowarc::CowArc;
|
use servo_util::cowarc::CowArc;
|
||||||
|
|
||||||
pub use cssparser::*;
|
pub use cssparser::*;
|
||||||
pub use cssparser::ast::*;
|
pub use cssparser::ast::*;
|
||||||
|
|
||||||
|
@ -470,10 +472,31 @@ pub mod longhands {
|
||||||
// CSS 2.1, Section 14 - Colors and Backgrounds
|
// CSS 2.1, Section 14 - Colors and Backgrounds
|
||||||
|
|
||||||
${new_style_struct("Background", is_inherited=False)}
|
${new_style_struct("Background", is_inherited=False)}
|
||||||
|
|
||||||
${predefined_type("background-color", "CSSColor",
|
${predefined_type("background-color", "CSSColor",
|
||||||
"RGBA(RGBA { red: 0., green: 0., blue: 0., alpha: 0. }) /* transparent */")}
|
"RGBA(RGBA { red: 0., green: 0., blue: 0., alpha: 0. }) /* transparent */")}
|
||||||
|
|
||||||
|
<%self:single_component_value name="background-image">
|
||||||
|
// The computed value is the same as the specified value.
|
||||||
|
pub use to_computed_value = super::computed_as_specified;
|
||||||
|
pub mod computed_value {
|
||||||
|
pub use extra::url::Url;
|
||||||
|
pub type T = Option<Url>;
|
||||||
|
}
|
||||||
|
pub type SpecifiedValue = computed_value::T;
|
||||||
|
#[inline] pub fn get_initial_value() -> SpecifiedValue {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
pub fn from_component_value(component_value: &ComponentValue) -> Option<SpecifiedValue> {
|
||||||
|
match component_value {
|
||||||
|
&ast::URL(ref url) => {
|
||||||
|
let image_url = parse_url(url.as_slice(), None);
|
||||||
|
Some(Some(image_url))
|
||||||
|
},
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</%self:single_component_value>
|
||||||
|
|
||||||
|
|
||||||
${new_style_struct("Color", is_inherited=True)}
|
${new_style_struct("Color", is_inherited=True)}
|
||||||
|
|
||||||
|
@ -809,12 +832,30 @@ pub mod shorthands {
|
||||||
</%self:shorthand>
|
</%self:shorthand>
|
||||||
</%def>
|
</%def>
|
||||||
|
|
||||||
|
|
||||||
// TODO: other background-* properties
|
// TODO: other background-* properties
|
||||||
<%self:shorthand name="background" sub_properties="background-color">
|
<%self:shorthand name="background" sub_properties="background-color background-image">
|
||||||
one_component_value(input).and_then(specified::CSSColor::parse).map(|color| {
|
let mut color = None;
|
||||||
Longhands { background_color: Some(color) }
|
let mut image = None;
|
||||||
})
|
let mut any = false;
|
||||||
|
|
||||||
|
for component_value in input.skip_whitespace() {
|
||||||
|
if color.is_none() {
|
||||||
|
match background_color::from_component_value(component_value) {
|
||||||
|
Some(v) => { color = Some(v); any = true; continue },
|
||||||
|
None => ()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if image.is_none() {
|
||||||
|
match background_image::from_component_value(component_value) {
|
||||||
|
Some(v) => { image = Some(v); any = true; continue },
|
||||||
|
None => (),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
if any { Some(Longhands { background_color: color, background_image: image }) }
|
||||||
|
else { None }
|
||||||
</%self:shorthand>
|
</%self:shorthand>
|
||||||
|
|
||||||
${four_sides_shorthand("margin", "margin-%s", "margin_top::from_component_value")}
|
${four_sides_shorthand("margin", "margin-%s", "margin_top::from_component_value")}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue