Repository: servo/servo
File: components/layout/query.rs (Rust)

Code before:
        .map(Fragment::client_rect)
        .unwrap_or_default()
}

/// Process a query for the current CSS zoom of an element.
/// <https://drafts.csswg.org/cssom-view/#dom-element-currentcsszoom>
///
/// Returns the effective zoom of the element, which is the product of all zoom
/// values from the element up to the root. Returns 1.0 if the element is not
/// being rendered (has no associated box or has display: none).
pub fn process_current_css_zoom_query(node: ServoLayoutNode<'_>) -> f32 {
    // If the element has no layout data (not being rendered), return 1.0
    let Some(layout_data) = node.to_threadsafe().inner_layout_data() else {
        return 1.0;
    };
    let layout_box = layout_data.self_box.borrow();
    let Some(layout_box) = layout_box.as_ref() else {
        return 1.0;
    };

    // Get the element's style to check if it has display: none
    let Some(base_style) = layout_box.with_first_base(|base| base.style.clone()) else {
        return 1.0;
    };

    // If element has display: none, return 1.0 according to spec
    if base_style.get_box().display.is_none() {
        return 1.0;
    }

    let mut effective_zoom = 1.0_f32;
    let zoom = base_style.get_box().zoom;
    effective_zoom *= zoom.value();

    // Walk up the tree from this element to the root
    let Some(mut current_ancestor) = node.as_element() else {
        return effective_zoom;
    };

    while let Some(ancestor) = current_ancestor.traversal_parent() {
        current_ancestor = ancestor;

        let Some(layout_data) = ancestor.as_node().to_threadsafe().inner_layout_data() else {
            continue;
        };
        let ancestor_layout_box = layout_data.self_box.borrow();
        let Some(ancestor_layout_box) = ancestor_layout_box.as_ref() else {
            continue;
        };

        let Some(ancestor_style) = ancestor_layout_box.with_first_base(|base| base.style.clone())

Review comment (suggestion):
This seems unnecessary, because with `display: none` there is no box so it has been handled above

Code after:
    transform_au_rectangle(rect_union, transform)
}

pub(crate) fn process_box_areas_request(
    stacking_context_tree: &StackingContextTree,
    node: ServoThreadSafeLayoutNode<'_>,
    area: BoxAreaType,
) -> Vec<Rect<Au>> {
    let fragments = node.fragments_for_pseudo(None);
    let box_areas = fragments
        .iter()
        .filter_map(|node| node.cumulative_box_area_rect(area))
        .map(|rect| rect.to_untyped());

    let Some(transform) =
        root_transform_for_layout_node(&stacking_context_tree.compositor_info.scroll_tree, node)
    else {
        return box_areas
            .map(|rect| Rect::new(rect.origin, Size2D::zero()))
            .collect();
    };

    box_areas
        .filter_map(|rect| transform_au_rectangle(rect, transform))
        .collect()
}

pub fn process_client_rect_request(node: ServoThreadSafeLayoutNode<'_>) -> Rect<i32> {
    node.fragments_for_pseudo(None)
        .first()
        .map(Fragment::client_rect)
        .unwrap_or_default()
}

/// Process a query for the current CSS zoom of an element.
/// <https://drafts.csswg.org/cssom-view/#dom-element-currentcsszoom>
///
/// Returns the effective zoom of the element, which is the product of all zoom
/// values from the element up to the root. Returns 1.0 if the element is not
/// being rendered (has no associated box).
pub fn process_current_css_zoom_query(node: ServoLayoutNode<'_>) -> f32 {
    let Some(layout_data) = node.to_threadsafe().inner_layout_data() else {
        return 1.0;
    };
    let layout_box = layout_data.self_box.borrow();
    let Some(layout_box) = layout_box.as_ref() else {
        return 1.0;
    };
    layout_box
        .with_first_base(|base| base.style.effective_zoom.value())
        .unwrap_or(1.0)