diff options
41 files changed, 613 insertions, 182 deletions
diff --git a/src/components/main/layout/box_builder.rs b/src/components/main/layout/box_builder.rs index 48859aa9d6e..6b72794a121 100644 --- a/src/components/main/layout/box_builder.rs +++ b/src/components/main/layout/box_builder.rs @@ -23,7 +23,7 @@ use style::computed_values::display; use style::computed_values::float; use layout::float_context::{FloatLeft, FloatRight}; use script::dom::node::{AbstractNode, CommentNodeTypeId, DoctypeNodeTypeId}; -use script::dom::node::{ElementNodeTypeId, LayoutView, TextNodeTypeId}; +use script::dom::node::{ElementNodeTypeId, LayoutView, TextNodeTypeId, DocumentNodeTypeId}; use script::dom::node::DocumentFragmentNodeTypeId; use servo_util::range::Range; use servo_util::tree::{TreeNodeRef, TreeNode}; @@ -391,6 +391,7 @@ impl LayoutTreeBuilder { display => display, }, TextNodeTypeId => display::inline, + DocumentNodeTypeId(_) | DoctypeNodeTypeId | DocumentFragmentNodeTypeId | CommentNodeTypeId => return NoGenerator, @@ -449,10 +450,10 @@ impl LayoutTreeBuilder { match (parent_generator.flow.as_block().is_root, node.parent_node()) { // If this is the root node, then use the root flow's // context. Otherwise, make a child block context. - (true, Some(_)) => { + (true, Some(parent)) if !parent.is_document() => { self.create_child_generator(node, parent_generator, BlockFlowType) } - (true, None) => return ParentGenerator, + (true, None) | (true, Some(_)) => return ParentGenerator, (false, _) => { self.create_child_generator(node, parent_generator, BlockFlowType) } diff --git a/src/components/script/dom/bindings/codegen/Document.webidl b/src/components/script/dom/bindings/codegen/Document.webidl index e834b875184..ef479f01a97 100644 --- a/src/components/script/dom/bindings/codegen/Document.webidl +++ b/src/components/script/dom/bindings/codegen/Document.webidl @@ -24,7 +24,7 @@ enum VisibilityState { "hidden", "visible" }; /* http://dom.spec.whatwg.org/#interface-document */ [Constructor] -interface Document /*: Node*/ { //XXXjdm Requires servo/#623 +interface Document : Node { /*[Throws] readonly attribute DOMImplementation implementation;*/ // readonly attribute DOMString URL; diff --git a/src/components/script/dom/bindings/node.rs b/src/components/script/dom/bindings/node.rs index 6ca2bb9e674..09f17770c56 100644 --- a/src/components/script/dom/bindings/node.rs +++ b/src/components/script/dom/bindings/node.rs @@ -3,10 +3,11 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::bindings::utils::{Reflectable, Reflector, Traceable}; +use dom::document::{PlainDocumentTypeId, HTMLDocumentTypeId}; use dom::element::*; use dom::types::*; use dom::node::{AbstractNode, ElementNodeTypeId, TextNodeTypeId, CommentNodeTypeId}; -use dom::node::{DoctypeNodeTypeId, DocumentFragmentNodeTypeId, ScriptView}; +use dom::node::{DoctypeNodeTypeId, DocumentFragmentNodeTypeId, ScriptView, DocumentNodeTypeId}; use std::cast; use std::libc; @@ -95,6 +96,8 @@ pub fn create(cx: *JSContext, node: &mut AbstractNode<ScriptView>) -> *JSObject CommentNodeTypeId => generate_element!(Comment), DoctypeNodeTypeId => generate_element!(DocumentType), DocumentFragmentNodeTypeId => generate_element!(DocumentFragment), + DocumentNodeTypeId(PlainDocumentTypeId) => generate_element!(Document), + DocumentNodeTypeId(HTMLDocumentTypeId) => generate_element!(HTMLDocument), TextNodeTypeId => generate_element!(Text), } } diff --git a/src/components/script/dom/document.rs b/src/components/script/dom/document.rs index d2bee663740..2cff5123f1f 100644 --- a/src/components/script/dom/document.rs +++ b/src/components/script/dom/document.rs @@ -9,18 +9,16 @@ use dom::bindings::utils::{Reflectable, Reflector, DerivedWrapper}; use dom::bindings::utils::{is_valid_element_name, InvalidCharacter, Traceable, null_str_as_empty, null_str_as_word_null}; use dom::documentfragment::DocumentFragment; use dom::element::{Element}; -use dom::element::{HTMLHtmlElementTypeId, HTMLHeadElementTypeId, HTMLTitleElementTypeId}; +use dom::element::{HTMLHeadElementTypeId, HTMLTitleElementTypeId}; use dom::htmlcollection::HTMLCollection; use dom::htmldocument::HTMLDocument; use dom::htmlelement::HTMLElement; -use dom::htmlhtmlelement::HTMLHtmlElement; -use dom::node::{AbstractNode, ScriptView, Node, ElementNodeTypeId}; +use dom::node::{AbstractNode, ScriptView, Node, ElementNodeTypeId, DocumentNodeTypeId}; use dom::text::Text; use dom::window::Window; use dom::htmltitleelement::HTMLTitleElement; use html::hubbub_html_parser::build_element_from_tag; -use js::jsapi::{JSObject, JSContext, JSVal}; -use js::jsapi::{JSTRACE_OBJECT, JSTracer, JS_CallTracer}; +use js::jsapi::{JSObject, JSContext, JSVal, JSTracer}; use js::glue::RUST_OBJECT_TO_JSVAL; use servo_util::tree::{TreeNodeRef, ElementLike}; @@ -29,12 +27,18 @@ use std::hashmap::HashMap; use std::cast; use std::ptr; use std::str::eq_slice; -use std::libc; use std::ascii::StrAsciiExt; use std::unstable::raw::Box; +#[deriving(Eq)] +pub enum DocumentTypeId { + PlainDocumentTypeId, + HTMLDocumentTypeId +} + pub trait ReflectableDocument { fn init_reflector(@mut self, cx: *JSContext); + fn init_node(@mut self, doc: AbstractDocument); } #[deriving(Eq)] @@ -45,9 +49,11 @@ pub struct AbstractDocument { impl AbstractDocument { pub fn as_abstract<T: ReflectableDocument>(cx: *JSContext, doc: @mut T) -> AbstractDocument { doc.init_reflector(cx); - AbstractDocument { + let abstract = AbstractDocument { document: unsafe { cast::transmute(doc) } - } + }; + doc.init_node(abstract); + abstract } pub fn document<'a>(&'a self) -> &'a Document { @@ -91,10 +97,9 @@ impl AbstractDocument { }); let document = self.mut_document(); - document.root = Some(root); + document.node.AppendChild(AbstractNode::from_document(*self), root); // Register elements having "id" attribute to the owner doc. document.register_nodes_with_id(&root); - document.content_changed(); } } @@ -105,7 +110,7 @@ pub enum DocumentType { } pub struct Document { - priv root: Option<AbstractNode<ScriptView>>, + node: Node<ScriptView>, reflector_: Reflector, window: @mut Window, doctype: DocumentType, @@ -116,8 +121,12 @@ pub struct Document { impl Document { #[fixed_stack_segment] pub fn new(window: @mut Window, doctype: DocumentType) -> Document { + let node_type = match doctype { + HTML => HTMLDocumentTypeId, + SVG | XML => PlainDocumentTypeId + }; Document { - root: None, + node: Node::new_without_doc(DocumentNodeTypeId(node_type)), reflector_: Reflector::new(), window: window, doctype: doctype, @@ -128,16 +137,7 @@ impl Document { pub fn Constructor(owner: @mut Window) -> Fallible<AbstractDocument> { let cx = owner.get_cx(); - - let document = AbstractDocument::as_abstract(cx, @mut Document::new(owner, XML)); - - let root = @HTMLHtmlElement { - htmlelement: HTMLElement::new(HTMLHtmlElementTypeId, ~"html", document) - }; - let root = unsafe { Node::as_abstract_node(cx, root) }; - document.set_root(root); - - Ok(document) + Ok(AbstractDocument::as_abstract(cx, @mut Document::new(owner, XML))) } } @@ -145,6 +145,10 @@ impl ReflectableDocument for Document { fn init_reflector(@mut self, cx: *JSContext) { self.wrap_object_shared(cx, ptr::null()); //XXXjdm a proper scope would be nice } + + fn init_node(@mut self, doc: AbstractDocument) { + self.node.set_owner_doc(doc); + } } impl Reflectable for AbstractDocument { @@ -184,11 +188,11 @@ impl DerivedWrapper for AbstractDocument { impl Reflectable for Document { fn reflector<'a>(&'a self) -> &'a Reflector { - &self.reflector_ + self.node.reflector() } fn mut_reflector<'a>(&'a mut self) -> &'a mut Reflector { - &mut self.reflector_ + self.node.mut_reflector() } fn wrap_object_shared(@mut self, cx: *JSContext, scope: *JSObject) -> *JSObject { @@ -202,7 +206,7 @@ impl Reflectable for Document { impl Document { pub fn GetDocumentElement(&self) -> Option<AbstractNode<ScriptView>> { - self.root + self.node.first_child } fn get_cx(&self) -> *JSContext { @@ -408,21 +412,6 @@ fn foreach_ided_elements(root: &AbstractNode<ScriptView>, impl Traceable for Document { #[fixed_stack_segment] fn trace(&self, tracer: *mut JSTracer) { - match self.root { - None => {}, - Some(root) => { - unsafe { - (*tracer).debugPrinter = ptr::null(); - (*tracer).debugPrintIndex = -1; - do "root".to_c_str().with_ref |name| { - (*tracer).debugPrintArg = name as *libc::c_void; - debug!("tracing root node"); - JS_CallTracer(tracer as *JSTracer, - root.reflector().get_jsobject(), - JSTRACE_OBJECT as u32); - } - } - } - } + self.node.trace(tracer); } } diff --git a/src/components/script/dom/domparser.rs b/src/components/script/dom/domparser.rs index 7cc5b8cbb6b..9eda13f93e9 100644 --- a/src/components/script/dom/domparser.rs +++ b/src/components/script/dom/domparser.rs @@ -5,12 +5,9 @@ use dom::bindings::codegen::DOMParserBinding; use dom::bindings::codegen::DOMParserBinding::SupportedTypeValues::{Text_html, Text_xml}; use dom::bindings::utils::{DOMString, Fallible, Reflector, Reflectable, reflect_dom_object}; +use dom::bindings::utils::FailureUnknown; use dom::document::{AbstractDocument, Document, XML}; -use dom::element::HTMLHtmlElementTypeId; use dom::htmldocument::HTMLDocument; -use dom::htmlelement::HTMLElement; -use dom::htmlhtmlelement::HTMLHtmlElement; -use dom::node::Node; use dom::window::Window; use js::jsapi::{JSContext, JSObject}; @@ -42,25 +39,17 @@ impl DOMParser { ty: DOMParserBinding::SupportedType) -> Fallible<AbstractDocument> { let cx = self.owner.get_cx(); - let document = match ty { + match ty { Text_html => { - HTMLDocument::new(self.owner) + Ok(HTMLDocument::new(self.owner)) } Text_xml => { - AbstractDocument::as_abstract(cx, @mut Document::new(self.owner, XML)) + Ok(AbstractDocument::as_abstract(cx, @mut Document::new(self.owner, XML))) } _ => { - fail!("unsupported document type") + Err(FailureUnknown) } - }; - - let root = @HTMLHtmlElement { - htmlelement: HTMLElement::new(HTMLHtmlElementTypeId, ~"html", document) - }; - let root = unsafe { Node::as_abstract_node(cx, root) }; - document.set_root(root); - - Ok(document) + } } } diff --git a/src/components/script/dom/htmlaudioelement.rs b/src/components/script/dom/htmlaudioelement.rs index dbb33a42331..6ece4235c7c 100644 --- a/src/components/script/dom/htmlaudioelement.rs +++ b/src/components/script/dom/htmlaudioelement.rs @@ -2,11 +2,25 @@ * 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::HTMLAudioElementBinding; +use dom::document::AbstractDocument; +use dom::element::HTMLAudioElementTypeId; use dom::htmlmediaelement::HTMLMediaElement; +use dom::node::{AbstractNode, Node, ScriptView}; pub struct HTMLAudioElement { htmlmediaelement: HTMLMediaElement } impl HTMLAudioElement { + pub fn new_inherited(localName: ~str, document: AbstractDocument) -> HTMLAudioElement { + HTMLAudioElement { + htmlmediaelement: HTMLMediaElement::new_inherited(HTMLAudioElementTypeId, localName, document) + } + } + + pub fn new(localName: ~str, document: AbstractDocument) -> AbstractNode<ScriptView> { + let element = HTMLAudioElement::new_inherited(localName, document); + Node::reflect_node(@mut element, document, HTMLAudioElementBinding::Wrap) + } } diff --git a/src/components/script/dom/htmldocument.rs b/src/components/script/dom/htmldocument.rs index cadba01ce97..1e9c4e11706 100644 --- a/src/components/script/dom/htmldocument.rs +++ b/src/components/script/dom/htmldocument.rs @@ -35,6 +35,10 @@ impl ReflectableDocument for HTMLDocument { fn init_reflector(@mut self, cx: *JSContext) { self.wrap_object_shared(cx, ptr::null()); //XXXjdm a proper scope would be nice } + + fn init_node(@mut self, doc: AbstractDocument) { + self.parent.node.set_owner_doc(doc); + } } impl HTMLDocument { diff --git a/src/components/script/dom/htmlheadingelement.rs b/src/components/script/dom/htmlheadingelement.rs index e9f470f7e8a..13370230c8b 100644 --- a/src/components/script/dom/htmlheadingelement.rs +++ b/src/components/script/dom/htmlheadingelement.rs @@ -2,8 +2,12 @@ * 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::HTMLHeadingElementBinding; use dom::bindings::utils::DOMString; +use dom::document::AbstractDocument; +use dom::element::HTMLHeadingElementTypeId; use dom::htmlelement::HTMLElement; +use dom::node::{AbstractNode, Node, ScriptView}; pub enum HeadingLevel { Heading1, @@ -20,6 +24,20 @@ pub struct HTMLHeadingElement { } impl HTMLHeadingElement { + pub fn new_inherited(localName: ~str, document: AbstractDocument, level: HeadingLevel) -> HTMLHeadingElement { + HTMLHeadingElement { + htmlelement: HTMLElement::new(HTMLHeadingElementTypeId, localName, document), + level: level, + } + } + + pub fn new(localName: ~str, document: AbstractDocument, level: HeadingLevel) -> AbstractNode<ScriptView> { + let element = HTMLHeadingElement::new_inherited(localName, document, level); + Node::reflect_node(@mut element, document, HTMLHeadingElementBinding::Wrap) + } +} + +impl HTMLHeadingElement { pub fn Align(&self) -> DOMString { None } diff --git a/src/components/script/dom/htmliframeelement.rs b/src/components/script/dom/htmliframeelement.rs index bbe98d4565e..efb47baaf48 100644 --- a/src/components/script/dom/htmliframeelement.rs +++ b/src/components/script/dom/htmliframeelement.rs @@ -2,10 +2,12 @@ * 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::HTMLIFrameElementBinding; use dom::bindings::utils::{DOMString, ErrorResult, null_str_as_empty}; use dom::document::AbstractDocument; +use dom::element::HTMLIframeElementTypeId; use dom::htmlelement::HTMLElement; -use dom::node::{AbstractNode, ScriptView}; +use dom::node::{AbstractNode, Node, ScriptView}; use dom::windowproxy::WindowProxy; use geom::size::Size2D; use geom::rect::Rect; @@ -59,6 +61,22 @@ impl HTMLIFrameElement { } impl HTMLIFrameElement { + pub fn new_inherited(localName: ~str, document: AbstractDocument) -> HTMLIFrameElement { + HTMLIFrameElement { + htmlelement: HTMLElement::new(HTMLIframeElementTypeId, localName, document), + frame: None, + size: None, + sandbox: None, + } + } + + pub fn new(localName: ~str, document: AbstractDocument) -> AbstractNode<ScriptView> { + let element = HTMLIFrameElement::new_inherited(localName, document); + Node::reflect_node(@mut element, document, HTMLIFrameElementBinding::Wrap) + } +} + +impl HTMLIFrameElement { pub fn Src(&self) -> DOMString { None } diff --git a/src/components/script/dom/htmlimageelement.rs b/src/components/script/dom/htmlimageelement.rs index 49010ee0f62..f10dccf28d4 100644 --- a/src/components/script/dom/htmlimageelement.rs +++ b/src/components/script/dom/htmlimageelement.rs @@ -2,9 +2,12 @@ * 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::HTMLImageElementBinding; use dom::bindings::utils::{DOMString, ErrorResult, null_str_as_empty}; +use dom::document::AbstractDocument; +use dom::element::HTMLImageElementTypeId; use dom::htmlelement::HTMLElement; -use dom::node::{ScriptView, AbstractNode}; +use dom::node::{AbstractNode, Node, ScriptView}; use extra::url::Url; use servo_util::geometry::to_px; use layout_interface::{ContentBoxQuery, ContentBoxResponse}; @@ -19,6 +22,20 @@ pub struct HTMLImageElement { } impl HTMLImageElement { + pub fn new_inherited(localName: ~str, document: AbstractDocument) -> HTMLImageElement { + HTMLImageElement { + htmlelement: HTMLElement::new(HTMLImageElementTypeId, localName, document), + image: None, + } + } + + pub fn new(localName: ~str, document: AbstractDocument) -> AbstractNode<ScriptView> { + let element = HTMLImageElement::new_inherited(localName, document); + Node::reflect_node(@mut element, document, HTMLImageElementBinding::Wrap) + } +} + +impl HTMLImageElement { /// Makes the local `image` member match the status of the `src` attribute and starts /// prefetching the image. This method must be called after `src` is changed. pub fn update_image(&mut self, image_cache: ImageCacheTask, url: Option<Url>) { diff --git a/src/components/script/dom/htmlmediaelement.rs b/src/components/script/dom/htmlmediaelement.rs index 39c45a3585d..683ae7bf2e1 100644 --- a/src/components/script/dom/htmlmediaelement.rs +++ b/src/components/script/dom/htmlmediaelement.rs @@ -12,7 +12,7 @@ pub struct HTMLMediaElement { } impl HTMLMediaElement { - pub fn new(type_id: ElementTypeId, tag_name: ~str, document: AbstractDocument) -> HTMLMediaElement { + pub fn new_inherited(type_id: ElementTypeId, tag_name: ~str, document: AbstractDocument) -> HTMLMediaElement { HTMLMediaElement { htmlelement: HTMLElement::new(type_id, tag_name, document) } diff --git a/src/components/script/dom/htmlparagraphelement.rs b/src/components/script/dom/htmlparagraphelement.rs index d8ed198e402..bfd39a240f9 100644 --- a/src/components/script/dom/htmlparagraphelement.rs +++ b/src/components/script/dom/htmlparagraphelement.rs @@ -2,14 +2,31 @@ * 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::HTMLParagraphElementBinding; use dom::bindings::utils::{DOMString, ErrorResult}; +use dom::document::AbstractDocument; +use dom::element::HTMLParagraphElementTypeId; use dom::htmlelement::HTMLElement; +use dom::node::{AbstractNode, Node, ScriptView}; pub struct HTMLParagraphElement { htmlelement: HTMLElement } impl HTMLParagraphElement { + pub fn new_inherited(localName: ~str, document: AbstractDocument) -> HTMLParagraphElement { + HTMLParagraphElement { + htmlelement: HTMLElement::new(HTMLParagraphElementTypeId, localName, document) + } + } + + pub fn new(localName: ~str, document: AbstractDocument) -> AbstractNode<ScriptView> { + let element = HTMLParagraphElement::new_inherited(localName, document); + Node::reflect_node(@mut element, document, HTMLParagraphElementBinding::Wrap) + } +} + +impl HTMLParagraphElement { pub fn Align(&self) -> DOMString { None } diff --git a/src/components/script/dom/htmlparamelement.rs b/src/components/script/dom/htmlparamelement.rs index c50ca16cb9e..38f48a22c5c 100644 --- a/src/components/script/dom/htmlparamelement.rs +++ b/src/components/script/dom/htmlparamelement.rs @@ -2,14 +2,31 @@ * 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::HTMLParamElementBinding; use dom::bindings::utils::{DOMString, ErrorResult}; +use dom::document::AbstractDocument; +use dom::element::HTMLParamElementTypeId; use dom::htmlelement::HTMLElement; +use dom::node::{AbstractNode, Node, ScriptView}; pub struct HTMLParamElement { htmlelement: HTMLElement } impl HTMLParamElement { + pub fn new_inherited(localName: ~str, document: AbstractDocument) -> HTMLParamElement { + HTMLParamElement { + htmlelement: HTMLElement::new(HTMLParamElementTypeId, localName, document) + } + } + + pub fn new(localName: ~str, document: AbstractDocument) -> AbstractNode<ScriptView> { + let element = HTMLParamElement::new_inherited(localName, document); + Node::reflect_node(@mut element, document, HTMLParamElementBinding::Wrap) + } +} + +impl HTMLParamElement { pub fn Name(&self) -> DOMString { None } diff --git a/src/components/script/dom/htmlpreelement.rs b/src/components/script/dom/htmlpreelement.rs index b866d360e60..2a2a9d64841 100644 --- a/src/components/script/dom/htmlpreelement.rs +++ b/src/components/script/dom/htmlpreelement.rs @@ -2,14 +2,31 @@ * 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::HTMLPreElementBinding; use dom::bindings::utils::{ErrorResult}; +use dom::document::AbstractDocument; +use dom::element::HTMLPreElementTypeId; use dom::htmlelement::HTMLElement; +use dom::node::{AbstractNode, Node, ScriptView}; pub struct HTMLPreElement { htmlelement: HTMLElement, } impl HTMLPreElement { + pub fn new_inherited(localName: ~str, document: AbstractDocument) -> HTMLPreElement { + HTMLPreElement { + htmlelement: HTMLElement::new(HTMLPreElementTypeId, localName, document) + } + } + + pub fn new(localName: ~str, document: AbstractDocument) -> AbstractNode<ScriptView> { + let element = HTMLPreElement::new_inherited(localName, document); + Node::reflect_node(@mut element, document, HTMLPreElementBinding::Wrap) + } +} + +impl HTMLPreElement { pub fn Width(&self) -> i32 { 0 } diff --git a/src/components/script/dom/htmlprogresselement.rs b/src/components/script/dom/htmlprogresselement.rs index 3ef1011a1dc..9983d71a0dd 100644 --- a/src/components/script/dom/htmlprogresselement.rs +++ b/src/components/script/dom/htmlprogresselement.rs @@ -2,14 +2,31 @@ * 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::HTMLProgressElementBinding; use dom::bindings::utils::{ErrorResult, Fallible}; +use dom::document::AbstractDocument; +use dom::element::HTMLProgressElementTypeId; use dom::htmlelement::HTMLElement; +use dom::node::{AbstractNode, Node, ScriptView}; pub struct HTMLProgressElement { htmlelement: HTMLElement, } impl HTMLProgressElement { + pub fn new_inherited(localName: ~str, document: AbstractDocument) -> HTMLProgressElement { + HTMLProgressElement { + htmlelement: HTMLElement::new(HTMLProgressElementTypeId, localName, document) + } + } + + pub fn new(localName: ~str, document: AbstractDocument) -> AbstractNode<ScriptView> { + let element = HTMLProgressElement::new_inherited(localName, document); + Node::reflect_node(@mut element, document, HTMLProgressElementBinding::Wrap) + } +} + +impl HTMLProgressElement { pub fn Value(&self) -> f64 { 0f64 } diff --git a/src/components/script/dom/htmlquoteelement.rs b/src/components/script/dom/htmlquoteelement.rs index 107603aa1d5..682b4e68b20 100644 --- a/src/components/script/dom/htmlquoteelement.rs +++ b/src/components/script/dom/htmlquoteelement.rs @@ -2,14 +2,31 @@ * 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::HTMLQuoteElementBinding; use dom::bindings::utils::{DOMString, ErrorResult}; +use dom::document::AbstractDocument; +use dom::element::HTMLQuoteElementTypeId; use dom::htmlelement::HTMLElement; +use dom::node::{AbstractNode, Node, ScriptView}; pub struct HTMLQuoteElement { htmlelement: HTMLElement, } impl HTMLQuoteElement { + pub fn new_inherited(localName: ~str, document: AbstractDocument) -> HTMLQuoteElement { + HTMLQuoteElement { + htmlelement: HTMLElement::new(HTMLQuoteElementTypeId, localName, document) + } + } + + pub fn new(localName: ~str, document: AbstractDocument) -> AbstractNode<ScriptView> { + let element = HTMLQuoteElement::new_inherited(localName, document); + Node::reflect_node(@mut element, document, HTMLQuoteElementBinding::Wrap) + } +} + +impl HTMLQuoteElement { pub fn Cite(&self) -> DOMString { None } diff --git a/src/components/script/dom/htmlscriptelement.rs b/src/components/script/dom/htmlscriptelement.rs index f3de42eae26..0925a0109f5 100644 --- a/src/components/script/dom/htmlscriptelement.rs +++ b/src/components/script/dom/htmlscriptelement.rs @@ -2,8 +2,12 @@ * 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::HTMLScriptElementBinding; use dom::bindings::utils::{DOMString, ErrorResult}; +use dom::document::AbstractDocument; +use dom::element::HTMLScriptElementTypeId; use dom::htmlelement::HTMLElement; +use dom::node::{AbstractNode, Node, ScriptView}; use servo_util::tree::ElementLike; pub struct HTMLScriptElement { @@ -11,6 +15,19 @@ pub struct HTMLScriptElement { } impl HTMLScriptElement { + pub fn new_inherited(localName: ~str, document: AbstractDocument) -> HTMLScriptElement { + HTMLScriptElement { + htmlelement: HTMLElement::new(HTMLScriptElementTypeId, localName, document) + } + } + + pub fn new(localName: ~str, document: AbstractDocument) -> AbstractNode<ScriptView> { + let element = HTMLScriptElement::new_inherited(localName, document); + Node::reflect_node(@mut element, document, HTMLScriptElementBinding::Wrap) + } +} + +impl HTMLScriptElement { pub fn Src(&self) -> DOMString { self.htmlelement.element.get_attr("src").map(|s| s.to_str()) } diff --git a/src/components/script/dom/htmlselectelement.rs b/src/components/script/dom/htmlselectelement.rs index 14b5de595d1..38c3da4292a 100644 --- a/src/components/script/dom/htmlselectelement.rs +++ b/src/components/script/dom/htmlselectelement.rs @@ -2,9 +2,12 @@ * 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::HTMLSelectElementBinding; use dom::bindings::utils::{DOMString, ErrorResult}; +use dom::document::AbstractDocument; +use dom::element::HTMLSelectElementTypeId; use dom::htmlelement::HTMLElement; -use dom::node::{AbstractNode, ScriptView}; +use dom::node::{AbstractNode, Node, ScriptView}; use dom::validitystate::ValidityState; pub struct HTMLSelectElement { @@ -12,6 +15,19 @@ pub struct HTMLSelectElement { } impl HTMLSelectElement { + pub fn new_inherited(localName: ~str, document: AbstractDocument) -> HTMLSelectElement { + HTMLSelectElement { + htmlelement: HTMLElement::new(HTMLSelectElementTypeId, localName, document) + } + } + + pub fn new(localName: ~str, document: AbstractDocument) -> AbstractNode<ScriptView> { + let element = HTMLSelectElement::new_inherited(localName, document); + Node::reflect_node(@mut element, document, HTMLSelectElementBinding::Wrap) + } +} + +impl HTMLSelectElement { pub fn Autofocus(&self) -> bool { false } diff --git a/src/components/script/dom/htmlsourceelement.rs b/src/components/script/dom/htmlsourceelement.rs index 0fe7bfdf57a..4168f891835 100644 --- a/src/components/script/dom/htmlsourceelement.rs +++ b/src/components/script/dom/htmlsourceelement.rs @@ -2,14 +2,31 @@ * 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::HTMLSourceElementBinding; use dom::bindings::utils::{DOMString, ErrorResult}; +use dom::document::AbstractDocument; +use dom::element::HTMLSourceElementTypeId; use dom::htmlelement::HTMLElement; +use dom::node::{AbstractNode, Node, ScriptView}; pub struct HTMLSourceElement { htmlelement: HTMLElement } impl HTMLSourceElement { + pub fn new_inherited(localName: ~str, document: AbstractDocument) -> HTMLSourceElement { + HTMLSourceElement { + htmlelement: HTMLElement::new(HTMLSourceElementTypeId, localName, document) + } + } + + pub fn new(localName: ~str, document: AbstractDocument) -> AbstractNode<ScriptView> { + let element = HTMLSourceElement::new_inherited(localName, document); + Node::reflect_node(@mut element, document, HTMLSourceElementBinding::Wrap) + } +} + +impl HTMLSourceElement { pub fn Src(&self) -> DOMString { None } diff --git a/src/components/script/dom/htmlspanelement.rs b/src/components/script/dom/htmlspanelement.rs index 9c3ed92f402..78eb18323b1 100644 --- a/src/components/script/dom/htmlspanelement.rs +++ b/src/components/script/dom/htmlspanelement.rs @@ -2,8 +2,25 @@ * 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::HTMLSpanElementBinding; +use dom::document::AbstractDocument; +use dom::element::HTMLSpanElementTypeId; use dom::htmlelement::HTMLElement; +use dom::node::{AbstractNode, Node, ScriptView}; pub struct HTMLSpanElement { htmlelement: HTMLElement } + +impl HTMLSpanElement { + pub fn new_inherited(localName: ~str, document: AbstractDocument) -> HTMLSpanElement { + HTMLSpanElement { + htmlelement: HTMLElement::new(HTMLSpanElementTypeId, localName, document) + } + } + + pub fn new(localName: ~str, document: AbstractDocument) -> AbstractNode<ScriptView> { + let element = HTMLSpanElement::new_inherited(localName, document); + Node::reflect_node(@mut element, document, HTMLSpanElementBinding::Wrap) + } +} diff --git a/src/components/script/dom/htmlstyleelement.rs b/src/components/script/dom/htmlstyleelement.rs index 3d1e0cc95f2..d6817a7d2b9 100644 --- a/src/components/script/dom/htmlstyleelement.rs +++ b/src/components/script/dom/htmlstyleelement.rs @@ -2,14 +2,31 @@ * 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::HTMLStyleElementBinding; use dom::bindings::utils::{DOMString, ErrorResult}; +use dom::document::AbstractDocument; +use dom::element::HTMLStyleElementTypeId; use dom::htmlelement::HTMLElement; +use dom::node::{AbstractNode, Node, ScriptView}; pub struct HTMLStyleElement { htmlelement: HTMLElement, } impl HTMLStyleElement { + pub fn new_inherited(localName: ~str, document: AbstractDocument) -> HTMLStyleElement { + HTMLStyleElement { + htmlelement: HTMLElement::new(HTMLStyleElementTypeId, localName, document) + } + } + + pub fn new(localName: ~str, document: AbstractDocument) -> AbstractNode<ScriptView> { + let element = HTMLStyleElement::new_inherited(localName, document); + Node::reflect_node(@mut element, document, HTMLStyleElementBinding::Wrap) + } +} + +impl HTMLStyleElement { pub fn Disabled(&self) -> bool { false } diff --git a/src/components/script/dom/htmltablecaptionelement.rs b/src/components/script/dom/htmltablecaptionelement.rs index f812e512ebc..405e59cf272 100644 --- a/src/components/script/dom/htmltablecaptionelement.rs +++ b/src/components/script/dom/htmltablecaptionelement.rs @@ -2,14 +2,31 @@ * 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::HTMLTableCaptionElementBinding; use dom::bindings::utils::{DOMString, ErrorResult}; +use dom::document::AbstractDocument; +use dom::element::HTMLTableCaptionElementTypeId; use dom::htmlelement::HTMLElement; +use dom::node::{AbstractNode, Node, ScriptView}; pub struct HTMLTableCaptionElement { htmlelement: HTMLElement } impl HTMLTableCaptionElement { + pub fn new_inherited(localName: ~str, document: AbstractDocument) -> HTMLTableCaptionElement { + HTMLTableCaptionElement { + htmlelement: HTMLElement::new(HTMLTableCaptionElementTypeId, localName, document) + } + } + + pub fn new(localName: ~str, document: AbstractDocument) -> AbstractNode<ScriptView> { + let element = HTMLTableCaptionElement::new_inherited(localName, document); + Node::reflect_node(@mut element, document, HTMLTableCaptionElementBinding::Wrap) + } +} + +impl HTMLTableCaptionElement { pub fn Align(&self) -> DOMString { None } diff --git a/src/components/script/dom/htmltablecellelement.rs b/src/components/script/dom/htmltablecellelement.rs index 365030b90be..771cd389ecb 100644 --- a/src/components/script/dom/htmltablecellelement.rs +++ b/src/components/script/dom/htmltablecellelement.rs @@ -12,7 +12,7 @@ pub struct HTMLTableCellElement { } impl HTMLTableCellElement { - pub fn new(type_id: ElementTypeId, tag_name: ~str, document: AbstractDocument) -> HTMLTableCellElement { + pub fn new_inherited(type_id: ElementTypeId, tag_name: ~str, document: AbstractDocument) -> HTMLTableCellElement { HTMLTableCellElement { htmlelement: HTMLElement::new(type_id, tag_name, document) } diff --git a/src/components/script/dom/htmltablecolelement.rs b/src/components/script/dom/htmltablecolelement.rs index 78ad9867e0e..27817306a2c 100644 --- a/src/components/script/dom/htmltablecolelement.rs +++ b/src/components/script/dom/htmltablecolelement.rs @@ -2,14 +2,31 @@ * 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::HTMLTableColElementBinding; use dom::bindings::utils::{DOMString, ErrorResult}; +use dom::document::AbstractDocument; +use dom::element::HTMLTableColElementTypeId; use dom::htmlelement::HTMLElement; +use dom::node::{AbstractNode, Node, ScriptView}; pub struct HTMLTableColElement { htmlelement: HTMLElement, } impl HTMLTableColElement { + pub fn new_inherited(localName: ~str, document: AbstractDocument) -> HTMLTableColElement { + HTMLTableColElement { + htmlelement: HTMLElement::new(HTMLTableColElementTypeId, localName, document) + } + } + + pub fn new(localName: ~str, document: AbstractDocument) -> AbstractNode<ScriptView> { + let element = HTMLTableColElement::new_inherited(localName, document); + Node::reflect_node(@mut element, document, HTMLTableColElementBinding::Wrap) + } +} + +impl HTMLTableColElement { pub fn Span(&self) -> u32 { 0 } diff --git a/src/components/script/dom/htmltabledatacellelement.rs b/src/components/script/dom/htmltabledatacellelement.rs index f0a69d97409..4b3dda09745 100644 --- a/src/components/script/dom/htmltabledatacellelement.rs +++ b/src/components/script/dom/htmltabledatacellelement.rs @@ -2,8 +2,25 @@ * 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::HTMLTableDataCellElementBinding; +use dom::document::AbstractDocument; +use dom::element::HTMLTableDataCellElementTypeId; use dom::htmltablecellelement::HTMLTableCellElement; +use dom::node::{AbstractNode, Node, ScriptView}; pub struct HTMLTableDataCellElement { htmltablecellelement: HTMLTableCellElement, } + +impl HTMLTableDataCellElement { + pub fn new_inherited(localName: ~str, document: AbstractDocument) -> HTMLTableDataCellElement { + HTMLTableDataCellElement { + htmltablecellelement: HTMLTableCellElement::new_inherited(HTMLTableDataCellElementTypeId, localName, document) + } + } + + pub fn new(localName: ~str, document: AbstractDocument) -> AbstractNode<ScriptView> { + let element = HTMLTableDataCellElement::new_inherited(localName, document); + Node::reflect_node(@mut element, document, HTMLTableDataCellElementBinding::Wrap) + } +} diff --git a/src/components/script/dom/htmltableelement.rs b/src/components/script/dom/htmltableelement.rs index 3d7d2bf9146..8cdf888440e 100644 --- a/src/components/script/dom/htmltableelement.rs +++ b/src/components/script/dom/htmltableelement.rs @@ -2,15 +2,31 @@ * 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::HTMLTableElementBinding; use dom::bindings::utils::{DOMString, ErrorResult}; +use dom::document::AbstractDocument; +use dom::element::HTMLTableElementTypeId; use dom::htmlelement::HTMLElement; +use dom::node::{AbstractNode, Node, ScriptView}; pub struct HTMLTableElement { htmlelement: HTMLElement, } impl HTMLTableElement { + pub fn new_inherited(localName: ~str, document: AbstractDocument) -> HTMLTableElement { + HTMLTableElement { + htmlelement: HTMLElement::new(HTMLTableElementTypeId, localName, document) + } + } + pub fn new(localName: ~str, document: AbstractDocument) -> AbstractNode<ScriptView> { + let element = HTMLTableElement::new_inherited(localName, document); + Node::reflect_node(@mut element, document, HTMLTableElementBinding::Wrap) + } +} + +impl HTMLTableElement { pub fn DeleteCaption(&self) { } diff --git a/src/components/script/dom/htmltableheadercellelement.rs b/src/components/script/dom/htmltableheadercellelement.rs index e7bb4b0fa38..59a9d596aea 100644 --- a/src/components/script/dom/htmltableheadercellelement.rs +++ b/src/components/script/dom/htmltableheadercellelement.rs @@ -2,8 +2,25 @@ * 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::HTMLTableHeaderCellElementBinding; +use dom::document::AbstractDocument; +use dom::element::HTMLTableHeaderCellElementTypeId; use dom::htmltablecellelement::HTMLTableCellElement; +use dom::node::{AbstractNode, Node, ScriptView}; pub struct HTMLTableHeaderCellElement { htmltablecellelement: HTMLTableCellElement, } + +impl HTMLTableHeaderCellElement { + pub fn new_inherited(localName: ~str, document: AbstractDocument) -> HTMLTableHeaderCellElement { + HTMLTableHeaderCellElement { + htmltablecellelement: HTMLTableCellElement::new_inherited(HTMLTableHeaderCellElementTypeId, localName, document) + } + } + + pub fn new(localName: ~str, document: AbstractDocument) -> AbstractNode<ScriptView> { + let element = HTMLTableHeaderCellElement::new_inherited(localName, document); + Node::reflect_node(@mut element, document, HTMLTableHeaderCellElementBinding::Wrap) + } +} diff --git a/src/components/script/dom/htmltablerowelement.rs b/src/components/script/dom/htmltablerowelement.rs index c86899c238a..5d61f0e7fb5 100644 --- a/src/components/script/dom/htmltablerowelement.rs +++ b/src/components/script/dom/htmltablerowelement.rs @@ -2,14 +2,31 @@ * 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::HTMLTableRowElementBinding; use dom::bindings::utils::{DOMString, ErrorResult}; +use dom::document::AbstractDocument; +use dom::element::HTMLTableRowElementTypeId; use dom::htmlelement::HTMLElement; +use dom::node::{AbstractNode, Node, ScriptView}; pub struct HTMLTableRowElement { htmlelement: HTMLElement, } impl HTMLTableRowElement { + pub fn new_inherited(localName: ~str, document: AbstractDocument) -> HTMLTableRowElement { + HTMLTableRowElement { + htmlelement: HTMLElement::new(HTMLTableRowElementTypeId, localName, document) + } + } + + pub fn new(localName: ~str, document: AbstractDocument) -> AbstractNode<ScriptView> { + let element = HTMLTableRowElement::new_inherited(localName, document); + Node::reflect_node(@mut element, document, HTMLTableRowElementBinding::Wrap) + } +} + +impl HTMLTableRowElement { pub fn RowIndex(&self) -> i32 { 0 } diff --git a/src/components/script/dom/htmltablesectionelement.rs b/src/components/script/dom/htmltablesectionelement.rs index 91579e252e5..08951af578a 100644 --- a/src/components/script/dom/htmltablesectionelement.rs +++ b/src/components/script/dom/htmltablesectionelement.rs @@ -2,14 +2,31 @@ * 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::HTMLTableSectionElementBinding; use dom::bindings::utils::{DOMString, ErrorResult}; +use dom::document::AbstractDocument; +use dom::element::HTMLTableSectionElementTypeId; use dom::htmlelement::HTMLElement; +use dom::node::{AbstractNode, Node, ScriptView}; pub struct HTMLTableSectionElement { htmlelement: HTMLElement, } impl HTMLTableSectionElement { + pub fn new_inherited(localName: ~str, document: AbstractDocument) -> HTMLTableSectionElement { + HTMLTableSectionElement { + htmlelement: HTMLElement::new(HTMLTableSectionElementTypeId, localName, document) + } + } + + pub fn new(localName: ~str, document: AbstractDocument) -> AbstractNode<ScriptView> { + let element = HTMLTableSectionElement::new_inherited(localName, document); + Node::reflect_node(@mut element, document, HTMLTableSectionElementBinding::Wrap) + } +} + +impl HTMLTableSectionElement { pub fn DeleteRow(&mut self, _index: i32) -> ErrorResult { Ok(()) } diff --git a/src/components/script/dom/htmltemplateelement.rs b/src/components/script/dom/htmltemplateelement.rs index 11e4e399948..8ccea37c420 100644 --- a/src/components/script/dom/htmltemplateelement.rs +++ b/src/components/script/dom/htmltemplateelement.rs @@ -2,11 +2,25 @@ * 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::HTMLTemplateElementBinding; +use dom::document::AbstractDocument; +use dom::element::HTMLTemplateElementTypeId; use dom::htmlelement::HTMLElement; +use dom::node::{AbstractNode, Node, ScriptView}; pub struct HTMLTemplateElement { htmlelement: HTMLElement, } impl HTMLTemplateElement { + pub fn new_inherited(localName: ~str, document: AbstractDocument) -> HTMLTemplateElement { + HTMLTemplateElement { + htmlelement: HTMLElement::new(HTMLTemplateElementTypeId, localName, document) + } + } + + pub fn new(localName: ~str, document: AbstractDocument) -> AbstractNode<ScriptView> { + let element = HTMLTemplateElement::new_inherited(localName, document); + Node::reflect_node(@mut element, document, HTMLTemplateElementBinding::Wrap) + } } diff --git a/src/components/script/dom/htmltextareaelement.rs b/src/components/script/dom/htmltextareaelement.rs index 07531e87a6f..67f8d8d5bba 100644 --- a/src/components/script/dom/htmltextareaelement.rs +++ b/src/components/script/dom/htmltextareaelement.rs @@ -2,14 +2,31 @@ * 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::HTMLTextAreaElementBinding; use dom::bindings::utils::{DOMString, ErrorResult, Fallible}; +use dom::document::AbstractDocument; +use dom::element::HTMLTextAreaElementTypeId; use dom::htmlelement::HTMLElement; +use dom::node::{AbstractNode, Node, ScriptView}; pub struct HTMLTextAreaElement { htmlelement: HTMLElement, } impl HTMLTextAreaElement { + pub fn new_inherited(localName: ~str, document: AbstractDocument) -> HTMLTextAreaElement { + HTMLTextAreaElement { + htmlelement: HTMLElement::new(HTMLTextAreaElementTypeId, localName, document) + } + } + + pub fn new(localName: ~str, document: AbstractDocument) -> AbstractNode<ScriptView> { + let element = HTMLTextAreaElement::new_inherited(localName, document); + Node::reflect_node(@mut element, document, HTMLTextAreaElementBinding::Wrap) + } +} + +impl HTMLTextAreaElement { pub fn Autofocus(&self) -> bool { false } diff --git a/src/components/script/dom/htmltimeelement.rs b/src/components/script/dom/htmltimeelement.rs index d0a685de3a3..ec615d60b8c 100644 --- a/src/components/script/dom/htmltimeelement.rs +++ b/src/components/script/dom/htmltimeelement.rs @@ -2,14 +2,31 @@ * 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::HTMLTimeElementBinding; use dom::bindings::utils::{DOMString, ErrorResult}; +use dom::document::AbstractDocument; +use dom::element::HTMLTimeElementTypeId; use dom::htmlelement::HTMLElement; +use dom::node::{AbstractNode, Node, ScriptView}; pub struct HTMLTimeElement { htmlelement: HTMLElement } impl HTMLTimeElement { + pub fn new_inherited(localName: ~str, document: AbstractDocument) -> HTMLTimeElement { + HTMLTimeElement { + htmlelement: HTMLElement::new(HTMLTimeElementTypeId, localName, document) + } + } + + pub fn new(localName: ~str, document: AbstractDocument) -> AbstractNode<ScriptView> { + let element = HTMLTimeElement::new_inherited(localName, document); + Node::reflect_node(@mut element, document, HTMLTimeElementBinding::Wrap) + } +} + +impl HTMLTimeElement { pub fn DateTime(&self) -> DOMString { None } diff --git a/src/components/script/dom/htmltitleelement.rs b/src/components/script/dom/htmltitleelement.rs index 5a3aed5f4ff..e54ebdebb22 100644 --- a/src/components/script/dom/htmltitleelement.rs +++ b/src/components/script/dom/htmltitleelement.rs @@ -2,14 +2,31 @@ * 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::HTMLTitleElementBinding; use dom::bindings::utils::{DOMString, ErrorResult}; +use dom::document::AbstractDocument; +use dom::element::HTMLTitleElementTypeId; use dom::htmlelement::HTMLElement; +use dom::node::{AbstractNode, Node, ScriptView}; pub struct HTMLTitleElement { htmlelement: HTMLElement, } impl HTMLTitleElement { + pub fn new_inherited(localName: ~str, document: AbstractDocument) -> HTMLTitleElement { + HTMLTitleElement { + htmlelement: HTMLElement::new(HTMLTitleElementTypeId, localName, document) + } + } + + pub fn new(localName: ~str, document: AbstractDocument) -> AbstractNode<ScriptView> { + let element = HTMLTitleElement::new_inherited(localName, document); + Node::reflect_node(@mut element, document, HTMLTitleElementBinding::Wrap) + } +} + +impl HTMLTitleElement { pub fn Text(&self) -> DOMString { None } diff --git a/src/components/script/dom/htmltrackelement.rs b/src/components/script/dom/htmltrackelement.rs index 4c3e7cb055c..9b6fae79360 100644 --- a/src/components/script/dom/htmltrackelement.rs +++ b/src/components/script/dom/htmltrackelement.rs @@ -2,14 +2,31 @@ * 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::HTMLTrackElementBinding; use dom::bindings::utils::{DOMString, ErrorResult}; +use dom::document::AbstractDocument; +use dom::element::HTMLTrackElementTypeId; use dom::htmlelement::HTMLElement; +use dom::node::{AbstractNode, Node, ScriptView}; pub struct HTMLTrackElement { htmlelement: HTMLElement, } impl HTMLTrackElement { + pub fn new_inherited(localName: ~str, document: AbstractDocument) -> HTMLTrackElement { + HTMLTrackElement { + htmlelement: HTMLElement::new(HTMLTrackElementTypeId, localName, document) + } + } + + pub fn new(localName: ~str, document: AbstractDocument) -> AbstractNode<ScriptView> { + let element = HTMLTrackElement::new_inherited(localName, document); + Node::reflect_node(@mut element, document, HTMLTrackElementBinding::Wrap) + } +} + +impl HTMLTrackElement { pub fn Kind(&self) -> DOMString { None } diff --git a/src/components/script/dom/htmlulistelement.rs b/src/components/script/dom/htmlulistelement.rs index 5883687b653..478d34681f9 100644 --- a/src/components/script/dom/htmlulistelement.rs +++ b/src/components/script/dom/htmlulistelement.rs @@ -2,14 +2,31 @@ * 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::HTMLUListElementBinding; use dom::bindings::utils::{DOMString, ErrorResult}; +use dom::document::AbstractDocument; +use dom::element::HTMLUListElementTypeId; use dom::htmlelement::HTMLElement; +use dom::node::{AbstractNode, Node, ScriptView}; pub struct HTMLUListElement { htmlelement: HTMLElement } impl HTMLUListElement { + pub fn new_inherited(localName: ~str, document: AbstractDocument) -> HTMLUListElement { + HTMLUListElement { + htmlelement: HTMLElement::new(HTMLUListElementTypeId, localName, document) + } + } + + pub fn new(localName: ~str, document: AbstractDocument) -> AbstractNode<ScriptView> { + let element = HTMLUListElement::new_inherited(localName, document); + Node::reflect_node(@mut element, document, HTMLUListElementBinding::Wrap) + } +} + +impl HTMLUListElement { pub fn Compact(&self) -> bool { false } diff --git a/src/components/script/dom/htmlvideoelement.rs b/src/components/script/dom/htmlvideoelement.rs index a485480ad04..b78e13947e8 100644 --- a/src/components/script/dom/htmlvideoelement.rs +++ b/src/components/script/dom/htmlvideoelement.rs @@ -2,14 +2,31 @@ * 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::HTMLVideoElementBinding; use dom::bindings::utils::{DOMString, ErrorResult}; +use dom::document::AbstractDocument; +use dom::element::HTMLVideoElementTypeId; use dom::htmlmediaelement::HTMLMediaElement; +use dom::node::{AbstractNode, Node, ScriptView}; pub struct HTMLVideoElement { htmlmediaelement: HTMLMediaElement } impl HTMLVideoElement { + pub fn new_inherited(localName: ~str, document: AbstractDocument) -> HTMLVideoElement { + HTMLVideoElement { + htmlmediaelement: HTMLMediaElement::new_inherited(HTMLVideoElementTypeId, localName, document) + } + } + + pub fn new(localName: ~str, document: AbstractDocument) -> AbstractNode<ScriptView> { + let element = HTMLVideoElement::new_inherited(localName, document); + Node::reflect_node(@mut element, document, HTMLVideoElementBinding::Wrap) + } +} + +impl HTMLVideoElement { pub fn Width(&self) -> u32 { 0 } diff --git a/src/components/script/dom/node.rs b/src/components/script/dom/node.rs index 40eb164469b..725d69e711f 100644 --- a/src/components/script/dom/node.rs +++ b/src/components/script/dom/node.rs @@ -9,7 +9,7 @@ use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::utils::{DOMString, null_str_as_empty}; use dom::bindings::utils::{ErrorResult, Fallible, NotFound, HierarchyRequest}; use dom::characterdata::CharacterData; -use dom::document::AbstractDocument; +use dom::document::{AbstractDocument, DocumentTypeId}; use dom::documenttype::DocumentType; use dom::element::{Element, ElementTypeId, HTMLImageElementTypeId, HTMLIframeElementTypeId}; use dom::element::{HTMLStyleElementTypeId}; @@ -88,7 +88,7 @@ pub struct Node<View> { prev_sibling: Option<AbstractNode<View>>, /// The document that this node belongs to. - priv owner_doc: AbstractDocument, + priv owner_doc: Option<AbstractDocument>, /// The live list of children return by .childNodes. child_list: Option<@mut NodeList>, @@ -103,6 +103,7 @@ pub enum NodeTypeId { DoctypeNodeTypeId, DocumentFragmentNodeTypeId, CommentNodeTypeId, + DocumentNodeTypeId(DocumentTypeId), ElementNodeTypeId(ElementTypeId), TextNodeTypeId, } @@ -204,6 +205,13 @@ impl<'self, View> AbstractNode<View> { } } + /// Allow consumers to upcast from derived classes. + pub fn from_document(doc: AbstractDocument) -> AbstractNode<View> { + unsafe { + cast::transmute(doc) + } + } + // Convenience accessors /// Returns the type ID of this node. Fails if this node is borrowed mutably. @@ -331,6 +339,13 @@ impl<'self, View> AbstractNode<View> { self.transmute_mut(f) } + pub fn is_document(self) -> bool { + match self.type_id() { + DocumentNodeTypeId(*) => true, + _ => false + } + } + // FIXME: This should be doing dynamic borrow checking for safety. pub fn with_imm_element<R>(self, f: &fn(&Element) -> R) -> R { if !self.is_element() { @@ -431,27 +446,7 @@ impl<'self, View> AbstractNode<View> { // Issue #1030: should not walk the tree pub fn is_in_doc(&self) -> bool { - let document = self.node().owner_doc(); - match document.document().GetDocumentElement() { - None => false, - Some(root) => { - let mut node = *self; - let mut in_doc; - loop { - match node.parent_node() { - Some(parent) => { - node = parent; - }, - None => { - // Issue #1029: this is horrible. - in_doc = unsafe { node.raw_object() as uint == root.raw_object() as uint }; - break; - } - } - } - in_doc - } - } + self.ancestors().any(|node| node.is_document()) } } @@ -495,11 +490,11 @@ impl<View> Iterator<AbstractNode<View>> for AbstractNodeChildrenIterator<View> { impl<View> Node<View> { pub fn owner_doc(&self) -> AbstractDocument { - self.owner_doc + self.owner_doc.unwrap() } pub fn set_owner_doc(&mut self, document: AbstractDocument) { - self.owner_doc = document; + self.owner_doc = Some(document); } } @@ -528,6 +523,14 @@ impl Node<ScriptView> { } pub fn new(type_id: NodeTypeId, doc: AbstractDocument) -> Node<ScriptView> { + Node::new_(type_id, Some(doc)) + } + + pub fn new_without_doc(type_id: NodeTypeId) -> Node<ScriptView> { + Node::new_(type_id, None) + } + + fn new_(type_id: NodeTypeId, doc: Option<AbstractDocument>) -> Node<ScriptView> { Node { reflector_: Reflector::new(), type_id: type_id, @@ -546,32 +549,16 @@ impl Node<ScriptView> { layout_data: LayoutData::new(), } } - - pub fn getNextSibling(&mut self) -> Option<&mut AbstractNode<ScriptView>> { - match self.next_sibling { - // transmute because the compiler can't deduce that the reference - // is safe outside of with_mut_base blocks. - Some(ref mut n) => Some(unsafe { cast::transmute(n) }), - None => None - } - } - - pub fn getFirstChild(&mut self) -> Option<&mut AbstractNode<ScriptView>> { - match self.first_child { - // transmute because the compiler can't deduce that the reference - // is safe outside of with_mut_base blocks. - Some(ref mut n) => Some(unsafe { cast::transmute(n) }), - None => None - } - } } impl Node<ScriptView> { + // http://dom.spec.whatwg.org/#dom-node-nodetype pub fn NodeType(&self) -> u16 { match self.type_id { ElementNodeTypeId(_) => 1, TextNodeTypeId => 3, CommentNodeTypeId => 8, + DocumentNodeTypeId(_)=> 9, DoctypeNodeTypeId => 10, DocumentFragmentNodeTypeId => 11, } @@ -592,6 +579,7 @@ impl Node<ScriptView> { } }, DocumentFragmentNodeTypeId => ~"#document-fragment", + DocumentNodeTypeId(_) => ~"#document" }) } @@ -606,7 +594,7 @@ impl Node<ScriptView> { TextNodeTypeId | DoctypeNodeTypeId | DocumentFragmentNodeTypeId => Some(self.owner_doc()), - // DocumentNodeTypeId => None + DocumentNodeTypeId(_) => None } } @@ -675,7 +663,7 @@ impl Node<ScriptView> { characterdata.Data() } } - DoctypeNodeTypeId => { + DoctypeNodeTypeId | DocumentNodeTypeId(_) => { None } } @@ -723,7 +711,7 @@ impl Node<ScriptView> { // Step 1. match parent.type_id() { - // DocumentNodeTypeId | + DocumentNodeTypeId(*) | DocumentFragmentNodeTypeId | ElementNodeTypeId(*) => (), _ => { @@ -754,21 +742,21 @@ impl Node<ScriptView> { TextNodeTypeId | // ProcessingInstructionNodeTypeId | CommentNodeTypeId => (), - /*_ => { XXX #838 - return Err(HierarchyRequest); - },*/ + DocumentNodeTypeId(*) => return Err(HierarchyRequest), } // Step 5. match node.type_id() { TextNodeTypeId => { - if false { // XXX #838 - return Err(HierarchyRequest); + match node.parent_node() { + Some(parent) if parent.is_document() => return Err(HierarchyRequest), + _ => () } }, DoctypeNodeTypeId => { - if true { // XXX #838 - return Err(HierarchyRequest); + match node.parent_node() { + Some(parent) if !parent.is_document() => return Err(HierarchyRequest), + _ => () } }, _ => (), @@ -899,7 +887,7 @@ impl Node<ScriptView> { document.document().content_changed(); } } - DoctypeNodeTypeId => {} + DoctypeNodeTypeId | DocumentNodeTypeId(_) => {} } Ok(()) } diff --git a/src/components/script/html/hubbub_html_parser.rs b/src/components/script/html/hubbub_html_parser.rs index 7aa91104507..b1f8cc96484 100644 --- a/src/components/script/html/hubbub_html_parser.rs +++ b/src/components/script/html/hubbub_html_parser.rs @@ -56,26 +56,15 @@ macro_rules! handle_htmlelement( $cx, $document, $tag, $string, $type_id, $ctor, []); ) ) -macro_rules! handle_htmlmediaelement( - ($cx: expr, - $document: expr, - $tag: expr, - $string: expr, - $type_id: expr, - $ctor: ident) => ( - handle_element_base!(htmlmediaelement, HTMLMediaElement, - $cx, $document, $tag, $string, $type_id, $ctor, []); - ) -) -macro_rules! handle_htmltablecellelement( - ($cx: expr, - $document: expr, - $tag: expr, +macro_rules! handle_newable_element( + ($document: expr, + $localName: expr, $string: expr, - $type_id: expr, - $ctor: ident) => ( - handle_element_base!(htmltablecellelement, HTMLTableCellElement, - $cx, $document, $tag, $string, $type_id, $ctor, []); + $ctor: ident + $(, $arg:expr )*) => ( + if eq_slice($localName, $string) { + return $ctor::new(($localName).to_str(), $document $(, $arg)*); + } ) ) macro_rules! handle_element_base( @@ -257,39 +246,6 @@ pub fn build_element_from_tag(cx: *JSContext, tag: &str, document: AbstractDocum handle_element!(cx, document, tag, "option", HTMLOptionElementTypeId, HTMLOptionElement, []); handle_element!(cx, document, tag, "optgroup",HTMLOptGroupElementTypeId, HTMLOptGroupElement, []); handle_element!(cx, document, tag, "output", HTMLOutputElementTypeId, HTMLOutputElement, []); - handle_element!(cx, document, tag, "p", HTMLParagraphElementTypeId, HTMLParagraphElement, []); - handle_element!(cx, document, tag, "param", HTMLParamElementTypeId, HTMLParamElement, []); - handle_element!(cx, document, tag, "pre", HTMLPreElementTypeId, HTMLPreElement, []); - handle_element!(cx, document, tag, "progress",HTMLProgressElementTypeId, HTMLProgressElement, []); - handle_element!(cx, document, tag, "q", HTMLQuoteElementTypeId, HTMLQuoteElement, []); - handle_element!(cx, document, tag, "script", HTMLScriptElementTypeId, HTMLScriptElement, []); - handle_element!(cx, document, tag, "select", HTMLSelectElementTypeId, HTMLSelectElement, []); - handle_element!(cx, document, tag, "source", HTMLSourceElementTypeId, HTMLSourceElement, []); - handle_element!(cx, document, tag, "span", HTMLSpanElementTypeId, HTMLSpanElement, []); - handle_element!(cx, document, tag, "style", HTMLStyleElementTypeId, HTMLStyleElement, []); - handle_element!(cx, document, tag, "table", HTMLTableElementTypeId, HTMLTableElement, []); - handle_element!(cx, document, tag, "caption", HTMLTableCaptionElementTypeId, HTMLTableCaptionElement, []); - handle_element!(cx, document, tag, "col", HTMLTableColElementTypeId, HTMLTableColElement, []); - handle_element!(cx, document, tag, "colgroup",HTMLTableColElementTypeId, HTMLTableColElement, []); - handle_element!(cx, document, tag, "tbody", HTMLTableSectionElementTypeId, HTMLTableSectionElement, []); - handle_element!(cx, document, tag, "template",HTMLTemplateElementTypeId, HTMLTemplateElement, []); - handle_element!(cx, document, tag, "textarea",HTMLTextAreaElementTypeId, HTMLTextAreaElement, []); - handle_element!(cx, document, tag, "time", HTMLTimeElementTypeId, HTMLTimeElement, []); - handle_element!(cx, document, tag, "title", HTMLTitleElementTypeId, HTMLTitleElement, []); - handle_element!(cx, document, tag, "tr", HTMLTableRowElementTypeId, HTMLTableRowElement, []); - handle_element!(cx, document, tag, "track", HTMLTrackElementTypeId, HTMLTrackElement, []); - handle_element!(cx, document, tag, "ul", HTMLUListElementTypeId, HTMLUListElement, []); - - handle_element!(cx, document, tag, "img", HTMLImageElementTypeId, HTMLImageElement, [(image: None)]); - handle_element!(cx, document, tag, "iframe", HTMLIframeElementTypeId, HTMLIFrameElement, [(frame: None), (size: None), (sandbox: None)]); - - handle_element!(cx, document, tag, "h1", HTMLHeadingElementTypeId, HTMLHeadingElement, [(level: Heading1)]); - handle_element!(cx, document, tag, "h2", HTMLHeadingElementTypeId, HTMLHeadingElement, [(level: Heading2)]); - handle_element!(cx, document, tag, "h3", HTMLHeadingElementTypeId, HTMLHeadingElement, [(level: Heading3)]); - handle_element!(cx, document, tag, "h4", HTMLHeadingElementTypeId, HTMLHeadingElement, [(level: Heading4)]); - handle_element!(cx, document, tag, "h5", HTMLHeadingElementTypeId, HTMLHeadingElement, [(level: Heading5)]); - handle_element!(cx, document, tag, "h6", HTMLHeadingElementTypeId, HTMLHeadingElement, [(level: Heading6)]); - handle_htmlelement!(cx, document, tag, "aside", HTMLElementTypeId, HTMLElement); handle_htmlelement!(cx, document, tag, "b", HTMLElementTypeId, HTMLElement); @@ -297,11 +253,40 @@ pub fn build_element_from_tag(cx: *JSContext, tag: &str, document: AbstractDocum handle_htmlelement!(cx, document, tag, "section", HTMLElementTypeId, HTMLElement); handle_htmlelement!(cx, document, tag, "small", HTMLElementTypeId, HTMLElement); - handle_htmlmediaelement!(cx, document, tag, "audio", HTMLAudioElementTypeId, HTMLAudioElement); - handle_htmlmediaelement!(cx, document, tag, "video", HTMLVideoElementTypeId, HTMLVideoElement); - - handle_htmltablecellelement!(cx, document, tag, "td", HTMLTableDataCellElementTypeId, HTMLTableDataCellElement); - handle_htmltablecellelement!(cx, document, tag, "th", HTMLTableHeaderCellElementTypeId, HTMLTableHeaderCellElement); + handle_newable_element!(document, tag, "audio", HTMLAudioElement); + handle_newable_element!(document, tag, "caption", HTMLTableCaptionElement); + handle_newable_element!(document, tag, "col", HTMLTableColElement); + handle_newable_element!(document, tag, "colgroup", HTMLTableColElement); + handle_newable_element!(document, tag, "h1", HTMLHeadingElement, Heading1); + handle_newable_element!(document, tag, "h2", HTMLHeadingElement, Heading2); + handle_newable_element!(document, tag, "h3", HTMLHeadingElement, Heading3); + handle_newable_element!(document, tag, "h4", HTMLHeadingElement, Heading4); + handle_newable_element!(document, tag, "h5", HTMLHeadingElement, Heading5); + handle_newable_element!(document, tag, "h6", HTMLHeadingElement, Heading6); + handle_newable_element!(document, tag, "iframe", HTMLIFrameElement); + handle_newable_element!(document, tag, "img", HTMLImageElement); + handle_newable_element!(document, tag, "p", HTMLParagraphElement); + handle_newable_element!(document, tag, "param", HTMLParamElement); + handle_newable_element!(document, tag, "pre", HTMLPreElement); + handle_newable_element!(document, tag, "progress", HTMLProgressElement); + handle_newable_element!(document, tag, "q", HTMLQuoteElement); + handle_newable_element!(document, tag, "script", HTMLScriptElement); + handle_newable_element!(document, tag, "select", HTMLSelectElement); + handle_newable_element!(document, tag, "source", HTMLSourceElement); + handle_newable_element!(document, tag, "span", HTMLSpanElement); + handle_newable_element!(document, tag, "style", HTMLStyleElement); + handle_newable_element!(document, tag, "table", HTMLTableElement); + handle_newable_element!(document, tag, "tbody", HTMLTableSectionElement); + handle_newable_element!(document, tag, "td", HTMLTableDataCellElement); + handle_newable_element!(document, tag, "template", HTMLTemplateElement); + handle_newable_element!(document, tag, "textarea", HTMLTextAreaElement); + handle_newable_element!(document, tag, "th", HTMLTableHeaderCellElement); + handle_newable_element!(document, tag, "time", HTMLTimeElement); + handle_newable_element!(document, tag, "title", HTMLTitleElement); + handle_newable_element!(document, tag, "tr", HTMLTableRowElement); + handle_newable_element!(document, tag, "track", HTMLTrackElement); + handle_newable_element!(document, tag, "ul", HTMLUListElement); + handle_newable_element!(document, tag, "video", HTMLVideoElement); return HTMLUnknownElement::new(tag.to_str(), document); } diff --git a/src/components/script/script_task.rs b/src/components/script/script_task.rs index 5966781a6dc..fed211c1fce 100644 --- a/src/components/script/script_task.rs +++ b/src/components/script/script_task.rs @@ -274,7 +274,7 @@ impl Page { /// This function fails if there is no root frame. fn reflow(&mut self, goal: ReflowGoal, script_chan: ScriptChan, compositor: @ScriptListener) { let root = match self.frame { - None => fail!(~"Tried to relayout with no root frame!"), + None => return, Some(ref frame) => { frame.document.document().GetDocumentElement() } diff --git a/src/test/html/content/test_parentnodes.html b/src/test/html/content/test_parentnodes.html index b45d5de011d..0b1bb610414 100644 --- a/src/test/html/content/test_parentnodes.html +++ b/src/test/html/content/test_parentnodes.html @@ -6,8 +6,7 @@ <body> <div id="div1"></div> <script> - // FIXME: This should be HTMLDocument. - //isnot(document.documentElement.parentNode, null); + is_a(document.documentElement.parentNode, HTMLDocument); is(document.documentElement.parentElement, null); var elem = document.createElement("p"); diff --git a/src/test/html/content/test_prototypes.html b/src/test/html/content/test_prototypes.html index 61835bd750e..11ee11242b5 100644 --- a/src/test/html/content/test_prototypes.html +++ b/src/test/html/content/test_prototypes.html @@ -5,6 +5,9 @@ <body> <foo-á>foo</foo-á> <script> +gc(); // ensure that our document rooting works; subsequent accesses should be valid. +is_a(window.document, Node); +is(window.document.nodeType, Node.DOCUMENT_NODE); is_a(window.document.documentElement, Node); is_a(window.document.documentElement, Element); is_a(window.document.documentElement, HTMLElement); |