mirror of
https://github.com/servo/servo.git
synced 2025-10-18 01:09:16 +01:00
Use generics for scroll-snap-points-*
This commit is contained in:
parent
bc1eef8f5e
commit
195e98e745
8 changed files with 122 additions and 110 deletions
11
components/style/values/computed/gecko.rs
Normal file
11
components/style/values/computed/gecko.rs
Normal file
|
@ -0,0 +1,11 @@
|
|||
/* 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/. */
|
||||
|
||||
//! Computed types for legacy Gecko-only properties.
|
||||
|
||||
use values::computed::length::LengthOrPercentage;
|
||||
use values::generics::gecko::ScrollSnapPoint as GenericScrollSnapPoint;
|
||||
|
||||
/// A computed type for scroll snap points.
|
||||
pub type ScrollSnapPoint = GenericScrollSnapPoint<LengthOrPercentage>;
|
|
@ -28,6 +28,8 @@ pub use self::background::BackgroundSize;
|
|||
pub use self::border::{BorderImageSlice, BorderImageWidth, BorderImageSideWidth};
|
||||
pub use self::border::{BorderRadius, BorderCornerRadius};
|
||||
pub use self::image::{Gradient, GradientItem, ImageLayer, LineDirection, Image, ImageRect};
|
||||
#[cfg(feature = "gecko")]
|
||||
pub use self::gecko::ScrollSnapPoint;
|
||||
pub use self::rect::LengthOrNumberRect;
|
||||
pub use super::{Auto, Either, None_};
|
||||
#[cfg(feature = "gecko")]
|
||||
|
@ -46,6 +48,8 @@ pub mod background;
|
|||
pub mod basic_shape;
|
||||
pub mod border;
|
||||
pub mod image;
|
||||
#[cfg(feature = "gecko")]
|
||||
pub mod gecko;
|
||||
pub mod length;
|
||||
pub mod position;
|
||||
pub mod rect;
|
||||
|
|
54
components/style/values/generics/gecko.rs
Normal file
54
components/style/values/generics/gecko.rs
Normal file
|
@ -0,0 +1,54 @@
|
|||
/* 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 legacy Gecko-only properties that should probably be
|
||||
//! unshipped at some point in the future.
|
||||
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
|
||||
/// A generic value for scroll snap points.
|
||||
#[derive(Clone, Copy, Debug, HasViewportPercentage, PartialEq, ToComputedValue)]
|
||||
pub enum ScrollSnapPoint<LengthOrPercentage> {
|
||||
/// `none`
|
||||
None,
|
||||
/// `repeat(<length-or-percentage>)`
|
||||
Repeat(LengthOrPercentage)
|
||||
}
|
||||
|
||||
impl<L> ScrollSnapPoint<L> {
|
||||
/// Returns `none`.
|
||||
#[inline]
|
||||
pub fn none() -> Self {
|
||||
ScrollSnapPoint::None
|
||||
}
|
||||
|
||||
/// Returns the repeat argument, if any.
|
||||
#[inline]
|
||||
pub fn repeated(&self) -> Option<&L> {
|
||||
match *self {
|
||||
ScrollSnapPoint::None => None,
|
||||
ScrollSnapPoint::Repeat(ref length) => Some(length),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<L> ToCss for ScrollSnapPoint<L>
|
||||
where
|
||||
L: ToCss,
|
||||
{
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
|
||||
where
|
||||
W: fmt::Write,
|
||||
{
|
||||
match *self {
|
||||
ScrollSnapPoint::None => dest.write_str("none"),
|
||||
ScrollSnapPoint::Repeat(ref length) => {
|
||||
dest.write_str("repeat(")?;
|
||||
length.to_css(dest)?;
|
||||
dest.write_str(")")
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
|
@ -16,6 +16,8 @@ use values::specified::url::SpecifiedUrl;
|
|||
pub mod background;
|
||||
pub mod basic_shape;
|
||||
pub mod border;
|
||||
#[cfg(feature = "gecko")]
|
||||
pub mod gecko;
|
||||
pub mod grid;
|
||||
pub mod image;
|
||||
pub mod position;
|
||||
|
|
26
components/style/values/specified/gecko.rs
Normal file
26
components/style/values/specified/gecko.rs
Normal file
|
@ -0,0 +1,26 @@
|
|||
/* 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/. */
|
||||
|
||||
//! Specified types for legacy Gecko-only properties.
|
||||
|
||||
use cssparser::Parser;
|
||||
use parser::{Parse, ParserContext};
|
||||
use values::generics::gecko::ScrollSnapPoint as GenericScrollSnapPoint;
|
||||
use values::specified::length::LengthOrPercentage;
|
||||
|
||||
/// A specified type for scroll snap points.
|
||||
pub type ScrollSnapPoint = GenericScrollSnapPoint<LengthOrPercentage>;
|
||||
|
||||
impl Parse for ScrollSnapPoint {
|
||||
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
|
||||
if input.try(|i| i.expect_ident_matching("none")).is_ok() {
|
||||
return Ok(GenericScrollSnapPoint::None);
|
||||
}
|
||||
input.expect_function_matching("repeat")?;
|
||||
let length = input.parse_nested_block(|i| {
|
||||
LengthOrPercentage::parse_non_negative(context, i)
|
||||
})?;
|
||||
Ok(GenericScrollSnapPoint::Repeat(length))
|
||||
}
|
||||
}
|
|
@ -35,7 +35,8 @@ pub use self::border::{BorderCornerRadius, BorderImageSlice, BorderImageWidth};
|
|||
pub use self::border::{BorderImageSideWidth, BorderRadius, BorderSideWidth};
|
||||
pub use self::color::Color;
|
||||
pub use self::rect::LengthOrNumberRect;
|
||||
pub use super::generics::grid::GridLine;
|
||||
#[cfg(feature = "gecko")]
|
||||
pub use self::gecko::ScrollSnapPoint;
|
||||
pub use self::image::{ColorStop, EndingShape as GradientEndingShape, Gradient};
|
||||
pub use self::image::{GradientItem, GradientKind, Image, ImageRect, ImageLayer};
|
||||
pub use self::length::AbsoluteLength;
|
||||
|
@ -46,6 +47,7 @@ pub use self::length::{MaxLength, MozLength};
|
|||
pub use self::position::{Position, PositionComponent};
|
||||
pub use self::text::{LetterSpacing, LineHeight, WordSpacing};
|
||||
pub use self::transform::{TimingFunction, TransformOrigin};
|
||||
pub use super::generics::grid::GridLine;
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
pub mod align;
|
||||
|
@ -54,6 +56,8 @@ pub mod basic_shape;
|
|||
pub mod border;
|
||||
pub mod calc;
|
||||
pub mod color;
|
||||
#[cfg(feature = "gecko")]
|
||||
pub mod gecko;
|
||||
pub mod grid;
|
||||
pub mod image;
|
||||
pub mod length;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue