/* 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 values for UI properties. use std::fmt::{self, Write}; use style_traits::{CssWriter, ToCss}; use style_traits::cursor::CursorKind; /// A generic value for the `cursor` property. /// /// https://drafts.csswg.org/css-ui/#cursor #[derive(Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToComputedValue)] pub struct Cursor { /// The parsed images for the cursor. pub images: Box<[Image]>, /// The kind of the cursor [default | help | ...]. pub keyword: CursorKind, } impl Cursor { /// Set `cursor` to `auto` #[inline] pub fn auto() -> Self { Self { images: vec![].into_boxed_slice(), keyword: CursorKind::Auto, } } } impl ToCss for Cursor { fn to_css(&self, dest: &mut CssWriter) -> fmt::Result where W: Write, { for image in &*self.images { image.to_css(dest)?; dest.write_str(", ")?; } self.keyword.to_css(dest) } } /// A generic value for item of `image cursors`. #[derive(Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToComputedValue)] pub struct CursorImage { /// The url to parse images from. pub url: ImageUrl, /// The and coordinates. pub hotspot: Option<(Number, Number)>, } impl ToCss for CursorImage { fn to_css(&self, dest: &mut CssWriter) -> fmt::Result where W: Write, { self.url.to_css(dest)?; if let Some((ref x, ref y)) = self.hotspot { dest.write_str(" ")?; x.to_css(dest)?; dest.write_str(" ")?; y.to_css(dest)?; } Ok(()) } } /// A generic value for `scrollbar-color` property. /// /// https://drafts.csswg.org/css-scrollbars-1/#scrollbar-color #[derive(Animate, Clone, ComputeSquaredDistance, Copy, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToAnimatedValue, ToAnimatedZero, ToComputedValue, ToCss)] pub enum ScrollbarColor { /// `auto` Auto, /// `{2}` Colors { /// First ``, for color of the scrollbar thumb. thumb: Color, /// Second ``, for color of the scrollbar track. track: Color, } } impl Default for ScrollbarColor { #[inline] fn default() -> Self { ScrollbarColor::Auto } }