/* 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 that share their serialization implementations //! for both specified and computed values. use euclid::size::Size2D; use std::fmt; use style_traits::ToCss; use super::HasViewportPercentage; use super::computed::{Context, ToComputedValue}; pub use self::basic_shape::serialize_radius_values; pub mod basic_shape; pub mod position; #[derive(Clone, PartialEq, Debug)] #[cfg_attr(feature = "servo", derive(HeapSizeOf))] /// A type for representing CSS `widthh` and `height` values. pub struct BorderRadiusSize(pub Size2D); impl HasViewportPercentage for BorderRadiusSize { #[inline] fn has_viewport_percentage(&self) -> bool { false } } impl BorderRadiusSize { #[inline] /// Create a new `BorderRadiusSize` for an area of given width and height. pub fn new(width: L, height: L) -> BorderRadiusSize { BorderRadiusSize(Size2D::new(width, height)) } } impl BorderRadiusSize { #[inline] /// Create a new `BorderRadiusSize` for a circle of given radius. pub fn circle(radius: L) -> BorderRadiusSize { BorderRadiusSize(Size2D::new(radius.clone(), radius)) } } impl ToCss for BorderRadiusSize { #[inline] fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { self.0.width.to_css(dest)?; dest.write_str(" ")?; self.0.height.to_css(dest) } } impl ToComputedValue for BorderRadiusSize { type ComputedValue = BorderRadiusSize; #[inline] fn to_computed_value(&self, context: &Context) -> Self::ComputedValue { let w = self.0.width.to_computed_value(context); let h = self.0.height.to_computed_value(context); BorderRadiusSize(Size2D::new(w, h)) } #[inline] fn from_computed_value(computed: &Self::ComputedValue) -> Self { let w = ToComputedValue::from_computed_value(&computed.0.width); let h = ToComputedValue::from_computed_value(&computed.0.height); BorderRadiusSize(Size2D::new(w, h)) } }