layout: Resolve canvas background properties during painting (#36917)

Instead of resolving the canvas background properties (essentially
keeping a possible reference to the `<body>`'s style) during fragment
tree construction, wait until painting to possibly find the style on an
appropriate `<body>` fragment. This is possible now because `Fragment`
keeps a list of flags with relevant information about the root and
`<body>` elements.

A benefit of this approach is that styles aren't cached in the fragment
tree, which would be problematic for incremental layout. In addition,
the old code was making an effort to transform the `<body>`'s background
by the root element's transform. Only Safari does this and there was
a resolution the WG that this should not happen in
https://github.com/w3c/csswg-drafts/issues/6683.

Testing:
 - `/css/css-transforms/transform-translate-background-001.html`
 - `/css/css-transforms/transform-translate-background-002.html`
 - `/css/CSS2/floats/float-root.html`
 
Fixes: #30475.
Closes: #30569.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
This commit is contained in:
Martin Robinson 2025-05-09 12:36:53 +02:00 committed by GitHub
parent c6f61e6b6e
commit 53be79a5b5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 116 additions and 195 deletions

View file

@ -16,7 +16,7 @@ use style::logical_geometry::WritingMode;
use style::properties::ComputedValues;
use style::values::specified::box_::DisplayOutside;
use super::{BaseFragment, BaseFragmentInfo, CollapsedBlockMargins, Fragment};
use super::{BaseFragment, BaseFragmentInfo, CollapsedBlockMargins, Fragment, FragmentFlags};
use crate::ArcRefCell;
use crate::display_list::ToWebRender;
use crate::formatting_contexts::Baselines;
@ -243,6 +243,16 @@ impl BoxFragment {
self.margin + self.border + self.padding
}
pub(crate) fn is_root_element(&self) -> bool {
self.base.flags.intersects(FragmentFlags::IS_ROOT_ELEMENT)
}
pub(crate) fn is_body_element_of_html_element_root(&self) -> bool {
self.base
.flags
.intersects(FragmentFlags::IS_BODY_ELEMENT_OF_HTML_ELEMENT_ROOT)
}
pub fn print(&self, tree: &mut PrintTree) {
tree.new_level(format!(
"Box\