diff --git a/components/style/gecko_bindings/bindings.rs b/components/style/gecko_bindings/bindings.rs index 7639d836e01..9a9d82de6e1 100644 --- a/components/style/gecko_bindings/bindings.rs +++ b/components/style/gecko_bindings/bindings.rs @@ -515,6 +515,13 @@ extern "C" { pub fn Gecko_NewBasicShape(type_: StyleBasicShapeType) -> *mut StyleBasicShape; } +extern "C" { + pub fn Gecko_ResetFilters(effects: *mut nsStyleEffects, new_len: usize); +} +extern "C" { + pub fn Gecko_CopyFiltersFrom(aSrc: *mut nsStyleEffects, + aDest: *mut nsStyleEffects); +} extern "C" { pub fn Gecko_FillAllBackgroundLists(layers: *mut nsStyleImageLayers, max_len: u32); diff --git a/components/style/gecko_bindings/structs_debug.rs b/components/style/gecko_bindings/structs_debug.rs index 5c7471923cf..d447674ea1a 100644 --- a/components/style/gecko_bindings/structs_debug.rs +++ b/components/style/gecko_bindings/structs_debug.rs @@ -11203,7 +11203,7 @@ fn bindgen_test_layout_nsStyleSVG() { #[repr(C)] #[derive(Debug)] pub struct nsStyleFilter { - pub mType: i32, + pub mType: u32, pub mFilterParameter: nsStyleCoord, pub __bindgen_anon_1: nsStyleFilter__bindgen_ty_bindgen_id_236550, } diff --git a/components/style/gecko_bindings/structs_release.rs b/components/style/gecko_bindings/structs_release.rs index 1968a24a8e0..91d155aea95 100644 --- a/components/style/gecko_bindings/structs_release.rs +++ b/components/style/gecko_bindings/structs_release.rs @@ -11147,7 +11147,7 @@ fn bindgen_test_layout_nsStyleSVG() { #[repr(C)] #[derive(Debug)] pub struct nsStyleFilter { - pub mType: i32, + pub mType: u32, pub mFilterParameter: nsStyleCoord, pub __bindgen_anon_1: nsStyleFilter__bindgen_ty_bindgen_id_229971, } diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index 24602685308..cf90c6e7f52 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -31,6 +31,7 @@ use gecko_bindings::bindings::Gecko_SetListStyleType; use gecko_bindings::bindings::Gecko_SetMozBinding; use gecko_bindings::bindings::Gecko_SetNullImageValue; use gecko_bindings::bindings::ServoComputedValuesBorrowedOrNull; +use gecko_bindings::bindings::{Gecko_ResetFilters, Gecko_CopyFiltersFrom}; use gecko_bindings::structs; use gecko_bindings::sugar::ns_style_coord::{CoordDataValue, CoordData, CoordDataMut}; use gecko_bindings::sugar::ownership::HasArcFFI; @@ -1495,7 +1496,7 @@ fn static_assert() { <%self:impl_trait style_struct_name="Effects" - skip_longhands="box-shadow"> + skip_longhands="box-shadow filter"> pub fn set_box_shadow(&mut self, v: longhands::box_shadow::computed_value::T) { use cssparser::Color; @@ -1542,6 +1543,70 @@ fn static_assert() { }).collect(); longhands::box_shadow::computed_value::T(buf) } + + pub fn set_filter(&mut self, v: longhands::filter::computed_value::T) { + use properties::longhands::filter::computed_value::Filter::*; + use gecko_bindings::structs::nsStyleFilter; + use gecko_bindings::structs::NS_STYLE_FILTER_BLUR; + use gecko_bindings::structs::NS_STYLE_FILTER_BRIGHTNESS; + use gecko_bindings::structs::NS_STYLE_FILTER_CONTRAST; + use gecko_bindings::structs::NS_STYLE_FILTER_GRAYSCALE; + use gecko_bindings::structs::NS_STYLE_FILTER_INVERT; + use gecko_bindings::structs::NS_STYLE_FILTER_OPACITY; + use gecko_bindings::structs::NS_STYLE_FILTER_SATURATE; + use gecko_bindings::structs::NS_STYLE_FILTER_SEPIA; + use gecko_bindings::structs::NS_STYLE_FILTER_HUE_ROTATE; + + fn fill_filter(m_type: u32, value: CoordDataValue, gecko_filter: &mut nsStyleFilter){ + gecko_filter.mType = m_type; + gecko_filter.mFilterParameter.set_value(value); + } + + unsafe { + Gecko_ResetFilters(&mut self.gecko, v.filters.len()); + } + debug_assert!(v.filters.len() == self.gecko.mFilters.len()); + + for (servo, gecko_filter) in v.filters.into_iter().zip(self.gecko.mFilters.iter_mut()) { + //TODO: URL, drop-shadow + match servo { + Blur(len) => fill_filter(NS_STYLE_FILTER_BLUR, + CoordDataValue::Coord(len.0), + gecko_filter), + Brightness(factor) => fill_filter(NS_STYLE_FILTER_BRIGHTNESS, + CoordDataValue::Factor(factor), + gecko_filter), + Contrast(factor) => fill_filter(NS_STYLE_FILTER_CONTRAST, + CoordDataValue::Factor(factor), + gecko_filter), + Grayscale(factor) => fill_filter(NS_STYLE_FILTER_GRAYSCALE, + CoordDataValue::Factor(factor), + gecko_filter), + HueRotate(angle) => fill_filter(NS_STYLE_FILTER_HUE_ROTATE, + CoordDataValue::Radian(angle.radians()), + gecko_filter), + Invert(factor) => fill_filter(NS_STYLE_FILTER_INVERT, + CoordDataValue::Factor(factor), + gecko_filter), + Opacity(factor) => fill_filter(NS_STYLE_FILTER_OPACITY, + CoordDataValue::Factor(factor), + gecko_filter), + Saturate(factor) => fill_filter(NS_STYLE_FILTER_SATURATE, + CoordDataValue::Factor(factor), + gecko_filter), + Sepia(factor) => fill_filter(NS_STYLE_FILTER_SEPIA, + CoordDataValue::Factor(factor), + gecko_filter), + } + } + } + + pub fn copy_filter_from(&mut self, other: &Self) { + unsafe { + Gecko_CopyFiltersFrom(&other.gecko as *const _ as *mut _, &mut self.gecko); + } + } + diff --git a/components/style/properties/longhand/effects.mako.rs b/components/style/properties/longhand/effects.mako.rs index cd20aa1527d..d9a70f4b574 100644 --- a/components/style/properties/longhand/effects.mako.rs +++ b/components/style/properties/longhand/effects.mako.rs @@ -403,7 +403,7 @@ ${helpers.predefined_type("opacity", // FIXME: This prop should be animatable -<%helpers:longhand name="filter" products="servo" animatable="False"> +<%helpers:longhand name="filter" animatable="False"> //pub use self::computed_value::T as SpecifiedValue; use cssparser::ToCss; use std::fmt;