script: Return None for offsetParent on root <html> and all <body> elements (#39397)

We were returning null for all `<html>` elements, but now we will check
for the root element instead.

We were also returning null for "the body element", now we will return
null for all `<body>` elements even if they aren't "the body element".
This part diverges from the spec, but matches what all browsers do.
https://github.com/w3c/csswg-drafts/issues/12834

Testing: Adding new test
Fixes: #10521

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
Oriol Brufau 2025-09-19 21:38:12 +02:00 committed by GitHub
parent c017420ee7
commit 994d767ae5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 55 additions and 1 deletions

View file

@ -462,7 +462,7 @@ impl HTMLElementMethods<crate::DomTypeHolder> for HTMLElement {
/// <https://drafts.csswg.org/cssom-view/#dom-htmlelement-offsetparent>
fn GetOffsetParent(&self) -> Option<DomRoot<Element>> {
if self.is_body_element() || self.is::<HTMLHtmlElement>() {
if self.is::<HTMLBodyElement>() || self.upcast::<Element>().is_root() {
return None;
}