style/values/specified/tree_counting.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//! Specified types for CSS tree-counting functions.
6//! https://drafts.csswg.org/css-values-5/#tree-counting
7
8use crate::derives::*;
9use crate::values::computed::Context;
10
11/// A CSS tree-counting function: `sibling-index()` or `sibling-count()`.
12/// See <https://www.w3.org/TR/css-values-5/#tree-counting>.
13#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, PartialOrd, ToCss, ToShmem, ToTyped)]
14#[repr(u8)]
15pub enum TreeCountingFunction {
16 /// `sibling-count()`: the total number of siblings of the element, including itself.
17 #[css(function)]
18 SiblingCount,
19 /// `sibling-index()`: the 1-based index of the element among its siblings.
20 #[css(function)]
21 SiblingIndex,
22}
23
24impl TreeCountingFunction {
25 /// Computes the value of this tree-counting function.
26 pub fn to_computed_value(&self, context: &Context) -> u32 {
27 match self {
28 TreeCountingFunction::SiblingCount => context.query_sibling_count(),
29 TreeCountingFunction::SiblingIndex => context.query_sibling_index(),
30 }
31 }
32}