tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

color.rs (1722B)


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