mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-22 10:19:20 +00:00
LibWeb: Frameset should be the body element if it comes before body
Fixes one WPT test: "Frameset followed by body inside the html element" http://wpt.live/html/dom/documents/dom-tree-accessors/Document.body.html
This commit is contained in:
parent
7c50903ddd
commit
5f9a36feac
Notes:
github-actions[bot]
2024-10-12 17:53:51 +00:00
Author: https://github.com/ronak69
Commit: 5f9a36feac
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1745
Reviewed-by: https://github.com/ADKaster ✅
3 changed files with 26 additions and 6 deletions
|
@ -0,0 +1,2 @@
|
||||||
|
BODY == BODY
|
||||||
|
FRAMESET == FRAMESET
|
|
@ -0,0 +1,17 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<script src="../include.js"></script>
|
||||||
|
<script>
|
||||||
|
test(() => {
|
||||||
|
var doc = document.implementation.createHTMLDocument("");
|
||||||
|
doc.removeChild(doc.documentElement);
|
||||||
|
var html = doc.appendChild(doc.createElement("html"));
|
||||||
|
html.appendChild(doc.createElement("body"));
|
||||||
|
html.appendChild(doc.createElement("frameset"));
|
||||||
|
println(`BODY == ${doc.body.tagName}`);
|
||||||
|
html.firstChild.remove();
|
||||||
|
html.firstChild.remove();
|
||||||
|
html.appendChild(doc.createElement("frameset"));
|
||||||
|
html.appendChild(doc.createElement("body"));
|
||||||
|
println(`FRAMESET == ${doc.body.tagName}`);
|
||||||
|
});
|
||||||
|
</script>
|
|
@ -842,17 +842,18 @@ void Document::set_dir(String const& dir)
|
||||||
html->set_dir(dir);
|
html->set_dir(dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/dom.html#the-body-element-2
|
||||||
HTML::HTMLElement* Document::body()
|
HTML::HTMLElement* Document::body()
|
||||||
{
|
{
|
||||||
|
// The body element of a document is the first of the html element's children that is either
|
||||||
|
// a body element or a frameset element, or null if there is no such element.
|
||||||
auto* html = html_element();
|
auto* html = html_element();
|
||||||
if (!html)
|
if (!html)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
auto* first_body = html->first_child_of_type<HTML::HTMLBodyElement>();
|
for (auto* child = html->first_child(); child; child = child->next_sibling()) {
|
||||||
if (first_body)
|
if (is<HTML::HTMLBodyElement>(*child) || is<HTML::HTMLFrameSetElement>(*child))
|
||||||
return first_body;
|
return static_cast<HTML::HTMLElement*>(child);
|
||||||
auto* first_frameset = html->first_child_of_type<HTML::HTMLFrameSetElement>();
|
}
|
||||||
if (first_frameset)
|
|
||||||
return first_frameset;
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue