mirror of
https://github.com/servo/servo.git
synced 2025-08-10 16:05:43 +01:00
Use generics for the filter property
This introduces an additional shadow type for drop-shadow().
This commit is contained in:
parent
e41b7d06b4
commit
6f4061d4ad
21 changed files with 822 additions and 496 deletions
51
components/style/values/generics/counters.rs
Normal file
51
components/style/values/generics/counters.rs
Normal file
|
@ -0,0 +1,51 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
//! Generic types for counters-related CSS values.
|
||||
|
||||
use std::fmt;
|
||||
use style_traits::{HasViewportPercentage, ToCss};
|
||||
use values::CustomIdent;
|
||||
|
||||
/// A generic value for the `counter-increment` property.
|
||||
///
|
||||
/// Keyword `none` is represented by an empty slice.
|
||||
#[derive(Clone, Debug, PartialEq, ToComputedValue)]
|
||||
pub struct CounterIncrement<Integer>(Box<[(CustomIdent, Integer)]);
|
||||
|
||||
impl<I> CounterIncrement<I> {
|
||||
/// Returns `none`.
|
||||
#[inline]
|
||||
pub fn none() -> Self {
|
||||
CounterIncrement(vec![].into_boxed_slice())
|
||||
}
|
||||
}
|
||||
|
||||
impl<I> HasViewportPercentage for CounterIncrement<I> {
|
||||
#[inline] fn has_viewport_percentage(&self) -> bool { false }
|
||||
}
|
||||
|
||||
impl<I> ToCss for CounterIncrement<I>
|
||||
where
|
||||
I: ToCss,
|
||||
{
|
||||
#[inline]
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
|
||||
where
|
||||
W: fmt::Write,
|
||||
{
|
||||
if self.0.is_empty() {
|
||||
return dest.write_str("none");
|
||||
}
|
||||
for (&(ref name, ref value), i) in self.0.iter().enumerate() {
|
||||
if i != 0 {
|
||||
dest.write_str(" ")?;
|
||||
}
|
||||
name.to_css(dest)?;
|
||||
dest.write_str(" ")?;
|
||||
value.to_css(dest)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
92
components/style/values/generics/effects.rs
Normal file
92
components/style/values/generics/effects.rs
Normal file
|
@ -0,0 +1,92 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
//! 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)]
|
||||
pub enum Filter<Angle, Factor, Length, DropShadow> {
|
||||
/// `blur(<length>)`
|
||||
#[css(function)]
|
||||
Blur(Length),
|
||||
/// `brightness(<factor>)`
|
||||
#[css(function)]
|
||||
Brightness(Factor),
|
||||
/// `contrast(<factor>)`
|
||||
#[css(function)]
|
||||
Contrast(Factor),
|
||||
/// `grayscale(<factor>)`
|
||||
#[css(function)]
|
||||
Grayscale(Factor),
|
||||
/// `hue-rotate(<angle>)`
|
||||
#[css(function)]
|
||||
HueRotate(Angle),
|
||||
/// `invert(<factor>)`
|
||||
#[css(function)]
|
||||
Invert(Factor),
|
||||
/// `opacity(<factor>)`
|
||||
#[css(function)]
|
||||
Opacity(Factor),
|
||||
/// `saturate(<factor>)`
|
||||
#[css(function)]
|
||||
Saturate(Factor),
|
||||
/// `sepia(<factor>)`
|
||||
#[css(function)]
|
||||
Sepia(Factor),
|
||||
/// `drop-shadow(...)`
|
||||
#[css(function)]
|
||||
DropShadow(DropShadow),
|
||||
/// `<url>`
|
||||
#[cfg(feature = "gecko")]
|
||||
Url(SpecifiedUrl),
|
||||
}
|
||||
|
||||
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")
|
||||
}
|
||||
}
|
||||
}
|
|
@ -16,6 +16,7 @@ use values::specified::url::SpecifiedUrl;
|
|||
pub mod background;
|
||||
pub mod basic_shape;
|
||||
pub mod border;
|
||||
pub mod effects;
|
||||
pub mod flex;
|
||||
#[cfg(feature = "gecko")]
|
||||
pub mod gecko;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue