diff --git a/components/style/gecko_bindings/bindings.rs b/components/style/gecko_bindings/bindings.rs index 4def95850e1..a380fefee8b 100644 --- a/components/style/gecko_bindings/bindings.rs +++ b/components/style/gecko_bindings/bindings.rs @@ -521,6 +521,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 0a3fad909e7..c5318ad1d81 100644 --- a/components/style/gecko_bindings/structs_debug.rs +++ b/components/style/gecko_bindings/structs_debug.rs @@ -10930,7 +10930,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_217312, } diff --git a/components/style/gecko_bindings/structs_release.rs b/components/style/gecko_bindings/structs_release.rs index c13e8761eeb..8b8e12a221e 100644 --- a/components/style/gecko_bindings/structs_release.rs +++ b/components/style/gecko_bindings/structs_release.rs @@ -10874,7 +10874,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_211452, } diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index bbd94e1ca29..5c1066b75ce 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -25,6 +25,7 @@ use gecko_bindings::bindings::{Gecko_CopyImageValueFrom, Gecko_CopyFontFamilyFro use gecko_bindings::bindings::{Gecko_FontFamilyList_AppendGeneric, Gecko_FontFamilyList_AppendNamed}; use gecko_bindings::bindings::{Gecko_FontFamilyList_Clear}; 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; @@ -1487,7 +1488,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; @@ -1534,6 +1535,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;