mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Implement CSS filter for Stylo
This commit is contained in:
parent
b468a191cd
commit
ff7bb691d7
5 changed files with 76 additions and 4 deletions
|
@ -521,6 +521,13 @@ extern "C" {
|
||||||
pub fn Gecko_NewBasicShape(type_: StyleBasicShapeType)
|
pub fn Gecko_NewBasicShape(type_: StyleBasicShapeType)
|
||||||
-> *mut StyleBasicShape;
|
-> *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" {
|
extern "C" {
|
||||||
pub fn Gecko_FillAllBackgroundLists(layers: *mut nsStyleImageLayers,
|
pub fn Gecko_FillAllBackgroundLists(layers: *mut nsStyleImageLayers,
|
||||||
max_len: u32);
|
max_len: u32);
|
||||||
|
|
|
@ -10930,7 +10930,7 @@ fn bindgen_test_layout_nsStyleSVG() {
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct nsStyleFilter {
|
pub struct nsStyleFilter {
|
||||||
pub mType: i32,
|
pub mType: u32,
|
||||||
pub mFilterParameter: nsStyleCoord,
|
pub mFilterParameter: nsStyleCoord,
|
||||||
pub __bindgen_anon_1: nsStyleFilter__bindgen_ty_bindgen_id_217312,
|
pub __bindgen_anon_1: nsStyleFilter__bindgen_ty_bindgen_id_217312,
|
||||||
}
|
}
|
||||||
|
|
|
@ -10874,7 +10874,7 @@ fn bindgen_test_layout_nsStyleSVG() {
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct nsStyleFilter {
|
pub struct nsStyleFilter {
|
||||||
pub mType: i32,
|
pub mType: u32,
|
||||||
pub mFilterParameter: nsStyleCoord,
|
pub mFilterParameter: nsStyleCoord,
|
||||||
pub __bindgen_anon_1: nsStyleFilter__bindgen_ty_bindgen_id_211452,
|
pub __bindgen_anon_1: nsStyleFilter__bindgen_ty_bindgen_id_211452,
|
||||||
}
|
}
|
||||||
|
|
|
@ -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_AppendGeneric, Gecko_FontFamilyList_AppendNamed};
|
||||||
use gecko_bindings::bindings::{Gecko_FontFamilyList_Clear};
|
use gecko_bindings::bindings::{Gecko_FontFamilyList_Clear};
|
||||||
use gecko_bindings::bindings::ServoComputedValuesBorrowedOrNull;
|
use gecko_bindings::bindings::ServoComputedValuesBorrowedOrNull;
|
||||||
|
use gecko_bindings::bindings::{Gecko_ResetFilters, Gecko_CopyFiltersFrom};
|
||||||
use gecko_bindings::structs;
|
use gecko_bindings::structs;
|
||||||
use gecko_bindings::sugar::ns_style_coord::{CoordDataValue, CoordData, CoordDataMut};
|
use gecko_bindings::sugar::ns_style_coord::{CoordDataValue, CoordData, CoordDataMut};
|
||||||
use gecko_bindings::sugar::ownership::HasArcFFI;
|
use gecko_bindings::sugar::ownership::HasArcFFI;
|
||||||
|
@ -1487,7 +1488,7 @@ fn static_assert() {
|
||||||
</%self:impl_trait>
|
</%self:impl_trait>
|
||||||
|
|
||||||
<%self:impl_trait style_struct_name="Effects"
|
<%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) {
|
pub fn set_box_shadow(&mut self, v: longhands::box_shadow::computed_value::T) {
|
||||||
use cssparser::Color;
|
use cssparser::Color;
|
||||||
|
|
||||||
|
@ -1534,6 +1535,70 @@ fn static_assert() {
|
||||||
}).collect();
|
}).collect();
|
||||||
longhands::box_shadow::computed_value::T(buf)
|
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>
|
</%self:impl_trait>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -403,7 +403,7 @@ ${helpers.predefined_type("opacity",
|
||||||
</%helpers:longhand>
|
</%helpers:longhand>
|
||||||
|
|
||||||
// FIXME: This prop should be animatable
|
// 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;
|
//pub use self::computed_value::T as SpecifiedValue;
|
||||||
use cssparser::ToCss;
|
use cssparser::ToCss;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue