mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Make use of generics for transform-origin
This allows us to preserve keywords during serialisation.
This commit is contained in:
parent
b42aaf28df
commit
5d70580813
12 changed files with 241 additions and 221 deletions
|
@ -19,6 +19,7 @@ pub mod grid;
|
|||
pub mod image;
|
||||
pub mod position;
|
||||
pub mod rect;
|
||||
pub mod transform;
|
||||
|
||||
// https://drafts.csswg.org/css-counter-styles/#typedef-symbols-type
|
||||
define_css_keyword_enum! { SymbolsType:
|
||||
|
|
45
components/style/values/generics/transform.rs
Normal file
45
components/style/values/generics/transform.rs
Normal file
|
@ -0,0 +1,45 @@
|
|||
/* 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 that are related to transformations.
|
||||
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
|
||||
/// A generic transform origin.
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[derive(Clone, Copy, Debug, HasViewportPercentage, PartialEq, ToComputedValue)]
|
||||
pub struct TransformOrigin<H, V, Depth> {
|
||||
/// The horizontal origin.
|
||||
pub horizontal: H,
|
||||
/// The vertical origin.
|
||||
pub vertical: V,
|
||||
/// The depth.
|
||||
pub depth: Depth,
|
||||
}
|
||||
|
||||
impl<H, V, D> TransformOrigin<H, V, D> {
|
||||
/// Returns a new transform origin.
|
||||
pub fn new(horizontal: H, vertical: V, depth: D) -> Self {
|
||||
Self {
|
||||
horizontal: horizontal,
|
||||
vertical: vertical,
|
||||
depth: depth,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<H, V, D> ToCss for TransformOrigin<H, V, D>
|
||||
where H: ToCss, V: ToCss, D: ToCss,
|
||||
{
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
|
||||
where W: fmt::Write,
|
||||
{
|
||||
self.horizontal.to_css(dest)?;
|
||||
dest.write_str(" ")?;
|
||||
self.vertical.to_css(dest)?;
|
||||
dest.write_str(" ")?;
|
||||
self.depth.to_css(dest)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue