servo/components/style/values/resolved/counters.rs
Ting-Yu Lin a0617bff0d style: Run rustfmt on servo/components/style and servo/ports/geckolib
This patch is generated by running `cargo +nightly fmt` under
`servo/components/style/` and `servo/ports/geckolib` against mozilla-central
https://hg.mozilla.org/mozilla-central/rev/b193f2e7a6a5d1f042c957ea4acd5c89bf210512

My nightly version is: 1.58.0-nightly (c9c4b5d72 2021-11-17)

Manually remove the redundant braces in author_styles.rs to fix a warning.

Differential Revision: https://phabricator.services.mozilla.com/D131556
2023-06-09 10:22:19 +02:00

58 lines
2.1 KiB
Rust

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
//! Resolved values for counter properties
use super::{Context, ToResolvedValue};
use crate::values::computed;
#[inline]
fn allow_element_content_none() -> bool {
#[cfg(feature = "gecko")]
return static_prefs::pref!("layout.css.element-content-none.enabled");
#[cfg(feature = "servo")]
return false;
}
/// https://drafts.csswg.org/css-content/#content-property
///
/// We implement this at resolved value time because otherwise it causes us to
/// allocate a bunch of useless initial structs for ::before / ::after, which is
/// a bit unfortunate.
///
/// Though these should be temporary, mostly, so if this causes complexity in
/// other places, it should be fine to move to `StyleAdjuster`.
///
/// See https://github.com/w3c/csswg-drafts/issues/4632 for where some related
/// issues are being discussed.
impl ToResolvedValue for computed::Content {
type ResolvedValue = Self;
#[inline]
fn to_resolved_value(self, context: &Context) -> Self {
let (is_pseudo, is_before_or_after, is_marker) = match context.style.pseudo() {
Some(ref pseudo) => (true, pseudo.is_before_or_after(), pseudo.is_marker()),
None => (false, false, false),
};
match self {
Self::Normal if is_before_or_after => Self::None,
// For now, make `content: none` compute to `normal` for pseudos
// other than ::before, ::after and ::marker, as we don't respect it.
// https://github.com/w3c/csswg-drafts/issues/6124
// Ditto for non-pseudo elements if the pref is disabled.
Self::None
if (is_pseudo && !is_before_or_after && !is_marker) ||
(!is_pseudo && !allow_element_content_none()) =>
{
Self::Normal
},
other => other,
}
}
#[inline]
fn from_resolved_value(resolved: Self) -> Self {
resolved
}
}