Implement HTML{Anchor,Area,Link}Element.relList.

https://github.com/servo/servo/issues/3994
This commit is contained in:
Achal Shah 2014-11-23 02:03:45 -08:00
parent 90007ee781
commit 23ed1f705b
9 changed files with 99 additions and 36 deletions

View file

@ -2,6 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use dom::attr::AttrValue;
use dom::bindings::codegen::Bindings::AttrBinding::AttrMethods; use dom::bindings::codegen::Bindings::AttrBinding::AttrMethods;
use dom::bindings::codegen::Bindings::EventBinding::EventMethods; use dom::bindings::codegen::Bindings::EventBinding::EventMethods;
use dom::bindings::codegen::Bindings::HTMLAnchorElementBinding; use dom::bindings::codegen::Bindings::HTMLAnchorElementBinding;
@ -9,9 +10,10 @@ use dom::bindings::codegen::Bindings::HTMLAnchorElementBinding::HTMLAnchorElemen
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
use dom::bindings::codegen::InheritTypes::HTMLAnchorElementDerived; use dom::bindings::codegen::InheritTypes::HTMLAnchorElementDerived;
use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLElementCast, NodeCast}; use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLElementCast, NodeCast};
use dom::bindings::js::{JSRef, Temporary, OptionalRootable}; use dom::bindings::js::{MutNullableJS, JSRef, Temporary, OptionalRootable};
use dom::bindings::utils::{Reflectable, Reflector}; use dom::bindings::utils::{Reflectable, Reflector};
use dom::document::{Document, DocumentHelpers}; use dom::document::{Document, DocumentHelpers};
use dom::domtokenlist::DOMTokenList;
use dom::element::{Element, AttributeHandlers, HTMLAnchorElementTypeId}; use dom::element::{Element, AttributeHandlers, HTMLAnchorElementTypeId};
use dom::event::Event; use dom::event::Event;
use dom::eventtarget::{EventTarget, NodeTargetTypeId}; use dom::eventtarget::{EventTarget, NodeTargetTypeId};
@ -19,11 +21,14 @@ use dom::htmlelement::HTMLElement;
use dom::node::{Node, NodeHelpers, ElementNodeTypeId}; use dom::node::{Node, NodeHelpers, ElementNodeTypeId};
use dom::virtualmethods::VirtualMethods; use dom::virtualmethods::VirtualMethods;
use std::default::Default;
use string_cache::Atom;
use servo_util::str::DOMString; use servo_util::str::DOMString;
#[dom_struct] #[dom_struct]
pub struct HTMLAnchorElement { pub struct HTMLAnchorElement {
htmlelement: HTMLElement htmlelement: HTMLElement,
rel_list: MutNullableJS<DOMTokenList>,
} }
impl HTMLAnchorElementDerived for EventTarget { impl HTMLAnchorElementDerived for EventTarget {
@ -35,7 +40,8 @@ impl HTMLAnchorElementDerived for EventTarget {
impl HTMLAnchorElement { impl HTMLAnchorElement {
fn new_inherited(localName: DOMString, prefix: Option<DOMString>, document: JSRef<Document>) -> HTMLAnchorElement { fn new_inherited(localName: DOMString, prefix: Option<DOMString>, document: JSRef<Document>) -> HTMLAnchorElement {
HTMLAnchorElement { HTMLAnchorElement {
htmlelement: HTMLElement::new_inherited(HTMLAnchorElementTypeId, localName, prefix, document) htmlelement: HTMLElement::new_inherited(HTMLAnchorElementTypeId, localName, prefix, document),
rel_list: Default::default(),
} }
} }
@ -84,6 +90,13 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLAnchorElement> {
} }
self.handle_event_impl(event); self.handle_event_impl(event);
} }
fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue {
match name {
&atom!("rel") => AttrValue::from_tokenlist(value),
_ => self.super_type().unwrap().parse_plain_attribute(name, value),
}
}
} }
impl Reflectable for HTMLAnchorElement { impl Reflectable for HTMLAnchorElement {
@ -102,4 +115,13 @@ impl<'a> HTMLAnchorElementMethods for JSRef<'a, HTMLAnchorElement> {
let node: JSRef<Node> = NodeCast::from_ref(self); let node: JSRef<Node> = NodeCast::from_ref(self);
node.SetTextContent(Some(value)) node.SetTextContent(Some(value))
} }
fn RelList(self) -> Temporary<DOMTokenList> {
if self.rel_list.get().is_none() {
let element: JSRef<Element> = ElementCast::from_ref(self);
let rel_list = DOMTokenList::new(element, &atom!("rel"));
self.rel_list.assign(Some(rel_list));
}
self.rel_list.get().unwrap()
}
} }

