servo: Merge #10513 - Extract out 'is the html body element' CSSOM concept (from frewsxcv:is_the_html_body_element); r=Ms2ger
authorCorey Farwell <coreyf@rwell.org>
Mon, 11 Apr 2016 20:07:01 +0500
changeset 338473 0b7a4788dea932a5e7f1c8829088afbabced7ec3
parent 338472 ffc7ece02cf828cea5e704dfaa03035a3e5a9b56
child 338474 0bdab191226e3c458469636d459e70b84b3e3798
push id31307
push usergszorc@mozilla.com
push dateSat, 04 Feb 2017 00:59:06 +0000
treeherdermozilla-central@94079d43835f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMs2ger
servo: Merge #10513 - Extract out 'is the html body element' CSSOM concept (from frewsxcv:is_the_html_body_element); r=Ms2ger Source-Repo: https://github.com/servo/servo Source-Revision: f9f3b7529ba2c66b6203b0742c4cd89d03ddd772
servo/components/script/dom/htmlbodyelement.rs
servo/components/script/dom/node.rs
--- a/servo/components/script/dom/htmlbodyelement.rs
+++ b/servo/components/script/dom/htmlbodyelement.rs
@@ -42,16 +42,26 @@ impl HTMLBodyElement {
     }
 
     #[allow(unrooted_must_root)]
     pub fn new(localName: Atom, prefix: Option<DOMString>, document: &Document)
                -> Root<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 {
     // https://html.spec.whatwg.org/multipage/#dom-body-bgcolor
     make_getter!(BgColor, "bgcolor");
 
     // https://html.spec.whatwg.org/multipage/#dom-body-bgcolor
     make_legacy_color_setter!(SetBgColor, "bgcolor");
--- a/servo/components/script/dom/node.rs
+++ b/servo/components/script/dom/node.rs
@@ -589,22 +589,18 @@ impl Node {
     pub fn scroll_area(&self) -> Rect<i32> {
         // Step 1
         let document = self.owner_doc();
         // Step 3
         let window = document.window();
 
         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());
 
         match (document != window.Document(), is_body_element, document.quirks_mode(),
                html_element.r() == self.downcast::<Element>()) {
             // Step 2 && Step 5
             (true, _, _, _) | (_, false, QuirksMode::Quirks, true) => Rect::zero(),
             // Step 6 && Step 7