Remove abstract_self.

This commit is contained in:
Josh Matthews 2014-04-10 22:13:08 -04:00
parent 76783b029e
commit 7daa97c7e5
19 changed files with 483 additions and 610 deletions

View file

@ -9,8 +9,6 @@
# The configuration table maps each interface name to a |descriptor|. # The configuration table maps each interface name to a |descriptor|.
# #
# Valid fields for all descriptors: # Valid fields for all descriptors:
# * needsAbstract: a list of members that require a JS<>-wrapped version of
# self to be passed to the native code.
# * createGlobal: True for global objects. # * createGlobal: True for global objects.
# * outerObjectHook: string to use in place of default value for outerObject and thisObject # * outerObjectHook: string to use in place of default value for outerObject and thisObject
# JS class hooks # JS class hooks
@ -26,123 +24,46 @@ DOMInterfaces = {
'ClientRect': {}, 'ClientRect': {},
'ClientRectList': {}, 'ClientRectList': {},
'Console': {}, 'Console': {},
'Document': { 'Document': {},
'needsAbstract': [
'adoptNode',
'anchors',
'applets',
'body',
'children',
'createComment',
'createDocumentFragment',
'createElement',
'createElementNS',
'createProcessingInstruction',
'createTextNode',
'embeds',
'forms',
'getElementsByClassName',
'getElementsByTagName',
'getElementsByTagNameNS',
'images',
'importNode',
'links',
'location',
'plugins',
'scripts',
'title',
],
},
'DOMException': {}, 'DOMException': {},
'DOMImplementation': {}, 'DOMImplementation': {},
'DOMParser': {}, 'DOMParser': {},
'Element': { 'Element': {},
'needsAbstract': [
'attributes',
'children',
'className',
'getAttribute',
'getAttributeNS',
'getBoundingClientRect',
'getClientRects',
'getElementsByClassName',
'getElementsByTagName',
'getElementsByTagNameNS',
'hasAttribute',
'hasAttributeNS',
'id',
'innerHTML',
'outerHTML',
'removeAttribute',
'removeAttributeNS',
'setAttribute',
'setAttributeNS',
]
},
'Event': {}, 'Event': {},
'EventListener': { 'EventListener': {
'nativeType': 'EventListenerBinding::EventListener', 'nativeType': 'EventListenerBinding::EventListener',
}, },
'EventTarget': { 'EventTarget': {},
'needsAbstract': ['dispatchEvent']
},
'FormData': {}, 'FormData': {},
'HTMLCollection': {}, 'HTMLCollection': {},
'Location': {}, 'Location': {},
'MouseEvent': {}, 'MouseEvent': {},
'Navigator': {}, 'Navigator': {},
'Node': { 'Node': {},
'needsAbstract': [
'appendChild',
'childNodes',
'cloneNode',
'compareDocumentPosition',
'contains',
'insertBefore',
'isEqualNode',
'namespaceURI',
'nodeName',
'nodeValue',
'normalize',
'removeChild',
'replaceChild',
'textContent',
]
},
'NodeList': {}, 'NodeList': {},
'UIEvent': {}, 'UIEvent': {},
'ValidityState': {}, 'ValidityState': {},
'Window': { 'Window': {
'createGlobal': True, 'createGlobal': True,
'outerObjectHook': 'Some(bindings::utils::outerize_global)', 'outerObjectHook': 'Some(bindings::utils::outerize_global)',
'needsAbstract': [
'console',
'location',
'navigator',
'self',
'window',
],
}, },
'XMLHttpRequest': {}, 'XMLHttpRequest': {},
'XMLHttpRequestEventTarget': {}, 'XMLHttpRequestEventTarget': {},
'XMLHttpRequestUpload': {}, 'XMLHttpRequestUpload': {},
#FIXME(jdm): This should be 'register': False, but then we don't generate enum types
'TestBinding': {}, 'TestBinding': {},
} }
# FIXME: This should be renamed: https://github.com/mozilla/servo/issues/1625 # FIXME: This should be renamed: https://github.com/mozilla/servo/issues/1625
def addHTMLElement(element, concrete=None, needsAbstract=[]): def addHTMLElement(element):
DOMInterfaces[element] = { DOMInterfaces[element] = {
'nativeType': 'JS<%s>' % element, 'nativeType': 'JS<%s>' % element,
'concreteType': concrete if concrete else element,
'needsAbstract': needsAbstract
} }
addHTMLElement('Comment') addHTMLElement('Comment')
addHTMLElement('DocumentFragment', concrete='DocumentFragment', needsAbstract=['children']) addHTMLElement('DocumentFragment')
addHTMLElement('DocumentType') addHTMLElement('DocumentType')
addHTMLElement('Text') addHTMLElement('Text')
addHTMLElement('ProcessingInstruction') addHTMLElement('ProcessingInstruction')
@ -158,12 +79,12 @@ addHTMLElement('HTMLBRElement')
addHTMLElement('HTMLCanvasElement') addHTMLElement('HTMLCanvasElement')
addHTMLElement('HTMLDataElement') addHTMLElement('HTMLDataElement')
addHTMLElement('HTMLDivElement') addHTMLElement('HTMLDivElement')
addHTMLElement('HTMLDataListElement', needsAbstract=['options']) addHTMLElement('HTMLDataListElement')
addHTMLElement('HTMLDirectoryElement') addHTMLElement('HTMLDirectoryElement')
addHTMLElement('HTMLDListElement') addHTMLElement('HTMLDListElement')
addHTMLElement('HTMLElement') addHTMLElement('HTMLElement')
addHTMLElement('HTMLEmbedElement') addHTMLElement('HTMLEmbedElement')
addHTMLElement('HTMLFieldSetElement', needsAbstract=['elements']) addHTMLElement('HTMLFieldSetElement')
addHTMLElement('HTMLFontElement') addHTMLElement('HTMLFontElement')
addHTMLElement('HTMLFormElement') addHTMLElement('HTMLFormElement')
addHTMLElement('HTMLFrameElement') addHTMLElement('HTMLFrameElement')
@ -172,8 +93,8 @@ addHTMLElement('HTMLHeadElement')
addHTMLElement('HTMLHeadingElement') addHTMLElement('HTMLHeadingElement')
addHTMLElement('HTMLHtmlElement') addHTMLElement('HTMLHtmlElement')
addHTMLElement('HTMLHRElement') addHTMLElement('HTMLHRElement')
addHTMLElement('HTMLIFrameElement', needsAbstract=['sandbox']) addHTMLElement('HTMLIFrameElement')
addHTMLElement('HTMLImageElement', needsAbstract=['alt', 'src', 'useMap', 'isMap', 'width', 'height', 'name', 'align', 'hspace', 'vspace', 'longDesc', 'border']) addHTMLElement('HTMLImageElement')
addHTMLElement('HTMLInputElement') addHTMLElement('HTMLInputElement')
addHTMLElement('HTMLLabelElement') addHTMLElement('HTMLLabelElement')
addHTMLElement('HTMLLegendElement') addHTMLElement('HTMLLegendElement')
@ -195,7 +116,7 @@ addHTMLElement('HTMLParamElement')
addHTMLElement('HTMLPreElement') addHTMLElement('HTMLPreElement')
addHTMLElement('HTMLProgressElement') addHTMLElement('HTMLProgressElement')
addHTMLElement('HTMLQuoteElement') addHTMLElement('HTMLQuoteElement')
addHTMLElement('HTMLScriptElement', needsAbstract=['src']) addHTMLElement('HTMLScriptElement')
addHTMLElement('HTMLSelectElement') addHTMLElement('HTMLSelectElement')
addHTMLElement('HTMLSourceElement') addHTMLElement('HTMLSourceElement')
addHTMLElement('HTMLSpanElement') addHTMLElement('HTMLSpanElement')

View file

@ -2494,12 +2494,6 @@ class CGSpecializedMethod(CGAbstractExternMethod):
nativeName = MakeNativeName(name) nativeName = MakeNativeName(name)
extraPre = '' extraPre = ''
argsPre = [] argsPre = []
if name in self.descriptor.needsAbstract:
abstractName = re.sub(r'<\w+>', '', self.descriptor.nativeType)
extraPre = """ let mut abstract_this = %s::from_raw(this);
let abstract_this = abstract_this.root(&roots);
""" % abstractName
argsPre = ['&mut abstract_this.root_ref()']
return CGWrapper(CGMethodCall(argsPre, nativeName, self.method.isStatic(), return CGWrapper(CGMethodCall(argsPre, nativeName, self.method.isStatic(),
self.descriptor, self.method), self.descriptor, self.method),
pre=extraPre + pre=extraPre +
@ -2552,12 +2546,6 @@ class CGSpecializedGetter(CGAbstractExternMethod):
infallible = ('infallible' in infallible = ('infallible' in
self.descriptor.getExtendedAttributes(self.attr, self.descriptor.getExtendedAttributes(self.attr,
getter=True)) getter=True))
if name in self.descriptor.needsAbstract:
abstractName = re.sub(r'<\w+>', '', self.descriptor.nativeType)
extraPre = """ let mut abstract_this = %s::from_raw(this);
let abstract_this = abstract_this.root(&roots);
""" % abstractName
argsPre = ['&mut abstract_this.root_ref()']
if self.attr.type.nullable() or not infallible: if self.attr.type.nullable() or not infallible:
nativeName = "Get" + nativeName nativeName = "Get" + nativeName
return CGWrapper(CGIndenter(CGGetterCall(argsPre, self.attr.type, nativeName, return CGWrapper(CGIndenter(CGGetterCall(argsPre, self.attr.type, nativeName,
@ -2614,12 +2602,6 @@ class CGSpecializedSetter(CGAbstractExternMethod):
nativeName = "Set" + MakeNativeName(name) nativeName = "Set" + MakeNativeName(name)
argsPre = [] argsPre = []
extraPre = '' extraPre = ''
if name in self.descriptor.needsAbstract:
abstractName = re.sub(r'<\w+>', '', self.descriptor.nativeType)
extraPre = """ let mut abstract_this = %s::from_raw(this);
let abstract_this = abstract_this.root(&roots);
""" % abstractName
argsPre = ['&mut abstract_this.root_ref()']
return CGWrapper(CGIndenter(CGSetterCall(argsPre, self.attr.type, nativeName, return CGWrapper(CGIndenter(CGSetterCall(argsPre, self.attr.type, nativeName,
self.descriptor, self.attr)), self.descriptor, self.attr)),
pre=extraPre + pre=extraPre +

View file

@ -136,7 +136,6 @@ class Descriptor(DescriptorProvider):
self.returnType = "Unrooted<%s>" % ifaceName self.returnType = "Unrooted<%s>" % ifaceName
self.nativeType = desc.get('nativeType', nativeTypeDefault) self.nativeType = desc.get('nativeType', nativeTypeDefault)
self.concreteType = desc.get('concreteType', ifaceName) self.concreteType = desc.get('concreteType', ifaceName)
self.needsAbstract = desc.get('needsAbstract', [])
self.createGlobal = desc.get('createGlobal', False) self.createGlobal = desc.get('createGlobal', False)
self.register = desc.get('register', True) self.register = desc.get('register', True)
self.outerObjectHook = desc.get('outerObjectHook', 'None') self.outerObjectHook = desc.get('outerObjectHook', 'None')

View file

@ -27,8 +27,8 @@ use dom::htmlheadelement::HTMLHeadElement;
use dom::htmlhtmlelement::HTMLHtmlElement; use dom::htmlhtmlelement::HTMLHtmlElement;
use dom::htmltitleelement::HTMLTitleElement; use dom::htmltitleelement::HTMLTitleElement;
use dom::mouseevent::MouseEvent; use dom::mouseevent::MouseEvent;
use dom::node::{Node, ElementNodeTypeId, DocumentNodeTypeId, NodeHelpers, AppendChild}; use dom::node::{Node, ElementNodeTypeId, DocumentNodeTypeId, NodeHelpers, NodeMethods};
use dom::node::{CloneChildren, DoNotCloneChildren, RemoveChild, ReplaceChild}; use dom::node::{CloneChildren, DoNotCloneChildren};
use dom::nodelist::NodeList; use dom::nodelist::NodeList;
use dom::text::Text; use dom::text::Text;
use dom::processinginstruction::ProcessingInstruction; use dom::processinginstruction::ProcessingInstruction;
@ -165,7 +165,7 @@ impl Document {
/// Remove any existing association between the provided id and any elements in this document. /// Remove any existing association between the provided id and any elements in this document.
pub fn unregister_named_element(&mut self, pub fn unregister_named_element(&mut self,
abstract_self: &JSRef<Element>, to_unregister: &JSRef<Element>,
id: DOMString) { id: DOMString) {
let roots = RootCollection::new(); let roots = RootCollection::new();
let mut is_empty = false; let mut is_empty = false;
@ -174,7 +174,7 @@ impl Document {
Some(elements) => { Some(elements) => {
let position = elements.iter() let position = elements.iter()
.map(|elem| elem.root(&roots)) .map(|elem| elem.root(&roots))
.position(|element| &*element == abstract_self) .position(|element| &*element == to_unregister)
.expect("This element should be in registered."); .expect("This element should be in registered.");
elements.remove(position); elements.remove(position);
is_empty = elements.is_empty(); is_empty = elements.is_empty();
@ -282,37 +282,35 @@ pub trait DocumentMethods {
fn ContentType(&self) -> DOMString; fn ContentType(&self) -> DOMString;
fn GetDoctype(&self) -> Option<Unrooted<DocumentType>>; fn GetDoctype(&self) -> Option<Unrooted<DocumentType>>;
fn GetDocumentElement(&self) -> Option<Unrooted<Element>>; fn GetDocumentElement(&self) -> Option<Unrooted<Element>>;
fn GetElementsByTagName(&self, abstract_self: &JSRef<Document>, tag_name: DOMString) -> Unrooted<HTMLCollection>; fn GetElementsByTagName(&self, tag_name: DOMString) -> Unrooted<HTMLCollection>;
fn GetElementsByTagNameNS(&self, abstract_self: &JSRef<Document>, maybe_ns: Option<DOMString>, tag_name: DOMString) -> Unrooted<HTMLCollection>; fn GetElementsByTagNameNS(&self, maybe_ns: Option<DOMString>, tag_name: DOMString) -> Unrooted<HTMLCollection>;
fn GetElementsByClassName(&self, abstract_self: &JSRef<Document>, classes: DOMString) -> Unrooted<HTMLCollection>; fn GetElementsByClassName(&self, classes: DOMString) -> Unrooted<HTMLCollection>;
fn GetElementById(&self, id: DOMString) -> Option<Unrooted<Element>>; fn GetElementById(&self, id: DOMString) -> Option<Unrooted<Element>>;
fn CreateElement(&self, abstract_self: &JSRef<Document>, local_name: DOMString) -> Fallible<Unrooted<Element>>; fn CreateElement(&self, local_name: DOMString) -> Fallible<Unrooted<Element>>;
fn CreateElementNS(&self, abstract_self: &JSRef<Document>, fn CreateElementNS(&self, namespace: Option<DOMString>, qualified_name: DOMString) -> Fallible<Unrooted<Element>>;
namespace: Option<DOMString>, fn CreateDocumentFragment(&self) -> Unrooted<DocumentFragment>;
qualified_name: DOMString) -> Fallible<Unrooted<Element>>; fn CreateTextNode(&self, data: DOMString) -> Unrooted<Text>;
fn CreateDocumentFragment(&self, abstract_self: &JSRef<Document>) -> Unrooted<DocumentFragment>; fn CreateComment(&self, data: DOMString) -> Unrooted<Comment>;
fn CreateTextNode(&self, abstract_self: &JSRef<Document>, data: DOMString) -> Unrooted<Text>; fn CreateProcessingInstruction(&self, target: DOMString, data: DOMString) -> Fallible<Unrooted<ProcessingInstruction>>;
fn CreateComment(&self, abstract_self: &JSRef<Document>, data: DOMString) -> Unrooted<Comment>; fn ImportNode(&self, node: &JSRef<Node>, deep: bool) -> Fallible<Unrooted<Node>>;
fn CreateProcessingInstruction(&self, abstract_self: &JSRef<Document>, target: DOMString, data: DOMString) -> Fallible<Unrooted<ProcessingInstruction>>; fn AdoptNode(&self, node: &mut JSRef<Node>) -> Fallible<Unrooted<Node>>;
fn ImportNode(&self, abstract_self: &JSRef<Document>, node: &JSRef<Node>, deep: bool) -> Fallible<Unrooted<Node>>;
fn AdoptNode(&self, abstract_self: &JSRef<Document>, node: &mut JSRef<Node>) -> Fallible<Unrooted<Node>>;
fn CreateEvent(&self, interface: DOMString) -> Fallible<Unrooted<Event>>; fn CreateEvent(&self, interface: DOMString) -> Fallible<Unrooted<Event>>;
fn Title(&self, _: &JSRef<Document>) -> DOMString; fn Title(&self) -> DOMString;
fn SetTitle(&self, abstract_self: &JSRef<Document>, title: DOMString) -> ErrorResult; fn SetTitle(&self, title: DOMString) -> ErrorResult;
fn GetHead(&self) -> Option<Unrooted<HTMLHeadElement>>; fn GetHead(&self) -> Option<Unrooted<HTMLHeadElement>>;
fn GetBody(&self, _: &JSRef<Document>) -> Option<Unrooted<HTMLElement>>; fn GetBody(&self) -> Option<Unrooted<HTMLElement>>;
fn SetBody(&self, abstract_self: &JSRef<Document>, new_body: Option<JSRef<HTMLElement>>) -> ErrorResult; fn SetBody(&self, new_body: Option<JSRef<HTMLElement>>) -> ErrorResult;
fn GetElementsByName(&self, name: DOMString) -> Unrooted<NodeList>; fn GetElementsByName(&self, name: DOMString) -> Unrooted<NodeList>;
fn Images(&self, abstract_self: &JSRef<Document>) -> Unrooted<HTMLCollection>; fn Images(&self) -> Unrooted<HTMLCollection>;
fn Embeds(&self, abstract_self: &JSRef<Document>) -> Unrooted<HTMLCollection>; fn Embeds(&self) -> Unrooted<HTMLCollection>;
fn Plugins(&self, abstract_self: &JSRef<Document>) -> Unrooted<HTMLCollection>; fn Plugins(&self) -> Unrooted<HTMLCollection>;
fn Links(&self, abstract_self: &JSRef<Document>) -> Unrooted<HTMLCollection>; fn Links(&self) -> Unrooted<HTMLCollection>;
fn Forms(&self, abstract_self: &JSRef<Document>) -> Unrooted<HTMLCollection>; fn Forms(&self) -> Unrooted<HTMLCollection>;
fn Scripts(&self, abstract_self: &JSRef<Document>) -> Unrooted<HTMLCollection>; fn Scripts(&self) -> Unrooted<HTMLCollection>;
fn Anchors(&self, abstract_self: &JSRef<Document>) -> Unrooted<HTMLCollection>; fn Anchors(&self) -> Unrooted<HTMLCollection>;
fn Applets(&self, abstract_self: &JSRef<Document>) -> Unrooted<HTMLCollection>; fn Applets(&self) -> Unrooted<HTMLCollection>;
fn Location(&mut self, _abstract_self: &JSRef<Document>) -> Unrooted<Location>; fn Location(&mut self) -> Unrooted<Location>;
fn Children(&self, abstract_self: &JSRef<Document>) -> Unrooted<HTMLCollection>; fn Children(&self) -> Unrooted<HTMLCollection>;
} }
impl<'a> DocumentMethods for JSRef<'a, Document> { impl<'a> DocumentMethods for JSRef<'a, Document> {
@ -370,14 +368,14 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
} }
// http://dom.spec.whatwg.org/#dom-document-getelementsbytagname // http://dom.spec.whatwg.org/#dom-document-getelementsbytagname
fn GetElementsByTagName(&self, abstract_self: &JSRef<Document>, tag_name: DOMString) -> Unrooted<HTMLCollection> { fn GetElementsByTagName(&self, tag_name: DOMString) -> Unrooted<HTMLCollection> {
let roots = RootCollection::new(); let roots = RootCollection::new();
let window = self.window.root(&roots); let window = self.window.root(&roots);
HTMLCollection::by_tag_name(&*window, NodeCast::from_ref(abstract_self), tag_name) HTMLCollection::by_tag_name(&*window, NodeCast::from_ref(self), tag_name)
} }
// http://dom.spec.whatwg.org/#dom-document-getelementsbytagnamens // http://dom.spec.whatwg.org/#dom-document-getelementsbytagnamens
fn GetElementsByTagNameNS(&self, abstract_self: &JSRef<Document>, maybe_ns: Option<DOMString>, tag_name: DOMString) -> Unrooted<HTMLCollection> { fn GetElementsByTagNameNS(&self, maybe_ns: Option<DOMString>, tag_name: DOMString) -> Unrooted<HTMLCollection> {
let roots = RootCollection::new(); let roots = RootCollection::new();
let window = self.window.root(&roots); let window = self.window.root(&roots);
@ -385,15 +383,15 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
Some(namespace) => Namespace::from_str(namespace), Some(namespace) => Namespace::from_str(namespace),
None => Null None => Null
}; };
HTMLCollection::by_tag_name_ns(&*window, NodeCast::from_ref(abstract_self), tag_name, namespace) HTMLCollection::by_tag_name_ns(&*window, NodeCast::from_ref(self), tag_name, namespace)
} }
// http://dom.spec.whatwg.org/#dom-document-getelementsbyclassname // http://dom.spec.whatwg.org/#dom-document-getelementsbyclassname
fn GetElementsByClassName(&self, abstract_self: &JSRef<Document>, classes: DOMString) -> Unrooted<HTMLCollection> { fn GetElementsByClassName(&self, classes: DOMString) -> Unrooted<HTMLCollection> {
let roots = RootCollection::new(); let roots = RootCollection::new();
let window = self.window.root(&roots); let window = self.window.root(&roots);
HTMLCollection::by_class_name(&*window, NodeCast::from_ref(abstract_self), classes) HTMLCollection::by_class_name(&*window, NodeCast::from_ref(self), classes)
} }
// http://dom.spec.whatwg.org/#dom-nonelementparentnode-getelementbyid // http://dom.spec.whatwg.org/#dom-nonelementparentnode-getelementbyid
@ -405,18 +403,17 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
} }
// http://dom.spec.whatwg.org/#dom-document-createelement // http://dom.spec.whatwg.org/#dom-document-createelement
fn CreateElement(&self, abstract_self: &JSRef<Document>, local_name: DOMString) fn CreateElement(&self, local_name: DOMString) -> Fallible<Unrooted<Element>> {
-> Fallible<Unrooted<Element>> {
if xml_name_type(local_name) == InvalidXMLName { if xml_name_type(local_name) == InvalidXMLName {
debug!("Not a valid element name"); debug!("Not a valid element name");
return Err(InvalidCharacter); return Err(InvalidCharacter);
} }
let local_name = local_name.to_ascii_lower(); let local_name = local_name.to_ascii_lower();
Ok(build_element_from_tag(local_name, abstract_self)) Ok(build_element_from_tag(local_name, self))
} }
// http://dom.spec.whatwg.org/#dom-document-createelementns // http://dom.spec.whatwg.org/#dom-document-createelementns
fn CreateElementNS(&self, abstract_self: &JSRef<Document>, fn CreateElementNS(&self,
namespace: Option<DOMString>, namespace: Option<DOMString>,
qualified_name: DOMString) -> Fallible<Unrooted<Element>> { qualified_name: DOMString) -> Fallible<Unrooted<Element>> {
let ns = Namespace::from_str(null_str_as_empty_ref(&namespace)); let ns = Namespace::from_str(null_str_as_empty_ref(&namespace));
@ -455,30 +452,30 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
} }
if ns == namespace::HTML { if ns == namespace::HTML {
Ok(build_element_from_tag(local_name_from_qname, abstract_self)) Ok(build_element_from_tag(local_name_from_qname, self))
} else { } else {
Ok(Element::new(local_name_from_qname, ns, prefix_from_qname, abstract_self)) Ok(Element::new(local_name_from_qname, ns, prefix_from_qname, self))
} }
} }
// http://dom.spec.whatwg.org/#dom-document-createdocumentfragment // http://dom.spec.whatwg.org/#dom-document-createdocumentfragment
fn CreateDocumentFragment(&self, abstract_self: &JSRef<Document>) -> Unrooted<DocumentFragment> { fn CreateDocumentFragment(&self) -> Unrooted<DocumentFragment> {
DocumentFragment::new(abstract_self) DocumentFragment::new(self)
} }
// http://dom.spec.whatwg.org/#dom-document-createtextnode // http://dom.spec.whatwg.org/#dom-document-createtextnode
fn CreateTextNode(&self, abstract_self: &JSRef<Document>, data: DOMString) fn CreateTextNode(&self, data: DOMString)
-> Unrooted<Text> { -> Unrooted<Text> {
Text::new(data, abstract_self) Text::new(data, self)
} }
// http://dom.spec.whatwg.org/#dom-document-createcomment // http://dom.spec.whatwg.org/#dom-document-createcomment
fn CreateComment(&self, abstract_self: &JSRef<Document>, data: DOMString) -> Unrooted<Comment> { fn CreateComment(&self, data: DOMString) -> Unrooted<Comment> {
Comment::new(data, abstract_self) Comment::new(data, self)
} }
// http://dom.spec.whatwg.org/#dom-document-createprocessinginstruction // http://dom.spec.whatwg.org/#dom-document-createprocessinginstruction
fn CreateProcessingInstruction(&self, abstract_self: &JSRef<Document>, target: DOMString, fn CreateProcessingInstruction(&self, target: DOMString,
data: DOMString) -> Fallible<Unrooted<ProcessingInstruction>> { data: DOMString) -> Fallible<Unrooted<ProcessingInstruction>> {
// Step 1. // Step 1.
if xml_name_type(target) == InvalidXMLName { if xml_name_type(target) == InvalidXMLName {
@ -491,11 +488,11 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
} }
// Step 3. // Step 3.
Ok(ProcessingInstruction::new(target, data, abstract_self)) Ok(ProcessingInstruction::new(target, data, self))
} }
// http://dom.spec.whatwg.org/#dom-document-importnode // http://dom.spec.whatwg.org/#dom-document-importnode
fn ImportNode(&self, abstract_self: &JSRef<Document>, node: &JSRef<Node>, deep: bool) -> Fallible<Unrooted<Node>> { fn ImportNode(&self, node: &JSRef<Node>, deep: bool) -> Fallible<Unrooted<Node>> {
// Step 1. // Step 1.
if node.is_document() { if node.is_document() {
return Err(NotSupported); return Err(NotSupported);
@ -507,18 +504,18 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
false => DoNotCloneChildren false => DoNotCloneChildren
}; };
Ok(Node::clone(node, Some(abstract_self), clone_children)) Ok(Node::clone(node, Some(self), clone_children))
} }
// http://dom.spec.whatwg.org/#dom-document-adoptnode // http://dom.spec.whatwg.org/#dom-document-adoptnode
fn AdoptNode(&self, abstract_self: &JSRef<Document>, node: &mut JSRef<Node>) -> Fallible<Unrooted<Node>> { fn AdoptNode(&self, node: &mut JSRef<Node>) -> Fallible<Unrooted<Node>> {
// Step 1. // Step 1.
if node.is_document() { if node.is_document() {
return Err(NotSupported); return Err(NotSupported);
} }
// Step 2. // Step 2.
Node::adopt(node, abstract_self); Node::adopt(node, self);
// Step 3. // Step 3.
Ok(Unrooted::new_rooted(node)) Ok(Unrooted::new_rooted(node))
@ -539,7 +536,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
} }
// http://www.whatwg.org/specs/web-apps/current-work/#document.title // http://www.whatwg.org/specs/web-apps/current-work/#document.title
fn Title(&self, _: &JSRef<Document>) -> DOMString { fn Title(&self) -> DOMString {
let mut title = ~""; let mut title = ~"";
let roots = RootCollection::new(); let roots = RootCollection::new();
self.GetDocumentElement().root(&roots).map(|root| { self.GetDocumentElement().root(&roots).map(|root| {
@ -561,7 +558,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
} }
// http://www.whatwg.org/specs/web-apps/current-work/#document.title // http://www.whatwg.org/specs/web-apps/current-work/#document.title
fn SetTitle(&self, abstract_self: &JSRef<Document>, title: DOMString) -> ErrorResult { fn SetTitle(&self, title: DOMString) -> ErrorResult {
let roots = RootCollection::new(); let roots = RootCollection::new();
self.GetDocumentElement().root(&roots).map(|root| { self.GetDocumentElement().root(&roots).map(|root| {
@ -577,20 +574,20 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
match title_node { match title_node {
Some(ref mut title_node) => { Some(ref mut title_node) => {
for mut title_child in title_node.children() { for mut title_child in title_node.children() {
assert!(RemoveChild(&mut *title_node, &mut title_child).is_ok()); assert!(title_node.RemoveChild(&mut title_child).is_ok());
} }
let mut new_text = self.CreateTextNode(abstract_self, title.clone()).root(&roots); let mut new_text = self.CreateTextNode(title.clone()).root(&roots);
assert!(AppendChild(&mut *title_node, NodeCast::from_mut_ref(&mut *new_text)).is_ok()); assert!(title_node.AppendChild(NodeCast::from_mut_ref(&mut *new_text)).is_ok());
}, },
None => { None => {
let mut new_title = HTMLTitleElement::new(~"title", abstract_self).root(&roots); let mut new_title = HTMLTitleElement::new(~"title", self).root(&roots);
let new_title: &mut JSRef<Node> = NodeCast::from_mut_ref(&mut *new_title); let new_title: &mut JSRef<Node> = NodeCast::from_mut_ref(&mut *new_title);
let mut new_text = self.CreateTextNode(abstract_self, title.clone()).root(&roots); let mut new_text = self.CreateTextNode(title.clone()).root(&roots);
assert!(AppendChild(&mut *new_title, NodeCast::from_mut_ref(&mut *new_text)).is_ok()); assert!(new_title.AppendChild(NodeCast::from_mut_ref(&mut *new_text)).is_ok());
assert!(AppendChild(&mut *head, &mut *new_title).is_ok()); assert!(head.AppendChild(&mut *new_title).is_ok());
}, },
} }
}); });
@ -613,7 +610,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
} }
// http://www.whatwg.org/specs/web-apps/current-work/#dom-document-body // http://www.whatwg.org/specs/web-apps/current-work/#dom-document-body
fn GetBody(&self, _: &JSRef<Document>) -> Option<Unrooted<HTMLElement>> { fn GetBody(&self) -> Option<Unrooted<HTMLElement>> {
let roots = RootCollection::new(); let roots = RootCollection::new();
self.get_html_element().and_then(|root| { self.get_html_element().and_then(|root| {
let root = root.root(&roots); let root = root.root(&roots);
@ -631,7 +628,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
} }
// http://www.whatwg.org/specs/web-apps/current-work/#dom-document-body // http://www.whatwg.org/specs/web-apps/current-work/#dom-document-body
fn SetBody(&self, abstract_self: &JSRef<Document>, new_body: Option<JSRef<HTMLElement>>) -> ErrorResult { fn SetBody(&self, new_body: Option<JSRef<HTMLElement>>) -> ErrorResult {
let roots = RootCollection::new(); let roots = RootCollection::new();
// Step 1. // Step 1.
@ -646,7 +643,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
} }
// Step 2. // Step 2.
let mut old_body = self.GetBody(abstract_self).root(&roots); let mut old_body = self.GetBody().root(&roots);
//FIXME: covariant lifetime workaround. do not judge. //FIXME: covariant lifetime workaround. do not judge.
if old_body.as_ref().map(|body| body.deref()) == new_body.as_ref().map(|a| &*a) { if old_body.as_ref().map(|body| body.deref()) == new_body.as_ref().map(|a| &*a) {
return Ok(()); return Ok(());
@ -665,9 +662,9 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
Some(ref mut child) => { Some(ref mut child) => {
let child: &mut JSRef<Node> = NodeCast::from_mut_ref(&mut **child); let child: &mut JSRef<Node> = NodeCast::from_mut_ref(&mut **child);
assert!(ReplaceChild(&mut *root, new_body, child).is_ok()) assert!(root.ReplaceChild(new_body, child).is_ok())
} }
None => assert!(AppendChild(&mut *root, new_body).is_ok()) None => assert!(root.AppendChild(new_body).is_ok())
}; };
} }
} }
@ -690,7 +687,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
}) })
} }
fn Images(&self, abstract_self: &JSRef<Document>) -> Unrooted<HTMLCollection> { fn Images(&self) -> Unrooted<HTMLCollection> {
let roots = RootCollection::new(); let roots = RootCollection::new();
let window = self.window.root(&roots); let window = self.window.root(&roots);
@ -702,10 +699,10 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
} }
} }
let filter = ~ImagesFilter; let filter = ~ImagesFilter;
HTMLCollection::create(&*window, NodeCast::from_ref(abstract_self), filter) HTMLCollection::create(&*window, NodeCast::from_ref(self), filter)
} }
fn Embeds(&self, abstract_self: &JSRef<Document>) -> Unrooted<HTMLCollection> { fn Embeds(&self) -> Unrooted<HTMLCollection> {
let roots = RootCollection::new(); let roots = RootCollection::new();
let window = self.window.root(&roots); let window = self.window.root(&roots);
@ -717,15 +714,15 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
} }
} }
let filter = ~EmbedsFilter; let filter = ~EmbedsFilter;
HTMLCollection::create(&*window, NodeCast::from_ref(abstract_self), filter) HTMLCollection::create(&*window, NodeCast::from_ref(self), filter)
} }
fn Plugins(&self, abstract_self: &JSRef<Document>) -> Unrooted<HTMLCollection> { fn Plugins(&self) -> Unrooted<HTMLCollection> {
// FIXME: https://github.com/mozilla/servo/issues/1847 // FIXME: https://github.com/mozilla/servo/issues/1847
self.Embeds(abstract_self) self.Embeds()
} }
fn Links(&self, abstract_self: &JSRef<Document>) -> Unrooted<HTMLCollection> { fn Links(&self) -> Unrooted<HTMLCollection> {
let roots = RootCollection::new(); let roots = RootCollection::new();
let window = self.window.root(&roots); let window = self.window.root(&roots);
@ -738,10 +735,10 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
} }
} }
let filter = ~LinksFilter; let filter = ~LinksFilter;
HTMLCollection::create(&*window, NodeCast::from_ref(abstract_self), filter) HTMLCollection::create(&*window, NodeCast::from_ref(self), filter)
} }
fn Forms(&self, abstract_self: &JSRef<Document>) -> Unrooted<HTMLCollection> { fn Forms(&self) -> Unrooted<HTMLCollection> {
let roots = RootCollection::new(); let roots = RootCollection::new();
let window = self.window.root(&roots); let window = self.window.root(&roots);
@ -753,10 +750,10 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
} }
} }
let filter = ~FormsFilter; let filter = ~FormsFilter;
HTMLCollection::create(&*window, NodeCast::from_ref(abstract_self), filter) HTMLCollection::create(&*window, NodeCast::from_ref(self), filter)
} }
fn Scripts(&self, abstract_self: &JSRef<Document>) -> Unrooted<HTMLCollection> { fn Scripts(&self) -> Unrooted<HTMLCollection> {
let roots = RootCollection::new(); let roots = RootCollection::new();
let window = self.window.root(&roots); let window = self.window.root(&roots);
@ -768,10 +765,10 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
} }
} }
let filter = ~ScriptsFilter; let filter = ~ScriptsFilter;
HTMLCollection::create(&*window, NodeCast::from_ref(abstract_self), filter) HTMLCollection::create(&*window, NodeCast::from_ref(self), filter)
} }
fn Anchors(&self, abstract_self: &JSRef<Document>) -> Unrooted<HTMLCollection> { fn Anchors(&self) -> Unrooted<HTMLCollection> {
let roots = RootCollection::new(); let roots = RootCollection::new();
let window = self.window.root(&roots); let window = self.window.root(&roots);
@ -783,10 +780,10 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
} }
} }
let filter = ~AnchorsFilter; let filter = ~AnchorsFilter;
HTMLCollection::create(&*window, NodeCast::from_ref(abstract_self), filter) HTMLCollection::create(&*window, NodeCast::from_ref(self), filter)
} }
fn Applets(&self, abstract_self: &JSRef<Document>) -> Unrooted<HTMLCollection> { fn Applets(&self) -> Unrooted<HTMLCollection> {
let roots = RootCollection::new(); let roots = RootCollection::new();
let window = self.window.root(&roots); let window = self.window.root(&roots);
@ -798,19 +795,18 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
} }
} }
let filter = ~AppletsFilter; let filter = ~AppletsFilter;
HTMLCollection::create(&*window, NodeCast::from_ref(abstract_self), filter) HTMLCollection::create(&*window, NodeCast::from_ref(self), filter)
} }
fn Location(&mut self, _abstract_self: &JSRef<Document>) -> Unrooted<Location> { fn Location(&mut self) -> Unrooted<Location> {
let roots = RootCollection::new(); let roots = RootCollection::new();
let mut window = self.window.root(&roots); let mut window = self.window.root(&roots);
let window_alias = self.window.root(&roots); window.Location()
window.Location(&*window_alias)
} }
fn Children(&self, abstract_self: &JSRef<Document>) -> Unrooted<HTMLCollection> { fn Children(&self) -> Unrooted<HTMLCollection> {
let roots = RootCollection::new(); let roots = RootCollection::new();
let window = self.window.root(&roots); let window = self.window.root(&roots);
HTMLCollection::children(&*window, NodeCast::from_ref(abstract_self)) HTMLCollection::children(&*window, NodeCast::from_ref(self))
} }
} }

View file

@ -49,13 +49,13 @@ impl DocumentFragment {
} }
pub trait DocumentFragmentMethods { pub trait DocumentFragmentMethods {
fn Children(&self, abstract_self: &JSRef<DocumentFragment>) -> Unrooted<HTMLCollection>; fn Children(&self) -> Unrooted<HTMLCollection>;
} }
impl<'a> DocumentFragmentMethods for JSRef<'a, DocumentFragment> { impl<'a> DocumentFragmentMethods for JSRef<'a, DocumentFragment> {
fn Children(&self, abstract_self: &JSRef<DocumentFragment>) -> Unrooted<HTMLCollection> { fn Children(&self) -> Unrooted<HTMLCollection> {
let roots = RootCollection::new(); let roots = RootCollection::new();
let window = window_from_node(abstract_self).root(&roots); let window = window_from_node(self).root(&roots);
HTMLCollection::children(&window.root_ref(), NodeCast::from_ref(abstract_self)) HTMLCollection::children(&window.root_ref(), NodeCast::from_ref(self))
} }
} }

View file

@ -14,7 +14,7 @@ use dom::htmlbodyelement::HTMLBodyElement;
use dom::htmlheadelement::HTMLHeadElement; use dom::htmlheadelement::HTMLHeadElement;
use dom::htmlhtmlelement::HTMLHtmlElement; use dom::htmlhtmlelement::HTMLHtmlElement;
use dom::htmltitleelement::HTMLTitleElement; use dom::htmltitleelement::HTMLTitleElement;
use dom::node::{Node, AppendChild}; use dom::node::{Node, NodeMethods};
use dom::text::Text; use dom::text::Text;
use dom::window::{Window, WindowMethods}; use dom::window::{Window, WindowMethods};
use servo_util::str::DOMString; use servo_util::str::DOMString;
@ -87,7 +87,7 @@ impl<'a> DOMImplementationMethods for JSRef<'a, DOMImplementation> {
let mut maybe_elem = if qname.is_empty() { let mut maybe_elem = if qname.is_empty() {
None None
} else { } else {
match doc.deref().CreateElementNS(&*doc, namespace, qname) { match doc.CreateElementNS(namespace, qname) {
Err(error) => return Err(error), Err(error) => return Err(error),
Ok(elem) => Some(elem) Ok(elem) => Some(elem)
} }
@ -100,7 +100,7 @@ impl<'a> DOMImplementationMethods for JSRef<'a, DOMImplementation> {
match maybe_doctype { match maybe_doctype {
None => (), None => (),
Some(ref mut doctype) => { Some(ref mut doctype) => {
assert!(AppendChild(doc_node, NodeCast::from_mut_ref(doctype)).is_ok()) assert!(doc_node.AppendChild(NodeCast::from_mut_ref(doctype)).is_ok())
} }
} }
@ -108,7 +108,7 @@ impl<'a> DOMImplementationMethods for JSRef<'a, DOMImplementation> {
match maybe_elem.root(&roots) { match maybe_elem.root(&roots) {
None => (), None => (),
Some(mut elem) => { Some(mut elem) => {
assert!(AppendChild(doc_node, NodeCast::from_mut_ref(&mut *elem)).is_ok()) assert!(doc_node.AppendChild(NodeCast::from_mut_ref(&mut *elem)).is_ok())
} }
} }
} }
@ -133,18 +133,18 @@ impl<'a> DOMImplementationMethods for JSRef<'a, DOMImplementation> {
{ {
// Step 3. // Step 3.
let mut doc_type = DocumentType::new(~"html", None, None, &*doc).root(&roots); let mut doc_type = DocumentType::new(~"html", None, None, &*doc).root(&roots);
assert!(AppendChild(&mut *doc_node, NodeCast::from_mut_ref(&mut *doc_type)).is_ok()); assert!(doc_node.AppendChild(NodeCast::from_mut_ref(&mut *doc_type)).is_ok());
} }
{ {
// Step 4. // Step 4.
let mut doc_html = NodeCast::from_unrooted(HTMLHtmlElement::new(~"html", &*doc)).root(&roots); let mut doc_html = NodeCast::from_unrooted(HTMLHtmlElement::new(~"html", &*doc)).root(&roots);
assert!(AppendChild(&mut *doc_node, &mut *doc_html).is_ok()); assert!(doc_node.AppendChild(&mut *doc_html).is_ok());
{ {
// Step 5. // Step 5.
let mut doc_head = NodeCast::from_unrooted(HTMLHeadElement::new(~"head", &*doc)).root(&roots); let mut doc_head = NodeCast::from_unrooted(HTMLHeadElement::new(~"head", &*doc)).root(&roots);
assert!(AppendChild(&mut *doc_html, &mut *doc_head).is_ok()); assert!(doc_html.AppendChild(&mut *doc_head).is_ok());
// Step 6. // Step 6.
match title { match title {
@ -152,18 +152,18 @@ impl<'a> DOMImplementationMethods for JSRef<'a, DOMImplementation> {
Some(title_str) => { Some(title_str) => {
// Step 6.1. // Step 6.1.
let mut doc_title = NodeCast::from_unrooted(HTMLTitleElement::new(~"title", &*doc)).root(&roots); let mut doc_title = NodeCast::from_unrooted(HTMLTitleElement::new(~"title", &*doc)).root(&roots);
assert!(AppendChild(&mut *doc_head, &mut *doc_title).is_ok()); assert!(doc_head.AppendChild(&mut *doc_title).is_ok());
// Step 6.2. // Step 6.2.
let mut title_text = Text::new(title_str, &*doc).root(&roots); let mut title_text = Text::new(title_str, &*doc).root(&roots);
assert!(AppendChild(&mut *doc_title, NodeCast::from_mut_ref(&mut *title_text)).is_ok()); assert!(doc_title.AppendChild(NodeCast::from_mut_ref(&mut *title_text)).is_ok());
} }
} }
} }
// Step 7. // Step 7.
let mut doc_body = HTMLBodyElement::new(~"body", &*doc).root(&roots); let mut doc_body = HTMLBodyElement::new(~"body", &*doc).root(&roots);
assert!(AppendChild(&mut *doc_html, NodeCast::from_mut_ref(&mut *doc_body)).is_ok()); assert!(doc_html.AppendChild(NodeCast::from_mut_ref(&mut *doc_body)).is_ok());
} }
// Step 8. // Step 8.

View file

@ -198,9 +198,6 @@ pub trait AttributeHandlers {
fn do_set_attribute(&mut self, local_name: DOMString, value: DOMString, fn do_set_attribute(&mut self, local_name: DOMString, value: DOMString,
name: DOMString, namespace: Namespace, name: DOMString, namespace: Namespace,
prefix: Option<DOMString>, cb: |&JSRef<Attr>| -> bool); prefix: Option<DOMString>, cb: |&JSRef<Attr>| -> bool);
fn SetAttribute_(&mut self, name: DOMString, value: DOMString) -> ErrorResult;
fn SetAttributeNS_(&mut self, namespace_url: Option<DOMString>,
name: DOMString, value: DOMString) -> ErrorResult;
fn remove_attribute(&mut self, namespace: Namespace, name: DOMString) -> ErrorResult; fn remove_attribute(&mut self, namespace: Namespace, name: DOMString) -> ErrorResult;
fn notify_attribute_changed(&self, local_name: DOMString); fn notify_attribute_changed(&self, local_name: DOMString);
@ -281,100 +278,10 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
self.get_mut().attrs.get(idx).root(&roots).set_value(set_type, value); self.get_mut().attrs.get(idx).root(&roots).set_value(set_type, value);
} }
// http://dom.spec.whatwg.org/#dom-element-setattribute
fn SetAttribute_(&mut self, name: DOMString, value: DOMString) -> ErrorResult {
{
let node: &JSRef<Node> = NodeCast::from_ref(self);
node.get().wait_until_safe_to_modify_dom();
}
// Step 1.
match xml_name_type(name) {
InvalidXMLName => return Err(InvalidCharacter),
_ => {}
}
// Step 2.
let name = if self.get().html_element_in_html_document() {
name.to_ascii_lower()
} else {
name
};
// Step 3-5.
self.do_set_attribute(name.clone(), value, name.clone(), namespace::Null, None, |attr| {
attr.get().name == name
});
Ok(())
}
fn SetAttributeNS_(&mut self, namespace_url: Option<DOMString>,
name: DOMString, value: DOMString) -> ErrorResult {
{
let node: &JSRef<Node> = NodeCast::from_ref(self);
node.get().wait_until_safe_to_modify_dom();
}
// Step 1.
let namespace = Namespace::from_str(null_str_as_empty_ref(&namespace_url));
let name_type = xml_name_type(name);
match name_type {
// Step 2.
InvalidXMLName => return Err(InvalidCharacter),
// Step 3.
Name => return Err(NamespaceError),
QName => {}
}
// Step 4.
let (prefix, local_name) = get_attribute_parts(name.clone());
match prefix {
Some(ref prefix_str) => {
// Step 5.
if namespace == namespace::Null {
return Err(NamespaceError);
}
// Step 6.
if "xml" == prefix_str.as_slice() && namespace != namespace::XML {
return Err(NamespaceError);
}
// Step 7b.
if "xmlns" == prefix_str.as_slice() && namespace != namespace::XMLNS {
return Err(NamespaceError);
}
},
None => {}
}
// Step 7a.
if "xmlns" == name && namespace != namespace::XMLNS {
return Err(NamespaceError);
}
// Step 8.
if namespace == namespace::XMLNS && "xmlns" != name && Some(~"xmlns") != prefix {
return Err(NamespaceError);
}
// Step 9.
self.do_set_attribute(local_name.clone(), value, name, namespace.clone(), prefix, |attr| {
attr.get().local_name == local_name &&
attr.get().namespace == namespace
});
Ok(())
}
fn remove_attribute(&mut self, namespace: Namespace, name: DOMString) -> ErrorResult { fn remove_attribute(&mut self, namespace: Namespace, name: DOMString) -> ErrorResult {
let roots = RootCollection::new(); let roots = RootCollection::new();
let (_, local_name) = get_attribute_parts(name.clone()); let (_, local_name) = get_attribute_parts(name.clone());
let self_alias = self.clone();
let node: &JSRef<Node> = NodeCast::from_ref(&self_alias);
node.wait_until_safe_to_modify_dom();
let idx = self.get().attrs.iter().map(|attr| attr.root(&roots)).position(|attr| { let idx = self.get().attrs.iter().map(|attr| attr.root(&roots)).position(|attr| {
attr.local_name == local_name attr.local_name == local_name
}); });
@ -382,9 +289,14 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
match idx { match idx {
None => (), None => (),
Some(idx) => { Some(idx) => {
{
let node: &JSRef<Node> = NodeCast::from_ref(self);
node.wait_until_safe_to_modify_dom();
}
if namespace == namespace::Null { if namespace == namespace::Null {
let removed_raw_value = self.get().attrs.get(idx).root(&roots).Value(); let removed_raw_value = self.get().attrs.get(idx).root(&roots).Value();
vtable_for(node).before_remove_attr(local_name.clone(), removed_raw_value); vtable_for(NodeCast::from_ref(self)).before_remove_attr(local_name.clone(), removed_raw_value);
} }
self.get_mut().attrs.remove(idx); self.get_mut().attrs.remove(idx);
@ -463,27 +375,27 @@ pub trait ElementMethods {
fn LocalName(&self) -> DOMString; fn LocalName(&self) -> DOMString;
fn GetPrefix(&self) -> Option<DOMString>; fn GetPrefix(&self) -> Option<DOMString>;
fn TagName(&self) -> DOMString; fn TagName(&self) -> DOMString;
fn Id(&self, abstract_self: &JSRef<Element>) -> DOMString; fn Id(&self) -> DOMString;
fn SetId(&mut self, abstract_self: &mut JSRef<Element>, id: DOMString); fn SetId(&mut self, id: DOMString);
fn ClassName(&self, abstract_self: &JSRef<Element>) -> DOMString; fn ClassName(&self) -> DOMString;
fn SetClassName(&self, abstract_self: &mut JSRef<Element>, class: DOMString); fn SetClassName(&mut self, class: DOMString);
fn Attributes(&mut self, abstract_self: &JSRef<Element>) -> Unrooted<AttrList>; fn Attributes(&mut self) -> Unrooted<AttrList>;
fn GetAttribute(&self, abstract_self: &JSRef<Element>, name: DOMString) -> Option<DOMString>; fn GetAttribute(&self, name: DOMString) -> Option<DOMString>;
fn GetAttributeNS(&self, abstract_self: &JSRef<Element>, namespace: Option<DOMString>, local_name: DOMString) -> Option<DOMString>; fn GetAttributeNS(&self, namespace: Option<DOMString>, local_name: DOMString) -> Option<DOMString>;
fn SetAttribute(&self, abstract_self: &mut JSRef<Element>, name: DOMString, value: DOMString) -> ErrorResult; fn SetAttribute(&mut self, name: DOMString, value: DOMString) -> ErrorResult;
fn SetAttributeNS(&self, abstract_self: &mut JSRef<Element>, namespace_url: Option<DOMString>, name: DOMString, value: DOMString) -> ErrorResult; fn SetAttributeNS(&mut self, namespace_url: Option<DOMString>, name: DOMString, value: DOMString) -> ErrorResult;
fn RemoveAttribute(&mut self, abstract_self: &mut JSRef<Element>, name: DOMString) -> ErrorResult; fn RemoveAttribute(&mut self, name: DOMString) -> ErrorResult;
fn RemoveAttributeNS(&mut self, abstract_self: &mut JSRef<Element>, namespace: Option<DOMString>, localname: DOMString) -> ErrorResult; fn RemoveAttributeNS(&mut self, namespace: Option<DOMString>, localname: DOMString) -> ErrorResult;
fn HasAttribute(&self, abstract_self: &JSRef<Element>, name: DOMString) -> bool; fn HasAttribute(&self, name: DOMString) -> bool;
fn HasAttributeNS(&self, abstract_self: &JSRef<Element>, namespace: Option<DOMString>, local_name: DOMString) -> bool; fn HasAttributeNS(&self, namespace: Option<DOMString>, local_name: DOMString) -> bool;
fn GetElementsByTagName(&self, abstract_self: &JSRef<Element>, localname: DOMString) -> Unrooted<HTMLCollection>; fn GetElementsByTagName(&self, localname: DOMString) -> Unrooted<HTMLCollection>;
fn GetElementsByTagNameNS(&self, abstract_self: &JSRef<Element>, maybe_ns: Option<DOMString>, localname: DOMString) -> Unrooted<HTMLCollection>; fn GetElementsByTagNameNS(&self, maybe_ns: Option<DOMString>, localname: DOMString) -> Unrooted<HTMLCollection>;
fn GetElementsByClassName(&self, abstract_self: &JSRef<Element>, classes: DOMString) -> Unrooted<HTMLCollection>; fn GetElementsByClassName(&self, classes: DOMString) -> Unrooted<HTMLCollection>;
fn GetClientRects(&self, abstract_self: &JSRef<Element>) -> Unrooted<ClientRectList>; fn GetClientRects(&self) -> Unrooted<ClientRectList>;
fn GetBoundingClientRect(&self, abstract_self: &JSRef<Element>) -> Unrooted<ClientRect>; fn GetBoundingClientRect(&self) -> Unrooted<ClientRect>;
fn GetInnerHTML(&self, abstract_self: &JSRef<Element>) -> Fallible<DOMString>; fn GetInnerHTML(&self) -> Fallible<DOMString>;
fn GetOuterHTML(&self, abstract_self: &JSRef<Element>) -> Fallible<DOMString>; fn GetOuterHTML(&self) -> Fallible<DOMString>;
fn Children(&self, abstract_self: &JSRef<Element>) -> Unrooted<HTMLCollection>; fn Children(&self) -> Unrooted<HTMLCollection>;
} }
impl<'a> ElementMethods for JSRef<'a, Element> { impl<'a> ElementMethods for JSRef<'a, Element> {
@ -514,27 +426,27 @@ impl<'a> ElementMethods for JSRef<'a, Element> {
} }
// http://dom.spec.whatwg.org/#dom-element-id // http://dom.spec.whatwg.org/#dom-element-id
fn Id(&self, abstract_self: &JSRef<Element>) -> DOMString { fn Id(&self) -> DOMString {
abstract_self.get_string_attribute("id") self.get_string_attribute("id")
} }
// http://dom.spec.whatwg.org/#dom-element-id // http://dom.spec.whatwg.org/#dom-element-id
fn SetId(&mut self, abstract_self: &mut JSRef<Element>, id: DOMString) { fn SetId(&mut self, id: DOMString) {
abstract_self.set_string_attribute("id", id); self.set_string_attribute("id", id);
} }
// http://dom.spec.whatwg.org/#dom-element-classname // http://dom.spec.whatwg.org/#dom-element-classname
fn ClassName(&self, abstract_self: &JSRef<Element>) -> DOMString { fn ClassName(&self) -> DOMString {
abstract_self.get_string_attribute("class") self.get_string_attribute("class")
} }
// http://dom.spec.whatwg.org/#dom-element-classname // http://dom.spec.whatwg.org/#dom-element-classname
fn SetClassName(&self, abstract_self: &mut JSRef<Element>, class: DOMString) { fn SetClassName(&mut self, class: DOMString) {
abstract_self.set_string_attribute("class", class); self.set_string_attribute("class", class);
} }
// http://dom.spec.whatwg.org/#dom-element-attributes // http://dom.spec.whatwg.org/#dom-element-attributes
fn Attributes(&mut self, abstract_self: &JSRef<Element>) -> Unrooted<AttrList> { fn Attributes(&mut self) -> Unrooted<AttrList> {
let roots = RootCollection::new(); let roots = RootCollection::new();
match self.attr_list { match self.attr_list {
None => (), None => (),
@ -543,111 +455,184 @@ impl<'a> ElementMethods for JSRef<'a, Element> {
let doc = self.node.owner_doc().root(&roots); let doc = self.node.owner_doc().root(&roots);
let window = doc.deref().window.root(&roots); let window = doc.deref().window.root(&roots);
let list = AttrList::new(&window.root_ref(), abstract_self); let list = AttrList::new(&*window, self);
self.attr_list.assign(Some(list)); self.attr_list.assign(Some(list));
Unrooted::new(self.attr_list.get_ref().clone()) Unrooted::new(self.attr_list.get_ref().clone())
} }
// http://dom.spec.whatwg.org/#dom-element-getattribute // http://dom.spec.whatwg.org/#dom-element-getattribute
fn GetAttribute(&self, abstract_self: &JSRef<Element>, name: DOMString) -> Option<DOMString> { fn GetAttribute(&self, name: DOMString) -> Option<DOMString> {
let roots = RootCollection::new(); let roots = RootCollection::new();
let name = if abstract_self.get().html_element_in_html_document() { let name = if self.get().html_element_in_html_document() {
name.to_ascii_lower() name.to_ascii_lower()
} else { } else {
name name
}; };
abstract_self.get_attribute(Null, name).root(&roots) self.get_attribute(Null, name).root(&roots)
.map(|s| s.deref().Value()) .map(|s| s.deref().Value())
} }
// http://dom.spec.whatwg.org/#dom-element-getattributens // http://dom.spec.whatwg.org/#dom-element-getattributens
fn GetAttributeNS(&self, abstract_self: &JSRef<Element>, fn GetAttributeNS(&self,
namespace: Option<DOMString>, namespace: Option<DOMString>,
local_name: DOMString) -> Option<DOMString> { local_name: DOMString) -> Option<DOMString> {
let roots = RootCollection::new(); let roots = RootCollection::new();
let namespace = Namespace::from_str(null_str_as_empty_ref(&namespace)); let namespace = Namespace::from_str(null_str_as_empty_ref(&namespace));
abstract_self.get_attribute(namespace, local_name).root(&roots) self.get_attribute(namespace, local_name).root(&roots)
.map(|attr| attr.deref().Value()) .map(|attr| attr.deref().Value())
} }
// http://dom.spec.whatwg.org/#dom-element-setattribute // http://dom.spec.whatwg.org/#dom-element-setattribute
fn SetAttribute(&self, abstract_self: &mut JSRef<Element>, fn SetAttribute(&mut self,
name: DOMString, name: DOMString,
value: DOMString) -> ErrorResult { value: DOMString) -> ErrorResult {
abstract_self.SetAttribute_(name, value) {
let node: &JSRef<Node> = NodeCast::from_ref(self);
node.get().wait_until_safe_to_modify_dom();
}
// Step 1.
match xml_name_type(name) {
InvalidXMLName => return Err(InvalidCharacter),
_ => {}
}
// Step 2.
let name = if self.get().html_element_in_html_document() {
name.to_ascii_lower()
} else {
name
};
// Step 3-5.
self.do_set_attribute(name.clone(), value, name.clone(), namespace::Null, None, |attr| {
attr.get().name == name
});
Ok(())
} }
// http://dom.spec.whatwg.org/#dom-element-setattributens // http://dom.spec.whatwg.org/#dom-element-setattributens
fn SetAttributeNS(&self, fn SetAttributeNS(&mut self,
abstract_self: &mut JSRef<Element>,
namespace_url: Option<DOMString>, namespace_url: Option<DOMString>,
name: DOMString, name: DOMString,
value: DOMString) -> ErrorResult { value: DOMString) -> ErrorResult {
abstract_self.SetAttributeNS_(namespace_url, name, value) {
let node: &JSRef<Node> = NodeCast::from_ref(self);
node.get().wait_until_safe_to_modify_dom();
}
// Step 1.
let namespace = Namespace::from_str(null_str_as_empty_ref(&namespace_url));
let name_type = xml_name_type(name);
match name_type {
// Step 2.
InvalidXMLName => return Err(InvalidCharacter),
// Step 3.
Name => return Err(NamespaceError),
QName => {}
}
// Step 4.
let (prefix, local_name) = get_attribute_parts(name.clone());
match prefix {
Some(ref prefix_str) => {
// Step 5.
if namespace == namespace::Null {
return Err(NamespaceError);
}
// Step 6.
if "xml" == prefix_str.as_slice() && namespace != namespace::XML {
return Err(NamespaceError);
}
// Step 7b.
if "xmlns" == prefix_str.as_slice() && namespace != namespace::XMLNS {
return Err(NamespaceError);
}
},
None => {}
}
// Step 7a.
if "xmlns" == name && namespace != namespace::XMLNS {
return Err(NamespaceError);
}
// Step 8.
if namespace == namespace::XMLNS && "xmlns" != name && Some(~"xmlns") != prefix {
return Err(NamespaceError);
}
// Step 9.
self.do_set_attribute(local_name.clone(), value, name, namespace.clone(), prefix, |attr| {
attr.get().local_name == local_name &&
attr.get().namespace == namespace
});
Ok(())
} }
// http://dom.spec.whatwg.org/#dom-element-removeattribute // http://dom.spec.whatwg.org/#dom-element-removeattribute
fn RemoveAttribute(&mut self, fn RemoveAttribute(&mut self,
abstract_self: &mut JSRef<Element>,
name: DOMString) -> ErrorResult { name: DOMString) -> ErrorResult {
let name = if self.html_element_in_html_document() { let name = if self.html_element_in_html_document() {
name.to_ascii_lower() name.to_ascii_lower()
} else { } else {
name name
}; };
abstract_self.remove_attribute(namespace::Null, name) self.remove_attribute(namespace::Null, name)
} }
// http://dom.spec.whatwg.org/#dom-element-removeattributens // http://dom.spec.whatwg.org/#dom-element-removeattributens
fn RemoveAttributeNS(&mut self, fn RemoveAttributeNS(&mut self,
abstract_self: &mut JSRef<Element>,
namespace: Option<DOMString>, namespace: Option<DOMString>,
localname: DOMString) -> ErrorResult { localname: DOMString) -> ErrorResult {
let namespace = Namespace::from_str(null_str_as_empty_ref(&namespace)); let namespace = Namespace::from_str(null_str_as_empty_ref(&namespace));
abstract_self.remove_attribute(namespace, localname) self.remove_attribute(namespace, localname)
} }
// http://dom.spec.whatwg.org/#dom-element-hasattribute // http://dom.spec.whatwg.org/#dom-element-hasattribute
fn HasAttribute(&self, abstract_self: &JSRef<Element>, fn HasAttribute(&self,
name: DOMString) -> bool { name: DOMString) -> bool {
self.GetAttribute(abstract_self, name).is_some() self.GetAttribute(name).is_some()
} }
// http://dom.spec.whatwg.org/#dom-element-hasattributens // http://dom.spec.whatwg.org/#dom-element-hasattributens
fn HasAttributeNS(&self, abstract_self: &JSRef<Element>, fn HasAttributeNS(&self,
namespace: Option<DOMString>, namespace: Option<DOMString>,
local_name: DOMString) -> bool { local_name: DOMString) -> bool {
self.GetAttributeNS(abstract_self, namespace, local_name).is_some() self.GetAttributeNS(namespace, local_name).is_some()
} }
fn GetElementsByTagName(&self, abstract_self: &JSRef<Element>, localname: DOMString) -> Unrooted<HTMLCollection> { fn GetElementsByTagName(&self, localname: DOMString) -> Unrooted<HTMLCollection> {
let roots = RootCollection::new(); let roots = RootCollection::new();
let window = window_from_node(abstract_self).root(&roots); let window = window_from_node(self).root(&roots);
HTMLCollection::by_tag_name(&*window, NodeCast::from_ref(abstract_self), localname) HTMLCollection::by_tag_name(&*window, NodeCast::from_ref(self), localname)
} }
fn GetElementsByTagNameNS(&self, abstract_self: &JSRef<Element>, maybe_ns: Option<DOMString>, fn GetElementsByTagNameNS(&self, maybe_ns: Option<DOMString>,
localname: DOMString) -> Unrooted<HTMLCollection> { localname: DOMString) -> Unrooted<HTMLCollection> {
let roots = RootCollection::new(); let roots = RootCollection::new();
let namespace = match maybe_ns { let namespace = match maybe_ns {
Some(namespace) => Namespace::from_str(namespace), Some(namespace) => Namespace::from_str(namespace),
None => Null None => Null
}; };
let window = window_from_node(abstract_self).root(&roots); let window = window_from_node(self).root(&roots);
HTMLCollection::by_tag_name_ns(&*window, NodeCast::from_ref(abstract_self), localname, namespace) HTMLCollection::by_tag_name_ns(&*window, NodeCast::from_ref(self), localname, namespace)
} }
fn GetElementsByClassName(&self, abstract_self: &JSRef<Element>, classes: DOMString) -> Unrooted<HTMLCollection> { fn GetElementsByClassName(&self, classes: DOMString) -> Unrooted<HTMLCollection> {
let roots = RootCollection::new(); let roots = RootCollection::new();
let window = window_from_node(abstract_self).root(&roots); let window = window_from_node(self).root(&roots);
HTMLCollection::by_class_name(&*window, NodeCast::from_ref(abstract_self), classes) HTMLCollection::by_class_name(&*window, NodeCast::from_ref(self), classes)
} }
// http://dev.w3.org/csswg/cssom-view/#dom-element-getclientrects // http://dev.w3.org/csswg/cssom-view/#dom-element-getclientrects
fn GetClientRects(&self, abstract_self: &JSRef<Element>) -> Unrooted<ClientRectList> { fn GetClientRects(&self) -> Unrooted<ClientRectList> {
let roots = RootCollection::new(); let roots = RootCollection::new();
let win = window_from_node(abstract_self).root(&roots); let win = window_from_node(self).root(&roots);
let node: &JSRef<Node> = NodeCast::from_ref(abstract_self); let node: &JSRef<Node> = NodeCast::from_ref(self);
let rects = node.get_content_boxes(); let rects = node.get_content_boxes();
let rects: ~[Root<ClientRect>] = rects.iter().map(|r| { let rects: ~[Root<ClientRect>] = rects.iter().map(|r| {
ClientRect::new( ClientRect::new(
@ -662,10 +647,10 @@ impl<'a> ElementMethods for JSRef<'a, Element> {
} }
// http://dev.w3.org/csswg/cssom-view/#dom-element-getboundingclientrect // http://dev.w3.org/csswg/cssom-view/#dom-element-getboundingclientrect
fn GetBoundingClientRect(&self, abstract_self: &JSRef<Element>) -> Unrooted<ClientRect> { fn GetBoundingClientRect(&self) -> Unrooted<ClientRect> {
let roots = RootCollection::new(); let roots = RootCollection::new();
let win = window_from_node(abstract_self).root(&roots); let win = window_from_node(self).root(&roots);
let node: &JSRef<Node> = NodeCast::from_ref(abstract_self); let node: &JSRef<Node> = NodeCast::from_ref(self);
let rect = node.get_bounding_content_box(); let rect = node.get_bounding_content_box();
ClientRect::new( ClientRect::new(
&*win, &*win,
@ -675,21 +660,21 @@ impl<'a> ElementMethods for JSRef<'a, Element> {
rect.origin.x + rect.size.width) rect.origin.x + rect.size.width)
} }
fn GetInnerHTML(&self, abstract_self: &JSRef<Element>) -> Fallible<DOMString> { fn GetInnerHTML(&self) -> Fallible<DOMString> {
//XXX TODO: XML case //XXX TODO: XML case
let roots = RootCollection::new(); let roots = RootCollection::new();
Ok(serialize(&mut NodeIterator::new(&roots, NodeCast::from_ref(abstract_self), false, false))) Ok(serialize(&mut NodeIterator::new(&roots, NodeCast::from_ref(self), false, false)))
} }
fn GetOuterHTML(&self, abstract_self: &JSRef<Element>) -> Fallible<DOMString> { fn GetOuterHTML(&self) -> Fallible<DOMString> {
let roots = RootCollection::new(); let roots = RootCollection::new();
Ok(serialize(&mut NodeIterator::new(&roots, NodeCast::from_ref(abstract_self), true, false))) Ok(serialize(&mut NodeIterator::new(&roots, NodeCast::from_ref(self), true, false)))
} }
fn Children(&self, abstract_self: &JSRef<Element>) -> Unrooted<HTMLCollection> { fn Children(&self) -> Unrooted<HTMLCollection> {
let roots = RootCollection::new(); let roots = RootCollection::new();
let window = window_from_node(abstract_self).root(&roots); let window = window_from_node(self).root(&roots);
HTMLCollection::children(&window.root_ref(), NodeCast::from_ref(abstract_self)) HTMLCollection::children(&*window, NodeCast::from_ref(self))
} }
} }

View file

@ -10,15 +10,18 @@ use dom::event::{Event, PhaseAtTarget, PhaseNone, PhaseBubbling, PhaseCapturing,
use dom::node::{Node, NodeHelpers}; use dom::node::{Node, NodeHelpers};
// See http://dom.spec.whatwg.org/#concept-event-dispatch for the full dispatch algorithm // See http://dom.spec.whatwg.org/#concept-event-dispatch for the full dispatch algorithm
pub fn dispatch_event<'a>(target: &JSRef<'a, EventTarget>, pub fn dispatch_event<'a, 'b>(target: &JSRef<'a, EventTarget>,
pseudo_target: Option<JSRef<'a, EventTarget>>, pseudo_target: Option<JSRef<'b, EventTarget>>,
event: &mut JSRef<Event>) -> bool { event: &mut JSRef<Event>) -> bool {
let roots = RootCollection::new(); let roots = RootCollection::new();
assert!(!event.get().dispatching); assert!(!event.get().dispatching);
{ {
let event = event.get_mut(); let event = event.get_mut();
event.target.assign(Some(pseudo_target.unwrap_or(target.clone()))); match pseudo_target {
Some(pseudo_target) => event.target.assign(Some(pseudo_target)),
None => event.target.assign(Some(target.clone())),
}
event.dispatching = true; event.dispatching = true;
} }

View file

@ -64,15 +64,22 @@ impl EventTarget {
filtered.map(|entry| entry.listener).collect() filtered.map(|entry| entry.listener).collect()
}) })
} }
}
pub fn dispatch_event_with_target<'a>(&self, pub trait EventTargetHelpers {
abstract_self: &JSRef<'a, EventTarget>, fn dispatch_event_with_target<'a>(&self,
abstract_target: Option<JSRef<'a, EventTarget>>, target: Option<JSRef<'a, EventTarget>>,
event: &mut JSRef<Event>) -> Fallible<bool>;
}
impl<'a> EventTargetHelpers for JSRef<'a, EventTarget> {
fn dispatch_event_with_target<'b>(&self,
target: Option<JSRef<'b, EventTarget>>,
event: &mut JSRef<Event>) -> Fallible<bool> { event: &mut JSRef<Event>) -> Fallible<bool> {
if event.get().dispatching || !event.get().initialized { if event.get().dispatching || !event.get().initialized {
return Err(InvalidState); return Err(InvalidState);
} }
Ok(dispatch_event(abstract_self, abstract_target, event)) Ok(dispatch_event(self, target, event))
} }
} }
@ -85,8 +92,7 @@ pub trait EventTargetMethods {
ty: DOMString, ty: DOMString,
listener: Option<EventListener>, listener: Option<EventListener>,
capture: bool); capture: bool);
fn DispatchEvent(&self, abstract_self: &JSRef<EventTarget>, fn DispatchEvent(&self, event: &mut JSRef<Event>) -> Fallible<bool>;
event: &mut JSRef<Event>) -> Fallible<bool>;
} }
impl<'a> EventTargetMethods for JSRef<'a, EventTarget> { impl<'a> EventTargetMethods for JSRef<'a, EventTarget> {
@ -127,9 +133,8 @@ impl<'a> EventTargetMethods for JSRef<'a, EventTarget> {
} }
} }
fn DispatchEvent(&self, abstract_self: &JSRef<EventTarget>, fn DispatchEvent(&self, event: &mut JSRef<Event>) -> Fallible<bool> {
event: &mut JSRef<Event>) -> Fallible<bool> { self.dispatch_event_with_target(None, event)
self.dispatch_event_with_target(abstract_self, None, event)
} }
} }

View file

@ -41,11 +41,11 @@ impl HTMLDataListElement {
} }
pub trait HTMLDataListElementMethods { pub trait HTMLDataListElementMethods {
fn Options(&self, abstract_self: &JSRef<HTMLDataListElement>) -> Unrooted<HTMLCollection>; fn Options(&self) -> Unrooted<HTMLCollection>;
} }
impl<'a> HTMLDataListElementMethods for JSRef<'a, HTMLDataListElement> { impl<'a> HTMLDataListElementMethods for JSRef<'a, HTMLDataListElement> {
fn Options(&self, abstract_self: &JSRef<HTMLDataListElement>) -> Unrooted<HTMLCollection> { fn Options(&self) -> Unrooted<HTMLCollection> {
struct HTMLDataListOptionsFilter; struct HTMLDataListOptionsFilter;
impl CollectionFilter for HTMLDataListOptionsFilter { impl CollectionFilter for HTMLDataListOptionsFilter {
fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool { fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool {
@ -53,7 +53,7 @@ impl<'a> HTMLDataListElementMethods for JSRef<'a, HTMLDataListElement> {
} }
} }
let roots = RootCollection::new(); let roots = RootCollection::new();
let node: &JSRef<Node> = NodeCast::from_ref(abstract_self); let node: &JSRef<Node> = NodeCast::from_ref(self);
let filter = ~HTMLDataListOptionsFilter; let filter = ~HTMLDataListOptionsFilter;
let window = window_from_node(node).root(&roots); let window = window_from_node(node).root(&roots);
HTMLCollection::create(&*window, node, filter) HTMLCollection::create(&*window, node, filter)

View file

@ -50,7 +50,7 @@ pub trait HTMLFieldSetElementMethods {
fn Name(&self) -> DOMString; fn Name(&self) -> DOMString;
fn SetName(&mut self, _name: DOMString) -> ErrorResult; fn SetName(&mut self, _name: DOMString) -> ErrorResult;
fn Type(&self) -> DOMString; fn Type(&self) -> DOMString;
fn Elements(&self, abstract_self: &JSRef<HTMLFieldSetElement>) -> Unrooted<HTMLCollection>; fn Elements(&self) -> Unrooted<HTMLCollection>;
fn WillValidate(&self) -> bool; fn WillValidate(&self) -> bool;
fn Validity(&self) -> Unrooted<ValidityState>; fn Validity(&self) -> Unrooted<ValidityState>;
fn ValidationMessage(&self) -> DOMString; fn ValidationMessage(&self) -> DOMString;
@ -84,7 +84,7 @@ impl<'a> HTMLFieldSetElementMethods for JSRef<'a, HTMLFieldSetElement> {
} }
// http://www.whatwg.org/html/#dom-fieldset-elements // http://www.whatwg.org/html/#dom-fieldset-elements
fn Elements(&self, abstract_self: &JSRef<HTMLFieldSetElement>) -> Unrooted<HTMLCollection> { fn Elements(&self) -> Unrooted<HTMLCollection> {
struct ElementsFilter; struct ElementsFilter;
impl CollectionFilter for ElementsFilter { impl CollectionFilter for ElementsFilter {
fn filter(&self, elem: &JSRef<Element>, root: &JSRef<Node>) -> bool { fn filter(&self, elem: &JSRef<Element>, root: &JSRef<Node>) -> bool {
@ -95,7 +95,7 @@ impl<'a> HTMLFieldSetElementMethods for JSRef<'a, HTMLFieldSetElement> {
} }
} }
let roots = RootCollection::new(); let roots = RootCollection::new();
let node: &JSRef<Node> = NodeCast::from_ref(abstract_self); let node: &JSRef<Node> = NodeCast::from_ref(self);
let filter = ~ElementsFilter; let filter = ~ElementsFilter;
let window = window_from_node(node).root(&roots); let window = window_from_node(node).root(&roots);
HTMLCollection::create(&*window, node, filter) HTMLCollection::create(&*window, node, filter)

View file

@ -87,8 +87,8 @@ pub trait HTMLIFrameElementMethods {
fn SetSrcdoc(&mut self, _srcdoc: DOMString) -> ErrorResult; fn SetSrcdoc(&mut self, _srcdoc: DOMString) -> ErrorResult;
fn Name(&self) -> DOMString; fn Name(&self) -> DOMString;
fn SetName(&mut self, _name: DOMString) -> ErrorResult; fn SetName(&mut self, _name: DOMString) -> ErrorResult;
fn Sandbox(&self, abstract_self: &JSRef<HTMLIFrameElement>) -> DOMString; fn Sandbox(&self) -> DOMString;
fn SetSandbox(&mut self, abstract_self: &mut JSRef<HTMLIFrameElement>, sandbox: DOMString); fn SetSandbox(&mut self, sandbox: DOMString);
fn AllowFullscreen(&self) -> bool; fn AllowFullscreen(&self) -> bool;
fn SetAllowFullscreen(&mut self, _allow: bool) -> ErrorResult; fn SetAllowFullscreen(&mut self, _allow: bool) -> ErrorResult;
fn Width(&self) -> DOMString; fn Width(&self) -> DOMString;
@ -137,13 +137,13 @@ impl<'a> HTMLIFrameElementMethods for JSRef<'a, HTMLIFrameElement> {
Ok(()) Ok(())
} }
fn Sandbox(&self, abstract_self: &JSRef<HTMLIFrameElement>) -> DOMString { fn Sandbox(&self) -> DOMString {
let element: &JSRef<Element> = ElementCast::from_ref(abstract_self); let element: &JSRef<Element> = ElementCast::from_ref(self);
element.get_string_attribute("sandbox") element.get_string_attribute("sandbox")
} }
fn SetSandbox(&mut self, abstract_self: &mut JSRef<HTMLIFrameElement>, sandbox: DOMString) { fn SetSandbox(&mut self, sandbox: DOMString) {
let element: &mut JSRef<Element> = ElementCast::from_mut_ref(abstract_self); let element: &mut JSRef<Element> = ElementCast::from_mut_ref(self);
element.set_string_attribute("sandbox", sandbox); element.set_string_attribute("sandbox", sandbox);
} }

View file

@ -80,55 +80,55 @@ impl HTMLImageElement {
} }
pub trait HTMLImageElementMethods { pub trait HTMLImageElementMethods {
fn Alt(&self, abstract_self: &JSRef<HTMLImageElement>) -> DOMString; fn Alt(&self) -> DOMString;
fn SetAlt(&mut self, abstract_self: &mut JSRef<HTMLImageElement>, alt: DOMString); fn SetAlt(&mut self, alt: DOMString);
fn Src(&self, abstract_self: &JSRef<HTMLImageElement>) -> DOMString; fn Src(&self) -> DOMString;
fn SetSrc(&mut self, abstract_self: &mut JSRef<HTMLImageElement>, src: DOMString); fn SetSrc(&mut self, src: DOMString);
fn CrossOrigin(&self) -> DOMString; fn CrossOrigin(&self) -> DOMString;
fn SetCrossOrigin(&mut self, _cross_origin: DOMString) -> ErrorResult; fn SetCrossOrigin(&mut self, _cross_origin: DOMString) -> ErrorResult;
fn UseMap(&self, abstract_self: &JSRef<HTMLImageElement>) -> DOMString; fn UseMap(&self) -> DOMString;
fn SetUseMap(&mut self, abstract_self: &mut JSRef<HTMLImageElement>, use_map: DOMString); fn SetUseMap(&mut self, use_map: DOMString);
fn IsMap(&self, abstract_self: &JSRef<HTMLImageElement>) -> bool; fn IsMap(&self) -> bool;
fn SetIsMap(&self, abstract_self: &mut JSRef<HTMLImageElement>, is_map: bool); fn SetIsMap(&mut self, is_map: bool);
fn Width(&self, abstract_self: &JSRef<HTMLImageElement>) -> u32; fn Width(&self) -> u32;
fn SetWidth(&mut self, abstract_self: &mut JSRef<HTMLImageElement>, width: u32); fn SetWidth(&mut self, width: u32);
fn Height(&self, abstract_self: &JSRef<HTMLImageElement>) -> u32; fn Height(&self) -> u32;
fn SetHeight(&mut self, abstract_self: &mut JSRef<HTMLImageElement>, height: u32); fn SetHeight(&mut self, height: u32);
fn NaturalWidth(&self) -> u32; fn NaturalWidth(&self) -> u32;
fn NaturalHeight(&self) -> u32; fn NaturalHeight(&self) -> u32;
fn Complete(&self) -> bool; fn Complete(&self) -> bool;
fn Name(&self, abstract_self: &JSRef<HTMLImageElement>) -> DOMString; fn Name(&self) -> DOMString;
fn SetName(&mut self, abstract_self: &mut JSRef<HTMLImageElement>, name: DOMString); fn SetName(&mut self, name: DOMString);
fn Align(&self, abstract_self: &JSRef<HTMLImageElement>) -> DOMString; fn Align(&self) -> DOMString;
fn SetAlign(&mut self, abstract_self: &mut JSRef<HTMLImageElement>, align: DOMString); fn SetAlign(&mut self, align: DOMString);
fn Hspace(&self, abstract_self: &JSRef<HTMLImageElement>) -> u32; fn Hspace(&self) -> u32;
fn SetHspace(&mut self, abstract_self: &mut JSRef<HTMLImageElement>, hspace: u32); fn SetHspace(&mut self, hspace: u32);
fn Vspace(&self, abstract_self: &JSRef<HTMLImageElement>) -> u32; fn Vspace(&self) -> u32;
fn SetVspace(&mut self, abstract_self: &mut JSRef<HTMLImageElement>, vspace: u32); fn SetVspace(&mut self, vspace: u32);
fn LongDesc(&self, abstract_self: &JSRef<HTMLImageElement>) -> DOMString; fn LongDesc(&self) -> DOMString;
fn SetLongDesc(&mut self, abstract_self: &mut JSRef<HTMLImageElement>, longdesc: DOMString); fn SetLongDesc(&mut self, longdesc: DOMString);
fn Border(&self, abstract_self: &JSRef<HTMLImageElement>) -> DOMString; fn Border(&self) -> DOMString;
fn SetBorder(&mut self, abstract_self: &mut JSRef<HTMLImageElement>, border: DOMString); fn SetBorder(&mut self, border: DOMString);
} }
impl<'a> HTMLImageElementMethods for JSRef<'a, HTMLImageElement> { impl<'a> HTMLImageElementMethods for JSRef<'a, HTMLImageElement> {
fn Alt(&self, abstract_self: &JSRef<HTMLImageElement>) -> DOMString { fn Alt(&self) -> DOMString {
let element: &JSRef<Element> = ElementCast::from_ref(abstract_self); let element: &JSRef<Element> = ElementCast::from_ref(self);
element.get_string_attribute("alt") element.get_string_attribute("alt")
} }
fn SetAlt(&mut self, abstract_self: &mut JSRef<HTMLImageElement>, alt: DOMString) { fn SetAlt(&mut self, alt: DOMString) {
let element: &mut JSRef<Element> = ElementCast::from_mut_ref(abstract_self); let element: &mut JSRef<Element> = ElementCast::from_mut_ref(self);
element.set_string_attribute("alt", alt) element.set_string_attribute("alt", alt)
} }
fn Src(&self, abstract_self: &JSRef<HTMLImageElement>) -> DOMString { fn Src(&self) -> DOMString {
let element: &JSRef<Element> = ElementCast::from_ref(abstract_self); let element: &JSRef<Element> = ElementCast::from_ref(self);
element.get_string_attribute("src") element.get_string_attribute("src")
} }
fn SetSrc(&mut self, abstract_self: &mut JSRef<HTMLImageElement>, src: DOMString) { fn SetSrc(&mut self, src: DOMString) {
let element: &mut JSRef<Element> = ElementCast::from_mut_ref(abstract_self); let element: &mut JSRef<Element> = ElementCast::from_mut_ref(self);
element.set_url_attribute("src", src) element.set_url_attribute("src", src)
} }
@ -140,45 +140,45 @@ impl<'a> HTMLImageElementMethods for JSRef<'a, HTMLImageElement> {
Ok(()) Ok(())
} }
fn UseMap(&self, abstract_self: &JSRef<HTMLImageElement>) -> DOMString { fn UseMap(&self) -> DOMString {
let element: &JSRef<Element> = ElementCast::from_ref(abstract_self); let element: &JSRef<Element> = ElementCast::from_ref(self);
element.get_string_attribute("useMap") element.get_string_attribute("useMap")
} }
fn SetUseMap(&mut self, abstract_self: &mut JSRef<HTMLImageElement>, use_map: DOMString) { fn SetUseMap(&mut self, use_map: DOMString) {
let element: &mut JSRef<Element> = ElementCast::from_mut_ref(abstract_self); let element: &mut JSRef<Element> = ElementCast::from_mut_ref(self);
element.set_string_attribute("useMap", use_map) element.set_string_attribute("useMap", use_map)
} }
fn IsMap(&self, abstract_self: &JSRef<HTMLImageElement>) -> bool { fn IsMap(&self) -> bool {
let element: &JSRef<Element> = ElementCast::from_ref(abstract_self); let element: &JSRef<Element> = ElementCast::from_ref(self);
from_str::<bool>(element.get_string_attribute("hspace")).unwrap() from_str::<bool>(element.get_string_attribute("hspace")).unwrap()
} }
fn SetIsMap(&self, abstract_self: &mut JSRef<HTMLImageElement>, is_map: bool) { fn SetIsMap(&mut self, is_map: bool) {
let element: &mut JSRef<Element> = ElementCast::from_mut_ref(abstract_self); let element: &mut JSRef<Element> = ElementCast::from_mut_ref(self);
element.set_string_attribute("isMap", is_map.to_str()) element.set_string_attribute("isMap", is_map.to_str())
} }
fn Width(&self, abstract_self: &JSRef<HTMLImageElement>) -> u32 { fn Width(&self) -> u32 {
let node: &JSRef<Node> = NodeCast::from_ref(abstract_self); let node: &JSRef<Node> = NodeCast::from_ref(self);
let rect = node.get_bounding_content_box(); let rect = node.get_bounding_content_box();
to_px(rect.size.width) as u32 to_px(rect.size.width) as u32
} }
fn SetWidth(&mut self, abstract_self: &mut JSRef<HTMLImageElement>, width: u32) { fn SetWidth(&mut self, width: u32) {
let elem: &mut JSRef<Element> = ElementCast::from_mut_ref(abstract_self); let elem: &mut JSRef<Element> = ElementCast::from_mut_ref(self);
elem.set_uint_attribute("width", width) elem.set_uint_attribute("width", width)
} }
fn Height(&self, abstract_self: &JSRef<HTMLImageElement>) -> u32 { fn Height(&self) -> u32 {
let node: &JSRef<Node> = NodeCast::from_ref(abstract_self); let node: &JSRef<Node> = NodeCast::from_ref(self);
let rect = node.get_bounding_content_box(); let rect = node.get_bounding_content_box();
to_px(rect.size.height) as u32 to_px(rect.size.height) as u32
} }
fn SetHeight(&mut self, abstract_self: &mut JSRef<HTMLImageElement>, height: u32) { fn SetHeight(&mut self, height: u32) {
let elem: &mut JSRef<Element> = ElementCast::from_mut_ref(abstract_self); let elem: &mut JSRef<Element> = ElementCast::from_mut_ref(self);
elem.set_uint_attribute("height", height) elem.set_uint_attribute("height", height)
} }
@ -194,63 +194,63 @@ impl<'a> HTMLImageElementMethods for JSRef<'a, HTMLImageElement> {
false false
} }
fn Name(&self, abstract_self: &JSRef<HTMLImageElement>) -> DOMString { fn Name(&self) -> DOMString {
let element: &JSRef<Element> = ElementCast::from_ref(abstract_self); let element: &JSRef<Element> = ElementCast::from_ref(self);
element.get_string_attribute("name") element.get_string_attribute("name")
} }
fn SetName(&mut self, abstract_self: &mut JSRef<HTMLImageElement>, name: DOMString) { fn SetName(&mut self, name: DOMString) {
let element: &mut JSRef<Element> = ElementCast::from_mut_ref(abstract_self); let element: &mut JSRef<Element> = ElementCast::from_mut_ref(self);
element.set_string_attribute("name", name) element.set_string_attribute("name", name)
} }
fn Align(&self, abstract_self: &JSRef<HTMLImageElement>) -> DOMString { fn Align(&self) -> DOMString {
let element: &JSRef<Element> = ElementCast::from_ref(abstract_self); let element: &JSRef<Element> = ElementCast::from_ref(self);
element.get_string_attribute("longdesc") element.get_string_attribute("longdesc")
} }
fn SetAlign(&mut self, abstract_self: &mut JSRef<HTMLImageElement>, align: DOMString) { fn SetAlign(&mut self, align: DOMString) {
let element: &mut JSRef<Element> = ElementCast::from_mut_ref(abstract_self); let element: &mut JSRef<Element> = ElementCast::from_mut_ref(self);
element.set_string_attribute("align", align) element.set_string_attribute("align", align)
} }
fn Hspace(&self, abstract_self: &JSRef<HTMLImageElement>) -> u32 { fn Hspace(&self) -> u32 {
let element: &JSRef<Element> = ElementCast::from_ref(abstract_self); let element: &JSRef<Element> = ElementCast::from_ref(self);
from_str::<u32>(element.get_string_attribute("hspace")).unwrap() from_str::<u32>(element.get_string_attribute("hspace")).unwrap()
} }
fn SetHspace(&mut self, abstract_self: &mut JSRef<HTMLImageElement>, hspace: u32) { fn SetHspace(&mut self, hspace: u32) {
let element: &mut JSRef<Element> = ElementCast::from_mut_ref(abstract_self); let element: &mut JSRef<Element> = ElementCast::from_mut_ref(self);
element.set_uint_attribute("hspace", hspace) element.set_uint_attribute("hspace", hspace)
} }
fn Vspace(&self, abstract_self: &JSRef<HTMLImageElement>) -> u32 { fn Vspace(&self) -> u32 {
let element: &JSRef<Element> = ElementCast::from_ref(abstract_self); let element: &JSRef<Element> = ElementCast::from_ref(self);
from_str::<u32>(element.get_string_attribute("vspace")).unwrap() from_str::<u32>(element.get_string_attribute("vspace")).unwrap()
} }
fn SetVspace(&mut self, abstract_self: &mut JSRef<HTMLImageElement>, vspace: u32) { fn SetVspace(&mut self, vspace: u32) {
let element: &mut JSRef<Element> = ElementCast::from_mut_ref(abstract_self); let element: &mut JSRef<Element> = ElementCast::from_mut_ref(self);
element.set_uint_attribute("vspace", vspace) element.set_uint_attribute("vspace", vspace)
} }
fn LongDesc(&self, abstract_self: &JSRef<HTMLImageElement>) -> DOMString { fn LongDesc(&self) -> DOMString {
let element: &JSRef<Element> = ElementCast::from_ref(abstract_self); let element: &JSRef<Element> = ElementCast::from_ref(self);
element.get_string_attribute("longdesc") element.get_string_attribute("longdesc")
} }
fn SetLongDesc(&mut self, abstract_self: &mut JSRef<HTMLImageElement>, longdesc: DOMString) { fn SetLongDesc(&mut self, longdesc: DOMString) {
let element: &mut JSRef<Element> = ElementCast::from_mut_ref(abstract_self); let element: &mut JSRef<Element> = ElementCast::from_mut_ref(self);
element.set_string_attribute("longdesc", longdesc) element.set_string_attribute("longdesc", longdesc)
} }
fn Border(&self, abstract_self: &JSRef<HTMLImageElement>) -> DOMString { fn Border(&self) -> DOMString {
let element: &JSRef<Element> = ElementCast::from_ref(abstract_self); let element: &JSRef<Element> = ElementCast::from_ref(self);
element.get_string_attribute("border") element.get_string_attribute("border")
} }
fn SetBorder(&mut self, abstract_self: &mut JSRef<HTMLImageElement>, border: DOMString) { fn SetBorder(&mut self, border: DOMString) {
let element: &mut JSRef<Element> = ElementCast::from_mut_ref(abstract_self); let element: &mut JSRef<Element> = ElementCast::from_mut_ref(self);
element.set_string_attribute("border", border) element.set_string_attribute("border", border)
} }
} }

View file

@ -42,8 +42,8 @@ impl HTMLScriptElement {
} }
pub trait HTMLScriptElementMethods { pub trait HTMLScriptElementMethods {
fn Src(&self, abstract_self: &JSRef<HTMLScriptElement>) -> DOMString; fn Src(&self) -> DOMString;
fn SetSrc(&mut self, _abstract_self: &JSRef<HTMLScriptElement>, _src: DOMString) -> ErrorResult; fn SetSrc(&mut self, _src: DOMString) -> ErrorResult;
fn Type(&self) -> DOMString; fn Type(&self) -> DOMString;
fn SetType(&mut self, _type: DOMString) -> ErrorResult; fn SetType(&mut self, _type: DOMString) -> ErrorResult;
fn Charset(&self) -> DOMString; fn Charset(&self) -> DOMString;
@ -63,12 +63,12 @@ pub trait HTMLScriptElementMethods {
} }
impl<'a> HTMLScriptElementMethods for JSRef<'a, HTMLScriptElement> { impl<'a> HTMLScriptElementMethods for JSRef<'a, HTMLScriptElement> {
fn Src(&self, abstract_self: &JSRef<HTMLScriptElement>) -> DOMString { fn Src(&self) -> DOMString {
let element: &JSRef<Element> = ElementCast::from_ref(abstract_self); let element: &JSRef<Element> = ElementCast::from_ref(self);
element.get_url_attribute("src") element.get_url_attribute("src")
} }
fn SetSrc(&mut self, _abstract_self: &JSRef<HTMLScriptElement>, _src: DOMString) -> ErrorResult { fn SetSrc(&mut self, _src: DOMString) -> ErrorResult {
Ok(()) Ok(())
} }

View file

@ -98,7 +98,7 @@ impl<'a> StyleElementHelpers for JSRef<'a, HTMLStyleElement> {
let win = window_from_node(node).root(&roots); let win = window_from_node(node).root(&roots);
let url = win.get().page().get_url(); let url = win.get().page().get_url();
let data = node.GetTextContent(node).expect("Element.textContent must be a string"); let data = node.GetTextContent().expect("Element.textContent must be a string");
let sheet = parse_inline_css(url, data); let sheet = parse_inline_css(url, data);
let LayoutChan(ref layout_chan) = *win.get().page().layout_chan; let LayoutChan(ref layout_chan) = *win.get().page().layout_chan;
layout_chan.send(AddStylesheetMsg(sheet)); layout_chan.send(AddStylesheetMsg(sheet));

View file

@ -224,21 +224,6 @@ pub enum NodeTypeId {
ProcessingInstructionNodeTypeId, ProcessingInstructionNodeTypeId,
} }
pub fn AppendChild<'a>(self_: &mut JSRef<'a, Node>, node: &mut JSRef<Node>) -> Fallible<Unrooted<Node>> {
let mut self_alias = self_.clone();
self_.AppendChild(&mut self_alias, node)
}
pub fn ReplaceChild<'a>(self_: &mut JSRef<'a, Node>, node: &mut JSRef<Node>, child: &mut JSRef<Node>) -> Fallible<Unrooted<Node>> {
let mut self_alias = self_.clone();
self_.ReplaceChild(&mut self_alias, node, child)
}
pub fn RemoveChild<'a>(self_: &mut JSRef<'a, Node>, node: &mut JSRef<Node>) -> Fallible<Unrooted<Node>> {
let mut self_alias = self_.clone();
self_.RemoveChild(&mut self_alias, node)
}
pub trait NodeHelpers { pub trait NodeHelpers {
fn ancestors(&self) -> AncestorIterator; fn ancestors(&self) -> AncestorIterator;
fn children(&self) -> AbstractNodeChildrenIterator; fn children(&self) -> AbstractNodeChildrenIterator;
@ -1386,30 +1371,30 @@ impl Node {
pub trait NodeMethods { pub trait NodeMethods {
fn NodeType(&self) -> u16; fn NodeType(&self) -> u16;
fn NodeName(&self, abstract_self: &JSRef<Node>) -> DOMString; fn NodeName(&self) -> DOMString;
fn GetBaseURI(&self) -> Option<DOMString>; fn GetBaseURI(&self) -> Option<DOMString>;
fn GetOwnerDocument(&self) -> Option<Unrooted<Document>>; fn GetOwnerDocument(&self) -> Option<Unrooted<Document>>;
fn GetParentNode(&self) -> Option<Unrooted<Node>>; fn GetParentNode(&self) -> Option<Unrooted<Node>>;
fn GetParentElement(&self) -> Option<Unrooted<Element>>; fn GetParentElement(&self) -> Option<Unrooted<Element>>;
fn HasChildNodes(&self) -> bool; fn HasChildNodes(&self) -> bool;
fn ChildNodes(&mut self, abstract_self: &JSRef<Node>) -> Unrooted<NodeList>; fn ChildNodes(&mut self) -> Unrooted<NodeList>;
fn GetFirstChild(&self) -> Option<Unrooted<Node>>; fn GetFirstChild(&self) -> Option<Unrooted<Node>>;
fn GetLastChild(&self) -> Option<Unrooted<Node>>; fn GetLastChild(&self) -> Option<Unrooted<Node>>;
fn GetPreviousSibling(&self) -> Option<Unrooted<Node>>; fn GetPreviousSibling(&self) -> Option<Unrooted<Node>>;
fn GetNextSibling(&self) -> Option<Unrooted<Node>>; fn GetNextSibling(&self) -> Option<Unrooted<Node>>;
fn GetNodeValue(&self, abstract_self: &JSRef<Node>) -> Option<DOMString>; fn GetNodeValue(&self) -> Option<DOMString>;
fn SetNodeValue(&mut self, abstract_self: &mut JSRef<Node>, val: Option<DOMString>) -> ErrorResult; fn SetNodeValue(&mut self, val: Option<DOMString>) -> ErrorResult;
fn GetTextContent(&self, abstract_self: &JSRef<Node>) -> Option<DOMString>; fn GetTextContent(&self) -> Option<DOMString>;
fn SetTextContent(&mut self, abstract_self: &mut JSRef<Node>, value: Option<DOMString>) -> ErrorResult; fn SetTextContent(&mut self, value: Option<DOMString>) -> ErrorResult;
fn InsertBefore(&self, abstract_self: &mut JSRef<Node>, node: &mut JSRef<Node>, child: Option<JSRef<Node>>) -> Fallible<Unrooted<Node>>; fn InsertBefore(&mut self, node: &mut JSRef<Node>, child: Option<JSRef<Node>>) -> Fallible<Unrooted<Node>>;
fn AppendChild(&self, abstract_self: &mut JSRef<Node>, node: &mut JSRef<Node>) -> Fallible<Unrooted<Node>>; fn AppendChild(&mut self, node: &mut JSRef<Node>) -> Fallible<Unrooted<Node>>;
fn ReplaceChild(&self, parent: &mut JSRef<Node>, node: &mut JSRef<Node>, child: &mut JSRef<Node>) -> Fallible<Unrooted<Node>>; fn ReplaceChild(&mut self, node: &mut JSRef<Node>, child: &mut JSRef<Node>) -> Fallible<Unrooted<Node>>;
fn RemoveChild(&self, abstract_self: &mut JSRef<Node>, node: &mut JSRef<Node>) -> Fallible<Unrooted<Node>>; fn RemoveChild(&mut self, node: &mut JSRef<Node>) -> Fallible<Unrooted<Node>>;
fn Normalize(&mut self, abstract_self: &mut JSRef<Node>); fn Normalize(&mut self);
fn CloneNode(&self, abstract_self: &mut JSRef<Node>, deep: bool) -> Unrooted<Node>; fn CloneNode(&self, deep: bool) -> Unrooted<Node>;
fn IsEqualNode(&self, abstract_self: &JSRef<Node>, maybe_node: Option<JSRef<Node>>) -> bool; fn IsEqualNode(&self, maybe_node: Option<JSRef<Node>>) -> bool;
fn CompareDocumentPosition(&self, abstract_self: &JSRef<Node>, other: &JSRef<Node>) -> u16; fn CompareDocumentPosition(&self, other: &JSRef<Node>) -> u16;
fn Contains(&self, abstract_self: &JSRef<Node>, maybe_other: Option<JSRef<Node>>) -> bool; fn Contains(&self, maybe_other: Option<JSRef<Node>>) -> bool;
fn LookupPrefix(&self, _prefix: Option<DOMString>) -> Option<DOMString>; fn LookupPrefix(&self, _prefix: Option<DOMString>) -> Option<DOMString>;
fn LookupNamespaceURI(&self, _namespace: Option<DOMString>) -> Option<DOMString>; fn LookupNamespaceURI(&self, _namespace: Option<DOMString>) -> Option<DOMString>;
fn IsDefaultNamespace(&self, _namespace: Option<DOMString>) -> bool; fn IsDefaultNamespace(&self, _namespace: Option<DOMString>) -> bool;
@ -1430,21 +1415,21 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
} }
// http://dom.spec.whatwg.org/#dom-node-nodename // http://dom.spec.whatwg.org/#dom-node-nodename
fn NodeName(&self, abstract_self: &JSRef<Node>) -> DOMString { fn NodeName(&self) -> DOMString {
match self.type_id { match self.type_id {
ElementNodeTypeId(..) => { ElementNodeTypeId(..) => {
let elem: &JSRef<Element> = ElementCast::to_ref(abstract_self).unwrap(); let elem: &JSRef<Element> = ElementCast::to_ref(self).unwrap();
elem.TagName() elem.TagName()
} }
TextNodeTypeId => ~"#text", TextNodeTypeId => ~"#text",
ProcessingInstructionNodeTypeId => { ProcessingInstructionNodeTypeId => {
let processing_instruction: &JSRef<ProcessingInstruction> = let processing_instruction: &JSRef<ProcessingInstruction> =
ProcessingInstructionCast::to_ref(abstract_self).unwrap(); ProcessingInstructionCast::to_ref(self).unwrap();
processing_instruction.Target() processing_instruction.Target()
} }
CommentNodeTypeId => ~"#comment", CommentNodeTypeId => ~"#comment",
DoctypeNodeTypeId => { DoctypeNodeTypeId => {
let doctype: &JSRef<DocumentType> = DocumentTypeCast::to_ref(abstract_self).unwrap(); let doctype: &JSRef<DocumentType> = DocumentTypeCast::to_ref(self).unwrap();
doctype.get().name.clone() doctype.get().name.clone()
}, },
DocumentFragmentNodeTypeId => ~"#document-fragment", DocumentFragmentNodeTypeId => ~"#document-fragment",
@ -1494,7 +1479,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
} }
// http://dom.spec.whatwg.org/#dom-node-childnodes // http://dom.spec.whatwg.org/#dom-node-childnodes
fn ChildNodes(&mut self, abstract_self: &JSRef<Node>) -> Unrooted<NodeList> { fn ChildNodes(&mut self) -> Unrooted<NodeList> {
let roots = RootCollection::new(); let roots = RootCollection::new();
match self.child_list { match self.child_list {
None => (), None => (),
@ -1503,7 +1488,8 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
let doc = self.deref().owner_doc().root(&roots); let doc = self.deref().owner_doc().root(&roots);
let window = doc.deref().window.root(&roots); let window = doc.deref().window.root(&roots);
self.child_list.assign(Some(NodeList::new_child_list(&*window, abstract_self))); let child_list = NodeList::new_child_list(&*window, self);
self.child_list.assign(Some(child_list));
Unrooted::new(self.child_list.get_ref().clone()) Unrooted::new(self.child_list.get_ref().clone())
} }
@ -1528,12 +1514,12 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
} }
// http://dom.spec.whatwg.org/#dom-node-nodevalue // http://dom.spec.whatwg.org/#dom-node-nodevalue
fn GetNodeValue(&self, abstract_self: &JSRef<Node>) -> Option<DOMString> { fn GetNodeValue(&self) -> Option<DOMString> {
match self.type_id { match self.type_id {
CommentNodeTypeId | CommentNodeTypeId |
TextNodeTypeId | TextNodeTypeId |
ProcessingInstructionNodeTypeId => { ProcessingInstructionNodeTypeId => {
let chardata: &JSRef<CharacterData> = CharacterDataCast::to_ref(abstract_self).unwrap(); let chardata: &JSRef<CharacterData> = CharacterDataCast::to_ref(self).unwrap();
Some(chardata.Data()) Some(chardata.Data())
} }
_ => { _ => {
@ -1543,26 +1529,26 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
} }
// http://dom.spec.whatwg.org/#dom-node-nodevalue // http://dom.spec.whatwg.org/#dom-node-nodevalue
fn SetNodeValue(&mut self, abstract_self: &mut JSRef<Node>, val: Option<DOMString>) fn SetNodeValue(&mut self, val: Option<DOMString>)
-> ErrorResult { -> ErrorResult {
match self.type_id { match self.type_id {
CommentNodeTypeId | CommentNodeTypeId |
TextNodeTypeId | TextNodeTypeId |
ProcessingInstructionNodeTypeId => { ProcessingInstructionNodeTypeId => {
self.SetTextContent(abstract_self, val) self.SetTextContent(val)
} }
_ => Ok(()) _ => Ok(())
} }
} }
// http://dom.spec.whatwg.org/#dom-node-textcontent // http://dom.spec.whatwg.org/#dom-node-textcontent
fn GetTextContent(&self, abstract_self: &JSRef<Node>) -> Option<DOMString> { fn GetTextContent(&self) -> Option<DOMString> {
let roots = RootCollection::new(); let roots = RootCollection::new();
match self.type_id { match self.type_id {
DocumentFragmentNodeTypeId | DocumentFragmentNodeTypeId |
ElementNodeTypeId(..) => { ElementNodeTypeId(..) => {
let mut content = ~""; let mut content = ~"";
for node in abstract_self.traverse_preorder(&roots) { for node in self.traverse_preorder(&roots) {
if node.is_text() { if node.is_text() {
let text: &JSRef<Text> = TextCast::to_ref(&node).unwrap(); let text: &JSRef<Text> = TextCast::to_ref(&node).unwrap();
content.push_str(text.get().characterdata.data.as_slice()); content.push_str(text.get().characterdata.data.as_slice());
@ -1573,7 +1559,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
CommentNodeTypeId | CommentNodeTypeId |
TextNodeTypeId | TextNodeTypeId |
ProcessingInstructionNodeTypeId => { ProcessingInstructionNodeTypeId => {
let characterdata: &JSRef<CharacterData> = CharacterDataCast::to_ref(abstract_self).unwrap(); let characterdata: &JSRef<CharacterData> = CharacterDataCast::to_ref(self).unwrap();
Some(characterdata.Data()) Some(characterdata.Data())
} }
DoctypeNodeTypeId | DoctypeNodeTypeId |
@ -1584,7 +1570,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
} }
// http://dom.spec.whatwg.org/#dom-node-textcontent // http://dom.spec.whatwg.org/#dom-node-textcontent
fn SetTextContent(&mut self, abstract_self: &mut JSRef<Node>, value: Option<DOMString>) fn SetTextContent(&mut self, value: Option<DOMString>)
-> ErrorResult { -> ErrorResult {
let roots = RootCollection::new(); let roots = RootCollection::new();
let value = null_str_as_empty(&value); let value = null_str_as_empty(&value);
@ -1596,19 +1582,21 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
None None
} else { } else {
let document = self.owner_doc().root(&roots); let document = self.owner_doc().root(&roots);
Some(NodeCast::from_unrooted(document.deref().CreateTextNode(&*document, value))) Some(NodeCast::from_unrooted(document.deref().CreateTextNode(value)))
}.root(&roots); }.root(&roots);
// Step 3. // Step 3.
Node::replace_all(node.root_ref(), abstract_self); Node::replace_all(node.root_ref(), self);
} }
CommentNodeTypeId | CommentNodeTypeId |
TextNodeTypeId | TextNodeTypeId |
ProcessingInstructionNodeTypeId => { ProcessingInstructionNodeTypeId => {
self.wait_until_safe_to_modify_dom(); self.wait_until_safe_to_modify_dom();
let characterdata: &mut JSRef<CharacterData> = CharacterDataCast::to_mut_ref(abstract_self).unwrap(); {
let characterdata: &mut JSRef<CharacterData> = CharacterDataCast::to_mut_ref(self).unwrap();
characterdata.get_mut().data = value.clone(); characterdata.get_mut().data = value.clone();
}
// Notify the document that the content of this node is different // Notify the document that the content of this node is different
let document = self.owner_doc().root(&roots); let document = self.owner_doc().root(&roots);
@ -1621,24 +1609,21 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
} }
// http://dom.spec.whatwg.org/#dom-node-insertbefore // http://dom.spec.whatwg.org/#dom-node-insertbefore
fn InsertBefore(&self, abstract_self: &mut JSRef<Node>, node: &mut JSRef<Node>, child: Option<JSRef<Node>>) fn InsertBefore(&mut self, node: &mut JSRef<Node>, child: Option<JSRef<Node>>) -> Fallible<Unrooted<Node>> {
-> Fallible<Unrooted<Node>> { Node::pre_insert(node, self, child)
Node::pre_insert(node, abstract_self, child)
} }
// http://dom.spec.whatwg.org/#dom-node-appendchild // http://dom.spec.whatwg.org/#dom-node-appendchild
fn AppendChild(&self, abstract_self: &mut JSRef<Node>, node: &mut JSRef<Node>) fn AppendChild(&mut self, node: &mut JSRef<Node>) -> Fallible<Unrooted<Node>> {
-> Fallible<Unrooted<Node>> { Node::pre_insert(node, self, None)
Node::pre_insert(node, abstract_self, None)
} }
// http://dom.spec.whatwg.org/#concept-node-replace // http://dom.spec.whatwg.org/#concept-node-replace
fn ReplaceChild(&self, parent: &mut JSRef<Node>, node: &mut JSRef<Node>, child: &mut JSRef<Node>) fn ReplaceChild(&mut self, node: &mut JSRef<Node>, child: &mut JSRef<Node>) -> Fallible<Unrooted<Node>> {
-> Fallible<Unrooted<Node>> {
let roots = RootCollection::new(); let roots = RootCollection::new();
// Step 1. // Step 1.
match parent.type_id() { match self.type_id() {
DocumentNodeTypeId | DocumentNodeTypeId |
DocumentFragmentNodeTypeId | DocumentFragmentNodeTypeId |
ElementNodeTypeId(..) => (), ElementNodeTypeId(..) => (),
@ -1646,19 +1631,19 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
} }
// Step 2. // Step 2.
if node.is_inclusive_ancestor_of(parent) { if node.is_inclusive_ancestor_of(self) {
return Err(HierarchyRequest); return Err(HierarchyRequest);
} }
// Step 3. // Step 3.
if !parent.is_parent_of(child) { if !self.is_parent_of(child) {
return Err(NotFound); return Err(NotFound);
} }
// Step 4-5. // Step 4-5.
match node.type_id() { match node.type_id() {
TextNodeTypeId if parent.is_document() => return Err(HierarchyRequest), TextNodeTypeId if self.is_document() => return Err(HierarchyRequest),
DoctypeNodeTypeId if !parent.is_document() => return Err(HierarchyRequest), DoctypeNodeTypeId if !self.is_document() => return Err(HierarchyRequest),
DocumentFragmentNodeTypeId | DocumentFragmentNodeTypeId |
DoctypeNodeTypeId | DoctypeNodeTypeId |
ElementNodeTypeId(..) | ElementNodeTypeId(..) |
@ -1669,7 +1654,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
} }
// Step 6. // Step 6.
match parent.type_id() { match self.type_id() {
DocumentNodeTypeId => { DocumentNodeTypeId => {
match node.type_id() { match node.type_id() {
// Step 6.1 // Step 6.1
@ -1682,7 +1667,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
0 => (), 0 => (),
// Step 6.1.2 // Step 6.1.2
1 => { 1 => {
if parent.child_elements().any(|c| NodeCast::from_ref(&c) != child) { if self.child_elements().any(|c| NodeCast::from_ref(&c) != child) {
return Err(HierarchyRequest); return Err(HierarchyRequest);
} }
if child.following_siblings() if child.following_siblings()
@ -1696,7 +1681,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
}, },
// Step 6.2 // Step 6.2
ElementNodeTypeId(..) => { ElementNodeTypeId(..) => {
if parent.child_elements().any(|c| NodeCast::from_ref(&c) != child) { if self.child_elements().any(|c| NodeCast::from_ref(&c) != child) {
return Err(HierarchyRequest); return Err(HierarchyRequest);
} }
if child.following_siblings() if child.following_siblings()
@ -1706,10 +1691,10 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
}, },
// Step 6.3 // Step 6.3
DoctypeNodeTypeId => { DoctypeNodeTypeId => {
if parent.children().any(|c| c.deref().is_doctype() && &c != child) { if self.children().any(|c| c.deref().is_doctype() && &c != child) {
return Err(HierarchyRequest); return Err(HierarchyRequest);
} }
if parent.children() if self.children()
.take_while(|c| c != child) .take_while(|c| c != child)
.any(|c| c.deref().is_element()) { .any(|c| c.deref().is_element()) {
return Err(HierarchyRequest); return Err(HierarchyRequest);
@ -1737,15 +1722,15 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
}; };
// Step 9. // Step 9.
let document = document_from_node(parent).root(&roots); let document = document_from_node(self).root(&roots);
Node::adopt(node, &*document); Node::adopt(node, &*document);
{ {
// Step 10. // Step 10.
Node::remove(child, parent, Suppressed); Node::remove(child, self, Suppressed);
// Step 11. // Step 11.
Node::insert(node, parent, reference_child, Suppressed); Node::insert(node, self, reference_child, Suppressed);
} }
// Step 12-14. // Step 12-14.
@ -1764,13 +1749,13 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
} }
// http://dom.spec.whatwg.org/#dom-node-removechild // http://dom.spec.whatwg.org/#dom-node-removechild
fn RemoveChild(&self, abstract_self: &mut JSRef<Node>, node: &mut JSRef<Node>) fn RemoveChild(&mut self, node: &mut JSRef<Node>)
-> Fallible<Unrooted<Node>> { -> Fallible<Unrooted<Node>> {
Node::pre_remove(node, abstract_self) Node::pre_remove(node, self)
} }
// http://dom.spec.whatwg.org/#dom-node-normalize // http://dom.spec.whatwg.org/#dom-node-normalize
fn Normalize(&mut self, abstract_self: &mut JSRef<Node>) { fn Normalize(&mut self) {
let roots = RootCollection::new(); let roots = RootCollection::new();
let mut prev_text = None; let mut prev_text = None;
for mut child in self.children() { for mut child in self.children() {
@ -1778,20 +1763,19 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
let mut child_alias = child.clone(); let mut child_alias = child.clone();
let characterdata: &JSRef<CharacterData> = CharacterDataCast::to_ref(&child).unwrap(); let characterdata: &JSRef<CharacterData> = CharacterDataCast::to_ref(&child).unwrap();
if characterdata.Length() == 0 { if characterdata.Length() == 0 {
abstract_self.remove_child(&mut child_alias); self.remove_child(&mut child_alias);
} else { } else {
match prev_text { match prev_text {
Some(ref mut text_node) => { Some(ref mut text_node) => {
let prev_characterdata: &mut JSRef<CharacterData> = CharacterDataCast::to_mut_ref(text_node).unwrap(); let prev_characterdata: &mut JSRef<CharacterData> = CharacterDataCast::to_mut_ref(text_node).unwrap();
let _ = prev_characterdata.AppendData(characterdata.Data()); let _ = prev_characterdata.AppendData(characterdata.Data());
abstract_self.remove_child(&mut child_alias); self.remove_child(&mut child_alias);
}, },
None => prev_text = Some(child_alias) None => prev_text = Some(child_alias)
} }
} }
} else { } else {
let mut c = child.clone(); child.Normalize();
child.Normalize(&mut c);
prev_text = None; prev_text = None;
} }
@ -1799,15 +1783,15 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
} }
// http://dom.spec.whatwg.org/#dom-node-clonenode // http://dom.spec.whatwg.org/#dom-node-clonenode
fn CloneNode(&self, abstract_self: &mut JSRef<Node>, deep: bool) -> Unrooted<Node> { fn CloneNode(&self, deep: bool) -> Unrooted<Node> {
match deep { match deep {
true => Node::clone(abstract_self, None, CloneChildren), true => Node::clone(self, None, CloneChildren),
false => Node::clone(abstract_self, None, DoNotCloneChildren) false => Node::clone(self, None, DoNotCloneChildren)
} }
} }
// http://dom.spec.whatwg.org/#dom-node-isequalnode // http://dom.spec.whatwg.org/#dom-node-isequalnode
fn IsEqualNode(&self, abstract_self: &JSRef<Node>, maybe_node: Option<JSRef<Node>>) -> bool { fn IsEqualNode(&self, maybe_node: Option<JSRef<Node>>) -> bool {
fn is_equal_doctype(node: &JSRef<Node>, other: &JSRef<Node>) -> bool { fn is_equal_doctype(node: &JSRef<Node>, other: &JSRef<Node>) -> bool {
let doctype: &JSRef<DocumentType> = DocumentTypeCast::to_ref(node).unwrap(); let doctype: &JSRef<DocumentType> = DocumentTypeCast::to_ref(node).unwrap();
let other_doctype: &JSRef<DocumentType> = DocumentTypeCast::to_ref(other).unwrap(); let other_doctype: &JSRef<DocumentType> = DocumentTypeCast::to_ref(other).unwrap();
@ -1879,20 +1863,20 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
// Step 1. // Step 1.
None => false, None => false,
// Step 2-6. // Step 2-6.
Some(ref node) => is_equal_node(abstract_self, node) Some(ref node) => is_equal_node(self, node)
} }
} }
// http://dom.spec.whatwg.org/#dom-node-comparedocumentposition // http://dom.spec.whatwg.org/#dom-node-comparedocumentposition
fn CompareDocumentPosition(&self, abstract_self: &JSRef<Node>, other: &JSRef<Node>) -> u16 { fn CompareDocumentPosition(&self, other: &JSRef<Node>) -> u16 {
let roots = RootCollection::new(); let roots = RootCollection::new();
if abstract_self == other { if self == other {
// step 2. // step 2.
0 0
} else { } else {
let mut lastself = abstract_self.clone(); let mut lastself = self.clone();
let mut lastother = other.clone(); let mut lastother = other.clone();
for ancestor in abstract_self.ancestors() { for ancestor in self.ancestors() {
if &ancestor == other { if &ancestor == other {
// step 4. // step 4.
return NodeConstants::DOCUMENT_POSITION_CONTAINS + return NodeConstants::DOCUMENT_POSITION_CONTAINS +
@ -1901,7 +1885,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
lastself = ancestor.clone(); lastself = ancestor.clone();
} }
for ancestor in other.ancestors() { for ancestor in other.ancestors() {
if &ancestor == abstract_self { if &ancestor == self {
// step 5. // step 5.
return NodeConstants::DOCUMENT_POSITION_CONTAINED_BY + return NodeConstants::DOCUMENT_POSITION_CONTAINED_BY +
NodeConstants::DOCUMENT_POSITION_FOLLOWING; NodeConstants::DOCUMENT_POSITION_FOLLOWING;
@ -1910,7 +1894,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
} }
if lastself != lastother { if lastself != lastother {
let abstract_uint: uintptr_t = as_uintptr(&*abstract_self); let abstract_uint: uintptr_t = as_uintptr(&*self);
let other_uint: uintptr_t = as_uintptr(&*other); let other_uint: uintptr_t = as_uintptr(&*other);
let random = if abstract_uint < other_uint { let random = if abstract_uint < other_uint {
@ -1929,7 +1913,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
// step 6. // step 6.
return NodeConstants::DOCUMENT_POSITION_PRECEDING; return NodeConstants::DOCUMENT_POSITION_PRECEDING;
} }
if &child == abstract_self { if &child == self {
// step 7. // step 7.
return NodeConstants::DOCUMENT_POSITION_FOLLOWING; return NodeConstants::DOCUMENT_POSITION_FOLLOWING;
} }
@ -1939,10 +1923,10 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
} }
// http://dom.spec.whatwg.org/#dom-node-contains // http://dom.spec.whatwg.org/#dom-node-contains
fn Contains(&self, abstract_self: &JSRef<Node>, maybe_other: Option<JSRef<Node>>) -> bool { fn Contains(&self, maybe_other: Option<JSRef<Node>>) -> bool {
match maybe_other { match maybe_other {
None => false, None => false,
Some(ref other) => abstract_self.is_inclusive_ancestor_of(other) Some(ref other) => self.is_inclusive_ancestor_of(other)
} }
} }

View file

@ -118,9 +118,9 @@ pub trait WindowMethods {
fn Focus(&self); fn Focus(&self);
fn Blur(&self); fn Blur(&self);
fn GetFrameElement(&self) -> Option<Unrooted<Element>>; fn GetFrameElement(&self) -> Option<Unrooted<Element>>;
fn Location(&mut self, abstract_self: &JSRef<Window>) -> Unrooted<Location>; fn Location(&mut self) -> Unrooted<Location>;
fn Console(&mut self, abstract_self: &JSRef<Window>) -> Unrooted<Console>; fn Console(&mut self) -> Unrooted<Console>;
fn Navigator(&mut self, abstract_self: &JSRef<Window>) -> Unrooted<Navigator>; fn Navigator(&mut self) -> Unrooted<Navigator>;
fn Confirm(&self, _message: DOMString) -> bool; fn Confirm(&self, _message: DOMString) -> bool;
fn Prompt(&self, _message: DOMString, _default: DOMString) -> Option<DOMString>; fn Prompt(&self, _message: DOMString, _default: DOMString) -> Option<DOMString>;
fn Print(&self); fn Print(&self);
@ -129,8 +129,8 @@ pub trait WindowMethods {
fn ClearTimeout(&mut self, handle: i32); fn ClearTimeout(&mut self, handle: i32);
fn SetInterval(&mut self, _cx: *JSContext, callback: JSVal, timeout: i32) -> i32; fn SetInterval(&mut self, _cx: *JSContext, callback: JSVal, timeout: i32) -> i32;
fn ClearInterval(&mut self, handle: i32); fn ClearInterval(&mut self, handle: i32);
fn Window(&self, abstract_self: &JSRef<Window>) -> Unrooted<Window>; fn Window(&self) -> Unrooted<Window>;
fn Self(&self, abstract_self: &JSRef<Window>) -> Unrooted<Window>; fn Self(&self) -> Unrooted<Window>;
} }
impl<'a> WindowMethods for JSRef<'a, Window> { impl<'a> WindowMethods for JSRef<'a, Window> {
@ -180,24 +180,27 @@ impl<'a> WindowMethods for JSRef<'a, Window> {
None None
} }
fn Location(&mut self, abstract_self: &JSRef<Window>) -> Unrooted<Location> { fn Location(&mut self) -> Unrooted<Location> {
if self.location.is_none() { if self.location.is_none() {
let page = self.deref().page.clone(); let page = self.deref().page.clone();
self.location.assign(Some(Location::new(abstract_self, page))); let location = Location::new(self, page);
self.location.assign(Some(location));
} }
Unrooted::new(self.location.get_ref().clone()) Unrooted::new(self.location.get_ref().clone())
} }
fn Console(&mut self, abstract_self: &JSRef<Window>) -> Unrooted<Console> { fn Console(&mut self) -> Unrooted<Console> {
if self.console.is_none() { if self.console.is_none() {
self.console.assign(Some(Console::new(abstract_self))); let console = Console::new(self);
self.console.assign(Some(console));
} }
Unrooted::new(self.console.get_ref().clone()) Unrooted::new(self.console.get_ref().clone())
} }
fn Navigator(&mut self, abstract_self: &JSRef<Window>) -> Unrooted<Navigator> { fn Navigator(&mut self) -> Unrooted<Navigator> {
if self.navigator.is_none() { if self.navigator.is_none() {
self.navigator.assign(Some(Navigator::new(abstract_self))); let navigator = Navigator::new(self);
self.navigator.assign(Some(navigator));
} }
Unrooted::new(self.navigator.get_ref().clone()) Unrooted::new(self.navigator.get_ref().clone())
} }
@ -238,12 +241,12 @@ impl<'a> WindowMethods for JSRef<'a, Window> {
self.ClearTimeout(handle); self.ClearTimeout(handle);
} }
fn Window(&self, abstract_self: &JSRef<Window>) -> Unrooted<Window> { fn Window(&self) -> Unrooted<Window> {
Unrooted::new_rooted(abstract_self) Unrooted::new_rooted(self)
} }
fn Self(&self, abstract_self: &JSRef<Window>) -> Unrooted<Window> { fn Self(&self) -> Unrooted<Window> {
self.Window(abstract_self) self.Window()
} }
} }

View file

@ -5,7 +5,7 @@
use dom::attr::AttrMethods; use dom::attr::AttrMethods;
use dom::bindings::codegen::InheritTypes::{NodeBase, NodeCast, TextCast, ElementCast}; use dom::bindings::codegen::InheritTypes::{NodeBase, NodeCast, TextCast, ElementCast};
use dom::bindings::codegen::InheritTypes::HTMLIFrameElementCast; use dom::bindings::codegen::InheritTypes::HTMLIFrameElementCast;
use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted, OptionalRootable}; use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted, OptionalRootable, Root};
use dom::bindings::utils::Reflectable; use dom::bindings::utils::Reflectable;
use dom::document::Document; use dom::document::Document;
use dom::element::{AttributeHandlers, HTMLLinkElementTypeId, HTMLIFrameElementTypeId}; use dom::element::{AttributeHandlers, HTMLLinkElementTypeId, HTMLIFrameElementTypeId};
@ -13,7 +13,7 @@ use dom::htmlelement::HTMLElement;
use dom::htmlheadingelement::{Heading1, Heading2, Heading3, Heading4, Heading5, Heading6}; use dom::htmlheadingelement::{Heading1, Heading2, Heading3, Heading4, Heading5, Heading6};
use dom::htmliframeelement::IFrameSize; use dom::htmliframeelement::IFrameSize;
use dom::htmlformelement::HTMLFormElement; use dom::htmlformelement::HTMLFormElement;
use dom::node::{ElementNodeTypeId, NodeHelpers, AppendChild}; use dom::node::{ElementNodeTypeId, NodeHelpers, NodeMethods};
use dom::types::*; use dom::types::*;
use html::cssparse::{StylesheetProvenance, UrlProvenance, spawn_css_parser}; use html::cssparse::{StylesheetProvenance, UrlProvenance, spawn_css_parser};
use script_task::Page; use script_task::Page;
@ -422,8 +422,8 @@ pub fn parse_html(page: &Page,
unsafe { unsafe {
debug!("append child {:x} {:x}", parent, child); debug!("append child {:x} {:x}", parent, child);
let mut child = from_hubbub_node(child, Some(&roots)).root(&roots); let mut child = from_hubbub_node(child, Some(&roots)).root(&roots);
let mut parent = from_hubbub_node(parent, None).root(&roots); let mut parent: Root<Node> = from_hubbub_node(parent, None).root(&roots);
assert!(AppendChild(&mut *parent, &mut *child).is_ok()); assert!(parent.AppendChild(&mut *child).is_ok());
} }
child child
}, },

View file

@ -17,7 +17,7 @@ use dom::element::{Element, AttributeHandlers};
use dom::event::{Event_, ResizeEvent, ReflowEvent, ClickEvent, MouseDownEvent, MouseMoveEvent, MouseUpEvent}; use dom::event::{Event_, ResizeEvent, ReflowEvent, ClickEvent, MouseDownEvent, MouseMoveEvent, MouseUpEvent};
use dom::event::{Event, EventMethods}; use dom::event::{Event, EventMethods};
use dom::uievent::{UIEvent, UIEventMethods}; use dom::uievent::{UIEvent, UIEventMethods};
use dom::eventtarget::EventTarget; use dom::eventtarget::{EventTarget, EventTargetHelpers};
use dom::node; use dom::node;
use dom::node::{Node, NodeHelpers}; use dom::node::{Node, NodeHelpers};
use dom::window::{TimerId, Window}; use dom::window::{TimerId, Window};
@ -988,10 +988,8 @@ impl ScriptTask {
let mut event = Event::new(&*window).root(&roots); let mut event = Event::new(&*window).root(&roots);
event.InitEvent(~"load", false, false); event.InitEvent(~"load", false, false);
let doctarget: &JSRef<EventTarget> = EventTargetCast::from_ref(&*document); let doctarget: &JSRef<EventTarget> = EventTargetCast::from_ref(&*document);
let wintarget: &mut JSRef<EventTarget> = EventTargetCast::from_mut_ref(&mut *window); let wintarget: &JSRef<EventTarget> = EventTargetCast::from_ref(&*window);
let wintarget_alias = wintarget.clone(); let _ = wintarget.dispatch_event_with_target(Some((*doctarget).clone()),
let _ = wintarget.get_mut().dispatch_event_with_target(&wintarget_alias,
Some((*doctarget).clone()),
&mut *event); &mut *event);
let mut fragment_node = page.fragment_node.deref().borrow_mut(); let mut fragment_node = page.fragment_node.deref().borrow_mut();
@ -1061,10 +1059,7 @@ impl ScriptTask {
let event: &mut JSRef<Event> = EventCast::from_mut_ref(&mut *uievent); let event: &mut JSRef<Event> = EventCast::from_mut_ref(&mut *uievent);
let wintarget: &mut JSRef<EventTarget> = EventTargetCast::from_mut_ref(&mut *window); let wintarget: &mut JSRef<EventTarget> = EventTargetCast::from_mut_ref(&mut *window);
let wintarget_alias = wintarget.clone(); let _ = wintarget.dispatch_event_with_target(None, &mut *event);
let _ = wintarget.get_mut().dispatch_event_with_target(&wintarget_alias,
None,
&mut *event);
} }
None => () None => ()
} }