aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMs2ger <ms2ger@gmail.com>2013-11-02 21:05:37 +0100
committerMs2ger <ms2ger@gmail.com>2013-11-02 21:05:37 +0100
commitb4559334bbd744a63c403478946bb7636dbc2552 (patch)
treeeaff1c797dfe07ff3f8610e420cea7626bdd5c7f /src
parente2c90d1198b78878ef490da2f98032ac64dcb9da (diff)
downloadservo-b4559334bbd744a63c403478946bb7636dbc2552.tar.gz
servo-b4559334bbd744a63c403478946bb7636dbc2552.zip
Introduce HTMLElement::new.
Diffstat (limited to 'src')
-rw-r--r--src/components/script/dom/htmlelement.rs10
-rw-r--r--src/components/script/html/hubbub_html_parser.rs47
2 files changed, 15 insertions, 42 deletions
diff --git a/src/components/script/dom/htmlelement.rs b/src/components/script/dom/htmlelement.rs
index 59a75e1353d..b7ff82b6e6d 100644
--- a/src/components/script/dom/htmlelement.rs
+++ b/src/components/script/dom/htmlelement.rs
@@ -2,10 +2,11 @@
* 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::HTMLElementBinding;
use dom::bindings::utils::{DOMString, ErrorResult, Fallible};
use dom::document::AbstractDocument;
-use dom::element::{Element, ElementTypeId};
-use dom::node::{AbstractNode, ScriptView};
+use dom::element::{Element, ElementTypeId, HTMLElementTypeId};
+use dom::node::{AbstractNode, Node, ScriptView};
use js::jsapi::{JSContext, JSVal};
use js::JSVAL_NULL;
@@ -19,6 +20,11 @@ impl HTMLElement {
element: Element::new(type_id, tag_name, document)
}
}
+
+ pub fn new(localName: ~str, document: AbstractDocument) -> AbstractNode<ScriptView> {
+ let element = HTMLElement::new_inherited(HTMLElementTypeId, localName, document);
+ Node::reflect_node(@mut element, document, HTMLElementBinding::Wrap)
+ }
}
impl HTMLElement {
diff --git a/src/components/script/html/hubbub_html_parser.rs b/src/components/script/html/hubbub_html_parser.rs
index f906a7d21e1..21b18b69577 100644
--- a/src/components/script/html/hubbub_html_parser.rs
+++ b/src/components/script/html/hubbub_html_parser.rs
@@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use dom::document::AbstractDocument;
-use dom::element::*;
+use dom::element::{HTMLLinkElementTypeId, HTMLIframeElementTypeId, HTMLImageElementTypeId};
use dom::htmlelement::HTMLElement;
use dom::htmlheadingelement::{Heading1, Heading2, Heading3, Heading4, Heading5, Heading6};
use dom::htmliframeelement::IFrameSize;
@@ -32,17 +32,6 @@ use extra::future::Future;
use extra::url::Url;
use geom::size::Size2D;
-macro_rules! handle_htmlelement(
- ($cx: expr,
- $document: expr,
- $tag: expr,
- $string: expr,
- $type_id: expr,
- $ctor: ident) => (
- handle_element_base!(element, Element,
- $cx, $document, $tag, $string, $type_id, $ctor, []);
- )
-)
macro_rules! handle_newable_element(
($document: expr,
$localName: expr,
@@ -54,27 +43,6 @@ macro_rules! handle_newable_element(
}
)
)
-macro_rules! handle_element_base(
- ($parent: ident,
- $parent_init: ident,
- $cx: expr,
- $document: expr,
- $tag: expr,
- $string: expr,
- $type_id: expr,
- $ctor: ident,
- [ $(($field:ident : $field_init:expr)),* ]) => (
- if eq_slice($tag, $string) {
- let _element = @$ctor {
- $parent: $parent_init::new($type_id, ($tag).to_str(), $document),
- $(
- $field: $field_init,
- )*
- };
- return unsafe { Node::as_abstract_node($cx, _element) };
- }
- )
-)
pub struct JSFile {
@@ -194,18 +162,14 @@ fn js_script_listener(to_parent: SharedChan<HtmlDiscoveryMessage>,
// Silly macros to handle constructing DOM nodes. This produces bad code and should be optimized
// via atomization (issue #85).
-pub fn build_element_from_tag(cx: *JSContext, tag: &str, document: AbstractDocument) -> AbstractNode<ScriptView> {
+pub fn build_element_from_tag(_cx: *JSContext, tag: &str, document: AbstractDocument) -> AbstractNode<ScriptView> {
// TODO (Issue #85): use atoms
- handle_htmlelement!(cx, document, tag, "aside", HTMLElementTypeId, HTMLElement);
- handle_htmlelement!(cx, document, tag, "b", HTMLElementTypeId, HTMLElement);
- handle_htmlelement!(cx, document, tag, "i", HTMLElementTypeId, HTMLElement);
- handle_htmlelement!(cx, document, tag, "section", HTMLElementTypeId, HTMLElement);
- handle_htmlelement!(cx, document, tag, "small", HTMLElementTypeId, HTMLElement);
-
handle_newable_element!(document, tag, "a", HTMLAnchorElement);
handle_newable_element!(document, tag, "applet", HTMLAppletElement);
handle_newable_element!(document, tag, "area", HTMLAreaElement);
+ handle_newable_element!(document, tag, "aside", HTMLElement);
handle_newable_element!(document, tag, "audio", HTMLAudioElement);
+ handle_newable_element!(document, tag, "b", HTMLElement);
handle_newable_element!(document, tag, "base", HTMLBaseElement);
handle_newable_element!(document, tag, "body", HTMLBodyElement);
handle_newable_element!(document, tag, "br", HTMLBRElement);
@@ -235,6 +199,7 @@ pub fn build_element_from_tag(cx: *JSContext, tag: &str, document: AbstractDocum
handle_newable_element!(document, tag, "head", HTMLHeadElement);
handle_newable_element!(document, tag, "hr", HTMLHRElement);
handle_newable_element!(document, tag, "html", HTMLHtmlElement);
+ handle_newable_element!(document, tag, "i", HTMLElement);
handle_newable_element!(document, tag, "iframe", HTMLIFrameElement);
handle_newable_element!(document, tag, "img", HTMLImageElement);
handle_newable_element!(document, tag, "input", HTMLInputElement);
@@ -258,7 +223,9 @@ pub fn build_element_from_tag(cx: *JSContext, tag: &str, document: AbstractDocum
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, "section", HTMLElement);
handle_newable_element!(document, tag, "select", HTMLSelectElement);
+ handle_newable_element!(document, tag, "small", HTMLElement);
handle_newable_element!(document, tag, "source", HTMLSourceElement);
handle_newable_element!(document, tag, "span", HTMLSpanElement);
handle_newable_element!(document, tag, "style", HTMLStyleElement);