Implement CSS filter for Stylo

This commit is contained in:
Shing Lyu 2016-10-17 12:04:02 +08:00 committed by Manish Goregaokar
parent b468a191cd
commit ff7bb691d7
5 changed files with 76 additions and 4 deletions

View file

@ -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);

View file

@ -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,
}

View file

@ -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,
}

View file

@ -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>
<%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);
}
}
</%self:impl_trait>

View file

@ -403,7 +403,7 @@ ${helpers.predefined_type("opacity",
</%helpers:longhand>
// 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;