aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorsaneyuki_s <saneyuki.s.snyk@gmail.com>2013-08-08 23:28:39 +0900
committersaneyuki_s <saneyuki.s.snyk@gmail.com>2013-08-09 01:57:12 +0900
commit9cbaf13334d63d506d50ce2a95e1319635dd4d91 (patch)
tree56e7d57e7f8949c5e6052929bbb9fe6e91949699 /src
parenta8b03857fc8fff5c07ec0f2648c1c8f27c92942e (diff)
downloadservo-9cbaf13334d63d506d50ce2a95e1319635dd4d91.tar.gz
servo-9cbaf13334d63d506d50ce2a95e1319635dd4d91.zip
Bindings for elements that use HTMLElement.
* aside * section * b * i
Diffstat (limited to 'src')
-rw-r--r--src/components/script/dom/bindings/node.rs3
-rw-r--r--src/components/script/dom/element.rs9
-rw-r--r--src/components/script/html/hubbub_html_parser.rs39
-rw-r--r--src/test/html/test_bindings.html4
-rw-r--r--src/test/html/test_bindings.js10
5 files changed, 44 insertions, 21 deletions
diff --git a/src/components/script/dom/bindings/node.rs b/src/components/script/dom/bindings/node.rs
index 5b5d26c5ec1..f248bd8d9ce 100644
--- a/src/components/script/dom/bindings/node.rs
+++ b/src/components/script/dom/bindings/node.rs
@@ -6,6 +6,7 @@ use dom::bindings::element;
use dom::bindings::text;
use dom::bindings::utils;
use dom::bindings::utils::{CacheableWrapper, WrapperCache, DerivedWrapper};
+use dom::element::{HTMLElementTypeId};
use dom::element::{HTMLHeadElementTypeId, HTMLHtmlElementTypeId, HTMLAnchorElementTypeId};
use dom::element::{HTMLDivElementTypeId, HTMLImageElementTypeId, HTMLSpanElementTypeId};
use dom::element::{HTMLBodyElementTypeId, HTMLHRElementTypeId, HTMLIframeElementTypeId};
@@ -13,6 +14,7 @@ use dom::element::{HTMLParagraphElementTypeId, HTMLScriptElementTypeId, HTMLMeta
use dom::element::{HTMLOListElementTypeId, HTMLStyleElementTypeId, HTMLTableElementTypeId};
use dom::element::{HTMLHeadElement, HTMLHtmlElement, HTMLDivElement, HTMLSpanElement};
use dom::element::{HTMLParagraphElement};
+use dom::htmlelement::HTMLElement;
use dom::htmlanchorelement::HTMLAnchorElement;
use dom::htmlbodyelement::HTMLBodyElement;
use dom::htmlhrelement::HTMLHRElement;
@@ -88,6 +90,7 @@ macro_rules! generate_element(
#[allow(non_implicitly_copyable_typarams)]
pub fn create(cx: *JSContext, node: &mut AbstractNode<ScriptView>) -> *JSObject {
match node.type_id() {
+ ElementNodeTypeId(HTMLElementTypeId) => generate_element!(HTMLElement),
ElementNodeTypeId(HTMLAnchorElementTypeId) => generate_element!(HTMLAnchorElement),
ElementNodeTypeId(HTMLBodyElementTypeId) => generate_element!(HTMLBodyElement),
ElementNodeTypeId(HTMLDivElementTypeId) => generate_element!(HTMLDivElement),
diff --git a/src/components/script/dom/element.rs b/src/components/script/dom/element.rs
index 2d547190b7b..20768771edb 100644
--- a/src/components/script/dom/element.rs
+++ b/src/components/script/dom/element.rs
@@ -64,11 +64,10 @@ impl BindingObject for Element {
#[deriving(Eq)]
pub enum ElementTypeId {
+ HTMLElementTypeId,
HTMLAnchorElementTypeId,
- HTMLAsideElementTypeId,
HTMLBRElementTypeId,
HTMLBodyElementTypeId,
- HTMLBoldElementTypeId,
HTMLDivElementTypeId,
HTMLFontElementTypeId,
HTMLFormElementTypeId,
@@ -79,7 +78,6 @@ pub enum ElementTypeId {
HTMLIframeElementTypeId,
HTMLImageElementTypeId,
HTMLInputElementTypeId,
- HTMLItalicElementTypeId,
HTMLLinkElementTypeId,
HTMLListItemElementTypeId,
HTMLMetaElementTypeId,
@@ -87,7 +85,6 @@ pub enum ElementTypeId {
HTMLOptionElementTypeId,
HTMLParagraphElementTypeId,
HTMLScriptElementTypeId,
- HTMLSectionElementTypeId,
HTMLSelectElementTypeId,
HTMLSmallElementTypeId,
HTMLSpanElementTypeId,
@@ -105,21 +102,17 @@ pub enum ElementTypeId {
// Regular old elements
//
-pub struct HTMLAsideElement { parent: HTMLElement }
pub struct HTMLBRElement { parent: HTMLElement }
-pub struct HTMLBoldElement { parent: HTMLElement }
pub struct HTMLDivElement { parent: HTMLElement }
pub struct HTMLFontElement { parent: HTMLElement }
pub struct HTMLFormElement { parent: HTMLElement }
pub struct HTMLHeadElement { parent: HTMLElement }
pub struct HTMLHtmlElement { parent: HTMLElement }
pub struct HTMLInputElement { parent: HTMLElement }
-pub struct HTMLItalicElement { parent: HTMLElement }
pub struct HTMLLinkElement { parent: HTMLElement }
pub struct HTMLListItemElement { parent: HTMLElement }
pub struct HTMLOptionElement { parent: HTMLElement }
pub struct HTMLParagraphElement { parent: HTMLElement }
-pub struct HTMLSectionElement { parent: HTMLElement }
pub struct HTMLSelectElement { parent: HTMLElement }
pub struct HTMLSmallElement { parent: HTMLElement }
pub struct HTMLSpanElement { parent: HTMLElement }
diff --git a/src/components/script/html/hubbub_html_parser.rs b/src/components/script/html/hubbub_html_parser.rs
index a5f1bf5d67b..c8220eda7ed 100644
--- a/src/components/script/html/hubbub_html_parser.rs
+++ b/src/components/script/html/hubbub_html_parser.rs
@@ -2,25 +2,26 @@
* 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::element::{HTMLAnchorElementTypeId, HTMLAsideElementTypeId, HTMLBRElementTypeId,
- HTMLBodyElementTypeId, HTMLBoldElementTypeId, HTMLDivElementTypeId,
+use dom::element::{HTMLElementTypeId,
+ HTMLAnchorElementTypeId, HTMLBRElementTypeId,
+ HTMLBodyElementTypeId, HTMLDivElementTypeId,
HTMLFontElementTypeId, HTMLFormElementTypeId, HTMLHRElementTypeId,
HTMLHeadElementTypeId, HTMLHtmlElementTypeId,
HTMLImageElementTypeId, HTMLIframeElementTypeId, HTMLInputElementTypeId,
- HTMLItalicElementTypeId, HTMLLinkElementTypeId, HTMLListItemElementTypeId,
+ HTMLLinkElementTypeId, HTMLListItemElementTypeId,
HTMLMetaElementTypeId, HTMLOListElementTypeId, HTMLOptionElementTypeId,
HTMLParagraphElementTypeId, HTMLScriptElementTypeId,
- HTMLSectionElementTypeId, HTMLSelectElementTypeId, HTMLSmallElementTypeId,
+ HTMLSelectElementTypeId, HTMLSmallElementTypeId,
HTMLSpanElementTypeId, HTMLStyleElementTypeId, HTMLTableBodyElementTypeId,
HTMLTableCellElementTypeId, HTMLTableElementTypeId,
HTMLTableRowElementTypeId, HTMLTitleElementTypeId, HTMLUListElementTypeId,
UnknownElementTypeId};
-use dom::element::{HTMLAsideElement, HTMLBRElement,
- HTMLBoldElement, HTMLDivElement, HTMLFontElement, HTMLFormElement,
+use dom::element::{HTMLBRElement,
+ HTMLDivElement, HTMLFontElement, HTMLFormElement,
HTMLHeadElement, HTMLHeadingElement, HTMLHtmlElement,
- HTMLInputElement, HTMLItalicElement, HTMLLinkElement,
+ HTMLInputElement, HTMLLinkElement,
HTMLOptionElement, HTMLParagraphElement, HTMLListItemElement,
- HTMLSectionElement, HTMLSelectElement, HTMLSmallElement,
+ HTMLSelectElement, HTMLSmallElement,
HTMLSpanElement, HTMLTableBodyElement,
HTMLTableCellElement, HTMLTableRowElement,
HTMLTitleElement, HTMLUListElement};
@@ -78,6 +79,16 @@ macro_rules! handle_element(
}
)
)
+macro_rules! handle_htmlelement(
+ ($cx: expr, $tag:expr, $string:expr, $type_id:expr, $ctor:ident) => (
+ if eq_slice($tag, $string) {
+ let _element = @HTMLElement::new($type_id, ($tag).to_str());
+ unsafe {
+ return Node::as_abstract_node(cx, _element);
+ }
+ }
+ )
+)
type JSResult = ~[~[u8]];
@@ -200,11 +211,9 @@ fn js_script_listener(to_parent: Chan<~[~[u8]]>,
fn build_element_from_tag(cx: *JSContext, tag: &str) -> AbstractNode<ScriptView> {
// TODO (Issue #85): use atoms
- handle_element!(cx, tag, "a", HTMLAnchorElementTypeId, HTMLAnchorElement, []);
- handle_element!(cx, tag, "aside", HTMLAsideElementTypeId, HTMLAsideElement, []);
+ handle_element!(cx, tag, "a", HTMLAnchorElementTypeId, HTMLAnchorElement, []);
handle_element!(cx, tag, "br", HTMLBRElementTypeId, HTMLBRElement, []);
handle_element!(cx, tag, "body", HTMLBodyElementTypeId, HTMLBodyElement, []);
- handle_element!(cx, tag, "bold", HTMLBoldElementTypeId, HTMLBoldElement, []);
handle_element!(cx, tag, "div", HTMLDivElementTypeId, HTMLDivElement, []);
handle_element!(cx, tag, "font", HTMLFontElementTypeId, HTMLFontElement, []);
handle_element!(cx, tag, "form", HTMLFormElementTypeId, HTMLFormElement, []);
@@ -212,7 +221,6 @@ fn build_element_from_tag(cx: *JSContext, tag: &str) -> AbstractNode<ScriptView>
handle_element!(cx, tag, "head", HTMLHeadElementTypeId, HTMLHeadElement, []);
handle_element!(cx, tag, "html", HTMLHtmlElementTypeId, HTMLHtmlElement, []);
handle_element!(cx, tag, "input", HTMLInputElementTypeId, HTMLInputElement, []);
- handle_element!(cx, tag, "i", HTMLItalicElementTypeId, HTMLItalicElement, []);
handle_element!(cx, tag, "link", HTMLLinkElementTypeId, HTMLLinkElement, []);
handle_element!(cx, tag, "li", HTMLListItemElementTypeId, HTMLListItemElement, []);
handle_element!(cx, tag, "meta", HTMLMetaElementTypeId, HTMLMetaElement, []);
@@ -220,7 +228,6 @@ fn build_element_from_tag(cx: *JSContext, tag: &str) -> AbstractNode<ScriptView>
handle_element!(cx, tag, "option", HTMLOptionElementTypeId, HTMLOptionElement, []);
handle_element!(cx, tag, "p", HTMLParagraphElementTypeId, HTMLParagraphElement, []);
handle_element!(cx, tag, "script", HTMLScriptElementTypeId, HTMLScriptElement, []);
- handle_element!(cx, tag, "section", HTMLSectionElementTypeId, HTMLSectionElement, []);
handle_element!(cx, tag, "select", HTMLSelectElementTypeId, HTMLSelectElement, []);
handle_element!(cx, tag, "small", HTMLSmallElementTypeId, HTMLSmallElement, []);
handle_element!(cx, tag, "span", HTMLSpanElementTypeId, HTMLSpanElement, []);
@@ -242,6 +249,12 @@ fn build_element_from_tag(cx: *JSContext, tag: &str) -> AbstractNode<ScriptView>
handle_element!(cx, tag, "h5", HTMLHeadingElementTypeId, HTMLHeadingElement, [(level: Heading5)]);
handle_element!(cx, tag, "h6", HTMLHeadingElementTypeId, HTMLHeadingElement, [(level: Heading6)]);
+
+ handle_htmlelement!(cx, tag, "aside", HTMLElementTypeId, HTMLElement);
+ handle_htmlelement!(cx, tag, "b", HTMLElementTypeId, HTMLElement);
+ handle_htmlelement!(cx, tag, "i", HTMLElementTypeId, HTMLElement);
+ handle_htmlelement!(cx, tag, "section", HTMLElementTypeId, HTMLElement);
+
unsafe {
Node::as_abstract_node(cx, @Element::new(UnknownElementTypeId, tag.to_str()))
}
diff --git a/src/test/html/test_bindings.html b/src/test/html/test_bindings.html
index 6abca570d85..75bb9906c29 100644
--- a/src/test/html/test_bindings.html
+++ b/src/test/html/test_bindings.html
@@ -21,5 +21,9 @@
<iframe></iframe>
<ol type="1"></ol>
<table></table>
+ <section>section</section>
+ <aside>aside</aside>
+ <b>b</b>
+ <i>i</i>
</body>
</html>
diff --git a/src/test/html/test_bindings.js b/src/test/html/test_bindings.js
index cdff29f53d4..952aedc51b9 100644
--- a/src/test/html/test_bindings.js
+++ b/src/test/html/test_bindings.js
@@ -141,6 +141,16 @@ window.alert(tags.length);
window.alert(tags[0]);
window.alert(tags[0].tagName);
+window.alert("HTMLElement:");
+let tagList = ["section", "aside", "b", "i"];
+for (let i = 0, l = tagList.length; i < l; ++i) {
+ let tags = document.getElementsByTagName(tagList[i]);
+ window.alert(tags);
+ window.alert(tags.length);
+ window.alert(tags[0].tagName);
+ window.alert(tags[0] instanceof HTMLElement);
+}
+
//TODO: Doesn't work until we throw proper exceptions instead of returning 0 on
// unwrap failure.
/*try {