style/values/resolved/
color.rs

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//! Resolved color values.
6
7use super::{Context, ToResolvedValue};
8
9use crate::color::AbsoluteColor;
10use crate::values::computed::color as computed;
11use crate::values::generics::color as generics;
12
13impl ToResolvedValue for computed::Color {
14    // A resolved color value is an rgba color, with currentcolor resolved.
15    type ResolvedValue = AbsoluteColor;
16
17    #[inline]
18    fn to_resolved_value(self, context: &Context) -> Self::ResolvedValue {
19        context.style.resolve_color(&self)
20    }
21
22    #[inline]
23    fn from_resolved_value(resolved: Self::ResolvedValue) -> Self {
24        generics::Color::Absolute(resolved)
25    }
26}
27
28impl ToResolvedValue for computed::CaretColor {
29    // A resolved caret-color value is an rgba color, with auto resolving to
30    // currentcolor.
31    type ResolvedValue = AbsoluteColor;
32
33    #[inline]
34    fn to_resolved_value(self, context: &Context) -> Self::ResolvedValue {
35        let color = match self.0 {
36            generics::ColorOrAuto::Color(color) => color,
37            generics::ColorOrAuto::Auto => generics::Color::currentcolor(),
38        };
39        color.to_resolved_value(context)
40    }
41
42    #[inline]
43    fn from_resolved_value(resolved: Self::ResolvedValue) -> Self {
44        generics::CaretColor(generics::ColorOrAuto::Color(
45            computed::Color::from_resolved_value(resolved),
46        ))
47    }
48}