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

Code before:

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 or has display: none).
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;
    };

    let mut effective_zoom = layout_box
        .with_first_base(|base| base.style.get_box().zoom.value())
        .unwrap_or(1.0);

    // 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 zoom = ancestor_layout_box
            .with_first_base(|base| base.style.get_box().zoom.value())
            .unwrap_or(1.0);

        effective_zoom *= zoom;
    }

    effective_zoom

Review comment (suggestion):
`with_first_base()` should only be None for `display: contents`, which we represent as `LayoutBox::DisplayContents` but in the CSS specs counts as no box. So just return.

Code after:
        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)
}

/// <https://drafts.csswg.org/cssom-view/#scrolling-area>
pub fn process_node_scroll_area_request(
    requested_node: Option<ServoThreadSafeLayoutNode<'_>>,
    fragment_tree: Option<Rc<FragmentTree>>,
) -> Rect<i32> {
    let Some(tree) = fragment_tree else {
        return Rect::zero();
    };

    let rect = match requested_node {
        Some(node) => node
            .fragments_for_pseudo(None)
            .first()