tor-browser

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

counters.rs (1768B)


      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 values for counter properties
      6 
      7 use super::{Context, ToResolvedValue};
      8 use crate::values::computed;
      9 #[cfg(feature = "gecko")]
     10 use selectors::parser::PseudoElement;
     11 
     12 /// https://drafts.csswg.org/css-content/#content-property
     13 ///
     14 /// We implement this at resolved value time because otherwise it causes us to allocate a bunch of
     15 /// useless initial structs for all ::before / ::after, which is a bit unfortunate.
     16 ///
     17 /// Though these should be temporary, mostly, so if this causes complexity in
     18 /// other places, it should be fine to move to `StyleAdjuster`.
     19 ///
     20 /// See https://github.com/w3c/csswg-drafts/issues/4632 for where some related
     21 /// issues are being discussed.
     22 impl ToResolvedValue for computed::Content {
     23    type ResolvedValue = Self;
     24 
     25    #[inline]
     26    fn to_resolved_value(self, context: &Context) -> Self {
     27        let (is_before_or_after, is_marker) = match context.style.pseudo() {
     28            Some(ref pseudo) => (pseudo.is_before_or_after(), pseudo.is_marker()),
     29            None => (false, false),
     30        };
     31        match self {
     32            Self::Normal if is_before_or_after => Self::None,
     33            // For now, make `content: none` resolve to `normal` for pseudos
     34            // other than ::before, ::after and ::marker, as we don't respect it.
     35            // https://github.com/w3c/csswg-drafts/issues/6124
     36            Self::None if !is_before_or_after && !is_marker => Self::Normal,
     37            other => other,
     38        }
     39    }
     40 
     41    #[inline]
     42    fn from_resolved_value(resolved: Self) -> Self {
     43        resolved
     44    }
     45 }