View file

@ -2,23 +2,32 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use dom::attr::AttrValue;
use dom::bindings::codegen::Bindings::HTMLAreaElementBinding; use dom::bindings::codegen::Bindings::HTMLAreaElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLAreaElementDerived; use dom::bindings::codegen::Bindings::HTMLAreaElementBinding::HTMLAreaElementMethods;
use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::codegen::InheritTypes::{HTMLAreaElementDerived, HTMLElementCast};
use dom::bindings::codegen::InheritTypes::ElementCast;
use dom::bindings::js::{MutNullableJS, JSRef, Temporary};
use dom::bindings::utils::{Reflectable, Reflector}; use dom::bindings::utils::{Reflectable, Reflector};
use dom::document::Document; use dom::document::Document;
use dom::domtokenlist::DOMTokenList;
use dom::element::Element;
use dom::element::HTMLAreaElementTypeId; use dom::element::HTMLAreaElementTypeId;
use dom::eventtarget::{EventTarget, NodeTargetTypeId}; use dom::eventtarget::{EventTarget, NodeTargetTypeId};
use dom::htmlelement::HTMLElement; use dom::htmlelement::HTMLElement;
use dom::node::{Node, NodeHelpers, ElementNodeTypeId}; use dom::node::{Node, NodeHelpers, ElementNodeTypeId};
use dom::virtualmethods::VirtualMethods;
use std::default::Default;
use string_cache::Atom;
use servo_util::str::DOMString; use servo_util::str::DOMString;
#[jstraceable] #[jstraceable]
#[must_root] #[must_root]
#[privatize] #[privatize]
pub struct HTMLAreaElement { pub struct HTMLAreaElement {
htmlelement: HTMLElement htmlelement: HTMLElement,
rel_list: MutNullableJS<DOMTokenList>,
} }
impl HTMLAreaElementDerived for EventTarget { impl HTMLAreaElementDerived for EventTarget {
@ -30,7 +39,8 @@ impl HTMLAreaElementDerived for EventTarget {
impl HTMLAreaElement { impl HTMLAreaElement {
fn new_inherited(localName: DOMString, prefix: Option<DOMString>, document: JSRef<Document>) -> HTMLAreaElement { fn new_inherited(localName: DOMString, prefix: Option<DOMString>, document: JSRef<Document>) -> HTMLAreaElement {
HTMLAreaElement { HTMLAreaElement {
htmlelement: HTMLElement::new_inherited(HTMLAreaElementTypeId, localName, prefix, document) htmlelement: HTMLElement::new_inherited(HTMLAreaElementTypeId, localName, prefix, document),
rel_list: Default::default(),
} }
} }
@ -41,8 +51,33 @@ impl HTMLAreaElement {
} }
} }
impl<'a> VirtualMethods for JSRef<'a, HTMLAreaElement> {
fn super_type<'a>(&'a self) -> Option<&'a VirtualMethods> {
let htmlelement: &JSRef<HTMLElement> = HTMLElementCast::from_borrowed_ref(self);
Some(htmlelement as &VirtualMethods)
}
fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue {
match name {
&atom!("rel") => AttrValue::from_tokenlist(value),
_ => self.super_type().unwrap().parse_plain_attribute(name, value),
}
}
}
impl Reflectable for HTMLAreaElement { impl Reflectable for HTMLAreaElement {
fn reflector<'a>(&'a self) -> &'a Reflector { fn reflector<'a>(&'a self) -> &'a Reflector {
self.htmlelement.reflector() self.htmlelement.reflector()
} }
} }
impl<'a> HTMLAreaElementMethods for JSRef<'a, HTMLAreaElement> {
fn RelList(self) -> Temporary<DOMTokenList> {
if self.rel_list.get().is_none() {
let element: JSRef<Element> = ElementCast::from_ref(self);
let rel_list = DOMTokenList::new(element, &atom!("rel"));
self.rel_list.assign(Some(rel_list));
}
self.rel_list.get().unwrap()
}
}

