mirror of
https://github.com/servo/servo.git
synced 2025-07-10 08:53:41 +01:00
Use it to be consistent in InsetRect serialization and storage between Servo and Gecko. Differential Revision: https://phabricator.services.mozilla.com/D21493
56 lines
1.7 KiB
Rust
56 lines
1.7 KiB
Rust
/* 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 https://mozilla.org/MPL/2.0/. */
|
|
|
|
//! CSS handling for the computed value of
|
|
//! [`position`][position] values.
|
|
//!
|
|
//! [position]: https://drafts.csswg.org/css-backgrounds-3/#position
|
|
|
|
use crate::values::computed::{Integer, LengthPercentage, Percentage};
|
|
use crate::values::generics::position::Position as GenericPosition;
|
|
use crate::values::generics::position::ZIndex as GenericZIndex;
|
|
pub use crate::values::specified::position::{GridAutoFlow, GridTemplateAreas};
|
|
use crate::Zero;
|
|
use std::fmt::{self, Write};
|
|
use style_traits::{CssWriter, ToCss};
|
|
|
|
/// The computed value of a CSS `<position>`
|
|
pub type Position = GenericPosition<HorizontalPosition, VerticalPosition>;
|
|
|
|
/// The computed value of a CSS horizontal position.
|
|
pub type HorizontalPosition = LengthPercentage;
|
|
|
|
/// The computed value of a CSS vertical position.
|
|
pub type VerticalPosition = LengthPercentage;
|
|
|
|
impl Position {
|
|
/// `50% 50%`
|
|
#[inline]
|
|
pub fn center() -> Self {
|
|
Self::new(
|
|
LengthPercentage::new_percent(Percentage(0.5)),
|
|
LengthPercentage::new_percent(Percentage(0.5)),
|
|
)
|
|
}
|
|
|
|
/// `0% 0%`
|
|
#[inline]
|
|
pub fn zero() -> Self {
|
|
Self::new(LengthPercentage::zero(), LengthPercentage::zero())
|
|
}
|
|
}
|
|
|
|
impl ToCss for Position {
|
|
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
|
where
|
|
W: Write,
|
|
{
|
|
self.horizontal.to_css(dest)?;
|
|
dest.write_str(" ")?;
|
|
self.vertical.to_css(dest)
|
|
}
|
|
}
|
|
|
|
/// A computed value for the `z-index` property.
|
|
pub type ZIndex = GenericZIndex<Integer>;
|