layout: return None bounding box when no nodes found (#31253)

Signed-off-by: syvb <me@iter.ca>
This commit is contained in:
Smitty 2024-02-02 18:24:20 -05:00 committed by GitHub
parent 95931de499
commit 436e949296
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 18 additions and 24 deletions

View file

@ -93,8 +93,9 @@ impl FragmentTree {
});
}
pub fn get_content_box_for_node(&self, requested_node: OpaqueNode) -> Rect<Au> {
pub fn get_content_box_for_node(&self, requested_node: OpaqueNode) -> Option<Rect<Au>> {
let mut bounding_box = PhysicalRect::zero();
let mut found_any_nodes = false;
let tag_to_find = Tag::new(requested_node);
self.find(|fragment, _, containing_block| {
if fragment.tag() != Some(tag_to_find) {
@ -114,22 +115,27 @@ impl FragmentTree {
Fragment::Anonymous(_) => return None,
};
found_any_nodes = true;
bounding_box = fragment_relative_rect
.translate(containing_block.origin.to_vector())
.union(&bounding_box);
None::<()>
});
Rect::new(
Point2D::new(
Au::from_f32_px(bounding_box.origin.x.px()),
Au::from_f32_px(bounding_box.origin.y.px()),
),
Size2D::new(
Au::from_f32_px(bounding_box.size.width.px()),
Au::from_f32_px(bounding_box.size.height.px()),
),
)
if found_any_nodes {
Some(Rect::new(
Point2D::new(
Au::from_f32_px(bounding_box.origin.x.px()),
Au::from_f32_px(bounding_box.origin.y.px()),
),
Size2D::new(
Au::from_f32_px(bounding_box.size.width.px()),
Au::from_f32_px(bounding_box.size.height.px()),
),
))
} else {
None
}
}
pub fn get_border_dimensions_for_node(&self, requested_node: OpaqueNode) -> Rect<i32> {