Skip to content

Commit

Permalink
stylo: Support URL filters
Browse files Browse the repository at this point in the history
MozReview-Commit-ID: 4QKKzJ1DVYP
  • Loading branch information
Manishearth committed Feb 18, 2017
1 parent e965b4e commit 2942e3b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
1 change: 1 addition & 0 deletions components/style/build_gecko.rs
Expand Up @@ -552,6 +552,7 @@ mod bindings {
"nsStyleCoord_CalcValue",
"nsStyleDisplay",
"nsStyleEffects",
"nsStyleFilter",
"nsStyleFont",
"nsStyleGradient",
"nsStyleGradientStop",
Expand Down
7 changes: 7 additions & 0 deletions components/style/gecko_bindings/bindings.rs
Expand Up @@ -70,6 +70,9 @@ unsafe impl Sync for nsStyleDisplay {}
use gecko_bindings::structs::nsStyleEffects;
unsafe impl Send for nsStyleEffects {}
unsafe impl Sync for nsStyleEffects {}
use gecko_bindings::structs::nsStyleFilter;
unsafe impl Send for nsStyleFilter {}
unsafe impl Sync for nsStyleFilter {}
use gecko_bindings::structs::nsStyleFont;
unsafe impl Send for nsStyleFont {}
unsafe impl Sync for nsStyleFont {}
Expand Down Expand Up @@ -708,6 +711,10 @@ extern "C" {
pub fn Gecko_CopyFiltersFrom(aSrc: *mut nsStyleEffects,
aDest: *mut nsStyleEffects);
}
extern "C" {
pub fn Gecko_nsStyleFilter_SetURLValue(effects: *mut nsStyleFilter,
uri: ServoBundledURI);
}
extern "C" {
pub fn Gecko_FillAllBackgroundLists(layers: *mut nsStyleImageLayers,
max_len: u32);
Expand Down
5 changes: 5 additions & 0 deletions components/style/properties/gecko.mako.rs
Expand Up @@ -2262,6 +2262,11 @@ fn static_assert() {
Color::CurrentColor => 0,
};
}
Url(ref url) => {
unsafe {
bindings::Gecko_nsStyleFilter_SetURLValue(gecko_filter, url.for_ffi());
}
}
}
}
}
Expand Down
33 changes: 30 additions & 3 deletions components/style/properties/longhand/effects.mako.rs
Expand Up @@ -94,6 +94,7 @@ ${helpers.predefined_type("clip",
use style_traits::{self, ToCss};
use values::{CSSFloat, HasViewportPercentage};
use values::specified::{Angle, CSSColor, Length, Shadow};
use values::specified::url::SpecifiedUrl;

impl HasViewportPercentage for SpecifiedValue {
fn has_viewport_percentage(&self) -> bool {
Expand Down Expand Up @@ -129,14 +130,16 @@ ${helpers.predefined_type("clip",
Sepia(CSSFloat),
% if product == "gecko":
DropShadow(Shadow),
Url(SpecifiedUrl),
% endif
}

pub mod computed_value {
use app_units::Au;
use values::CSSFloat;
use values::computed::{CSSColor, Shadow};
use values::specified::{Angle};
use values::specified::Angle;
use values::specified::url::SpecifiedUrl;

#[derive(Clone, PartialEq, Debug)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf, Deserialize, Serialize))]
Expand All @@ -152,6 +155,7 @@ ${helpers.predefined_type("clip",
Sepia(CSSFloat),
% if product == "gecko":
DropShadow(Shadow),
Url(SpecifiedUrl),
% endif
}

Expand Down Expand Up @@ -262,6 +266,11 @@ ${helpers.predefined_type("clip",
try!(shadow.color.to_css(dest));
try!(dest.write_str(")"));
}
computed_value::Filter::Url(ref url) => {
dest.write_str("url(")?;
url.to_css(dest)?;
dest.write_str(")")?;
}
% endif
}
Ok(())
Expand Down Expand Up @@ -302,6 +311,11 @@ ${helpers.predefined_type("clip",
}
try!(dest.write_str(")"));
}
SpecifiedFilter::Url(ref url) => {
dest.write_str("url(")?;
url.to_css(dest)?;
dest.write_str(")")?;
}
% endif
}
Ok(())
Expand All @@ -319,6 +333,11 @@ ${helpers.predefined_type("clip",
return Ok(SpecifiedValue(filters))
}
loop {
% if product == "gecko":
if let Ok(url) = input.try(|i| SpecifiedUrl::parse(context, i)) {
filters.push(SpecifiedFilter::Url(url));
} else
% endif
if let Ok(function_name) = input.try(|input| input.expect_function()) {
filters.push(try!(input.parse_nested_block(|input| {
match_ignore_ascii_case! { function_name,
Expand Down Expand Up @@ -375,6 +394,9 @@ ${helpers.predefined_type("clip",
SpecifiedFilter::DropShadow(ref shadow) => {
computed_value::Filter::DropShadow(shadow.to_computed_value(context))
},
SpecifiedFilter::Url(ref url) => {
computed_value::Filter::Url(url.to_computed_value(context))
}
% endif
}
}).collect() }
Expand All @@ -394,9 +416,14 @@ ${helpers.predefined_type("clip",
computed_value::Filter::Saturate(factor) => SpecifiedFilter::Saturate(factor),
computed_value::Filter::Sepia(factor) => SpecifiedFilter::Sepia(factor),
% if product == "gecko":
computed_value::Filter::DropShadow(shadow) => {
computed_value::Filter::DropShadow(ref shadow) => {
SpecifiedFilter::DropShadow(
ToComputedValue::from_computed_value(&shadow),
ToComputedValue::from_computed_value(shadow),
)
}
computed_value::Filter::Url(ref url) => {
SpecifiedFilter::Url(
ToComputedValue::from_computed_value(url),
)
}
% endif
Expand Down

0 comments on commit 2942e3b

Please sign in to comment.