mirror of
https://github.com/servo/servo.git
synced 2025-08-02 04:00:32 +01:00
Use the Separator trait for the filter property
This commit is contained in:
parent
813883e1bd
commit
395f6be0a6
13 changed files with 66 additions and 131 deletions
|
@ -28,7 +28,8 @@ use std::cmp::{self, Ordering};
|
|||
use std::collections::HashMap;
|
||||
use std::fmt;
|
||||
use std::sync::Arc;
|
||||
use style::computed_values::{border_style, filter, image_rendering};
|
||||
use style::computed_values::{border_style, image_rendering};
|
||||
use style::values::computed::Filter;
|
||||
use style_traits::cursor::Cursor;
|
||||
use text::TextRun;
|
||||
use text::glyph::ByteIndex;
|
||||
|
@ -419,7 +420,7 @@ pub struct StackingContext {
|
|||
pub z_index: i32,
|
||||
|
||||
/// CSS filters to be applied to this stacking context (including opacity).
|
||||
pub filters: filter::T,
|
||||
pub filters: Vec<Filter>,
|
||||
|
||||
/// The blend mode with which this stacking context blends with its backdrop.
|
||||
pub mix_blend_mode: MixBlendMode,
|
||||
|
@ -448,7 +449,7 @@ impl StackingContext {
|
|||
bounds: &Rect<Au>,
|
||||
overflow: &Rect<Au>,
|
||||
z_index: i32,
|
||||
filters: filter::T,
|
||||
filters: Vec<Filter>,
|
||||
mix_blend_mode: MixBlendMode,
|
||||
transform: Option<Transform3D<f32>>,
|
||||
transform_style: TransformStyle,
|
||||
|
@ -479,7 +480,7 @@ impl StackingContext {
|
|||
&Rect::zero(),
|
||||
&Rect::zero(),
|
||||
0,
|
||||
filter::T::none(),
|
||||
vec![],
|
||||
MixBlendMode::Normal,
|
||||
None,
|
||||
TransformStyle::Flat,
|
||||
|
|
|
@ -2010,7 +2010,7 @@ impl FragmentDisplayListBuilding for Fragment {
|
|||
|
||||
// Create the filter pipeline.
|
||||
let effects = self.style().get_effects();
|
||||
let mut filters = effects.filter.clone().0.into_vec();
|
||||
let mut filters = effects.filter.0.clone();
|
||||
if effects.opacity != 1.0 {
|
||||
filters.push(Filter::Opacity(effects.opacity))
|
||||
}
|
||||
|
|
|
@ -13,9 +13,8 @@ use gfx::display_list::{BorderDetails, BorderRadii, BoxShadowClipMode, ClippingR
|
|||
use gfx::display_list::{DisplayItem, DisplayList, DisplayListTraversal, StackingContextType};
|
||||
use msg::constellation_msg::PipelineId;
|
||||
use style::computed_values::{image_rendering, mix_blend_mode, transform_style};
|
||||
use style::computed_values::filter;
|
||||
use style::values::computed::BorderStyle;
|
||||
use style::values::generics::effects::Filter;
|
||||
use style::values::computed::{BorderStyle, Filter};
|
||||
use style::values::generics::effects::Filter as GenericFilter;
|
||||
use webrender_traits::{self, DisplayListBuilder, ExtendMode};
|
||||
use webrender_traits::{LayoutTransform, ClipId, ClipRegionToken};
|
||||
|
||||
|
@ -202,21 +201,21 @@ trait ToFilterOps {
|
|||
fn to_filter_ops(&self) -> Vec<webrender_traits::FilterOp>;
|
||||
}
|
||||
|
||||
impl ToFilterOps for filter::T {
|
||||
impl ToFilterOps for Vec<Filter> {
|
||||
fn to_filter_ops(&self) -> Vec<webrender_traits::FilterOp> {
|
||||
let mut result = Vec::with_capacity(self.0.len());
|
||||
for filter in self.0.iter() {
|
||||
let mut result = Vec::with_capacity(self.len());
|
||||
for filter in self.iter() {
|
||||
match *filter {
|
||||
Filter::Blur(radius) => result.push(webrender_traits::FilterOp::Blur(radius)),
|
||||
Filter::Brightness(amount) => result.push(webrender_traits::FilterOp::Brightness(amount)),
|
||||
Filter::Contrast(amount) => result.push(webrender_traits::FilterOp::Contrast(amount)),
|
||||
Filter::Grayscale(amount) => result.push(webrender_traits::FilterOp::Grayscale(amount)),
|
||||
Filter::HueRotate(angle) => result.push(webrender_traits::FilterOp::HueRotate(angle.radians())),
|
||||
Filter::Invert(amount) => result.push(webrender_traits::FilterOp::Invert(amount)),
|
||||
Filter::Opacity(amount) => result.push(webrender_traits::FilterOp::Opacity(amount.into())),
|
||||
Filter::Saturate(amount) => result.push(webrender_traits::FilterOp::Saturate(amount)),
|
||||
Filter::Sepia(amount) => result.push(webrender_traits::FilterOp::Sepia(amount)),
|
||||
Filter::DropShadow(ref shadow) => match *shadow {},
|
||||
GenericFilter::Blur(radius) => result.push(webrender_traits::FilterOp::Blur(radius)),
|
||||
GenericFilter::Brightness(amount) => result.push(webrender_traits::FilterOp::Brightness(amount)),
|
||||
GenericFilter::Contrast(amount) => result.push(webrender_traits::FilterOp::Contrast(amount)),
|
||||
GenericFilter::Grayscale(amount) => result.push(webrender_traits::FilterOp::Grayscale(amount)),
|
||||
GenericFilter::HueRotate(angle) => result.push(webrender_traits::FilterOp::HueRotate(angle.radians())),
|
||||
GenericFilter::Invert(amount) => result.push(webrender_traits::FilterOp::Invert(amount)),
|
||||
GenericFilter::Opacity(amount) => result.push(webrender_traits::FilterOp::Opacity(amount.into())),
|
||||
GenericFilter::Saturate(amount) => result.push(webrender_traits::FilterOp::Saturate(amount)),
|
||||
GenericFilter::Sepia(amount) => result.push(webrender_traits::FilterOp::Sepia(amount)),
|
||||
GenericFilter::DropShadow(ref shadow) => match *shadow {},
|
||||
}
|
||||
}
|
||||
result
|
||||
|
|
|
@ -60,7 +60,7 @@ use std::ptr;
|
|||
use stylearc::Arc;
|
||||
use std::cmp;
|
||||
use values::{Auto, CustomIdent, Either, KeyframesName};
|
||||
use values::computed::Shadow;
|
||||
use values::computed::{Filter, Shadow};
|
||||
use values::specified::length::Percentage;
|
||||
use computed_values::border_style;
|
||||
|
||||
|
@ -3300,7 +3300,11 @@ fn static_assert() {
|
|||
'Opacity', 'Saturate', 'Sepia' ]
|
||||
%>
|
||||
|
||||
pub fn set_filter(&mut self, v: longhands::filter::computed_value::T) {
|
||||
pub fn set_filter<I>(&mut self, v: I)
|
||||
where
|
||||
I: IntoIterator<Item = Filter>,
|
||||
I::IntoIter: ExactSizeIterator,
|
||||
{
|
||||
use values::generics::effects::Filter::*;
|
||||
use gecko_bindings::structs::nsCSSShadowArray;
|
||||
use gecko_bindings::structs::nsStyleFilter;
|
||||
|
@ -3320,12 +3324,13 @@ fn static_assert() {
|
|||
gecko_filter.mFilterParameter.set_value(value);
|
||||
}
|
||||
|
||||
let v = v.into_iter();
|
||||
unsafe {
|
||||
Gecko_ResetFilters(&mut self.gecko, v.0.len());
|
||||
Gecko_ResetFilters(&mut self.gecko, v.len());
|
||||
}
|
||||
debug_assert!(v.0.len() == self.gecko.mFilters.len());
|
||||
debug_assert_eq!(v.len(), self.gecko.mFilters.len());
|
||||
|
||||
for (servo, gecko_filter) in v.0.into_vec().into_iter().zip(self.gecko.mFilters.iter_mut()) {
|
||||
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()},
|
||||
|
@ -3372,7 +3377,7 @@ fn static_assert() {
|
|||
}
|
||||
|
||||
pub fn clone_filter(&self) -> longhands::filter::computed_value::T {
|
||||
use values::generics::effects::{Filter, FilterList};
|
||||
use values::generics::effects::Filter;
|
||||
use values::specified::url::SpecifiedUrl;
|
||||
use gecko_bindings::structs::NS_STYLE_FILTER_BLUR;
|
||||
use gecko_bindings::structs::NS_STYLE_FILTER_BRIGHTNESS;
|
||||
|
@ -3422,7 +3427,7 @@ fn static_assert() {
|
|||
_ => {},
|
||||
}
|
||||
}
|
||||
FilterList(filters.into_boxed_slice())
|
||||
longhands::filter::computed_value::T(filters)
|
||||
}
|
||||
|
||||
</%self:impl_trait>
|
||||
|
@ -3942,10 +3947,9 @@ clip-path
|
|||
}
|
||||
|
||||
pub fn clone_stroke_dasharray(&self) -> longhands::stroke_dasharray::computed_value::T {
|
||||
use smallvec::SmallVec;
|
||||
use values::computed::LengthOrPercentage;
|
||||
|
||||
let mut vec = SmallVec::new();
|
||||
let mut vec = vec![];
|
||||
for gecko in self.gecko.mStrokeDasharray.iter() {
|
||||
match gecko.as_value() {
|
||||
CoordDataValue::Factor(number) => vec.push(Either::First(number)),
|
||||
|
|
|
@ -88,7 +88,7 @@
|
|||
use std::fmt;
|
||||
#[allow(unused_imports)]
|
||||
use style_traits::HasViewportPercentage;
|
||||
use style_traits::ToCss;
|
||||
use style_traits::{Separator, ToCss};
|
||||
|
||||
pub mod single_value {
|
||||
#[allow(unused_imports)]
|
||||
|
@ -186,7 +186,7 @@
|
|||
% endif
|
||||
}
|
||||
for i in iter {
|
||||
dest.write_str(", ")?;
|
||||
dest.write_str(::style_traits::${separator}::separator())?;
|
||||
i.to_css(dest)?;
|
||||
}
|
||||
Ok(())
|
||||
|
@ -213,7 +213,7 @@
|
|||
% endif
|
||||
}
|
||||
for i in iter {
|
||||
dest.write_str(", ")?;
|
||||
dest.write_str(::style_traits::${separator}::separator())?;
|
||||
i.to_css(dest)?;
|
||||
}
|
||||
Ok(())
|
||||
|
|
|
@ -3340,11 +3340,11 @@ impl Animatable for AnimatedFilterList {
|
|||
}
|
||||
}
|
||||
|
||||
Ok(filters.into())
|
||||
Ok(AnimatedFilterList(filters))
|
||||
}
|
||||
|
||||
fn add(&self, other: &Self) -> Result<Self, ()> {
|
||||
Ok(self.0.iter().chain(other.0.iter()).cloned().collect::<Vec<_>>().into())
|
||||
Ok(AnimatedFilterList(self.0.iter().chain(other.0.iter()).cloned().collect()))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
|
@ -43,8 +43,10 @@ ${helpers.predefined_type("clip",
|
|||
|
||||
${helpers.predefined_type(
|
||||
"filter",
|
||||
"FilterList",
|
||||
"computed::FilterList::none()",
|
||||
"Filter",
|
||||
None,
|
||||
vector=True,
|
||||
separator="Space",
|
||||
animation_value_type="AnimatedFilterList",
|
||||
extra_prefixes="webkit",
|
||||
flags="CREATES_STACKING_CONTEXT FIXPOS_CB",
|
||||
|
|
|
@ -5,21 +5,21 @@
|
|||
//! Animated types for CSS values related to effects.
|
||||
|
||||
use properties::animated_properties::{Animatable, IntermediateColor};
|
||||
use properties::longhands::filter::computed_value::T as ComputedFilterList;
|
||||
#[cfg(not(feature = "gecko"))]
|
||||
use values::Impossible;
|
||||
use values::computed::{Angle, Number};
|
||||
#[cfg(feature = "gecko")]
|
||||
use values::computed::effects::Filter as ComputedFilter;
|
||||
#[cfg(feature = "gecko")]
|
||||
use values::computed::effects::FilterList as ComputedFilterList;
|
||||
use values::computed::effects::SimpleShadow as ComputedSimpleShadow;
|
||||
use values::computed::length::Length;
|
||||
use values::generics::effects::Filter as GenericFilter;
|
||||
use values::generics::effects::FilterList as GenericFilterList;
|
||||
use values::generics::effects::SimpleShadow as GenericSimpleShadow;
|
||||
|
||||
/// An animated value for the `filter` property.
|
||||
pub type FilterList = GenericFilterList<Filter>;
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct FilterList(pub Vec<Filter>);
|
||||
|
||||
/// An animated value for a single `filter`.
|
||||
#[cfg(feature = "gecko")]
|
||||
|
@ -32,19 +32,31 @@ pub type Filter = GenericFilter<Angle, Number, Length, Impossible>;
|
|||
/// An animated value for the `drop-shadow()` filter.
|
||||
pub type SimpleShadow = GenericSimpleShadow<IntermediateColor, Length, Length>;
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
impl From<ComputedFilterList> for FilterList {
|
||||
#[cfg(not(feature = "gecko"))]
|
||||
#[inline]
|
||||
fn from(filters: ComputedFilterList) -> Self {
|
||||
filters.0.into_vec().into_iter().map(|f| f.into()).collect::<Vec<_>>().into()
|
||||
FilterList(filters.0)
|
||||
}
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
#[inline]
|
||||
fn from(filters: ComputedFilterList) -> Self {
|
||||
FilterList(filters.0.into_iter().map(|f| f.into()).collect())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
impl From<FilterList> for ComputedFilterList {
|
||||
#[cfg(not(feature = "gecko"))]
|
||||
#[inline]
|
||||
fn from(filters: FilterList) -> Self {
|
||||
filters.0.into_vec().into_iter().map(|f| f.into()).collect::<Vec<_>>().into()
|
||||
ComputedFilterList(filters.0)
|
||||
}
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
#[inline]
|
||||
fn from(filters: FilterList) -> Self {
|
||||
ComputedFilterList(filters.0.into_iter().map(|f| f.into()).collect())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,12 +10,8 @@ use values::computed::{Angle, Number};
|
|||
use values::computed::color::Color;
|
||||
use values::computed::length::Length;
|
||||
use values::generics::effects::Filter as GenericFilter;
|
||||
use values::generics::effects::FilterList as GenericFilterList;
|
||||
use values::generics::effects::SimpleShadow as GenericSimpleShadow;
|
||||
|
||||
/// A computed value for the `filter` property.
|
||||
pub type FilterList = GenericFilterList<Filter>;
|
||||
|
||||
/// A computed value for a single `filter`.
|
||||
#[cfg(feature = "gecko")]
|
||||
pub type Filter = GenericFilter<Angle, Number, Length, SimpleShadow>;
|
||||
|
@ -26,16 +22,3 @@ pub type Filter = GenericFilter<Angle, Number, Length, Impossible>;
|
|||
|
||||
/// A computed value for the `drop-shadow()` filter.
|
||||
pub type SimpleShadow = GenericSimpleShadow<Color, Length, Length>;
|
||||
|
||||
impl FilterList {
|
||||
/// Returns the resulting opacity of this filter pipeline.
|
||||
pub fn opacity(&self) -> Number {
|
||||
let mut opacity = 0.;
|
||||
for filter in &*self.0 {
|
||||
if let GenericFilter::Opacity(factor) = *filter {
|
||||
opacity *= factor
|
||||
}
|
||||
}
|
||||
opacity
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ pub use self::background::BackgroundSize;
|
|||
pub use self::border::{BorderImageSlice, BorderImageWidth, BorderImageSideWidth};
|
||||
pub use self::border::{BorderRadius, BorderCornerRadius};
|
||||
pub use self::color::{Color, RGBAColor};
|
||||
pub use self::effects::FilterList;
|
||||
pub use self::effects::Filter;
|
||||
pub use self::flex::FlexBasis;
|
||||
pub use self::image::{Gradient, GradientItem, ImageLayer, LineDirection, Image, ImageRect};
|
||||
#[cfg(feature = "gecko")]
|
||||
|
|
|
@ -4,18 +4,9 @@
|
|||
|
||||
//! Generic types for CSS values related to effects.
|
||||
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
#[cfg(feature = "gecko")]
|
||||
use values::specified::url::SpecifiedUrl;
|
||||
|
||||
/// A generic value for the `filter` property.
|
||||
///
|
||||
/// Keyword `none` is represented by an empty slice.
|
||||
#[cfg_attr(feature = "servo", derive(Deserialize, HeapSizeOf, Serialize))]
|
||||
#[derive(Clone, Debug, HasViewportPercentage, PartialEq, ToComputedValue)]
|
||||
pub struct FilterList<Filter>(pub Box<[Filter]>);
|
||||
|
||||
/// A generic value for a single `filter`.
|
||||
#[cfg_attr(feature = "servo", derive(Deserialize, HeapSizeOf, Serialize))]
|
||||
#[derive(Clone, Debug, HasViewportPercentage, PartialEq, ToComputedValue, ToCss)]
|
||||
|
@ -71,39 +62,3 @@ pub struct SimpleShadow<Color, SizeLength, ShapeLength> {
|
|||
/// Blur radius.
|
||||
pub blur: ShapeLength,
|
||||
}
|
||||
|
||||
impl<F> FilterList<F> {
|
||||
/// Returns `none`.
|
||||
#[inline]
|
||||
pub fn none() -> Self {
|
||||
FilterList(vec![].into_boxed_slice())
|
||||
}
|
||||
}
|
||||
|
||||
impl<F> From<Vec<F>> for FilterList<F> {
|
||||
#[inline]
|
||||
fn from(vec: Vec<F>) -> Self {
|
||||
FilterList(vec.into_boxed_slice())
|
||||
}
|
||||
}
|
||||
|
||||
impl<F> ToCss for FilterList<F>
|
||||
where
|
||||
F: ToCss,
|
||||
{
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
|
||||
where
|
||||
W: fmt::Write
|
||||
{
|
||||
if let Some((first, rest)) = self.0.split_first() {
|
||||
first.to_css(dest)?;
|
||||
for filter in rest {
|
||||
dest.write_str(" ")?;
|
||||
filter.to_css(dest)?;
|
||||
}
|
||||
Ok(())
|
||||
} else {
|
||||
dest.write_str("none")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,6 @@ use values::Impossible;
|
|||
use values::computed::{Context, Number as ComputedNumber, ToComputedValue};
|
||||
use values::computed::effects::SimpleShadow as ComputedSimpleShadow;
|
||||
use values::generics::effects::Filter as GenericFilter;
|
||||
use values::generics::effects::FilterList as GenericFilterList;
|
||||
use values::generics::effects::SimpleShadow as GenericSimpleShadow;
|
||||
use values::specified::{Angle, Percentage};
|
||||
use values::specified::color::Color;
|
||||
|
@ -20,9 +19,6 @@ use values::specified::length::Length;
|
|||
#[cfg(feature = "gecko")]
|
||||
use values::specified::url::SpecifiedUrl;
|
||||
|
||||
/// A specified value for the `filter` property.
|
||||
pub type FilterList = GenericFilterList<Filter>;
|
||||
|
||||
/// A specified value for a single `filter`.
|
||||
#[cfg(feature = "gecko")]
|
||||
pub type Filter = GenericFilter<Angle, Factor, Length, SimpleShadow>;
|
||||
|
@ -46,23 +42,6 @@ pub enum Factor {
|
|||
/// A specified value for the `drop-shadow()` filter.
|
||||
pub type SimpleShadow = GenericSimpleShadow<Option<Color>, Length, Option<Length>>;
|
||||
|
||||
impl Parse for FilterList {
|
||||
#[inline]
|
||||
fn parse<'i, 't>(
|
||||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
let mut filters = vec![];
|
||||
while let Ok(filter) = input.try(|i| Filter::parse(context, i)) {
|
||||
filters.push(filter);
|
||||
}
|
||||
if filters.is_empty() {
|
||||
input.expect_ident_matching("none")?;
|
||||
}
|
||||
Ok(GenericFilterList(filters.into_boxed_slice()))
|
||||
}
|
||||
}
|
||||
|
||||
impl Parse for Filter {
|
||||
#[inline]
|
||||
fn parse<'i, 't>(
|
||||
|
@ -113,7 +92,7 @@ impl Parse for Factor {
|
|||
|
||||
impl ToComputedValue for Factor {
|
||||
/// This should actually be `ComputedNumberOrPercentage`, but layout uses
|
||||
/// `computed::effects::FilterList` directly in `StackingContext`.
|
||||
/// `computed::effects::Filter` directly in `StackingContext`.
|
||||
type ComputedValue = ComputedNumber;
|
||||
|
||||
#[inline]
|
||||
|
|
|
@ -33,7 +33,7 @@ pub use self::background::BackgroundSize;
|
|||
pub use self::border::{BorderCornerRadius, BorderImageSlice, BorderImageWidth};
|
||||
pub use self::border::{BorderImageSideWidth, BorderRadius, BorderSideWidth};
|
||||
pub use self::color::{Color, RGBAColor};
|
||||
pub use self::effects::FilterList;
|
||||
pub use self::effects::Filter;
|
||||
pub use self::flex::FlexBasis;
|
||||
#[cfg(feature = "gecko")]
|
||||
pub use self::gecko::ScrollSnapPoint;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue