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