From 2c8107e81132f2abc0e1d097903bedfab4eb5ceb Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Sat, 22 Feb 2014 13:40:43 +0100 Subject: [PATCH 1/5] Remove methods from IDL that don't do anything useful. --- src/components/script/dom/document.rs | 10 ---------- src/components/script/dom/webidls/Document.webidl | 2 -- 2 files changed, 12 deletions(-) diff --git a/src/components/script/dom/document.rs b/src/components/script/dom/document.rs index f699c859d74..d6165b7b85e 100644 --- a/src/components/script/dom/document.rs +++ b/src/components/script/dom/document.rs @@ -223,16 +223,6 @@ impl Document { self.createHTMLCollection(|elem| elem.tag_name == tag) } - // http://dom.spec.whatwg.org/#dom-document-getelementsbytagnamens - pub fn GetElementsByTagNameNS(&self, _ns: Option, _tag: DOMString) -> JS { - HTMLCollection::new(&self.window, ~[]) - } - - // http://dom.spec.whatwg.org/#dom-document-getelementsbyclassname - pub fn GetElementsByClassName(&self, _class: DOMString) -> JS { - HTMLCollection::new(&self.window, ~[]) - } - // http://dom.spec.whatwg.org/#dom-nonelementparentnode-getelementbyid pub fn GetElementById(&self, id: DOMString) -> Option> { // TODO: "in tree order, within the context object's tree" diff --git a/src/components/script/dom/webidls/Document.webidl b/src/components/script/dom/webidls/Document.webidl index 12769016f38..feb312c559d 100644 --- a/src/components/script/dom/webidls/Document.webidl +++ b/src/components/script/dom/webidls/Document.webidl @@ -21,8 +21,6 @@ interface Document : Node { readonly attribute DocumentType? doctype; readonly attribute Element? documentElement; HTMLCollection getElementsByTagName(DOMString localName); - HTMLCollection getElementsByTagNameNS(DOMString? namespace, DOMString localName); - HTMLCollection getElementsByClassName(DOMString classNames); Element? getElementById(DOMString elementId); [Creator, Throws] From 7190feb5e3d62b37d59229c26966d0f864ddf479 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Sat, 22 Feb 2014 13:49:56 +0100 Subject: [PATCH 2/5] Move HTMLDocument members to Document. --- src/components/script/dom/document.rs | 38 +++++++++++++++++ src/components/script/dom/htmldocument.rs | 42 ------------------- .../script/dom/webidls/Document.webidl | 9 ++++ .../script/dom/webidls/HTMLDocument.webidl | 11 +---- 4 files changed, 48 insertions(+), 52 deletions(-) diff --git a/src/components/script/dom/document.rs b/src/components/script/dom/document.rs index d6165b7b85e..5dbd8b1194b 100644 --- a/src/components/script/dom/document.rs +++ b/src/components/script/dom/document.rs @@ -431,6 +431,44 @@ impl Document { }) } + pub fn Images(&self) -> JS { + self.createHTMLCollection(|elem| "img" == elem.tag_name) + } + + pub fn Embeds(&self) -> JS { + self.createHTMLCollection(|elem| "embed" == elem.tag_name) + } + + pub fn Plugins(&self) -> JS { + self.Embeds() + } + + pub fn Links(&self) -> JS { + self.createHTMLCollection(|elem| { + ("a" == elem.tag_name || "area" == elem.tag_name) && + elem.get_attribute(Null, "href").is_some() + }) + } + + pub fn Forms(&self) -> JS { + self.createHTMLCollection(|elem| "form" == elem.tag_name) + } + + pub fn Scripts(&self) -> JS { + self.createHTMLCollection(|elem| "script" == elem.tag_name) + } + + pub fn Anchors(&self) -> JS { + self.createHTMLCollection(|elem| { + "a" == elem.tag_name && elem.get_attribute(Null, "name").is_some() + }) + } + + pub fn Applets(&self) -> JS { + // FIXME: This should be return OBJECT elements containing applets. + self.createHTMLCollection(|elem| "applet" == elem.tag_name) + } + pub fn createHTMLCollection(&self, callback: |elem: &Element| -> bool) -> JS { let mut elements = ~[]; match self.GetDocumentElement() { diff --git a/src/components/script/dom/htmldocument.rs b/src/components/script/dom/htmldocument.rs index 7b967d68bea..64bed6c211c 100644 --- a/src/components/script/dom/htmldocument.rs +++ b/src/components/script/dom/htmldocument.rs @@ -8,10 +8,8 @@ use dom::bindings::js::JS; use dom::bindings::utils::{Reflectable, Reflector}; use dom::document::{Document, HTML, HTMLDocumentTypeId}; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; -use dom::htmlcollection::HTMLCollection; use dom::node::DocumentNodeTypeId; use dom::window::Window; -use servo_util::namespace::Null; use extra::url::Url; @@ -42,46 +40,6 @@ impl HTMLDocument { } } -impl HTMLDocument { - pub fn Images(&self) -> JS { - self.parent.createHTMLCollection(|elem| "img" == elem.tag_name) - } - - pub fn Embeds(&self) -> JS { - self.parent.createHTMLCollection(|elem| "embed" == elem.tag_name) - } - - pub fn Plugins(&self) -> JS { - self.Embeds() - } - - pub fn Links(&self) -> JS { - self.parent.createHTMLCollection(|elem| { - ("a" == elem.tag_name || "area" == elem.tag_name) && - elem.get_attribute(Null, "href").is_some() - }) - } - - pub fn Forms(&self) -> JS { - self.parent.createHTMLCollection(|elem| "form" == elem.tag_name) - } - - pub fn Scripts(&self) -> JS { - self.parent.createHTMLCollection(|elem| "script" == elem.tag_name) - } - - pub fn Anchors(&self) -> JS { - self.parent.createHTMLCollection(|elem| { - "a" == elem.tag_name && elem.get_attribute(Null, "name").is_some() - }) - } - - pub fn Applets(&self) -> JS { - // FIXME: This should be return OBJECT elements containing applets. - self.parent.createHTMLCollection(|elem| "applet" == elem.tag_name) - } -} - impl Reflectable for HTMLDocument { fn reflector<'a>(&'a self) -> &'a Reflector { self.parent.reflector() diff --git a/src/components/script/dom/webidls/Document.webidl b/src/components/script/dom/webidls/Document.webidl index feb312c559d..daa91f540fb 100644 --- a/src/components/script/dom/webidls/Document.webidl +++ b/src/components/script/dom/webidls/Document.webidl @@ -45,4 +45,13 @@ partial interface Document { attribute HTMLElement? body; readonly attribute HTMLHeadElement? head; /*NodeList*/ HTMLCollection getElementsByName(DOMString elementName); + + readonly attribute HTMLCollection images; + readonly attribute HTMLCollection embeds; + readonly attribute HTMLCollection plugins; + readonly attribute HTMLCollection links; + readonly attribute HTMLCollection forms; + readonly attribute HTMLCollection scripts; + readonly attribute HTMLCollection anchors; + readonly attribute HTMLCollection applets; }; diff --git a/src/components/script/dom/webidls/HTMLDocument.webidl b/src/components/script/dom/webidls/HTMLDocument.webidl index b899a46678f..464d771df62 100644 --- a/src/components/script/dom/webidls/HTMLDocument.webidl +++ b/src/components/script/dom/webidls/HTMLDocument.webidl @@ -5,13 +5,4 @@ */ /* http://www.whatwg.org/specs/web-apps/current-work/#the-document-object */ -interface HTMLDocument : Document { - readonly attribute HTMLCollection images; - readonly attribute HTMLCollection embeds; - readonly attribute HTMLCollection plugins; - readonly attribute HTMLCollection links; - readonly attribute HTMLCollection forms; - readonly attribute HTMLCollection scripts; - readonly attribute HTMLCollection anchors; - readonly attribute HTMLCollection applets; -}; +interface HTMLDocument : Document {}; From e2617a6396e6f9fd0aac43c418ad786957c475e6 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Sat, 22 Feb 2014 14:11:31 +0100 Subject: [PATCH 3/5] Remove HTMLDocument. --- .../script/dom/bindings/codegen/Bindings.conf | 4 -- .../script/dom/domimplementation.rs | 5 +- src/components/script/dom/domparser.rs | 6 +-- src/components/script/dom/htmldocument.rs | 51 ------------------- .../script/dom/webidls/HTMLDocument.webidl | 8 --- src/components/script/script.rs | 1 - src/components/script/script_task.rs | 7 ++- .../html/content/test_documentElement.html | 1 - .../content/test_document_contenttype.html | 4 +- .../content/test_document_implementation.html | 1 - src/test/html/content/test_parentnodes.html | 2 +- src/test/html/content/test_prototypes.html | 1 - 12 files changed, 10 insertions(+), 81 deletions(-) delete mode 100644 src/components/script/dom/htmldocument.rs delete mode 100644 src/components/script/dom/webidls/HTMLDocument.webidl diff --git a/src/components/script/dom/bindings/codegen/Bindings.conf b/src/components/script/dom/bindings/codegen/Bindings.conf index cc4a5996865..8485377ed8b 100644 --- a/src/components/script/dom/bindings/codegen/Bindings.conf +++ b/src/components/script/dom/bindings/codegen/Bindings.conf @@ -224,10 +224,6 @@ DOMInterfaces = { { }], -'HTMLDocument': { - 'customTrace': 'trace' -}, - 'HTMLOptionsCollection': [ { 'nativeType': 'nsHTMLOptionCollection', diff --git a/src/components/script/dom/domimplementation.rs b/src/components/script/dom/domimplementation.rs index 48c26ff4871..329bcc74263 100644 --- a/src/components/script/dom/domimplementation.rs +++ b/src/components/script/dom/domimplementation.rs @@ -3,14 +3,13 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::bindings::codegen::DOMImplementationBinding; -use dom::bindings::codegen::InheritTypes::{NodeCast, DocumentCast}; +use dom::bindings::codegen::InheritTypes::NodeCast; use dom::bindings::js::JS; use dom::bindings::utils::{Reflector, Reflectable, reflect_dom_object}; use dom::bindings::utils::{Fallible, InvalidCharacter, NamespaceError}; use dom::bindings::utils::{QName, Name, InvalidXMLName, xml_name_type}; use dom::document::{Document, HTML, HTMLDocumentTypeId}; use dom::documenttype::DocumentType; -use dom::htmldocument::HTMLDocument; use dom::htmlbodyelement::HTMLBodyElement; use dom::htmlheadelement::HTMLHeadElement; use dom::htmlhtmlelement::HTMLHtmlElement; @@ -67,7 +66,7 @@ impl DOMImplementation { // http://dom.spec.whatwg.org/#dom-domimplementation-createhtmldocument pub fn CreateHTMLDocument(&self, title: Option) -> JS { // Step 1-2. - let doc: JS = DocumentCast::from(&HTMLDocument::new(&self.owner, None)); + let doc = Document::new(&self.owner, None, HTML, None); assert!(doc.get().doctype == HTML); let mut doc_node: JS = NodeCast::from(&doc); diff --git a/src/components/script/dom/domparser.rs b/src/components/script/dom/domparser.rs index 3b545e0be62..031cd8b3b4a 100644 --- a/src/components/script/dom/domparser.rs +++ b/src/components/script/dom/domparser.rs @@ -4,13 +4,11 @@ use dom::bindings::codegen::DOMParserBinding; use dom::bindings::codegen::DOMParserBinding::SupportedTypeValues::{Text_html, Text_xml}; -use dom::bindings::codegen::InheritTypes::DocumentCast; use dom::bindings::js::JS; use dom::bindings::utils::{Reflector, Reflectable, reflect_dom_object}; use dom::bindings::utils::Fallible; use dom::bindings::utils::FailureUnknown; -use dom::document::Document; -use dom::htmldocument::HTMLDocument; +use dom::document::{Document, HTML}; use dom::window::Window; use servo_util::str::DOMString; @@ -43,7 +41,7 @@ impl DOMParser { -> Fallible> { match ty { Text_html => { - Ok(DocumentCast::from(&HTMLDocument::new(&self.owner, None))) + Ok(Document::new(&self.owner, None, HTML, None)) } Text_xml => { Document::Constructor(&self.owner) diff --git a/src/components/script/dom/htmldocument.rs b/src/components/script/dom/htmldocument.rs deleted file mode 100644 index 64bed6c211c..00000000000 --- a/src/components/script/dom/htmldocument.rs +++ /dev/null @@ -1,51 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -use dom::bindings::codegen::HTMLDocumentBinding; -use dom::bindings::codegen::InheritTypes::HTMLDocumentDerived; -use dom::bindings::js::JS; -use dom::bindings::utils::{Reflectable, Reflector}; -use dom::document::{Document, HTML, HTMLDocumentTypeId}; -use dom::eventtarget::{EventTarget, NodeTargetTypeId}; -use dom::node::DocumentNodeTypeId; -use dom::window::Window; - -use extra::url::Url; - -#[deriving(Encodable)] -pub struct HTMLDocument { - parent: Document -} - -impl HTMLDocumentDerived for EventTarget { - fn is_htmldocument(&self) -> bool { - match self.type_id { - NodeTargetTypeId(DocumentNodeTypeId(HTMLDocumentTypeId)) => true, - _ => false - } - } -} - -impl HTMLDocument { - pub fn new_inherited(window: JS, url: Option) -> HTMLDocument { - HTMLDocument { - parent: Document::new_inherited(window, url, HTML, None) - } - } - - pub fn new(window: &JS, url: Option) -> JS { - let document = HTMLDocument::new_inherited(window.clone(), url); - Document::reflect_document(~document, window, HTMLDocumentBinding::Wrap) - } -} - -impl Reflectable for HTMLDocument { - fn reflector<'a>(&'a self) -> &'a Reflector { - self.parent.reflector() - } - - fn mut_reflector<'a>(&'a mut self) -> &'a mut Reflector { - self.parent.mut_reflector() - } -} diff --git a/src/components/script/dom/webidls/HTMLDocument.webidl b/src/components/script/dom/webidls/HTMLDocument.webidl deleted file mode 100644 index 464d771df62..00000000000 --- a/src/components/script/dom/webidls/HTMLDocument.webidl +++ /dev/null @@ -1,8 +0,0 @@ -/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -/* http://www.whatwg.org/specs/web-apps/current-work/#the-document-object */ -interface HTMLDocument : Document {}; diff --git a/src/components/script/script.rs b/src/components/script/script.rs index d85df63ba08..8cfbc737255 100644 --- a/src/components/script/script.rs +++ b/src/components/script/script.rs @@ -81,7 +81,6 @@ pub mod dom { pub mod htmldirectoryelement; pub mod htmldivelement; pub mod htmldlistelement; - pub mod htmldocument; pub mod htmlelement; pub mod htmlembedelement; pub mod htmlfieldsetelement; diff --git a/src/components/script/script_task.rs b/src/components/script/script_task.rs index d0c53384231..0f17d4afce0 100644 --- a/src/components/script/script_task.rs +++ b/src/components/script/script_task.rs @@ -6,15 +6,14 @@ //! and layout tasks. use dom::bindings::codegen::RegisterBindings; -use dom::bindings::codegen::InheritTypes::{EventTargetCast, NodeCast, DocumentCast, ElementCast}; +use dom::bindings::codegen::InheritTypes::{EventTargetCast, NodeCast, ElementCast}; use dom::bindings::js::JS; use dom::bindings::utils::{Reflectable, GlobalStaticData, with_gc_enabled}; -use dom::document::Document; +use dom::document::{Document, HTML}; use dom::element::Element; use dom::event::{Event_, ResizeEvent, ReflowEvent, ClickEvent, MouseDownEvent, MouseMoveEvent, MouseUpEvent}; use dom::event::Event; use dom::eventtarget::EventTarget; -use dom::htmldocument::HTMLDocument; use dom::node::{Node, NodeHelpers}; use dom::window::{TimerData, TimerHandle, Window}; use html::hubbub_html_parser::HtmlParserResult; @@ -718,7 +717,7 @@ impl ScriptTask { // Parse HTML. // // Note: We can parse the next document in parallel with any previous documents. - let mut document = DocumentCast::from(&HTMLDocument::new(&window, Some(url.clone()))); + let mut document = Document::new(&window, Some(url.clone()), HTML, None); let html_parsing_result = hubbub_html_parser::parse_html(cx.ptr, &mut document, url.clone(), diff --git a/src/test/html/content/test_documentElement.html b/src/test/html/content/test_documentElement.html index eea379456b1..efe68e086d0 100644 --- a/src/test/html/content/test_documentElement.html +++ b/src/test/html/content/test_documentElement.html @@ -6,7 +6,6 @@ is_a(window, Window); is_a(document.documentElement, HTMLHtmlElement); is_a(document.documentElement.firstChild, HTMLHeadElement); is(document.documentElement.nextSibling, null); -is_a(document, HTMLDocument); is_a(document, Document); finish(); diff --git a/src/test/html/content/test_document_contenttype.html b/src/test/html/content/test_document_contenttype.html index ede2696f98a..4a63a654547 100644 --- a/src/test/html/content/test_document_contenttype.html +++ b/src/test/html/content/test_document_contenttype.html @@ -5,14 +5,14 @@