layout: Implement node geometry queries against BoxTree's Fragment (#36663)

This is a followup to #36629, continuing to implement script-based
layout queries  using the `Fragment`s attached to the `BoxTree`. In this
change, geometry queris (apart from parent offset) are calculated using
`Fragment`s hanging of the `BoxTree`.

In order to make this work, all `Fragment`s for inlines split by blocks,
need to be accessible in the `BoxTree`. This required some changes to
the way that box tree items were stored in DOM `BoxSlot`s. Now every
inline level item can have more than a single `BoxTree` item. These are
carefully collected by the `InlineFormattingContextBuilder` -- currently
a bit fragile, but with more documentation.

Testing: There are tests for these changes.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
This commit is contained in:
Martin Robinson 2025-04-25 15:38:05 +02:00 committed by GitHub
parent cc91395397
commit b63a1818c4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 197 additions and 170 deletions

View file

@ -46,42 +46,36 @@ use crate::fragment_tree::{
use crate::geom::{PhysicalRect, PhysicalVec};
use crate::taffy::SpecificTaffyGridInfo;
pub fn process_content_box_request(
requested_node: OpaqueNode,
fragment_tree: Option<Arc<FragmentTree>>,
) -> Option<Rect<Au>> {
let rects = fragment_tree?.get_content_boxes_for_node(requested_node);
pub fn process_content_box_request<'dom>(node: impl LayoutNode<'dom> + 'dom) -> Option<Rect<Au>> {
let rects: Vec<_> = node
.fragments_for_pseudo(None)
.iter()
.filter_map(Fragment::cumulative_content_box_rect)
.collect();
if rects.is_empty() {
return None;
}
Some(
rects
.iter()
.fold(Rect::zero(), |unioned_rect, rect| rect.union(&unioned_rect)),
)
Some(rects.iter().fold(Rect::zero(), |unioned_rect, rect| {
rect.to_untyped().union(&unioned_rect)
}))
}
pub fn process_content_boxes_request(
requested_node: OpaqueNode,
fragment_tree: Option<Arc<FragmentTree>>,
) -> Vec<Rect<Au>> {
fragment_tree
.map(|tree| tree.get_content_boxes_for_node(requested_node))
pub fn process_content_boxes_request<'dom>(node: impl LayoutNode<'dom> + 'dom) -> Vec<Rect<Au>> {
node.fragments_for_pseudo(None)
.iter()
.filter_map(Fragment::cumulative_content_box_rect)
.map(|rect| rect.to_untyped())
.collect()
}
pub fn process_client_rect_request<'dom>(node: impl LayoutNode<'dom> + 'dom) -> Rect<i32> {
node.fragments_for_pseudo(None)
.first()
.map(Fragment::client_rect)
.unwrap_or_default()
}
pub fn process_node_geometry_request(
requested_node: OpaqueNode,
fragment_tree: Option<Arc<FragmentTree>>,
) -> Rect<i32> {
if let Some(fragment_tree) = fragment_tree {
fragment_tree.get_border_dimensions_for_node(requested_node)
} else {
Rect::zero()
}
}
/// <https://drafts.csswg.org/cssom-view/#scrolling-area>
pub fn process_node_scroll_area_request<'dom>(
requested_node: Option<impl LayoutNode<'dom> + 'dom>,