Detect body elements during layout

During layout it is often useful, for various specification reasons, to
know if an element is the `<body>` element of an `<html>` element root. There
are a couple places where a brittle heuristic is used to detect `<body>`
elements. This information is going to be even more important to
properly handle `<html>` elements that inherit their overflow property from
their `<body>` children.

Implementing this properly requires updating the DOM wrapper interface.
This check does reach up to the parent of thread-safe nodes, but this is
essentially the same kind of operation that `parent_style()` does, so is
ostensibly safe.

This change should not change any behavior and is just a preparation
step for properly handle `<body>` overflow.
This commit is contained in:
Martin Robinson 2023-04-30 20:21:58 +02:00
parent 77a184a0e7
commit 72302e2dae
26 changed files with 487 additions and 277 deletions

View file

@ -4,7 +4,8 @@
use crate::context::LayoutContext;
use crate::dom_traversal::NodeExt;
use crate::fragments::{DebugId, Fragment, IFrameFragment, ImageFragment};
use crate::fragment_tree::BaseFragmentInfo;
use crate::fragments::{Fragment, IFrameFragment, ImageFragment};
use crate::geom::flow_relative::{Rect, Vec2};
use crate::geom::PhysicalSize;
use crate::sizing::ContentSizes;
@ -29,6 +30,7 @@ use webrender_api::ImageKey;
pub(crate) struct ReplacedContent {
pub kind: ReplacedContentKind,
intrinsic: IntrinsicSizes,
base_fragment_info: BaseFragmentInfo,
}
/// * Raster images always have an intrinsic width and height, with 1 image pixel = 1px.
@ -140,7 +142,12 @@ impl ReplacedContent {
},
);
return Some(Self { kind, intrinsic });
let base_fragment_info = BaseFragmentInfo::new_for_node(element.as_opaque());
return Some(Self {
kind,
intrinsic,
base_fragment_info,
});
}
pub fn from_image_url<'dom>(
@ -171,6 +178,7 @@ impl ReplacedContent {
// FIXME https://github.com/w3c/csswg-drafts/issues/4572
ratio: Some(width / height),
},
base_fragment_info: BaseFragmentInfo::new_for_node(element.as_opaque()),
});
}
None
@ -219,7 +227,7 @@ impl ReplacedContent {
.and_then(|image| image.id)
.map(|image_key| {
Fragment::Image(ImageFragment {
debug_id: DebugId::new(),
base: self.base_fragment_info.into(),
style: style.clone(),
rect: Rect {
start_corner: Vec2::zero(),
@ -232,7 +240,7 @@ impl ReplacedContent {
.collect(),
ReplacedContentKind::IFrame(iframe) => {
vec![Fragment::IFrame(IFrameFragment {
debug_id: DebugId::new(),
base: self.base_fragment_info.into(),
style: style.clone(),
pipeline_id: iframe.pipeline_id,
browsing_context_id: iframe.browsing_context_id,
@ -268,7 +276,7 @@ impl ReplacedContent {
},
};
vec![Fragment::Image(ImageFragment {
debug_id: DebugId::new(),
base: self.base_fragment_info.into(),
style: style.clone(),
rect: Rect {
start_corner: Vec2::zero(),