View file

@ -2,14 +2,16 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use dom::attr::Attr; use dom::attr::{Attr, AttrValue};
use dom::attr::AttrHelpers; use dom::attr::AttrHelpers;
use dom::bindings::codegen::Bindings::HTMLLinkElementBinding; use dom::bindings::codegen::Bindings::HTMLLinkElementBinding;
use dom::bindings::codegen::Bindings::HTMLLinkElementBinding::HTMLLinkElementMethods;
use dom::bindings::codegen::InheritTypes::HTMLLinkElementDerived; use dom::bindings::codegen::InheritTypes::HTMLLinkElementDerived;
use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLElementCast}; use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLElementCast};
use dom::bindings::js::{JSRef, Temporary, OptionalRootable}; use dom::bindings::js::{MutNullableJS, JSRef, Temporary, OptionalRootable};
use dom::bindings::utils::{Reflectable, Reflector}; use dom::bindings::utils::{Reflectable, Reflector};
use dom::document::Document; use dom::document::Document;
use dom::domtokenlist::DOMTokenList;
use dom::element::{AttributeHandlers, Element, HTMLLinkElementTypeId}; use dom::element::{AttributeHandlers, Element, HTMLLinkElementTypeId};
use dom::eventtarget::{EventTarget, NodeTargetTypeId}; use dom::eventtarget::{EventTarget, NodeTargetTypeId};
use dom::htmlelement::HTMLElement; use dom::htmlelement::HTMLElement;
@ -19,12 +21,14 @@ use layout_interface::{LayoutChan, LoadStylesheetMsg};
use servo_util::str::{DOMString, HTML_SPACE_CHARACTERS}; use servo_util::str::{DOMString, HTML_SPACE_CHARACTERS};
use std::ascii::AsciiExt; use std::ascii::AsciiExt;
use std::default::Default;
use url::UrlParser; use url::UrlParser;
use string_cache::Atom; use string_cache::Atom;
#[dom_struct] #[dom_struct]
pub struct HTMLLinkElement { pub struct HTMLLinkElement {
htmlelement: HTMLElement, htmlelement: HTMLElement,
rel_list: MutNullableJS<DOMTokenList>,
} }
impl HTMLLinkElementDerived for EventTarget { impl HTMLLinkElementDerived for EventTarget {
@ -36,7 +40,8 @@ impl HTMLLinkElementDerived for EventTarget {
impl HTMLLinkElement { impl HTMLLinkElement {
fn new_inherited(localName: DOMString, prefix: Option<DOMString>, document: JSRef<Document>) -> HTMLLinkElement { fn new_inherited(localName: DOMString, prefix: Option<DOMString>, document: JSRef<Document>) -> HTMLLinkElement {
HTMLLinkElement { HTMLLinkElement {
htmlelement: HTMLElement::new_inherited(HTMLLinkElementTypeId, localName, prefix, document) htmlelement: HTMLElement::new_inherited(HTMLLinkElementTypeId, localName, prefix, document),
rel_list: Default::default(),
} }
} }
@ -87,6 +92,13 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLLinkElement> {
} }
} }
fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue {
match name {
&atom!("rel") => AttrValue::from_tokenlist(value),
_ => self.super_type().unwrap().parse_plain_attribute(name, value),
}
}
fn bind_to_tree(&self, tree_in_doc: bool) { fn bind_to_tree(&self, tree_in_doc: bool) {
match self.super_type() { match self.super_type() {
Some(ref s) => s.bind_to_tree(tree_in_doc), Some(ref s) => s.bind_to_tree(tree_in_doc),
@ -132,3 +144,13 @@ impl Reflectable for HTMLLinkElement {
} }
} }
impl<'a> HTMLLinkElementMethods for JSRef<'a, HTMLLinkElement> {
fn RelList(self) -> Temporary<DOMTokenList> {
if self.rel_list.get().is_none() {
let element: JSRef<Element> = ElementCast::from_ref(self);
let rel_list = DOMTokenList::new(element, &atom!("rel"));
self.rel_list.assign(Some(rel_list));
}
self.rel_list.get().unwrap()
}
}

View file

@ -6,6 +6,7 @@ use dom::attr::Attr;
use dom::attr::{AttrValue, StringAttrValue}; use dom::attr::{AttrValue, StringAttrValue};
use dom::bindings::codegen::InheritTypes::ElementCast; use dom::bindings::codegen::InheritTypes::ElementCast;
use dom::bindings::codegen::InheritTypes::HTMLAnchorElementCast; use dom::bindings::codegen::InheritTypes::HTMLAnchorElementCast;
use dom::bindings::codegen::InheritTypes::HTMLAreaElementCast;
use dom::bindings::codegen::InheritTypes::HTMLBodyElementCast; use dom::bindings::codegen::InheritTypes::HTMLBodyElementCast;
use dom::bindings::codegen::InheritTypes::HTMLButtonElementCast; use dom::bindings::codegen::InheritTypes::HTMLButtonElementCast;
use dom::bindings::codegen::InheritTypes::HTMLCanvasElementCast; use dom::bindings::codegen::InheritTypes::HTMLCanvasElementCast;
@ -28,6 +29,7 @@ use dom::document::Document;
use dom::element::Element; use dom::element::Element;
use dom::element::ElementTypeId_; use dom::element::ElementTypeId_;
use dom::element::HTMLAnchorElementTypeId; use dom::element::HTMLAnchorElementTypeId;
use dom::element::HTMLAreaElementTypeId;
use dom::element::HTMLBodyElementTypeId; use dom::element::HTMLBodyElementTypeId;
use dom::element::HTMLButtonElementTypeId; use dom::element::HTMLButtonElementTypeId;
use dom::element::HTMLCanvasElementTypeId; use dom::element::HTMLCanvasElementTypeId;
@ -47,6 +49,7 @@ use dom::element::HTMLTableHeaderCellElementTypeId;
use dom::element::HTMLTextAreaElementTypeId; use dom::element::HTMLTextAreaElementTypeId;
use dom::event::Event; use dom::event::Event;
use dom::htmlanchorelement::HTMLAnchorElement; use dom::htmlanchorelement::HTMLAnchorElement;
use dom::htmlareaelement::HTMLAreaElement;
use dom::htmlbodyelement::HTMLBodyElement; use dom::htmlbodyelement::HTMLBodyElement;
use dom::htmlbuttonelement::HTMLButtonElement; use dom::htmlbuttonelement::HTMLButtonElement;
use dom::htmlcanvaselement::HTMLCanvasElement; use dom::htmlcanvaselement::HTMLCanvasElement;
@ -160,6 +163,10 @@ pub fn vtable_for<'a>(node: &'a JSRef<'a, Node>) -> &'a VirtualMethods + 'a {
let element: &'a JSRef<'a, HTMLAnchorElement> = HTMLAnchorElementCast::to_borrowed_ref(node).unwrap(); let element: &'a JSRef<'a, HTMLAnchorElement> = HTMLAnchorElementCast::to_borrowed_ref(node).unwrap();
element as &'a VirtualMethods + 'a element as &'a VirtualMethods + 'a
} }
ElementNodeTypeId(HTMLAreaElementTypeId) => {
let element: &'a JSRef<'a, HTMLAreaElement> = HTMLAreaElementCast::to_borrowed_ref(node).unwrap();
element as &'a VirtualMethods + 'a
}
ElementNodeTypeId(HTMLBodyElementTypeId) => { ElementNodeTypeId(HTMLBodyElementTypeId) => {
let element: &'a JSRef<'a, HTMLBodyElement> = HTMLBodyElementCast::to_borrowed_ref(node).unwrap(); let element: &'a JSRef<'a, HTMLBodyElement> = HTMLBodyElementCast::to_borrowed_ref(node).unwrap();
element as &'a VirtualMethods + 'a element as &'a VirtualMethods + 'a

View file

@ -17,7 +17,7 @@ interface HTMLAnchorElement : HTMLElement {
// attribute DOMString download; // attribute DOMString download;
//[PutForwards=value] attribute DOMSettableTokenList ping; //[PutForwards=value] attribute DOMSettableTokenList ping;
// attribute DOMString rel; // attribute DOMString rel;
//readonly attribute DOMTokenList relList; readonly attribute DOMTokenList relList;
// attribute DOMString hreflang; // attribute DOMString hreflang;
// attribute DOMString type; // attribute DOMString type;

View file

@ -12,7 +12,7 @@ interface HTMLAreaElement : HTMLElement {
// attribute DOMString download; // attribute DOMString download;
//[PutForwards=value] attribute DOMSettableTokenList ping; //[PutForwards=value] attribute DOMSettableTokenList ping;
// attribute DOMString rel; // attribute DOMString rel;
//readonly attribute DOMTokenList relList; readonly attribute DOMTokenList relList;
// attribute DOMString hreflang; // attribute DOMString hreflang;
// attribute DOMString type; // attribute DOMString type;

View file

@ -8,7 +8,7 @@ interface HTMLLinkElement : HTMLElement {
// attribute DOMString href; // attribute DOMString href;
// attribute DOMString crossOrigin; // attribute DOMString crossOrigin;
// attribute DOMString rel; // attribute DOMString rel;
//readonly attribute DOMTokenList relList; readonly attribute DOMTokenList relList;
// attribute DOMString media; // attribute DOMString media;
// attribute DOMString hreflang; // attribute DOMString hreflang;
// attribute DOMString type; // attribute DOMString type;

View file

@ -2418,9 +2418,6 @@
[HTMLLinkElement interface: attribute rel] [HTMLLinkElement interface: attribute rel]
expected: FAIL expected: FAIL
[HTMLLinkElement interface: attribute relList]
expected: FAIL
[HTMLLinkElement interface: attribute media] [HTMLLinkElement interface: attribute media]
expected: FAIL expected: FAIL
@ -2451,9 +2448,6 @@
[HTMLLinkElement interface: document.createElement("link") must inherit property "rel" with the proper type (2)] [HTMLLinkElement interface: document.createElement("link") must inherit property "rel" with the proper type (2)]
expected: FAIL expected: FAIL
[HTMLLinkElement interface: document.createElement("link") must inherit property "relList" with the proper type (3)]
expected: FAIL
[HTMLLinkElement interface: document.createElement("link") must inherit property "media" with the proper type (4)] [HTMLLinkElement interface: document.createElement("link") must inherit property "media" with the proper type (4)]
expected: FAIL expected: FAIL
@ -2829,9 +2823,6 @@
[HTMLAnchorElement interface: attribute rel] [HTMLAnchorElement interface: attribute rel]
expected: FAIL expected: FAIL
[HTMLAnchorElement interface: attribute relList]
expected: FAIL
[HTMLAnchorElement interface: attribute hreflang] [HTMLAnchorElement interface: attribute hreflang]
expected: FAIL expected: FAIL
@ -2865,9 +2856,6 @@
[HTMLAnchorElement interface: document.createElement("a") must inherit property "rel" with the proper type (3)] [HTMLAnchorElement interface: document.createElement("a") must inherit property "rel" with the proper type (3)]
expected: FAIL expected: FAIL
[HTMLAnchorElement interface: document.createElement("a") must inherit property "relList" with the proper type (4)]
expected: FAIL
[HTMLAnchorElement interface: document.createElement("a") must inherit property "hreflang" with the proper type (5)] [HTMLAnchorElement interface: document.createElement("a") must inherit property "hreflang" with the proper type (5)]
expected: FAIL expected: FAIL
@ -4884,9 +4872,6 @@
[HTMLAreaElement interface: attribute rel] [HTMLAreaElement interface: attribute rel]
expected: FAIL expected: FAIL
[HTMLAreaElement interface: attribute relList]
expected: FAIL
[HTMLAreaElement interface: attribute hreflang] [HTMLAreaElement interface: attribute hreflang]
expected: FAIL expected: FAIL
@ -4917,9 +4902,6 @@
[HTMLAreaElement interface: document.createElement("area") must inherit property "rel" with the proper type (6)] [HTMLAreaElement interface: document.createElement("area") must inherit property "rel" with the proper type (6)]
expected: FAIL expected: FAIL
[HTMLAreaElement interface: document.createElement("area") must inherit property "relList" with the proper type (7)]
expected: FAIL
[HTMLAreaElement interface: document.createElement("area") must inherit property "hreflang" with the proper type (8)] [HTMLAreaElement interface: document.createElement("area") must inherit property "hreflang" with the proper type (8)]
expected: FAIL expected: FAIL

View file

@ -1,5 +0,0 @@
[link-rellist.html]
type: testharness
[link.relList: non-string contains]
expected: FAIL