From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- servo/components/style/values/generics/ui.rs | 129 +++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 servo/components/style/values/generics/ui.rs (limited to 'servo/components/style/values/generics/ui.rs') diff --git a/servo/components/style/values/generics/ui.rs b/servo/components/style/values/generics/ui.rs new file mode 100644 index 0000000000..87c8674182 --- /dev/null +++ b/servo/components/style/values/generics/ui.rs @@ -0,0 +1,129 @@ +/* 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/. */ + +//! Generic values for UI properties. + +use crate::values::specified::ui::CursorKind; +use std::fmt::{self, Write}; +use style_traits::{CssWriter, ToCss}; + +/// A generic value for the `cursor` property. +/// +/// https://drafts.csswg.org/css-ui/#cursor +#[derive( + Clone, + Debug, + MallocSizeOf, + PartialEq, + SpecifiedValueInfo, + ToComputedValue, + ToResolvedValue, + ToShmem, +)] +#[repr(C)] +pub struct GenericCursor { + /// The parsed images for the cursor. + pub images: crate::OwnedSlice, + /// The kind of the cursor [default | help | ...]. + pub keyword: CursorKind, +} + +pub use self::GenericCursor as Cursor; + +impl Cursor { + /// Set `cursor` to `auto` + #[inline] + pub fn auto() -> Self { + Self { + images: Default::default(), + 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, ToComputedValue, ToResolvedValue, ToShmem)] +#[repr(C)] +pub struct GenericCursorImage { + /// The url to parse images from. + pub image: Image, + /// Whether the image has a hotspot or not. + pub has_hotspot: bool, + /// The x coordinate. + pub hotspot_x: Number, + /// The y coordinate. + pub hotspot_y: Number, +} + +pub use self::GenericCursorImage as CursorImage; + +impl ToCss for CursorImage { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result + where + W: Write, + { + self.image.to_css(dest)?; + if self.has_hotspot { + dest.write_char(' ')?; + self.hotspot_x.to_css(dest)?; + dest.write_char(' ')?; + self.hotspot_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, + ToResolvedValue, + ToShmem, +)] +#[repr(C, u8)] +pub enum GenericScrollbarColor { + /// `auto` + Auto, + /// `{2}` + Colors { + /// First ``, for color of the scrollbar thumb. + thumb: Color, + /// Second ``, for color of the scrollbar track. + track: Color, + }, +} + +pub use self::GenericScrollbarColor as ScrollbarColor; + +impl Default for ScrollbarColor { + #[inline] + fn default() -> Self { + ScrollbarColor::Auto + } +} -- cgit v1.2.3