aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/document.rs
diff options
context:
space:
mode:
Diffstat (limited to 'components/script/dom/document.rs')
-rw-r--r--components/script/dom/document.rs49
1 files changed, 27 insertions, 22 deletions
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs
index 22334b3b2a1..d7e9ce0daa2 100644
--- a/components/script/dom/document.rs
+++ b/components/script/dom/document.rs
@@ -23,7 +23,7 @@ use dom::bindings::error::{ErrorResult, Fallible};
use dom::bindings::error::Error::{NotSupported, InvalidCharacter};
use dom::bindings::error::Error::{HierarchyRequest, NamespaceError};
use dom::bindings::global::GlobalRef;
-use dom::bindings::js::{MutNullableJS, JS, JSRef, Temporary, OptionalSettable, TemporaryPushable};
+use dom::bindings::js::{MutNullableJS, JS, JSRef, Temporary, TemporaryPushable};
use dom::bindings::js::{OptionalRootable, RootedReference};
use dom::bindings::utils::reflect_dom_object;
use dom::bindings::utils::xml_name_type;
@@ -63,14 +63,15 @@ use layout_interface::{LayoutChan, Msg};
use string_cache::{Atom, QualName};
use url::Url;
+use std::borrow::ToOwned;
use std::collections::HashMap;
-use std::collections::hash_map::{Vacant, Occupied};
+use std::collections::hash_map::Entry::{Occupied, Vacant};
use std::ascii::AsciiExt;
use std::cell::{Cell, Ref};
use std::default::Default;
use time;
-#[deriving(PartialEq)]
+#[derive(PartialEq)]
#[jstraceable]
pub enum IsHTMLDocument {
HTMLDocument,
@@ -283,7 +284,7 @@ impl<'a> DocumentHelpers<'a> for JSRef<'a, Document> {
match idmap.entry(id) {
Vacant(entry) => {
- entry.set(vec!(element.unrooted()));
+ entry.insert(vec!(element.unrooted()));
}
Occupied(entry) => {
let elements = entry.into_mut();
@@ -320,7 +321,7 @@ impl<'a> DocumentHelpers<'a> for JSRef<'a, Document> {
/// https://html.spec.whatwg.org/multipage/#the-indicated-part-of-the-document
fn find_fragment_node(self, fragid: DOMString) -> Option<Temporary<Element>> {
self.GetElementById(fragid.clone()).or_else(|| {
- let check_anchor = |&node: &JSRef<HTMLAnchorElement>| {
+ let check_anchor = |&:&node: &JSRef<HTMLAnchorElement>| {
let elem: JSRef<Element> = ElementCast::from_ref(node);
elem.get_attribute(ns!(""), &atom!("name")).root().map_or(false, |attr| {
attr.r().value().as_slice() == fragid.as_slice()
@@ -339,7 +340,7 @@ impl<'a> DocumentHelpers<'a> for JSRef<'a, Document> {
self.ready_state.set(state);
let window = self.window.root();
- let event = Event::new(GlobalRef::Window(window.r()), "readystatechange".into_string(),
+ let event = Event::new(GlobalRef::Window(window.r()), "readystatechange".to_owned(),
EventBubbles::DoesNotBubble,
EventCancelable::NotCancelable).root();
let target: JSRef<EventTarget> = EventTargetCast::from_ref(self);
@@ -384,7 +385,7 @@ impl<'a> DocumentHelpers<'a> for JSRef<'a, Document> {
}
}
-#[deriving(PartialEq)]
+#[derive(PartialEq)]
pub enum DocumentSource {
FromParser,
NotFromParser,
@@ -425,9 +426,9 @@ impl Document {
Some(string) => string.clone(),
None => match is_html_document {
// http://dom.spec.whatwg.org/#dom-domimplementation-createhtmldocument
- IsHTMLDocument::HTMLDocument => "text/html".into_string(),
+ IsHTMLDocument::HTMLDocument => "text/html".to_owned(),
// http://dom.spec.whatwg.org/#concept-document-content-type
- IsHTMLDocument::NonHTMLDocument => "application/xml".into_string()
+ IsHTMLDocument::NonHTMLDocument => "application/xml".to_owned()
}
},
last_modified: DOMRefCell::new(None),
@@ -435,7 +436,7 @@ impl Document {
// http://dom.spec.whatwg.org/#concept-document-quirks
quirks_mode: Cell::new(NoQuirks),
// http://dom.spec.whatwg.org/#concept-document-encoding
- encoding_name: DOMRefCell::new("UTF-8".into_string()),
+ encoding_name: DOMRefCell::new("UTF-8".to_owned()),
is_html_document: is_html_document == IsHTMLDocument::HTMLDocument,
images: Default::default(),
embeds: Default::default(),
@@ -474,12 +475,12 @@ impl Document {
}
trait PrivateDocumentHelpers {
- fn createNodeList(self, callback: |node: JSRef<Node>| -> bool) -> Temporary<NodeList>;
+ fn createNodeList<F: Fn(JSRef<Node>) -> bool>(self, callback: F) -> Temporary<NodeList>;
fn get_html_element(self) -> Option<Temporary<HTMLHtmlElement>>;
}
impl<'a> PrivateDocumentHelpers for JSRef<'a, Document> {
- fn createNodeList(self, callback: |node: JSRef<Node>| -> bool) -> Temporary<NodeList> {
+ fn createNodeList<F: Fn(JSRef<Node>) -> bool>(self, callback: F) -> Temporary<NodeList> {
let window = self.window.root();
let document_element = self.GetDocumentElement().root();
let nodes = match document_element {
@@ -520,8 +521,8 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
// http://dom.spec.whatwg.org/#dom-document-compatmode
fn CompatMode(self) -> DOMString {
match self.quirks_mode.get() {
- LimitedQuirks | NoQuirks => "CSS1Compat".into_string(),
- Quirks => "BackCompat".into_string()
+ LimitedQuirks | NoQuirks => "CSS1Compat".to_owned(),
+ Quirks => "BackCompat".to_owned()
}
}
@@ -590,7 +591,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
return Err(InvalidCharacter);
}
let local_name = if self.is_html_document {
- local_name.as_slice().to_ascii_lower()
+ local_name.as_slice().to_ascii_lowercase()
} else {
local_name
};
@@ -639,7 +640,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
}
let name = QualName::new(ns, Atom::from_slice(local_name_from_qname));
- Ok(Element::create(name, prefix_from_qname.map(|s| s.into_string()), self,
+ Ok(Element::create(name, prefix_from_qname.map(|s| s.to_owned()), self,
ElementCreator::ScriptCreated))
}
@@ -654,7 +655,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
let name = Atom::from_slice(local_name.as_slice());
// repetition used because string_cache::atom::Atom is non-copyable
let l_name = Atom::from_slice(local_name.as_slice());
- let value = AttrValue::String("".into_string());
+ let value = AttrValue::String("".to_owned());
Ok(Attr::new(window.r(), name, value, l_name, ns!(""), None, None))
}
@@ -726,7 +727,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
fn CreateEvent(self, interface: DOMString) -> Fallible<Temporary<Event>> {
let window = self.window.root();
- match interface.as_slice().to_ascii_lower().as_slice() {
+ match interface.as_slice().to_ascii_lowercase().as_slice() {
"uievents" | "uievent" => Ok(EventCast::from_temporary(
UIEvent::new_uninitialized(window.r()))),
"mouseevents" | "mouseevent" => Ok(EventCast::from_temporary(
@@ -770,7 +771,11 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
root.traverse_preorder()
.find(|node| node.type_id() == NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLTitleElement)))
.map(|title_elem| {
- for text in title_elem.children().filter_map::<JSRef<Text>>(TextCast::to_ref) {
+ let mut children = title_elem.children().filter_map(|n| {
+ let t: Option<JSRef<Text>> = TextCast::to_ref(n);
+ t
+ });
+ for text in children {
title.push_str(text.characterdata().data().as_slice());
}
});
@@ -802,7 +807,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
}
},
None => {
- let new_title = HTMLTitleElement::new("title".into_string(), None, self).root();
+ let new_title = HTMLTitleElement::new("title".to_owned(), None, self).root();
let new_title: JSRef<Node> = NodeCast::from_ref(new_title.r());
if !title.is_empty() {
@@ -999,7 +1004,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
Temporary::new(self.window)
}
- global_event_handlers!()
- event_handler!(readystatechange, GetOnreadystatechange, SetOnreadystatechange)
+ global_event_handlers!();
+ event_handler!(readystatechange, GetOnreadystatechange, SetOnreadystatechange);
}