mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
style: Use cbindgen for filters.
Had to implement some OwnedSlice bits that the canvas code used. Differential Revision: https://phabricator.services.mozilla.com/D31799
This commit is contained in:
parent
ccff9b294f
commit
57868f571f
8 changed files with 26 additions and 150 deletions
|
@ -256,7 +256,6 @@ impl ToComputedValue for SpecifiedUrl {
|
|||
|
||||
/// A specified image `url()` value.
|
||||
#[derive(Clone, Debug, Eq, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToCss, ToShmem)]
|
||||
#[repr(C)]
|
||||
pub struct SpecifiedImageUrl(pub SpecifiedUrl);
|
||||
|
||||
impl SpecifiedImageUrl {
|
||||
|
@ -340,6 +339,7 @@ impl ToCss for ComputedUrl {
|
|||
|
||||
/// The computed value of a CSS image `url()`.
|
||||
#[derive(Clone, Debug, Eq, MallocSizeOf, PartialEq)]
|
||||
#[repr(transparent)]
|
||||
pub struct ComputedImageUrl(pub ComputedUrl);
|
||||
|
||||
impl ComputedImageUrl {
|
||||
|
|
|
@ -33,13 +33,11 @@ use crate::gecko_bindings::bindings::Gecko_nsStyleFont_CopyLangFrom;
|
|||
use crate::gecko_bindings::bindings::Gecko_SetListStyleImageNone;
|
||||
use crate::gecko_bindings::bindings::Gecko_SetListStyleImageImageValue;
|
||||
use crate::gecko_bindings::bindings::Gecko_SetNullImageValue;
|
||||
use crate::gecko_bindings::bindings::{Gecko_ResetFilters, Gecko_CopyFiltersFrom};
|
||||
use crate::gecko_bindings::structs;
|
||||
use crate::gecko_bindings::structs::nsCSSPropertyID;
|
||||
use crate::gecko_bindings::structs::mozilla::PseudoStyleType;
|
||||
use crate::gecko_bindings::sugar::ns_style_coord::{CoordDataValue, CoordDataMut};
|
||||
use crate::gecko_bindings::sugar::ns_style_coord::CoordDataMut;
|
||||
use crate::gecko_bindings::sugar::refptr::RefPtr;
|
||||
use crate::gecko::values::GeckoStyleCoordConvertible;
|
||||
use crate::gecko::values::round_border_to_device_pixels;
|
||||
use crate::logical_geometry::WritingMode;
|
||||
use crate::media_queries::Device;
|
||||
|
@ -52,11 +50,10 @@ use std::marker::PhantomData;
|
|||
use std::mem::{forget, uninitialized, zeroed, ManuallyDrop};
|
||||
use std::{cmp, ops, ptr};
|
||||
use crate::values::{self, CustomIdent, Either, KeyframesName, None_};
|
||||
use crate::values::computed::{NonNegativeLength, Percentage, TransitionProperty};
|
||||
use crate::values::computed::{Percentage, TransitionProperty};
|
||||
use crate::values::computed::url::ComputedImageUrl;
|
||||
use crate::values::computed::BorderStyle;
|
||||
use crate::values::computed::font::FontSize;
|
||||
use crate::values::computed::effects::Filter;
|
||||
use crate::values::generics::column::ColumnCount;
|
||||
use crate::values::generics::transform::TransformStyle;
|
||||
use crate::values::generics::url::UrlOrNone;
|
||||
|
@ -2162,6 +2159,7 @@ fn static_assert() {
|
|||
gecko_inexhaustive=True,
|
||||
) %>
|
||||
${impl_keyword('clear', 'mBreakType', clear_keyword)}
|
||||
|
||||
${impl_transition_time_value('delay', 'Delay')}
|
||||
${impl_transition_time_value('duration', 'Duration')}
|
||||
${impl_transition_timing_function()}
|
||||
|
@ -2926,8 +2924,7 @@ fn static_assert() {
|
|||
${impl_simple_copy('_x_span', 'mSpan')}
|
||||
</%self:impl_trait>
|
||||
|
||||
<%self:impl_trait style_struct_name="Effects"
|
||||
skip_longhands="clip filter">
|
||||
<%self:impl_trait style_struct_name="Effects" skip_longhands="clip">
|
||||
pub fn set_clip(&mut self, v: longhands::clip::computed_value::T) {
|
||||
use crate::gecko_bindings::structs::NS_STYLE_CLIP_AUTO;
|
||||
use crate::gecko_bindings::structs::NS_STYLE_CLIP_RECT;
|
||||
|
@ -3035,136 +3032,6 @@ fn static_assert() {
|
|||
|
||||
Either::First(ClipRect { top, right, bottom, left })
|
||||
}
|
||||
|
||||
<%
|
||||
# This array is several filter function which has percentage or
|
||||
# number value for function of clone / set.
|
||||
# The setting / cloning process of other function(e.g. Blur / HueRotate) is
|
||||
# different from these function. So this array don't include such function.
|
||||
FILTER_FUNCTIONS = [ 'Brightness', 'Contrast', 'Grayscale', 'Invert',
|
||||
'Opacity', 'Saturate', 'Sepia' ]
|
||||
%>
|
||||
|
||||
pub fn set_filter<I>(&mut self, v: I)
|
||||
where
|
||||
I: IntoIterator<Item = Filter>,
|
||||
I::IntoIter: ExactSizeIterator,
|
||||
{
|
||||
use crate::values::generics::effects::Filter::*;
|
||||
use crate::gecko_bindings::structs::nsStyleFilter;
|
||||
use crate::gecko_bindings::structs::NS_STYLE_FILTER_BLUR;
|
||||
use crate::gecko_bindings::structs::NS_STYLE_FILTER_BRIGHTNESS;
|
||||
use crate::gecko_bindings::structs::NS_STYLE_FILTER_CONTRAST;
|
||||
use crate::gecko_bindings::structs::NS_STYLE_FILTER_GRAYSCALE;
|
||||
use crate::gecko_bindings::structs::NS_STYLE_FILTER_INVERT;
|
||||
use crate::gecko_bindings::structs::NS_STYLE_FILTER_OPACITY;
|
||||
use crate::gecko_bindings::structs::NS_STYLE_FILTER_SATURATE;
|
||||
use crate::gecko_bindings::structs::NS_STYLE_FILTER_SEPIA;
|
||||
use crate::gecko_bindings::structs::NS_STYLE_FILTER_HUE_ROTATE;
|
||||
use crate::gecko_bindings::structs::NS_STYLE_FILTER_DROP_SHADOW;
|
||||
|
||||
fn fill_filter(m_type: u32, value: CoordDataValue, gecko_filter: &mut nsStyleFilter){
|
||||
gecko_filter.mType = m_type;
|
||||
gecko_filter.mFilterParameter.set_value(value);
|
||||
}
|
||||
|
||||
let v = v.into_iter();
|
||||
unsafe {
|
||||
Gecko_ResetFilters(&mut *self.gecko, v.len());
|
||||
}
|
||||
debug_assert_eq!(v.len(), self.gecko.mFilters.len());
|
||||
|
||||
for (servo, gecko_filter) in v.zip(self.gecko.mFilters.iter_mut()) {
|
||||
match servo {
|
||||
% for func in FILTER_FUNCTIONS:
|
||||
${func}(factor) => fill_filter(NS_STYLE_FILTER_${func.upper()},
|
||||
CoordDataValue::Factor(factor.0),
|
||||
gecko_filter),
|
||||
% endfor
|
||||
Blur(length) => fill_filter(NS_STYLE_FILTER_BLUR,
|
||||
CoordDataValue::Coord(length.0.to_i32_au()),
|
||||
gecko_filter),
|
||||
|
||||
HueRotate(angle) => fill_filter(NS_STYLE_FILTER_HUE_ROTATE,
|
||||
CoordDataValue::from(angle),
|
||||
gecko_filter),
|
||||
|
||||
DropShadow(shadow) => {
|
||||
gecko_filter.mType = NS_STYLE_FILTER_DROP_SHADOW;
|
||||
unsafe {
|
||||
let ref mut union = gecko_filter.__bindgen_anon_1;
|
||||
ptr::write(union.mDropShadow.as_mut(), shadow);
|
||||
}
|
||||
},
|
||||
Url(ref url) => {
|
||||
unsafe {
|
||||
bindings::Gecko_nsStyleFilter_SetURLValue(gecko_filter, url);
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn copy_filter_from(&mut self, other: &Self) {
|
||||
unsafe {
|
||||
Gecko_CopyFiltersFrom(&other.gecko as *const _ as *mut _, &mut *self.gecko);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn reset_filter(&mut self, other: &Self) {
|
||||
self.copy_filter_from(other)
|
||||
}
|
||||
|
||||
pub fn clone_filter(&self) -> longhands::filter::computed_value::T {
|
||||
use crate::values::generics::effects::Filter;
|
||||
use crate::gecko_bindings::structs::NS_STYLE_FILTER_BLUR;
|
||||
use crate::gecko_bindings::structs::NS_STYLE_FILTER_BRIGHTNESS;
|
||||
use crate::gecko_bindings::structs::NS_STYLE_FILTER_CONTRAST;
|
||||
use crate::gecko_bindings::structs::NS_STYLE_FILTER_GRAYSCALE;
|
||||
use crate::gecko_bindings::structs::NS_STYLE_FILTER_INVERT;
|
||||
use crate::gecko_bindings::structs::NS_STYLE_FILTER_OPACITY;
|
||||
use crate::gecko_bindings::structs::NS_STYLE_FILTER_SATURATE;
|
||||
use crate::gecko_bindings::structs::NS_STYLE_FILTER_SEPIA;
|
||||
use crate::gecko_bindings::structs::NS_STYLE_FILTER_HUE_ROTATE;
|
||||
use crate::gecko_bindings::structs::NS_STYLE_FILTER_DROP_SHADOW;
|
||||
use crate::gecko_bindings::structs::NS_STYLE_FILTER_URL;
|
||||
|
||||
longhands::filter::computed_value::List(self.gecko.mFilters.iter().map(|filter| {
|
||||
match filter.mType {
|
||||
% for func in FILTER_FUNCTIONS:
|
||||
NS_STYLE_FILTER_${func.upper()} => {
|
||||
Filter::${func}(
|
||||
GeckoStyleCoordConvertible::from_gecko_style_coord(
|
||||
&filter.mFilterParameter
|
||||
).unwrap()
|
||||
)
|
||||
},
|
||||
% endfor
|
||||
NS_STYLE_FILTER_BLUR => {
|
||||
Filter::Blur(NonNegativeLength::from_gecko_style_coord(
|
||||
&filter.mFilterParameter
|
||||
).unwrap())
|
||||
},
|
||||
NS_STYLE_FILTER_HUE_ROTATE => {
|
||||
Filter::HueRotate(GeckoStyleCoordConvertible::from_gecko_style_coord(
|
||||
&filter.mFilterParameter,
|
||||
).unwrap())
|
||||
},
|
||||
NS_STYLE_FILTER_DROP_SHADOW => {
|
||||
Filter::DropShadow(unsafe {
|
||||
(*filter.__bindgen_anon_1.mDropShadow.as_ref()).clone()
|
||||
})
|
||||
},
|
||||
NS_STYLE_FILTER_URL => {
|
||||
Filter::Url(unsafe {
|
||||
filter.__bindgen_anon_1.mURL.as_ref().clone()
|
||||
})
|
||||
}
|
||||
_ => unreachable!("Unknown filter function?"),
|
||||
}
|
||||
}).collect())
|
||||
}
|
||||
|
||||
</%self:impl_trait>
|
||||
|
||||
<%self:impl_trait style_struct_name="InheritedBox">
|
||||
|
|
|
@ -22,7 +22,7 @@ use std::mem::{self, ManuallyDrop};
|
|||
use crate::hash::FxHashMap;
|
||||
use super::ComputedValues;
|
||||
use crate::values::animated::{Animate, Procedure, ToAnimatedValue, ToAnimatedZero};
|
||||
use crate::values::animated::effects::Filter as AnimatedFilter;
|
||||
use crate::values::animated::effects::AnimatedFilter;
|
||||
#[cfg(feature = "gecko")] use crate::values::computed::TransitionProperty;
|
||||
use crate::values::computed::{ClipRect, Context};
|
||||
use crate::values::computed::ToComputedValue;
|
||||
|
|
|
@ -47,6 +47,8 @@ ${helpers.predefined_type(
|
|||
"Filter",
|
||||
None,
|
||||
vector=True,
|
||||
simple_vector_bindings=True,
|
||||
gecko_ffi_name="mFilters",
|
||||
separator="Space",
|
||||
animation_value_type="AnimatedFilterList",
|
||||
vector_animation_type="with_zero",
|
||||
|
|
|
@ -19,8 +19,8 @@ pub type AnimatedSimpleShadow = GenericSimpleShadow<Color, Length, Length>;
|
|||
|
||||
/// An animated value for a single `filter`.
|
||||
#[cfg(feature = "gecko")]
|
||||
pub type Filter = GenericFilter<Angle, Number, Length, AnimatedSimpleShadow, ComputedUrl>;
|
||||
pub type AnimatedFilter = GenericFilter<Angle, Number, Length, AnimatedSimpleShadow, ComputedUrl>;
|
||||
|
||||
/// An animated value for a single `filter`.
|
||||
#[cfg(not(feature = "gecko"))]
|
||||
pub type Filter = GenericFilter<Angle, Number, Length, Impossible, Impossible>;
|
||||
pub type AnimatedFilter = GenericFilter<Angle, Number, Length, Impossible, Impossible>;
|
||||
|
|
|
@ -24,7 +24,7 @@ pub type Filter =
|
|||
GenericFilter<Angle, NonNegativeNumber, NonNegativeLength, SimpleShadow, ComputedUrl>;
|
||||
|
||||
/// A computed value for a single `filter`.
|
||||
#[cfg(not(feature = "gecko"))]
|
||||
#[cfg(feature = "servo")]
|
||||
pub type Filter =
|
||||
GenericFilter<Angle, NonNegativeNumber, NonNegativeLength, Impossible, Impossible>;
|
||||
|
||||
|
|
|
@ -34,8 +34,10 @@ pub struct GenericBoxShadow<Color, SizeLength, BlurShapeLength, ShapeLength> {
|
|||
pub use self::GenericBoxShadow as BoxShadow;
|
||||
|
||||
/// A generic value for a single `filter`.
|
||||
///
|
||||
/// cbindgen:derive-tagged-enum-copy-constructor=true
|
||||
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
|
||||
#[animation(no_bound(Url))]
|
||||
#[animation(no_bound(U))]
|
||||
#[derive(
|
||||
Clone,
|
||||
ComputeSquaredDistance,
|
||||
|
@ -49,7 +51,8 @@ pub use self::GenericBoxShadow as BoxShadow;
|
|||
ToResolvedValue,
|
||||
ToShmem,
|
||||
)]
|
||||
pub enum Filter<Angle, Factor, Length, DropShadow, Url> {
|
||||
#[repr(C, u8)]
|
||||
pub enum GenericFilter<Angle, Factor, Length, Shadow, U> {
|
||||
/// `blur(<length>)`
|
||||
#[css(function)]
|
||||
Blur(Length),
|
||||
|
@ -79,12 +82,14 @@ pub enum Filter<Angle, Factor, Length, DropShadow, Url> {
|
|||
Sepia(Factor),
|
||||
/// `drop-shadow(...)`
|
||||
#[css(function)]
|
||||
DropShadow(DropShadow),
|
||||
DropShadow(Shadow),
|
||||
/// `<url>`
|
||||
#[animation(error)]
|
||||
Url(Url),
|
||||
Url(U),
|
||||
}
|
||||
|
||||
pub use self::GenericFilter as Filter;
|
||||
|
||||
/// A generic value for the `drop-shadow()` filter and the `text-shadow` property.
|
||||
///
|
||||
/// Contrary to the canonical order from the spec, the color is serialised
|
||||
|
|
|
@ -18,7 +18,7 @@ use crate::values::specified::length::{Length, NonNegativeLength};
|
|||
#[cfg(feature = "gecko")]
|
||||
use crate::values::specified::url::SpecifiedUrl;
|
||||
use crate::values::specified::{Angle, Number, NumberOrPercentage};
|
||||
#[cfg(not(feature = "gecko"))]
|
||||
#[cfg(feature = "servo")]
|
||||
use crate::values::Impossible;
|
||||
use crate::Zero;
|
||||
use cssparser::{self, BasicParseErrorKind, Parser, Token};
|
||||
|
@ -30,11 +30,13 @@ pub type BoxShadow =
|
|||
|
||||
/// A specified value for a single `filter`.
|
||||
#[cfg(feature = "gecko")]
|
||||
pub type Filter = GenericFilter<Angle, Factor, NonNegativeLength, SimpleShadow, SpecifiedUrl>;
|
||||
pub type SpecifiedFilter = GenericFilter<Angle, Factor, NonNegativeLength, SimpleShadow, SpecifiedUrl>;
|
||||
|
||||
/// A specified value for a single `filter`.
|
||||
#[cfg(not(feature = "gecko"))]
|
||||
pub type Filter = GenericFilter<Angle, Factor, NonNegativeLength, Impossible, Impossible>;
|
||||
#[cfg(feature = "servo")]
|
||||
pub type SpecifiedFilter = GenericFilter<Angle, Factor, NonNegativeLength, Impossible, Impossible>;
|
||||
|
||||
pub use self::SpecifiedFilter as Filter;
|
||||
|
||||
/// A value for the `<factor>` parts in `Filter`.
|
||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToCss, ToShmem)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue