mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Improvements, cleanup for script::dom::document
* Add whatwg spec links for some Document methods * Wrap some lines that exceed 100 characters * Other misc cleanup/refactoring
This commit is contained in:
parent
d999fb9db0
commit
c90e8c19cd
1 changed files with 21 additions and 15 deletions
|
@ -269,15 +269,12 @@ impl<'a> DocumentHelpers<'a> for JSRef<'a, Document> {
|
||||||
fn set_quirks_mode(self, mode: QuirksMode) {
|
fn set_quirks_mode(self, mode: QuirksMode) {
|
||||||
self.quirks_mode.set(mode);
|
self.quirks_mode.set(mode);
|
||||||
|
|
||||||
match mode {
|
if mode == Quirks {
|
||||||
Quirks => {
|
|
||||||
let window = self.window.root();
|
let window = self.window.root();
|
||||||
let window = window.r();
|
let window = window.r();
|
||||||
let LayoutChan(ref layout_chan) = window.layout_chan();
|
let LayoutChan(ref layout_chan) = window.layout_chan();
|
||||||
layout_chan.send(Msg::SetQuirksMode).unwrap();
|
layout_chan.send(Msg::SetQuirksMode).unwrap();
|
||||||
}
|
}
|
||||||
NoQuirks | LimitedQuirks => {}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_encoding_name(self, name: DOMString) {
|
fn set_encoding_name(self, name: DOMString) {
|
||||||
|
@ -376,7 +373,7 @@ impl<'a> DocumentHelpers<'a> for JSRef<'a, Document> {
|
||||||
};
|
};
|
||||||
let doc_node: JSRef<Node> = NodeCast::from_ref(self);
|
let doc_node: JSRef<Node> = NodeCast::from_ref(self);
|
||||||
doc_node.traverse_preorder()
|
doc_node.traverse_preorder()
|
||||||
.filter_map(|node| HTMLAnchorElementCast::to_ref(node))
|
.filter_map(HTMLAnchorElementCast::to_ref)
|
||||||
.find(check_anchor)
|
.find(check_anchor)
|
||||||
.map(|node| Temporary::from_rooted(ElementCast::from_ref(node)))
|
.map(|node| Temporary::from_rooted(ElementCast::from_ref(node)))
|
||||||
})
|
})
|
||||||
|
@ -919,7 +916,8 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// http://dom.spec.whatwg.org/#dom-document-getelementsbytagnamens
|
// http://dom.spec.whatwg.org/#dom-document-getelementsbytagnamens
|
||||||
fn GetElementsByTagNameNS(self, maybe_ns: Option<DOMString>, tag_name: DOMString) -> Temporary<HTMLCollection> {
|
fn GetElementsByTagNameNS(self, maybe_ns: Option<DOMString>, tag_name: DOMString)
|
||||||
|
-> Temporary<HTMLCollection> {
|
||||||
let window = self.window.root();
|
let window = self.window.root();
|
||||||
HTMLCollection::by_tag_name_ns(window.r(), NodeCast::from_ref(self), tag_name, maybe_ns)
|
HTMLCollection::by_tag_name_ns(window.r(), NodeCast::from_ref(self), tag_name, maybe_ns)
|
||||||
}
|
}
|
||||||
|
@ -969,8 +967,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
||||||
QName => {}
|
QName => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
let (prefix_from_qname, local_name_from_qname)
|
let (prefix_from_qname, local_name_from_qname) = get_attribute_parts(&qualified_name);
|
||||||
= get_attribute_parts(&qualified_name);
|
|
||||||
match (&ns, prefix_from_qname, local_name_from_qname) {
|
match (&ns, prefix_from_qname, local_name_from_qname) {
|
||||||
// throw if prefix is not null and namespace is null
|
// throw if prefix is not null and namespace is null
|
||||||
(&ns!(""), Some(_), _) => {
|
(&ns!(""), Some(_), _) => {
|
||||||
|
@ -982,7 +979,8 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
||||||
debug!("Namespace must be the xml namespace if the prefix is 'xml'");
|
debug!("Namespace must be the xml namespace if the prefix is 'xml'");
|
||||||
return Err(NamespaceError);
|
return Err(NamespaceError);
|
||||||
},
|
},
|
||||||
// throw if namespace is the XMLNS namespace and neither qualifiedName nor prefix is "xmlns"
|
// throw if namespace is the XMLNS namespace and neither qualifiedName nor prefix is
|
||||||
|
// "xmlns"
|
||||||
(&ns!(XMLNS), Some(ref prefix), _) if "xmlns" == *prefix => {},
|
(&ns!(XMLNS), Some(ref prefix), _) if "xmlns" == *prefix => {},
|
||||||
(&ns!(XMLNS), _, "xmlns") => {},
|
(&ns!(XMLNS), _, "xmlns") => {},
|
||||||
(&ns!(XMLNS), _, _) => {
|
(&ns!(XMLNS), _, _) => {
|
||||||
|
@ -1134,8 +1132,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let v: Vec<&str> = split_html_space_chars(&title).collect();
|
split_html_space_chars(&title).collect::<Vec<_>>().connect(" ")
|
||||||
v.connect(" ")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Support root SVG namespace: https://github.com/servo/servo/issues/5315
|
// TODO: Support root SVG namespace: https://github.com/servo/servo/issues/5315
|
||||||
|
@ -1271,6 +1268,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/#dom-document-images
|
||||||
fn Images(self) -> Temporary<HTMLCollection> {
|
fn Images(self) -> Temporary<HTMLCollection> {
|
||||||
self.images.or_init(|| {
|
self.images.or_init(|| {
|
||||||
let window = self.window.root();
|
let window = self.window.root();
|
||||||
|
@ -1280,6 +1278,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/#dom-document-embeds
|
||||||
fn Embeds(self) -> Temporary<HTMLCollection> {
|
fn Embeds(self) -> Temporary<HTMLCollection> {
|
||||||
self.embeds.or_init(|| {
|
self.embeds.or_init(|| {
|
||||||
let window = self.window.root();
|
let window = self.window.root();
|
||||||
|
@ -1289,10 +1288,12 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/#dom-document-plugins
|
||||||
fn Plugins(self) -> Temporary<HTMLCollection> {
|
fn Plugins(self) -> Temporary<HTMLCollection> {
|
||||||
self.Embeds()
|
self.Embeds()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/#dom-document-links
|
||||||
fn Links(self) -> Temporary<HTMLCollection> {
|
fn Links(self) -> Temporary<HTMLCollection> {
|
||||||
self.links.or_init(|| {
|
self.links.or_init(|| {
|
||||||
let window = self.window.root();
|
let window = self.window.root();
|
||||||
|
@ -1302,6 +1303,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/#dom-document-forms
|
||||||
fn Forms(self) -> Temporary<HTMLCollection> {
|
fn Forms(self) -> Temporary<HTMLCollection> {
|
||||||
self.forms.or_init(|| {
|
self.forms.or_init(|| {
|
||||||
let window = self.window.root();
|
let window = self.window.root();
|
||||||
|
@ -1311,6 +1313,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/#dom-document-scripts
|
||||||
fn Scripts(self) -> Temporary<HTMLCollection> {
|
fn Scripts(self) -> Temporary<HTMLCollection> {
|
||||||
self.scripts.or_init(|| {
|
self.scripts.or_init(|| {
|
||||||
let window = self.window.root();
|
let window = self.window.root();
|
||||||
|
@ -1320,6 +1323,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/#dom-document-anchors
|
||||||
fn Anchors(self) -> Temporary<HTMLCollection> {
|
fn Anchors(self) -> Temporary<HTMLCollection> {
|
||||||
self.anchors.or_init(|| {
|
self.anchors.or_init(|| {
|
||||||
let window = self.window.root();
|
let window = self.window.root();
|
||||||
|
@ -1329,6 +1333,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/#dom-document-applets
|
||||||
fn Applets(self) -> Temporary<HTMLCollection> {
|
fn Applets(self) -> Temporary<HTMLCollection> {
|
||||||
// FIXME: This should be return OBJECT elements containing applets.
|
// FIXME: This should be return OBJECT elements containing applets.
|
||||||
self.applets.or_init(|| {
|
self.applets.or_init(|| {
|
||||||
|
@ -1339,6 +1344,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/#dom-document-location
|
||||||
fn Location(self) -> Temporary<Location> {
|
fn Location(self) -> Temporary<Location> {
|
||||||
let window = self.window.root();
|
let window = self.window.root();
|
||||||
let window = window.r();
|
let window = window.r();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue