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 https://mozilla.org/MPL/2.0/. */ 4 5 //! Generic values for UI properties. 6 7 use crate::values::specified::ui::CursorKind; 8 use std::fmt::{self, Write}; 9 use style_traits::{CssWriter, ToCss}; 10 11 /// A generic value for the `cursor` property. 12 /// 13 /// https://drafts.csswg.org/css-ui/#cursor 14 #[derive( 15 Clone, 16 Debug, 17 MallocSizeOf, 18 PartialEq, 19 SpecifiedValueInfo, 20 ToComputedValue, 21 ToResolvedValue, 22 ToShmem, 23 )] 24 #[repr(C)] 25 pub struct GenericCursor<Image> { 26 /// The parsed images for the cursor. 27 pub images: crate::OwnedSlice<Image>, 28 /// The kind of the cursor [default | help | ...]. 29 pub keyword: CursorKind, 30 } 31 32 pub use self::GenericCursor as Cursor; 33 34 impl<Image> Cursor<Image> { 35 /// Set `cursor` to `auto` 36 #[inline] auto() -> Self37 pub fn auto() -> Self { 38 Self { 39 images: Default::default(), 40 keyword: CursorKind::Auto, 41 } 42 } 43 } 44 45 impl<Image: ToCss> ToCss for Cursor<Image> { to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: Write,46 fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result 47 where 48 W: Write, 49 { 50 for image in &*self.images { 51 image.to_css(dest)?; 52 dest.write_str(", ")?; 53 } 54 self.keyword.to_css(dest) 55 } 56 } 57 58 /// A generic value for item of `image cursors`. 59 #[derive( 60 Clone, 61 Debug, 62 MallocSizeOf, 63 PartialEq, 64 ToComputedValue, 65 ToResolvedValue, 66 ToShmem, 67 )] 68 #[repr(C)] 69 pub struct GenericCursorImage<Image, Number> { 70 /// The url to parse images from. 71 pub image: Image, 72 /// Whether the image has a hotspot or not. 73 pub has_hotspot: bool, 74 /// The x coordinate. 75 pub hotspot_x: Number, 76 /// The y coordinate. 77 pub hotspot_y: Number, 78 } 79 80 pub use self::GenericCursorImage as CursorImage; 81 82 impl<Image: ToCss, Number: ToCss> ToCss for CursorImage<Image, Number> { to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: Write,83 fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result 84 where 85 W: Write, 86 { 87 self.image.to_css(dest)?; 88 if self.has_hotspot { 89 dest.write_str(" ")?; 90 self.hotspot_x.to_css(dest)?; 91 dest.write_str(" ")?; 92 self.hotspot_y.to_css(dest)?; 93 } 94 Ok(()) 95 } 96 } 97 98 /// A generic value for `scrollbar-color` property. 99 /// 100 /// https://drafts.csswg.org/css-scrollbars-1/#scrollbar-color 101 #[derive( 102 Animate, 103 Clone, 104 ComputeSquaredDistance, 105 Copy, 106 Debug, 107 MallocSizeOf, 108 PartialEq, 109 SpecifiedValueInfo, 110 ToAnimatedValue, 111 ToAnimatedZero, 112 ToComputedValue, 113 ToCss, 114 ToResolvedValue, 115 ToShmem, 116 )] 117 #[repr(C, u8)] 118 pub enum GenericScrollbarColor<Color> { 119 /// `auto` 120 Auto, 121 /// `<color>{2}` 122 Colors { 123 /// First `<color>`, for color of the scrollbar thumb. 124 thumb: Color, 125 /// Second `<color>`, for color of the scrollbar track. 126 track: Color, 127 }, 128 } 129 130 pub use self::GenericScrollbarColor as ScrollbarColor; 131 132 impl<Color> Default for ScrollbarColor<Color> { 133 #[inline] default() -> Self134 fn default() -> Self { 135 ScrollbarColor::Auto 136 } 137 } 138