diff --git a/src/components/script/dom/bindings/codegen/Document.webidl b/src/components/script/dom/bindings/codegen/Document.webidl index ade88958b36..78983ae1253 100644 --- a/src/components/script/dom/bindings/codegen/Document.webidl +++ b/src/components/script/dom/bindings/codegen/Document.webidl @@ -101,7 +101,7 @@ partial interface Document { attribute DOMString title; // attribute DOMString dir; attribute HTMLElement? body; - //(HTML only)readonly attribute HTMLHeadElement? head; + readonly attribute HTMLHeadElement? head; //(HTML only)readonly attribute HTMLCollection images; //(HTML only)readonly attribute HTMLCollection embeds; //(HTML only)readonly attribute HTMLCollection plugins; diff --git a/src/components/script/dom/document.rs b/src/components/script/dom/document.rs index e627ee55911..c22884ca07d 100644 --- a/src/components/script/dom/document.rs +++ b/src/components/script/dom/document.rs @@ -303,6 +303,15 @@ impl Document { } } + // http://www.whatwg.org/specs/web-apps/current-work/#dom-document-head + pub fn GetHead(&self) -> Option { + self.get_html_element().and_then(|root| { + root.traverse_preorder().find(|child| { + child.type_id() == ElementNodeTypeId(HTMLHeadElementTypeId) + }) + }) + } + pub fn GetBody(&self, _: AbstractDocument) -> Option { match self.get_html_element() { None => None, diff --git a/src/components/script/dom/htmldocument.rs b/src/components/script/dom/htmldocument.rs index 8e92a4b41db..57a5c96b7bd 100644 --- a/src/components/script/dom/htmldocument.rs +++ b/src/components/script/dom/htmldocument.rs @@ -34,12 +34,11 @@ impl HTMLDocument { impl HTMLDocument { pub fn GetHead(&self) -> Option { - match self.parent.GetDocumentElement() { - None => None, - Some(root) => root.traverse_preorder().find(|child| { + self.parent.GetDocumentElement().and_then(|root| { + root.traverse_preorder().find(|child| { child.type_id() == ElementNodeTypeId(HTMLHeadElementTypeId) }) - } + }) } pub fn Images(&self) -> @mut HTMLCollection { diff --git a/src/test/html/content/test_document_head.html b/src/test/html/content/test_document_head.html new file mode 100644 index 00000000000..c4384d8f024 --- /dev/null +++ b/src/test/html/content/test_document_head.html @@ -0,0 +1,35 @@ + + + + + + + +