diff options
author | bors-servo <release+servo@mozilla.com> | 2014-01-07 12:07:32 -0800 |
---|---|---|
committer | bors-servo <release+servo@mozilla.com> | 2014-01-07 12:07:32 -0800 |
commit | a910e4ee8d2f5d64247849624ef54df8ea85fd5d (patch) | |
tree | c35a30572cb7abe01fa5ac0d4884e9cfe7134d0b | |
parent | 608ee006abf1c67f438fb8504ec28b4ab08dfde9 (diff) | |
parent | 17b35d52fff79f56b3aa734a1bb3924780e8fb04 (diff) | |
download | servo-a910e4ee8d2f5d64247849624ef54df8ea85fd5d.tar.gz servo-a910e4ee8d2f5d64247849624ef54df8ea85fd5d.zip |
auto merge of #1466 : brunoabinader/servo/document-head, r=kmcallister
Implementation details according to the specification below:
http://www.whatwg.org/specs/web-apps/current-work/#dom-document-head
This patch is for:
https://github.com/mozilla/servo/issues/1465
Closes #1465.
-rw-r--r-- | src/components/script/dom/bindings/codegen/Document.webidl | 2 | ||||
-rw-r--r-- | src/components/script/dom/document.rs | 9 | ||||
-rw-r--r-- | src/components/script/dom/htmldocument.rs | 7 | ||||
-rw-r--r-- | src/test/html/content/test_document_head.html | 35 |
4 files changed, 48 insertions, 5 deletions
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<AbstractNode> { + self.get_html_element().and_then(|root| { + root.traverse_preorder().find(|child| { + child.type_id() == ElementNodeTypeId(HTMLHeadElementTypeId) + }) + }) + } + pub fn GetBody(&self, _: AbstractDocument) -> Option<AbstractNode> { 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<AbstractNode> { - 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 @@ +<html> + <head> + <script src="harness.js"></script> + </head> + <body> + <script> + // test1: existing document's head + { + isnot(document.head, null, "test1-0, existing document's head"); + is_a(document.head, HTMLHeadElement, "test1-1, exising document's head"); + is(document.head && document.head.tagName, "HEAD", "test1-2, existing document's head"); + } + + // test2: append head to a new document + { + let new_document = new Document(); + new_document.appendChild(new_document.createElement("html")); + let new_head = new_document.createElement("head"); + + isnot(new_head, null, "test2-0, append head to a new document"); + is_a(new_head, HTMLHeadElement, "test2-1, append head to a new document"); + is(new_head && new_head.tagName, "HEAD", "test2-2, append head to a new document"); + + // Document::head is read-only. + new_document.head = new_head; + is(new_document.head, null, "test2-3, append head to a new document"); + + new_document.documentElement.appendChild(new_head); + is(new_document.head, new_head, "test2-4, append head to a new document"); + } + + finish(); + </script> + </body> +</html> |