1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4 
5 //! CSS handling for the computed value of
6 //! [`position`][position] values.
7 //!
8 //! [position]: https://drafts.csswg.org/css-backgrounds-3/#position
9 
10 use std::fmt::{self, Write};
11 use style_traits::{CssWriter, ToCss};
12 use values::computed::{Integer, LengthOrPercentage, Percentage};
13 use values::generics::position::Position as GenericPosition;
14 use values::generics::position::ZIndex as GenericZIndex;
15 pub use values::specified::position::{GridAutoFlow, GridTemplateAreas};
16 
17 /// The computed value of a CSS `<position>`
18 pub type Position = GenericPosition<HorizontalPosition, VerticalPosition>;
19 
20 /// The computed value of a CSS horizontal position.
21 pub type HorizontalPosition = LengthOrPercentage;
22 
23 /// The computed value of a CSS vertical position.
24 pub type VerticalPosition = LengthOrPercentage;
25 
26 impl Position {
27     /// `50% 50%`
28     #[inline]
center() -> Self29     pub fn center() -> Self {
30         Self::new(
31             LengthOrPercentage::Percentage(Percentage(0.5)),
32             LengthOrPercentage::Percentage(Percentage(0.5)),
33         )
34     }
35 
36     /// `0% 0%`
37     #[inline]
zero() -> Self38     pub fn zero() -> Self {
39         Self::new(LengthOrPercentage::zero(), LengthOrPercentage::zero())
40     }
41 }
42 
43 impl ToCss for Position {
to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: Write,44     fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
45     where
46         W: Write,
47     {
48         self.horizontal.to_css(dest)?;
49         dest.write_str(" ")?;
50         self.vertical.to_css(dest)
51     }
52 }
53 
54 /// A computed value for the `z-index` property.
55 pub type ZIndex = GenericZIndex<Integer>;
56