Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -2,28 +2,33 @@
* 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::attr::AttrValue;
use dom::bindings::codegen::Bindings::AttrBinding::AttrMethods;
use dom::bindings::codegen::Bindings::EventBinding::EventMethods;
use dom::bindings::codegen::Bindings::HTMLAnchorElementBinding;
use dom::bindings::codegen::Bindings::HTMLAnchorElementBinding::HTMLAnchorElementMethods;
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
use dom::bindings::codegen::InheritTypes::HTMLAnchorElementDerived;
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::document::{Document, DocumentHelpers};
use dom::domtokenlist::DOMTokenList;
use dom::element::{Element, AttributeHandlers, HTMLAnchorElementTypeId};
use dom::event::Event;
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
use dom::htmlelement::HTMLElement;
use dom::node::{Node, NodeHelpers, ElementNodeTypeId};
use dom::virtualmethods::VirtualMethods;

use std::default::Default;
use string_cache::Atom;
use servo_util::str::DOMString;

#[dom_struct]
pub struct HTMLAnchorElement {
htmlelement: HTMLElement
htmlelement: HTMLElement,
rel_list: MutNullableJS<DOMTokenList>,
}

impl HTMLAnchorElementDerived for EventTarget {
@@ -35,7 +40,8 @@ impl HTMLAnchorElementDerived for EventTarget {
impl HTMLAnchorElement {
fn new_inherited(localName: DOMString, prefix: Option<DOMString>, document: JSRef<Document>) -> 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,14 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLAnchorElement> {
}
self.handle_event_impl(event);
}

fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue {
match name {
&atom!("id") => AttrValue::from_atomic(value),
&atom!("rel") => AttrValue::from_tokenlist(value),
_ => self.super_type().unwrap().parse_plain_attribute(name, value),
}
}
}

impl Reflectable for HTMLAnchorElement {
@@ -102,4 +116,13 @@ impl<'a> HTMLAnchorElementMethods for JSRef<'a, HTMLAnchorElement> {
let node: JSRef<Node> = NodeCast::from_ref(self);
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()
}
}
@@ -2,23 +2,32 @@
* 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::attr::AttrValue;
use dom::bindings::codegen::Bindings::HTMLAreaElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLAreaElementDerived;
use dom::bindings::js::{JSRef, Temporary};
use dom::bindings::codegen::Bindings::HTMLAreaElementBinding::HTMLAreaElementMethods;
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::document::Document;
use dom::domtokenlist::DOMTokenList;
use dom::element::Element;
use dom::element::HTMLAreaElementTypeId;
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
use dom::htmlelement::HTMLElement;
use dom::node::{Node, NodeHelpers, ElementNodeTypeId};
use dom::virtualmethods::VirtualMethods;

use std::default::Default;
use string_cache::Atom;
use servo_util::str::DOMString;

#[jstraceable]
#[must_root]
#[privatize]
pub struct HTMLAreaElement {
htmlelement: HTMLElement
htmlelement: HTMLElement,
rel_list: MutNullableJS<DOMTokenList>,
}

impl HTMLAreaElementDerived for EventTarget {
@@ -30,7 +39,8 @@ impl HTMLAreaElementDerived for EventTarget {
impl HTMLAreaElement {
fn new_inherited(localName: DOMString, prefix: Option<DOMString>, document: JSRef<Document>) -> 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,34 @@ 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!("id") => AttrValue::from_atomic(value),
&atom!("rel") => AttrValue::from_tokenlist(value),
_ => self.super_type().unwrap().parse_plain_attribute(name, value),
}
}
}

impl Reflectable for HTMLAreaElement {
fn reflector<'a>(&'a self) -> &'a 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()
}
}
@@ -2,14 +2,16 @@
* 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::attr::Attr;
use dom::attr::{Attr, AttrValue};
use dom::attr::AttrHelpers;
use dom::bindings::codegen::Bindings::HTMLLinkElementBinding;
use dom::bindings::codegen::Bindings::HTMLLinkElementBinding::HTMLLinkElementMethods;
use dom::bindings::codegen::InheritTypes::HTMLLinkElementDerived;
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::document::Document;
use dom::domtokenlist::DOMTokenList;
use dom::element::{AttributeHandlers, Element, HTMLLinkElementTypeId};
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
use dom::htmlelement::HTMLElement;
@@ -19,12 +21,15 @@ use layout_interface::{LayoutChan, LoadStylesheetMsg};
use servo_util::str::{DOMString, HTML_SPACE_CHARACTERS};

use std::ascii::AsciiExt;
use std::default::Default;
use url::UrlParser;
use string_cache::Atom;

#[dom_struct]
pub struct HTMLLinkElement {
htmlelement: HTMLElement,
rel_list: MutNullableJS<DOMTokenList>,

}

impl HTMLLinkElementDerived for EventTarget {
@@ -36,7 +41,8 @@ impl HTMLLinkElementDerived for EventTarget {
impl HTMLLinkElement {
fn new_inherited(localName: DOMString, prefix: Option<DOMString>, document: JSRef<Document>) -> HTMLLinkElement {
HTMLLinkElement {
htmlelement: HTMLElement::new_inherited(HTMLLinkElementTypeId, localName, prefix, document)
htmlelement: HTMLElement::new_inherited(HTMLLinkElementTypeId, localName, prefix, document),
rel_list: Default::default(),
}
}

@@ -87,6 +93,14 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLLinkElement> {
}
}

fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue {
match name {
&atom!("id") => AttrValue::from_atomic(value),
&atom!("rel") => AttrValue::from_tokenlist(value),
_ => self.super_type().unwrap().parse_plain_attribute(name, value),
}
}

fn bind_to_tree(&self, tree_in_doc: bool) {
match self.super_type() {
Some(ref s) => s.bind_to_tree(tree_in_doc),
@@ -132,3 +146,14 @@ 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()
}
}

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

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

@@ -8,7 +8,7 @@ interface HTMLLinkElement : HTMLElement {
// attribute DOMString href;
// attribute DOMString crossOrigin;
// attribute DOMString rel;
//readonly attribute DOMTokenList relList;
readonly attribute DOMTokenList relList;
// attribute DOMString media;
// attribute DOMString hreflang;
// attribute DOMString type;
@@ -2418,9 +2418,6 @@
[HTMLLinkElement interface: attribute rel]
expected: FAIL
[HTMLLinkElement interface: attribute relList]
expected: FAIL
[HTMLLinkElement interface: attribute media]
expected: FAIL
@@ -2451,9 +2448,6 @@
[HTMLLinkElement interface: document.createElement("link") must inherit property "rel" with the proper type (2)]
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)]
expected: FAIL
@@ -2829,9 +2823,6 @@
[HTMLAnchorElement interface: attribute rel]
expected: FAIL
[HTMLAnchorElement interface: attribute relList]
expected: FAIL
[HTMLAnchorElement interface: attribute hreflang]
expected: FAIL
@@ -2865,9 +2856,6 @@
[HTMLAnchorElement interface: document.createElement("a") must inherit property "rel" with the proper type (3)]
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)]
expected: FAIL
@@ -4884,9 +4872,6 @@
[HTMLAreaElement interface: attribute rel]
expected: FAIL
[HTMLAreaElement interface: attribute relList]
expected: FAIL
[HTMLAreaElement interface: attribute hreflang]
expected: FAIL
@@ -4917,9 +4902,6 @@
[HTMLAreaElement interface: document.createElement("area") must inherit property "rel" with the proper type (6)]
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)]
expected: FAIL

This file was deleted.

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.