Skip to main content

kozan_core/layout/
box_model.rs

1//! Shared box model utilities — stacking context detection.
2//!
3//! Chrome equivalent: helpers in `PaintLayer` and `ComputedStyleUtils`.
4
5use style::properties::ComputedValues;
6
7/// Check if an element establishes a stacking context.
8///
9/// Chrome: `PaintLayer::ComputeStackingContext()`.
10pub(crate) fn is_stacking_context(style: &ComputedValues) -> bool {
11    use style::computed_values::position::T as Position;
12
13    let position = style.clone_position();
14    if matches!(
15        position,
16        Position::Relative | Position::Absolute | Position::Fixed
17    ) {
18        // z-index: auto does NOT establish a stacking context for positioned elements
19        // (only an integer value does). Stylo's clone_z_index returns ZIndex.
20        let z_index = style.clone_z_index();
21        if !z_index.is_auto() {
22            return true;
23        }
24    }
25    if style.get_effects().opacity != 1.0 {
26        return true;
27    }
28    if !style.get_box().transform.0.is_empty() {
29        return true;
30    }
31    false
32}
33
34#[cfg(test)]
35mod tests {
36    use super::*;
37
38    #[test]
39    fn stacking_context_default_is_false() {
40        let style = crate::styling::initial_values_arc();
41        assert!(!is_stacking_context(&style));
42    }
43}