mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Auto merge of #10513 - frewsxcv:is_the_html_body_element, r=Ms2ger
Extract out 'is the html body element' CSSOM concept. <!-- Reviewable:start --> This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/10513) <!-- Reviewable:end -->
This commit is contained in:
commit
f9f3b7529b
2 changed files with 12 additions and 6 deletions
|
@ -47,6 +47,16 @@ impl HTMLBodyElement {
|
|||
let element = HTMLBodyElement::new_inherited(localName, prefix, document);
|
||||
Node::reflect_node(box element, document, HTMLBodyElementBinding::Wrap)
|
||||
}
|
||||
|
||||
/// https://drafts.csswg.org/cssom-view/#the-html-body-element
|
||||
pub fn is_the_html_body_element(&self) -> bool {
|
||||
let self_node = self.upcast::<Node>();
|
||||
let root_elem = self.upcast::<Element>().root_element();
|
||||
let root_node = root_elem.upcast::<Node>();
|
||||
root_node.is_parent_of(self_node) &&
|
||||
self_node.preceding_siblings().all(|n| !n.is::<HTMLBodyElement>())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl HTMLBodyElementMethods for HTMLBodyElement {
|
||||
|
|
|
@ -594,12 +594,8 @@ impl Node {
|
|||
|
||||
let html_element = document.GetDocumentElement();
|
||||
|
||||
let is_body_element = html_element.r().and_then(|root| {
|
||||
let node = root.upcast::<Node>();
|
||||
node.children().find(|child| { child.is::<HTMLBodyElement>() }).map(|node| {
|
||||
*node.r() == *self
|
||||
})
|
||||
}).unwrap_or(false);
|
||||
let is_body_element = self.downcast::<HTMLBodyElement>()
|
||||
.map_or(false, |e| e.is_the_html_body_element());
|
||||
|
||||
let scroll_area = window.scroll_area_query(self.to_trusted_node_address());
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue