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

View file

@ -2494,12 +2494,6 @@ class CGSpecializedMethod(CGAbstractExternMethod):
nativeName = MakeNativeName(name)
extraPre = ''
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(),
self.descriptor, self.method),
pre=extraPre +
@ -2552,12 +2546,6 @@ class CGSpecializedGetter(CGAbstractExternMethod):
infallible = ('infallible' in
self.descriptor.getExtendedAttributes(self.attr,
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:
nativeName = "Get" + nativeName
return CGWrapper(CGIndenter(CGGetterCall(argsPre, self.attr.type, nativeName,
@ -2614,12 +2602,6 @@ class CGSpecializedSetter(CGAbstractExternMethod):
nativeName = "Set" + MakeNativeName(name)
argsPre = []
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,
self.descriptor, self.attr)),
pre=extraPre +

View file

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

View file

@ -27,8 +27,8 @@ use dom::htmlheadelement::HTMLHeadElement;
use dom::htmlhtmlelement::HTMLHtmlElement;
use dom::htmltitleelement::HTMLTitleElement;
use dom::mouseevent::MouseEvent;
use dom::node::{Node, ElementNodeTypeId, DocumentNodeTypeId, NodeHelpers, AppendChild};
use dom::node::{CloneChildren, DoNotCloneChildren, RemoveChild, ReplaceChild};
use dom::node::{Node, ElementNodeTypeId, DocumentNodeTypeId, NodeHelpers, NodeMethods};
use dom::node::{CloneChildren, DoNotCloneChildren};
use dom::nodelist::NodeList;
use dom::text::Text;
use dom::processinginstruction::ProcessingInstruction;
@ -165,7 +165,7 @@ impl Document {
/// Remove any existing association between the provided id and any elements in this document.
pub fn unregister_named_element(&mut self,
abstract_self: &JSRef<Element>,
to_unregister: &JSRef<Element>,
id: DOMString) {
let roots = RootCollection::new();
let mut is_empty = false;
@ -174,7 +174,7 @@ impl Document {
Some(elements) => {
let position = elements.iter()
.map(|elem| elem.root(&roots))
.position(|element| &*element == abstract_self)
.position(|element| &*element == to_unregister)
.expect("This element should be in registered.");
elements.remove(position);
is_empty = elements.is_empty();
@ -282,37 +282,35 @@ pub trait DocumentMethods {
fn ContentType(&self) -> DOMString;
fn GetDoctype(&self) -> Option<Unrooted<DocumentType>>;
fn GetDocumentElement(&self) -> Option<Unrooted<Element>>;
fn GetElementsByTagName(&self, abstract_self: &JSRef<Document>, tag_name: DOMString) -> Unrooted<HTMLCollection>;
fn GetElementsByTagNameNS(&self, abstract_self: &JSRef<Document>, maybe_ns: Option<DOMString>, tag_name: DOMString) -> Unrooted<HTMLCollection>;
fn GetElementsByClassName(&self, abstract_self: &JSRef<Document>, classes: DOMString) -> Unrooted<HTMLCollection>;
fn GetElementsByTagName(&self, tag_name: DOMString) -> Unrooted<HTMLCollection>;
fn GetElementsByTagNameNS(&self, maybe_ns: Option<DOMString>, tag_name: DOMString) -> Unrooted<HTMLCollection>;
fn GetElementsByClassName(&self, classes: DOMString) -> Unrooted<HTMLCollection>;
fn GetElementById(&self, id: DOMString) -> Option<Unrooted<Element>>;
fn CreateElement(&self, abstract_self: &JSRef<Document>, local_name: DOMString) -> Fallible<Unrooted<Element>>;
fn CreateElementNS(&self, abstract_self: &JSRef<Document>,
namespace: Option<DOMString>,
qualified_name: DOMString) -> Fallible<Unrooted<Element>>;
fn CreateDocumentFragment(&self, abstract_self: &JSRef<Document>) -> Unrooted<DocumentFragment>;
fn CreateTextNode(&self, abstract_self: &JSRef<Document>, data: DOMString) -> Unrooted<Text>;
fn CreateComment(&self, abstract_self: &JSRef<Document>, data: DOMString) -> Unrooted<Comment>;
fn CreateProcessingInstruction(&self, abstract_self: &JSRef<Document>, target: DOMString, data: DOMString) -> Fallible<Unrooted<ProcessingInstruction>>;
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 CreateElement(&self, local_name: DOMString) -> Fallible<Unrooted<Element>>;
fn CreateElementNS(&self, namespace: Option<DOMString>, qualified_name: DOMString) -> Fallible<Unrooted<Element>>;
fn CreateDocumentFragment(&self) -> Unrooted<DocumentFragment>;
fn CreateTextNode(&self, data: DOMString) -> Unrooted<Text>;
fn CreateComment(&self, data: DOMString) -> Unrooted<Comment>;
fn CreateProcessingInstruction(&self, target: DOMString, data: DOMString) -> Fallible<Unrooted<ProcessingInstruction>>;
fn ImportNode(&self, node: &JSRef<Node>, deep: bool) -> Fallible<Unrooted<Node>>;
fn AdoptNode(&self, node: &mut JSRef<Node>) -> Fallible<Unrooted<Node>>;
fn CreateEvent(&self, interface: DOMString) -> Fallible<Unrooted<Event>>;
fn Title(&self, _: &JSRef<Document>) -> DOMString;
fn SetTitle(&self, abstract_self: &JSRef<Document>, title: DOMString) -> ErrorResult;
fn Title(&self) -> DOMString;
fn SetTitle(&self, title: DOMString) -> ErrorResult;
fn GetHead(&self) -> Option<Unrooted<HTMLHeadElement>>;
fn GetBody(&self, _: &JSRef<Document>) -> Option<Unrooted<HTMLElement>>;
fn SetBody(&self, abstract_self: &JSRef<Document>, new_body: Option<JSRef<HTMLElement>>) -> ErrorResult;
fn GetBody(&self) -> Option<Unrooted<HTMLElement>>;
fn SetBody(&self, new_body: Option<JSRef<HTMLElement>>) -> ErrorResult;
fn GetElementsByName(&self, name: DOMString) -> Unrooted<NodeList>;
fn Images(&self, abstract_self: &JSRef<Document>) -> Unrooted<HTMLCollection>;
fn Embeds(&self, abstract_self: &JSRef<Document>) -> Unrooted<HTMLCollection>;
fn Plugins(&self, abstract_self: &JSRef<Document>) -> Unrooted<HTMLCollection>;
fn Links(&self, abstract_self: &JSRef<Document>) -> Unrooted<HTMLCollection>;
fn Forms(&self, abstract_self: &JSRef<Document>) -> Unrooted<HTMLCollection>;
fn Scripts(&self, abstract_self: &JSRef<Document>) -> Unrooted<HTMLCollection>;
fn Anchors(&self, abstract_self: &JSRef<Document>) -> Unrooted<HTMLCollection>;
fn Applets(&self, abstract_self: &JSRef<Document>) -> Unrooted<HTMLCollection>;
fn Location(&mut self, _abstract_self: &JSRef<Document>) -> Unrooted<Location>;
fn Children(&self, abstract_self: &JSRef<Document>) -> Unrooted<HTMLCollection>;
fn Images(&self) -> Unrooted<HTMLCollection>;
fn Embeds(&self) -> Unrooted<HTMLCollection>;
fn Plugins(&self) -> Unrooted<HTMLCollection>;
fn Links(&self) -> Unrooted<HTMLCollection>;
fn Forms(&self) -> Unrooted<HTMLCollection>;
fn Scripts(&self) -> Unrooted<HTMLCollection>;
fn Anchors(&self) -> Unrooted<HTMLCollection>;
fn Applets(&self) -> Unrooted<HTMLCollection>;
fn Location(&mut self) -> Unrooted<Location>;
fn Children(&self) -> Unrooted<HTMLCollection>;
}
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
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 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
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 window = self.window.root(&roots);
@ -385,15 +383,15 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
Some(namespace) => Namespace::from_str(namespace),
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
fn GetElementsByClassName(&self, abstract_self: &JSRef<Document>, classes: DOMString) -> Unrooted<HTMLCollection> {
fn GetElementsByClassName(&self, classes: DOMString) -> Unrooted<HTMLCollection> {
let roots = RootCollection::new();
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
@ -405,18 +403,17 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
}
// http://dom.spec.whatwg.org/#dom-document-createelement
fn CreateElement(&self, abstract_self: &JSRef<Document>, local_name: DOMString)
-> Fallible<Unrooted<Element>> {
fn CreateElement(&self, local_name: DOMString) -> Fallible<Unrooted<Element>> {
if xml_name_type(local_name) == InvalidXMLName {
debug!("Not a valid element name");
return Err(InvalidCharacter);
}
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
fn CreateElementNS(&self, abstract_self: &JSRef<Document>,
fn CreateElementNS(&self,
namespace: Option<DOMString>,
qualified_name: DOMString) -> Fallible<Unrooted<Element>> {
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 {
Ok(build_element_from_tag(local_name_from_qname, abstract_self))
Ok(build_element_from_tag(local_name_from_qname, self))
} 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
fn CreateDocumentFragment(&self, abstract_self: &JSRef<Document>) -> Unrooted<DocumentFragment> {
DocumentFragment::new(abstract_self)
fn CreateDocumentFragment(&self) -> Unrooted<DocumentFragment> {
DocumentFragment::new(self)
}
// http://dom.spec.whatwg.org/#dom-document-createtextnode
fn CreateTextNode(&self, abstract_self: &JSRef<Document>, data: DOMString)
fn CreateTextNode(&self, data: DOMString)
-> Unrooted<Text> {
Text::new(data, abstract_self)
Text::new(data, self)
}
// http://dom.spec.whatwg.org/#dom-document-createcomment
fn CreateComment(&self, abstract_self: &JSRef<Document>, data: DOMString) -> Unrooted<Comment> {
Comment::new(data, abstract_self)
fn CreateComment(&self, data: DOMString) -> Unrooted<Comment> {
Comment::new(data, self)
}
// 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>> {
// Step 1.
if xml_name_type(target) == InvalidXMLName {
@ -491,11 +488,11 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
}
// Step 3.
Ok(ProcessingInstruction::new(target, data, abstract_self))
Ok(ProcessingInstruction::new(target, data, self))
}
// 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.
if node.is_document() {
return Err(NotSupported);
@ -507,18 +504,18 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
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
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.
if node.is_document() {
return Err(NotSupported);
}
// Step 2.
Node::adopt(node, abstract_self);
Node::adopt(node, self);
// Step 3.
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
fn Title(&self, _: &JSRef<Document>) -> DOMString {
fn Title(&self) -> DOMString {
let mut title = ~"";
let roots = RootCollection::new();
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
fn SetTitle(&self, abstract_self: &JSRef<Document>, title: DOMString) -> ErrorResult {
fn SetTitle(&self, title: DOMString) -> ErrorResult {
let roots = RootCollection::new();
self.GetDocumentElement().root(&roots).map(|root| {
@ -577,20 +574,20 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
match title_node {
Some(ref mut title_node) => {
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 => {
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 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!(AppendChild(&mut *head, &mut *new_title).is_ok());
assert!(new_title.AppendChild(NodeCast::from_mut_ref(&mut *new_text)).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
fn GetBody(&self, _: &JSRef<Document>) -> Option<Unrooted<HTMLElement>> {
fn GetBody(&self) -> Option<Unrooted<HTMLElement>> {
let roots = RootCollection::new();
self.get_html_element().and_then(|root| {
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
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();
// Step 1.
@ -646,7 +643,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
}
// 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.
if old_body.as_ref().map(|body| body.deref()) == new_body.as_ref().map(|a| &*a) {
return Ok(());
@ -665,9 +662,9 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
Some(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 window = self.window.root(&roots);
@ -702,10 +699,10 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
}
}
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 window = self.window.root(&roots);
@ -717,15 +714,15 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
}
}
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
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 window = self.window.root(&roots);
@ -738,10 +735,10 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
}
}
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 window = self.window.root(&roots);
@ -753,10 +750,10 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
}
}
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 window = self.window.root(&roots);
@ -768,10 +765,10 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
}
}
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 window = self.window.root(&roots);
@ -783,10 +780,10 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
}
}
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 window = self.window.root(&roots);
@ -798,19 +795,18 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
}
}
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 mut window = self.window.root(&roots);
let window_alias = self.window.root(&roots);
window.Location(&*window_alias)
window.Location()
}
fn Children(&self, abstract_self: &JSRef<Document>) -> Unrooted<HTMLCollection> {
fn Children(&self) -> Unrooted<HTMLCollection> {
let roots = RootCollection::new();
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 {
fn Children(&self, abstract_self: &JSRef<DocumentFragment>) -> Unrooted<HTMLCollection>;
fn Children(&self) -> Unrooted<HTMLCollection>;
}
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 window = window_from_node(abstract_self).root(&roots);
HTMLCollection::children(&window.root_ref(), NodeCast::from_ref(abstract_self))
let window = window_from_node(self).root(&roots);
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::htmlhtmlelement::HTMLHtmlElement;
use dom::htmltitleelement::HTMLTitleElement;
use dom::node::{Node, AppendChild};
use dom::node::{Node, NodeMethods};
use dom::text::Text;
use dom::window::{Window, WindowMethods};
use servo_util::str::DOMString;
@ -87,7 +87,7 @@ impl<'a> DOMImplementationMethods for JSRef<'a, DOMImplementation> {
let mut maybe_elem = if qname.is_empty() {
None
} else {
match doc.deref().CreateElementNS(&*doc, namespace, qname) {
match doc.CreateElementNS(namespace, qname) {
Err(error) => return Err(error),
Ok(elem) => Some(elem)
}
@ -100,7 +100,7 @@ impl<'a> DOMImplementationMethods for JSRef<'a, DOMImplementation> {
match maybe_doctype {
None => (),
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) {
None => (),
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.
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.
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.
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.
match title {
@ -152,18 +152,18 @@ impl<'a> DOMImplementationMethods for JSRef<'a, DOMImplementation> {
Some(title_str) => {
// Step 6.1.
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.
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.
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.

View file

@ -198,9 +198,6 @@ pub trait AttributeHandlers {
fn do_set_attribute(&mut self, local_name: DOMString, value: DOMString,
name: DOMString, namespace: Namespace,
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 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);
}
// 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 {
let roots = RootCollection::new();
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| {
attr.local_name == local_name
});
@ -382,9 +289,14 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
match idx {
None => (),
Some(idx) => {
{
let node: &JSRef<Node> = NodeCast::from_ref(self);
node.wait_until_safe_to_modify_dom();
}
if namespace == namespace::Null {
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);
@ -463,27 +375,27 @@ pub trait ElementMethods {
fn LocalName(&self) -> DOMString;
fn GetPrefix(&self) -> Option<DOMString>;
fn TagName(&self) -> DOMString;
fn Id(&self, abstract_self: &JSRef<Element>) -> DOMString;
fn SetId(&mut self, abstract_self: &mut JSRef<Element>, id: DOMString);
fn ClassName(&self, abstract_self: &JSRef<Element>) -> DOMString;
fn SetClassName(&self, abstract_self: &mut JSRef<Element>, class: DOMString);
fn Attributes(&mut self, abstract_self: &JSRef<Element>) -> Unrooted<AttrList>;
fn GetAttribute(&self, abstract_self: &JSRef<Element>, name: DOMString) -> Option<DOMString>;
fn GetAttributeNS(&self, abstract_self: &JSRef<Element>, namespace: Option<DOMString>, local_name: DOMString) -> Option<DOMString>;
fn SetAttribute(&self, abstract_self: &mut JSRef<Element>, name: DOMString, value: DOMString) -> ErrorResult;
fn SetAttributeNS(&self, abstract_self: &mut JSRef<Element>, namespace_url: Option<DOMString>, name: DOMString, value: DOMString) -> ErrorResult;
fn RemoveAttribute(&mut self, abstract_self: &mut JSRef<Element>, name: DOMString) -> ErrorResult;
fn RemoveAttributeNS(&mut self, abstract_self: &mut JSRef<Element>, namespace: Option<DOMString>, localname: DOMString) -> ErrorResult;
fn HasAttribute(&self, abstract_self: &JSRef<Element>, name: DOMString) -> bool;
fn HasAttributeNS(&self, abstract_self: &JSRef<Element>, namespace: Option<DOMString>, local_name: DOMString) -> bool;
fn GetElementsByTagName(&self, abstract_self: &JSRef<Element>, localname: DOMString) -> Unrooted<HTMLCollection>;
fn GetElementsByTagNameNS(&self, abstract_self: &JSRef<Element>, maybe_ns: Option<DOMString>, localname: DOMString) -> Unrooted<HTMLCollection>;
fn GetElementsByClassName(&self, abstract_self: &JSRef<Element>, classes: DOMString) -> Unrooted<HTMLCollection>;
fn GetClientRects(&self, abstract_self: &JSRef<Element>) -> Unrooted<ClientRectList>;
fn GetBoundingClientRect(&self, abstract_self: &JSRef<Element>) -> Unrooted<ClientRect>;
fn GetInnerHTML(&self, abstract_self: &JSRef<Element>) -> Fallible<DOMString>;
fn GetOuterHTML(&self, abstract_self: &JSRef<Element>) -> Fallible<DOMString>;
fn Children(&self, abstract_self: &JSRef<Element>) -> Unrooted<HTMLCollection>;
fn Id(&self) -> DOMString;
fn SetId(&mut self, id: DOMString);
fn ClassName(&self) -> DOMString;
fn SetClassName(&mut self, class: DOMString);
fn Attributes(&mut self) -> Unrooted<AttrList>;
fn GetAttribute(&self, name: DOMString) -> Option<DOMString>;
fn GetAttributeNS(&self, namespace: Option<DOMString>, local_name: DOMString) -> Option<DOMString>;
fn SetAttribute(&mut self, name: DOMString, value: DOMString) -> ErrorResult;
fn SetAttributeNS(&mut self, namespace_url: Option<DOMString>, name: DOMString, value: DOMString) -> ErrorResult;
fn RemoveAttribute(&mut self, name: DOMString) -> ErrorResult;
fn RemoveAttributeNS(&mut self, namespace: Option<DOMString>, localname: DOMString) -> ErrorResult;
fn HasAttribute(&self, name: DOMString) -> bool;
fn HasAttributeNS(&self, namespace: Option<DOMString>, local_name: DOMString) -> bool;
fn GetElementsByTagName(&self, localname: DOMString) -> Unrooted<HTMLCollection>;
fn GetElementsByTagNameNS(&self, maybe_ns: Option<DOMString>, localname: DOMString) -> Unrooted<HTMLCollection>;
fn GetElementsByClassName(&self, classes: DOMString) -> Unrooted<HTMLCollection>;
fn GetClientRects(&self) -> Unrooted<ClientRectList>;
fn GetBoundingClientRect(&self) -> Unrooted<ClientRect>;
fn GetInnerHTML(&self) -> Fallible<DOMString>;
fn GetOuterHTML(&self) -> Fallible<DOMString>;
fn Children(&self) -> Unrooted<HTMLCollection>;
}
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
fn Id(&self, abstract_self: &JSRef<Element>) -> DOMString {
abstract_self.get_string_attribute("id")
fn Id(&self) -> DOMString {
self.get_string_attribute("id")
}
// http://dom.spec.whatwg.org/#dom-element-id
fn SetId(&mut self, abstract_self: &mut JSRef<Element>, id: DOMString) {
abstract_self.set_string_attribute("id", id);
fn SetId(&mut self, id: DOMString) {
self.set_string_attribute("id", id);
}
// http://dom.spec.whatwg.org/#dom-element-classname
fn ClassName(&self, abstract_self: &JSRef<Element>) -> DOMString {
abstract_self.get_string_attribute("class")
fn ClassName(&self) -> DOMString {
self.get_string_attribute("class")
}
// http://dom.spec.whatwg.org/#dom-element-classname
fn SetClassName(&self, abstract_self: &mut JSRef<Element>, class: DOMString) {
abstract_self.set_string_attribute("class", class);
fn SetClassName(&mut self, class: DOMString) {
self.set_string_attribute("class", class);
}
// 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();
match self.attr_list {
None => (),
@ -543,111 +455,184 @@ impl<'a> ElementMethods for JSRef<'a, Element> {
let doc = self.node.owner_doc().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));
Unrooted::new(self.attr_list.get_ref().clone())
}
// 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 name = if abstract_self.get().html_element_in_html_document() {
let name = if self.get().html_element_in_html_document() {
name.to_ascii_lower()
} else {
name
};
abstract_self.get_attribute(Null, name).root(&roots)
self.get_attribute(Null, name).root(&roots)
.map(|s| s.deref().Value())
}
// http://dom.spec.whatwg.org/#dom-element-getattributens
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> {
let roots = RootCollection::new();
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())
}
// http://dom.spec.whatwg.org/#dom-element-setattribute
fn SetAttribute(&self, abstract_self: &mut JSRef<Element>,
fn SetAttribute(&mut self,
name: DOMString,
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
fn SetAttributeNS(&self,
abstract_self: &mut JSRef<Element>,
fn SetAttributeNS(&mut self,
namespace_url: Option<DOMString>,
name: DOMString,
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
fn RemoveAttribute(&mut self,
abstract_self: &mut JSRef<Element>,
name: DOMString) -> ErrorResult {
let name = if self.html_element_in_html_document() {
name.to_ascii_lower()
} else {
name
};
abstract_self.remove_attribute(namespace::Null, name)
self.remove_attribute(namespace::Null, name)
}
// http://dom.spec.whatwg.org/#dom-element-removeattributens
fn RemoveAttributeNS(&mut self,
abstract_self: &mut JSRef<Element>,
namespace: Option<DOMString>,
localname: DOMString) -> ErrorResult {
namespace: Option<DOMString>,
localname: DOMString) -> ErrorResult {
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
fn HasAttribute(&self, abstract_self: &JSRef<Element>,
name: DOMString) -> bool {
self.GetAttribute(abstract_self, name).is_some()
fn HasAttribute(&self,
name: DOMString) -> bool {
self.GetAttribute(name).is_some()
}
// http://dom.spec.whatwg.org/#dom-element-hasattributens
fn HasAttributeNS(&self, abstract_self: &JSRef<Element>,
namespace: Option<DOMString>,
local_name: DOMString) -> bool {
self.GetAttributeNS(abstract_self, namespace, local_name).is_some()
fn HasAttributeNS(&self,
namespace: Option<DOMString>,
local_name: DOMString) -> bool {
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 window = window_from_node(abstract_self).root(&roots);
HTMLCollection::by_tag_name(&*window, NodeCast::from_ref(abstract_self), localname)
let window = window_from_node(self).root(&roots);
HTMLCollection::by_tag_name(&*window, NodeCast::from_ref(self), localname)
}
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> {
let roots = RootCollection::new();
let namespace = match maybe_ns {
Some(namespace) => Namespace::from_str(namespace),
None => Null
};
let window = window_from_node(abstract_self).root(&roots);
HTMLCollection::by_tag_name_ns(&*window, NodeCast::from_ref(abstract_self), localname, namespace)
let window = window_from_node(self).root(&roots);
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 window = window_from_node(abstract_self).root(&roots);
HTMLCollection::by_class_name(&*window, NodeCast::from_ref(abstract_self), classes)
let window = window_from_node(self).root(&roots);
HTMLCollection::by_class_name(&*window, NodeCast::from_ref(self), classes)
}
// 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 win = window_from_node(abstract_self).root(&roots);
let node: &JSRef<Node> = NodeCast::from_ref(abstract_self);
let win = window_from_node(self).root(&roots);
let node: &JSRef<Node> = NodeCast::from_ref(self);
let rects = node.get_content_boxes();
let rects: ~[Root<ClientRect>] = rects.iter().map(|r| {
ClientRect::new(
@ -662,10 +647,10 @@ impl<'a> ElementMethods for JSRef<'a, Element> {
}
// 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 win = window_from_node(abstract_self).root(&roots);
let node: &JSRef<Node> = NodeCast::from_ref(abstract_self);
let win = window_from_node(self).root(&roots);
let node: &JSRef<Node> = NodeCast::from_ref(self);
let rect = node.get_bounding_content_box();
ClientRect::new(
&*win,
@ -675,21 +660,21 @@ impl<'a> ElementMethods for JSRef<'a, Element> {
rect.origin.x + rect.size.width)
}
fn GetInnerHTML(&self, abstract_self: &JSRef<Element>) -> Fallible<DOMString> {
fn GetInnerHTML(&self) -> Fallible<DOMString> {
//XXX TODO: XML case
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();
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 window = window_from_node(abstract_self).root(&roots);
HTMLCollection::children(&window.root_ref(), NodeCast::from_ref(abstract_self))
let window = window_from_node(self).root(&roots);
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};
// See http://dom.spec.whatwg.org/#concept-event-dispatch for the full dispatch algorithm
pub fn dispatch_event<'a>(target: &JSRef<'a, EventTarget>,
pseudo_target: Option<JSRef<'a, EventTarget>>,
event: &mut JSRef<Event>) -> bool {
pub fn dispatch_event<'a, 'b>(target: &JSRef<'a, EventTarget>,
pseudo_target: Option<JSRef<'b, EventTarget>>,
event: &mut JSRef<Event>) -> bool {
let roots = RootCollection::new();
assert!(!event.get().dispatching);
{
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;
}

View file

@ -64,15 +64,22 @@ impl EventTarget {
filtered.map(|entry| entry.listener).collect()
})
}
}
pub fn dispatch_event_with_target<'a>(&self,
abstract_self: &JSRef<'a, EventTarget>,
abstract_target: Option<JSRef<'a, EventTarget>>,
event: &mut JSRef<Event>) -> Fallible<bool> {
pub trait EventTargetHelpers {
fn dispatch_event_with_target<'a>(&self,
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> {
if event.get().dispatching || !event.get().initialized {
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,
listener: Option<EventListener>,
capture: bool);
fn DispatchEvent(&self, abstract_self: &JSRef<EventTarget>,
event: &mut JSRef<Event>) -> Fallible<bool>;
fn DispatchEvent(&self, event: &mut JSRef<Event>) -> Fallible<bool>;
}
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>,
event: &mut JSRef<Event>) -> Fallible<bool> {
self.dispatch_event_with_target(abstract_self, None, event)
fn DispatchEvent(&self, event: &mut JSRef<Event>) -> Fallible<bool> {
self.dispatch_event_with_target(None, event)
}
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -98,7 +98,7 @@ impl<'a> StyleElementHelpers for JSRef<'a, HTMLStyleElement> {
let win = window_from_node(node).root(&roots);
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 LayoutChan(ref layout_chan) = *win.get().page().layout_chan;
layout_chan.send(AddStylesheetMsg(sheet));

View file

@ -224,21 +224,6 @@ pub enum NodeTypeId {
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 {
fn ancestors(&self) -> AncestorIterator;
fn children(&self) -> AbstractNodeChildrenIterator;
@ -1386,30 +1371,30 @@ impl Node {
pub trait NodeMethods {
fn NodeType(&self) -> u16;
fn NodeName(&self, abstract_self: &JSRef<Node>) -> DOMString;
fn NodeName(&self) -> DOMString;
fn GetBaseURI(&self) -> Option<DOMString>;
fn GetOwnerDocument(&self) -> Option<Unrooted<Document>>;
fn GetParentNode(&self) -> Option<Unrooted<Node>>;
fn GetParentElement(&self) -> Option<Unrooted<Element>>;
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 GetLastChild(&self) -> Option<Unrooted<Node>>;
fn GetPreviousSibling(&self) -> Option<Unrooted<Node>>;
fn GetNextSibling(&self) -> Option<Unrooted<Node>>;
fn GetNodeValue(&self, abstract_self: &JSRef<Node>) -> Option<DOMString>;
fn SetNodeValue(&mut self, abstract_self: &mut JSRef<Node>, val: Option<DOMString>) -> ErrorResult;
fn GetTextContent(&self, abstract_self: &JSRef<Node>) -> Option<DOMString>;
fn SetTextContent(&mut self, abstract_self: &mut JSRef<Node>, value: Option<DOMString>) -> ErrorResult;
fn InsertBefore(&self, abstract_self: &mut JSRef<Node>, 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 ReplaceChild(&self, parent: &mut JSRef<Node>, 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 Normalize(&mut self, abstract_self: &mut JSRef<Node>);
fn CloneNode(&self, abstract_self: &mut JSRef<Node>, deep: bool) -> Unrooted<Node>;
fn IsEqualNode(&self, abstract_self: &JSRef<Node>, maybe_node: Option<JSRef<Node>>) -> bool;
fn CompareDocumentPosition(&self, abstract_self: &JSRef<Node>, other: &JSRef<Node>) -> u16;
fn Contains(&self, abstract_self: &JSRef<Node>, maybe_other: Option<JSRef<Node>>) -> bool;
fn GetNodeValue(&self) -> Option<DOMString>;
fn SetNodeValue(&mut self, val: Option<DOMString>) -> ErrorResult;
fn GetTextContent(&self) -> Option<DOMString>;
fn SetTextContent(&mut self, value: Option<DOMString>) -> ErrorResult;
fn InsertBefore(&mut self, node: &mut JSRef<Node>, child: Option<JSRef<Node>>) -> Fallible<Unrooted<Node>>;
fn AppendChild(&mut self, node: &mut JSRef<Node>) -> Fallible<Unrooted<Node>>;
fn ReplaceChild(&mut self, node: &mut JSRef<Node>, child: &mut JSRef<Node>) -> Fallible<Unrooted<Node>>;
fn RemoveChild(&mut self, node: &mut JSRef<Node>) -> Fallible<Unrooted<Node>>;
fn Normalize(&mut self);
fn CloneNode(&self, deep: bool) -> Unrooted<Node>;
fn IsEqualNode(&self, maybe_node: Option<JSRef<Node>>) -> bool;
fn CompareDocumentPosition(&self, other: &JSRef<Node>) -> u16;
fn Contains(&self, maybe_other: Option<JSRef<Node>>) -> bool;
fn LookupPrefix(&self, _prefix: Option<DOMString>) -> Option<DOMString>;
fn LookupNamespaceURI(&self, _namespace: Option<DOMString>) -> Option<DOMString>;
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
fn NodeName(&self, abstract_self: &JSRef<Node>) -> DOMString {
fn NodeName(&self) -> DOMString {
match self.type_id {
ElementNodeTypeId(..) => {
let elem: &JSRef<Element> = ElementCast::to_ref(abstract_self).unwrap();
let elem: &JSRef<Element> = ElementCast::to_ref(self).unwrap();
elem.TagName()
}
TextNodeTypeId => ~"#text",
ProcessingInstructionNodeTypeId => {
let processing_instruction: &JSRef<ProcessingInstruction> =
ProcessingInstructionCast::to_ref(abstract_self).unwrap();
ProcessingInstructionCast::to_ref(self).unwrap();
processing_instruction.Target()
}
CommentNodeTypeId => ~"#comment",
DoctypeNodeTypeId => {
let doctype: &JSRef<DocumentType> = DocumentTypeCast::to_ref(abstract_self).unwrap();
let doctype: &JSRef<DocumentType> = DocumentTypeCast::to_ref(self).unwrap();
doctype.get().name.clone()
},
DocumentFragmentNodeTypeId => ~"#document-fragment",
@ -1494,7 +1479,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
}
// 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();
match self.child_list {
None => (),
@ -1503,7 +1488,8 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
let doc = self.deref().owner_doc().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())
}
@ -1528,12 +1514,12 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
}
// 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 {
CommentNodeTypeId |
TextNodeTypeId |
ProcessingInstructionNodeTypeId => {
let chardata: &JSRef<CharacterData> = CharacterDataCast::to_ref(abstract_self).unwrap();
let chardata: &JSRef<CharacterData> = CharacterDataCast::to_ref(self).unwrap();
Some(chardata.Data())
}
_ => {
@ -1543,26 +1529,26 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
}
// 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 {
match self.type_id {
CommentNodeTypeId |
TextNodeTypeId |
ProcessingInstructionNodeTypeId => {
self.SetTextContent(abstract_self, val)
self.SetTextContent(val)
}
_ => Ok(())
}
}
// 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();
match self.type_id {
DocumentFragmentNodeTypeId |
ElementNodeTypeId(..) => {
let mut content = ~"";
for node in abstract_self.traverse_preorder(&roots) {
for node in self.traverse_preorder(&roots) {
if node.is_text() {
let text: &JSRef<Text> = TextCast::to_ref(&node).unwrap();
content.push_str(text.get().characterdata.data.as_slice());
@ -1573,7 +1559,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
CommentNodeTypeId |
TextNodeTypeId |
ProcessingInstructionNodeTypeId => {
let characterdata: &JSRef<CharacterData> = CharacterDataCast::to_ref(abstract_self).unwrap();
let characterdata: &JSRef<CharacterData> = CharacterDataCast::to_ref(self).unwrap();
Some(characterdata.Data())
}
DoctypeNodeTypeId |
@ -1584,7 +1570,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
}
// 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 {
let roots = RootCollection::new();
let value = null_str_as_empty(&value);
@ -1596,19 +1582,21 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
None
} else {
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);
// Step 3.
Node::replace_all(node.root_ref(), abstract_self);
Node::replace_all(node.root_ref(), self);
}
CommentNodeTypeId |
TextNodeTypeId |
ProcessingInstructionNodeTypeId => {
self.wait_until_safe_to_modify_dom();
let characterdata: &mut JSRef<CharacterData> = CharacterDataCast::to_mut_ref(abstract_self).unwrap();
characterdata.get_mut().data = value.clone();
{
let characterdata: &mut JSRef<CharacterData> = CharacterDataCast::to_mut_ref(self).unwrap();
characterdata.get_mut().data = value.clone();
}
// Notify the document that the content of this node is different
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
fn InsertBefore(&self, abstract_self: &mut JSRef<Node>, node: &mut JSRef<Node>, child: Option<JSRef<Node>>)
-> Fallible<Unrooted<Node>> {
Node::pre_insert(node, abstract_self, child)
fn InsertBefore(&mut self, node: &mut JSRef<Node>, child: Option<JSRef<Node>>) -> Fallible<Unrooted<Node>> {
Node::pre_insert(node, self, child)
}
// http://dom.spec.whatwg.org/#dom-node-appendchild
fn AppendChild(&self, abstract_self: &mut JSRef<Node>, node: &mut JSRef<Node>)
-> Fallible<Unrooted<Node>> {
Node::pre_insert(node, abstract_self, None)
fn AppendChild(&mut self, node: &mut JSRef<Node>) -> Fallible<Unrooted<Node>> {
Node::pre_insert(node, self, None)
}
// http://dom.spec.whatwg.org/#concept-node-replace
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>> {
let roots = RootCollection::new();
// Step 1.
match parent.type_id() {
match self.type_id() {
DocumentNodeTypeId |
DocumentFragmentNodeTypeId |
ElementNodeTypeId(..) => (),
@ -1646,19 +1631,19 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
}
// Step 2.
if node.is_inclusive_ancestor_of(parent) {
if node.is_inclusive_ancestor_of(self) {
return Err(HierarchyRequest);
}
// Step 3.
if !parent.is_parent_of(child) {
if !self.is_parent_of(child) {
return Err(NotFound);
}
// Step 4-5.
match node.type_id() {
TextNodeTypeId if parent.is_document() => return Err(HierarchyRequest),
DoctypeNodeTypeId if !parent.is_document() => return Err(HierarchyRequest),
TextNodeTypeId if self.is_document() => return Err(HierarchyRequest),
DoctypeNodeTypeId if !self.is_document() => return Err(HierarchyRequest),
DocumentFragmentNodeTypeId |
DoctypeNodeTypeId |
ElementNodeTypeId(..) |
@ -1669,7 +1654,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
}
// Step 6.
match parent.type_id() {
match self.type_id() {
DocumentNodeTypeId => {
match node.type_id() {
// Step 6.1
@ -1682,7 +1667,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
0 => (),
// Step 6.1.2
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);
}
if child.following_siblings()
@ -1696,7 +1681,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
},
// Step 6.2
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);
}
if child.following_siblings()
@ -1706,10 +1691,10 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
},
// Step 6.3
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);
}
if parent.children()
if self.children()
.take_while(|c| c != child)
.any(|c| c.deref().is_element()) {
return Err(HierarchyRequest);
@ -1737,15 +1722,15 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
};
// Step 9.
let document = document_from_node(parent).root(&roots);
let document = document_from_node(self).root(&roots);
Node::adopt(node, &*document);
{
// Step 10.
Node::remove(child, parent, Suppressed);
Node::remove(child, self, Suppressed);
// Step 11.
Node::insert(node, parent, reference_child, Suppressed);
Node::insert(node, self, reference_child, Suppressed);
}
// Step 12-14.
@ -1764,13 +1749,13 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
}
// 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>> {
Node::pre_remove(node, abstract_self)
Node::pre_remove(node, self)
}
// 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 mut prev_text = None;
for mut child in self.children() {
@ -1778,20 +1763,19 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
let mut child_alias = child.clone();
let characterdata: &JSRef<CharacterData> = CharacterDataCast::to_ref(&child).unwrap();
if characterdata.Length() == 0 {
abstract_self.remove_child(&mut child_alias);
self.remove_child(&mut child_alias);
} else {
match prev_text {
Some(ref mut text_node) => {
let prev_characterdata: &mut JSRef<CharacterData> = CharacterDataCast::to_mut_ref(text_node).unwrap();
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)
}
}
} else {
let mut c = child.clone();
child.Normalize(&mut c);
child.Normalize();
prev_text = None;
}
@ -1799,15 +1783,15 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
}
// 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 {
true => Node::clone(abstract_self, None, CloneChildren),
false => Node::clone(abstract_self, None, DoNotCloneChildren)
true => Node::clone(self, None, CloneChildren),
false => Node::clone(self, None, DoNotCloneChildren)
}
}
// 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 {
let doctype: &JSRef<DocumentType> = DocumentTypeCast::to_ref(node).unwrap();
let other_doctype: &JSRef<DocumentType> = DocumentTypeCast::to_ref(other).unwrap();
@ -1879,20 +1863,20 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
// Step 1.
None => false,
// 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
fn CompareDocumentPosition(&self, abstract_self: &JSRef<Node>, other: &JSRef<Node>) -> u16 {
fn CompareDocumentPosition(&self, other: &JSRef<Node>) -> u16 {
let roots = RootCollection::new();
if abstract_self == other {
if self == other {
// step 2.
0
} else {
let mut lastself = abstract_self.clone();
let mut lastself = self.clone();
let mut lastother = other.clone();
for ancestor in abstract_self.ancestors() {
for ancestor in self.ancestors() {
if &ancestor == other {
// step 4.
return NodeConstants::DOCUMENT_POSITION_CONTAINS +
@ -1901,7 +1885,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
lastself = ancestor.clone();
}
for ancestor in other.ancestors() {
if &ancestor == abstract_self {
if &ancestor == self {
// step 5.
return NodeConstants::DOCUMENT_POSITION_CONTAINED_BY +
NodeConstants::DOCUMENT_POSITION_FOLLOWING;
@ -1910,7 +1894,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
}
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 random = if abstract_uint < other_uint {
@ -1929,7 +1913,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
// step 6.
return NodeConstants::DOCUMENT_POSITION_PRECEDING;
}
if &child == abstract_self {
if &child == self {
// step 7.
return NodeConstants::DOCUMENT_POSITION_FOLLOWING;
}
@ -1939,10 +1923,10 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
}
// 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 {
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 Blur(&self);
fn GetFrameElement(&self) -> Option<Unrooted<Element>>;
fn Location(&mut self, abstract_self: &JSRef<Window>) -> Unrooted<Location>;
fn Console(&mut self, abstract_self: &JSRef<Window>) -> Unrooted<Console>;
fn Navigator(&mut self, abstract_self: &JSRef<Window>) -> Unrooted<Navigator>;
fn Location(&mut self) -> Unrooted<Location>;
fn Console(&mut self) -> Unrooted<Console>;
fn Navigator(&mut self) -> Unrooted<Navigator>;
fn Confirm(&self, _message: DOMString) -> bool;
fn Prompt(&self, _message: DOMString, _default: DOMString) -> Option<DOMString>;
fn Print(&self);
@ -129,8 +129,8 @@ pub trait WindowMethods {
fn ClearTimeout(&mut self, handle: i32);
fn SetInterval(&mut self, _cx: *JSContext, callback: JSVal, timeout: i32) -> i32;
fn ClearInterval(&mut self, handle: i32);
fn Window(&self, abstract_self: &JSRef<Window>) -> Unrooted<Window>;
fn Self(&self, abstract_self: &JSRef<Window>) -> Unrooted<Window>;
fn Window(&self) -> Unrooted<Window>;
fn Self(&self) -> Unrooted<Window>;
}
impl<'a> WindowMethods for JSRef<'a, Window> {
@ -180,24 +180,27 @@ impl<'a> WindowMethods for JSRef<'a, Window> {
None
}
fn Location(&mut self, abstract_self: &JSRef<Window>) -> Unrooted<Location> {
fn Location(&mut self) -> Unrooted<Location> {
if self.location.is_none() {
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())
}
fn Console(&mut self, abstract_self: &JSRef<Window>) -> Unrooted<Console> {
fn Console(&mut self) -> Unrooted<Console> {
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())
}
fn Navigator(&mut self, abstract_self: &JSRef<Window>) -> Unrooted<Navigator> {
fn Navigator(&mut self) -> Unrooted<Navigator> {
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())
}
@ -238,12 +241,12 @@ impl<'a> WindowMethods for JSRef<'a, Window> {
self.ClearTimeout(handle);
}
fn Window(&self, abstract_self: &JSRef<Window>) -> Unrooted<Window> {
Unrooted::new_rooted(abstract_self)
fn Window(&self) -> Unrooted<Window> {
Unrooted::new_rooted(self)
}
fn Self(&self, abstract_self: &JSRef<Window>) -> Unrooted<Window> {
self.Window(abstract_self)
fn Self(&self) -> Unrooted<Window> {
self.Window()
}
}

View file

@ -5,7 +5,7 @@
use dom::attr::AttrMethods;
use dom::bindings::codegen::InheritTypes::{NodeBase, NodeCast, TextCast, ElementCast};
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::document::Document;
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::htmliframeelement::IFrameSize;
use dom::htmlformelement::HTMLFormElement;
use dom::node::{ElementNodeTypeId, NodeHelpers, AppendChild};
use dom::node::{ElementNodeTypeId, NodeHelpers, NodeMethods};
use dom::types::*;
use html::cssparse::{StylesheetProvenance, UrlProvenance, spawn_css_parser};
use script_task::Page;
@ -422,8 +422,8 @@ pub fn parse_html(page: &Page,
unsafe {
debug!("append child {:x} {:x}", parent, child);
let mut child = from_hubbub_node(child, Some(&roots)).root(&roots);
let mut parent = from_hubbub_node(parent, None).root(&roots);
assert!(AppendChild(&mut *parent, &mut *child).is_ok());
let mut parent: Root<Node> = from_hubbub_node(parent, None).root(&roots);
assert!(parent.AppendChild(&mut *child).is_ok());
}
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, EventMethods};
use dom::uievent::{UIEvent, UIEventMethods};
use dom::eventtarget::EventTarget;
use dom::eventtarget::{EventTarget, EventTargetHelpers};
use dom::node;
use dom::node::{Node, NodeHelpers};
use dom::window::{TimerId, Window};
@ -988,11 +988,9 @@ impl ScriptTask {
let mut event = Event::new(&*window).root(&roots);
event.InitEvent(~"load", false, false);
let doctarget: &JSRef<EventTarget> = EventTargetCast::from_ref(&*document);
let wintarget: &mut JSRef<EventTarget> = EventTargetCast::from_mut_ref(&mut *window);
let wintarget_alias = wintarget.clone();
let _ = wintarget.get_mut().dispatch_event_with_target(&wintarget_alias,
Some((*doctarget).clone()),
&mut *event);
let wintarget: &JSRef<EventTarget> = EventTargetCast::from_ref(&*window);
let _ = wintarget.dispatch_event_with_target(Some((*doctarget).clone()),
&mut *event);
let mut fragment_node = page.fragment_node.deref().borrow_mut();
(*fragment_node).assign(fragment.map_or(None, |fragid| page.find_fragment_node(fragid)));
@ -1061,10 +1059,7 @@ impl ScriptTask {
let event: &mut JSRef<Event> = EventCast::from_mut_ref(&mut *uievent);
let wintarget: &mut JSRef<EventTarget> = EventTargetCast::from_mut_ref(&mut *window);
let wintarget_alias = wintarget.clone();
let _ = wintarget.get_mut().dispatch_event_with_target(&wintarget_alias,
None,
&mut *event);
let _ = wintarget.dispatch_event_with_target(None, &mut *event);
}
None => ()
}