aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/element.rs
diff options
context:
space:
mode:
Diffstat (limited to 'components/script/dom/element.rs')
-rw-r--r--components/script/dom/element.rs100
1 files changed, 54 insertions, 46 deletions
diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs
index 0735e19299f..f0ab72b430a 100644
--- a/components/script/dom/element.rs
+++ b/components/script/dom/element.rs
@@ -50,8 +50,8 @@ use dom::node::{window_from_node};
use dom::nodelist::NodeList;
use dom::virtualmethods::{VirtualMethods, vtable_for};
use devtools_traits::AttrInfo;
-use style::{mod, StylesheetOrigin, SimpleColorAttribute, UnsignedIntegerAttribute};
-use style::{IntegerAttribute, LengthAttribute, ParserContext, matches};
+use style::{self, SimpleColorAttribute, UnsignedIntegerAttribute};
+use style::{IntegerAttribute, LengthAttribute, matches};
use servo_util::namespace;
use servo_util::str::{DOMString, LengthOrPercentageOrAuto};
@@ -59,6 +59,7 @@ use html5ever::tree_builder::{NoQuirks, LimitedQuirks, Quirks};
use cssparser::RGBA;
use std::ascii::AsciiExt;
+use std::borrow::{IntoCow, ToOwned};
use std::cell::{Ref, RefMut};
use std::default::Default;
use std::mem;
@@ -88,14 +89,14 @@ impl ElementDerived for EventTarget {
}
}
-#[deriving(Copy, PartialEq, Show)]
+#[derive(Copy, PartialEq, Show)]
#[jstraceable]
pub enum ElementTypeId {
HTMLElement(HTMLElementTypeId),
Element,
}
-#[deriving(PartialEq)]
+#[derive(PartialEq)]
pub enum ElementCreator {
ParserCreated,
ScriptCreated,
@@ -387,7 +388,7 @@ impl LayoutElementHelpers for JS<Element> {
}
}
-#[deriving(PartialEq)]
+#[derive(PartialEq)]
pub enum StylePriority {
Important,
Normal,
@@ -423,7 +424,7 @@ impl<'a> ElementHelpers<'a> for JSRef<'a, Element> {
// https://dom.spec.whatwg.org/#concept-element-attributes-get-by-name
fn parsed_name(self, name: DOMString) -> DOMString {
if self.html_element_in_html_document() {
- name.as_slice().to_ascii_lower()
+ name.as_slice().to_ascii_lowercase()
} else {
name
}
@@ -504,7 +505,7 @@ impl<'a> ElementHelpers<'a> for JSRef<'a, Element> {
fn update_inline_style(self, property_decl: style::PropertyDeclaration, style_priority: StylePriority) {
let mut inline_declarations = self.style_attribute().borrow_mut();
- if let Some(ref mut declarations) = *inline_declarations.deref_mut() {
+ if let &mut Some(ref mut declarations) = &mut *inline_declarations {
let existing_declarations = if style_priority == StylePriority::Important {
declarations.important.make_unique()
} else {
@@ -568,9 +569,10 @@ pub trait AttributeHandlers {
prefix: Option<DOMString>);
fn set_attribute(self, name: &Atom, value: AttrValue);
fn set_custom_attribute(self, name: DOMString, value: DOMString) -> ErrorResult;
- fn do_set_attribute(self, local_name: Atom, value: AttrValue,
- name: Atom, namespace: Namespace,
- prefix: Option<DOMString>, cb: |JSRef<Attr>| -> bool);
+ fn do_set_attribute<F>(self, local_name: Atom, value: AttrValue,
+ name: Atom, namespace: Namespace,
+ prefix: Option<DOMString>, cb: F)
+ where F: Fn(JSRef<Attr>) -> bool;
fn parse_attribute(self, namespace: &Namespace, local_name: &Atom,
value: DOMString) -> AttrValue;
@@ -632,7 +634,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
}
fn set_attribute(self, name: &Atom, value: AttrValue) {
- assert!(name.as_slice() == name.as_slice().to_ascii_lower().as_slice());
+ assert!(name.as_slice() == name.as_slice().to_ascii_lowercase().as_slice());
assert!(!name.as_slice().contains(":"));
self.do_set_attribute(name.clone(), value, name.clone(),
@@ -656,9 +658,15 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
Ok(())
}
- fn do_set_attribute(self, local_name: Atom, value: AttrValue,
- name: Atom, namespace: Namespace,
- prefix: Option<DOMString>, cb: |JSRef<Attr>| -> bool) {
+ fn do_set_attribute<F>(self,
+ local_name: Atom,
+ value: AttrValue,
+ name: Atom,
+ namespace: Namespace,
+ prefix: Option<DOMString>,
+ cb: F)
+ where F: Fn(JSRef<Attr>) -> bool
+ {
let idx = self.attrs.borrow().iter()
.map(|attr| attr.root())
.position(|attr| cb(attr.r()));
@@ -723,7 +731,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
let owner_doc = node.owner_doc().root();
owner_doc.r().quirks_mode()
};
- let is_equal = |lhs: &Atom, rhs: &Atom| match quirks_mode {
+ let is_equal = |&:lhs: &Atom, rhs: &Atom| match quirks_mode {
NoQuirks | LimitedQuirks => lhs == rhs,
Quirks => lhs.as_slice().eq_ignore_ascii_case(rhs.as_slice())
};
@@ -741,9 +749,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
}
fn has_attribute(self, name: &Atom) -> bool {
- assert!(name.as_slice().chars().all(|ch| {
- !ch.is_ascii() || ch.to_ascii().to_lowercase() == ch.to_ascii()
- }));
+ assert!(name.as_slice().bytes().all(|&:b| b.to_ascii_lowercase() == b));
self.attrs.borrow().iter().map(|attr| attr.root()).any(|attr| {
*attr.r().local_name() == *name && *attr.r().namespace() == ns!("")
})
@@ -759,9 +765,9 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
}
fn get_url_attribute(self, name: &Atom) -> DOMString {
- assert!(name.as_slice() == name.as_slice().to_ascii_lower().as_slice());
+ assert!(name.as_slice() == name.as_slice().to_ascii_lowercase().as_slice());
if !self.has_attribute(name) {
- return "".into_string();
+ return "".to_owned();
}
let url = self.get_string_attribute(name);
let doc = document_from_node(self).root();
@@ -770,7 +776,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
// XXXManishearth this doesn't handle `javascript:` urls properly
match UrlParser::new().base_url(base).parse(url.as_slice()) {
Ok(parsed) => parsed.serialize(),
- Err(_) => "".into_string()
+ Err(_) => "".to_owned()
}
}
fn set_url_attribute(self, name: &Atom, value: DOMString) {
@@ -780,11 +786,11 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
fn get_string_attribute(self, name: &Atom) -> DOMString {
match self.get_attribute(ns!(""), name) {
Some(x) => x.root().r().Value(),
- None => "".into_string()
+ None => "".to_owned()
}
}
fn set_string_attribute(self, name: &Atom, value: DOMString) {
- assert!(name.as_slice() == name.as_slice().to_ascii_lower().as_slice());
+ assert!(name.as_slice() == name.as_slice().to_ascii_lowercase().as_slice());
self.set_attribute(name, AttrValue::String(value));
}
@@ -799,18 +805,18 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
}
fn set_tokenlist_attribute(self, name: &Atom, value: DOMString) {
- assert!(name.as_slice() == name.as_slice().to_ascii_lower().as_slice());
+ assert!(name.as_slice() == name.as_slice().to_ascii_lowercase().as_slice());
self.set_attribute(name, AttrValue::from_serialized_tokenlist(value));
}
fn set_atomic_tokenlist_attribute(self, name: &Atom, tokens: Vec<Atom>) {
- assert!(name.as_slice() == name.as_slice().to_ascii_lower().as_slice());
+ assert!(name.as_slice() == name.as_slice().to_ascii_lowercase().as_slice());
self.set_attribute(name, AttrValue::from_atomic_tokens(tokens));
}
fn get_uint_attribute(self, name: &Atom) -> u32 {
assert!(name.as_slice().chars().all(|ch| {
- !ch.is_ascii() || ch.to_ascii().to_lowercase() == ch.to_ascii()
+ !ch.is_ascii() || ch.to_ascii_lowercase() == ch
}));
let attribute = self.get_attribute(ns!(""), name).root();
match attribute {
@@ -825,7 +831,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
}
}
fn set_uint_attribute(self, name: &Atom, value: u32) {
- assert!(name.as_slice() == name.as_slice().to_ascii_lower().as_slice());
+ assert!(name.as_slice() == name.as_slice().to_ascii_lowercase().as_slice());
self.set_attribute(name, AttrValue::UInt(value.to_string(), value));
}
}
@@ -835,12 +841,12 @@ impl<'a> ElementMethods for JSRef<'a, Element> {
fn GetNamespaceURI(self) -> Option<DOMString> {
match self.namespace {
ns!("") => None,
- Namespace(ref ns) => Some(ns.as_slice().into_string())
+ Namespace(ref ns) => Some(ns.as_slice().to_owned())
}
}
fn LocalName(self) -> DOMString {
- self.local_name.as_slice().into_string()
+ self.local_name.as_slice().to_owned()
}
// http://dom.spec.whatwg.org/#dom-element-prefix
@@ -859,9 +865,9 @@ impl<'a> ElementMethods for JSRef<'a, Element> {
None => self.local_name.as_slice().into_cow()
};
if self.html_element_in_html_document() {
- qualified_name.as_slice().to_ascii_upper()
+ qualified_name.as_slice().to_ascii_uppercase()
} else {
- qualified_name.into_string()
+ qualified_name.into_owned()
}
}
@@ -996,7 +1002,7 @@ impl<'a> ElementMethods for JSRef<'a, Element> {
// Step 9.
let value = self.parse_attribute(&namespace, &local_name, value);
self.do_set_attribute(local_name.clone(), value, name,
- namespace.clone(), prefix.map(|s| s.into_string()),
+ namespace.clone(), prefix.map(|s| s.to_owned()),
|attr| {
*attr.local_name() == local_name &&
*attr.namespace() == namespace
@@ -1111,10 +1117,7 @@ impl<'a> ElementMethods for JSRef<'a, Element> {
// http://dom.spec.whatwg.org/#dom-element-matches
fn Matches(self, selectors: DOMString) -> Fallible<bool> {
- let parser_context = ParserContext {
- origin: StylesheetOrigin::Author,
- };
- match style::parse_selector_list_from_str(&parser_context, selectors.as_slice()) {
+ match style::parse_author_origin_selector_list_from_str(selectors.as_slice()) {
Err(()) => Err(Syntax),
Ok(ref selectors) => {
let root: JSRef<Node> = NodeCast::from_ref(self);
@@ -1125,10 +1128,7 @@ impl<'a> ElementMethods for JSRef<'a, Element> {
// https://dom.spec.whatwg.org/#dom-element-closest
fn Closest(self, selectors: DOMString) -> Fallible<Option<Temporary<Element>>> {
- let parser_context = ParserContext {
- origin: StylesheetOrigin::Author,
- };
- match style::parse_selector_list_from_str(&parser_context, selectors.as_slice()) {
+ match style::parse_author_origin_selector_list_from_str(selectors.as_slice()) {
Err(()) => Err(Syntax),
Ok(ref selectors) => {
let root: JSRef<Node> = NodeCast::from_ref(self);
@@ -1155,7 +1155,7 @@ pub fn get_attribute_parts<'a>(name: &'a str) -> (Option<&'a str>, &'a str) {
}
impl<'a> VirtualMethods for JSRef<'a, Element> {
- fn super_type<'a>(&'a self) -> Option<&'a VirtualMethods> {
+ fn super_type<'b>(&'b self) -> Option<&'b VirtualMethods> {
let node: &JSRef<Node> = NodeCast::from_borrowed_ref(self);
Some(node as &VirtualMethods)
}
@@ -1379,13 +1379,15 @@ impl<'a> style::TElement<'a> for JSRef<'a, Element> {
node.get_enabled_state()
}
fn get_checked_state(self) -> bool {
- match HTMLInputElementCast::to_ref(self) {
+ let input_element: Option<JSRef<HTMLInputElement>> = HTMLInputElementCast::to_ref(self);
+ match input_element {
Some(input) => input.Checked(),
None => false,
}
}
fn get_indeterminate_state(self) -> bool {
- match HTMLInputElementCast::to_ref(self) {
+ let input_element: Option<JSRef<HTMLInputElement>> = HTMLInputElementCast::to_ref(self);
+ match input_element {
Some(input) => input.get_indeterminate_state(),
None => false,
}
@@ -1399,7 +1401,9 @@ impl<'a> style::TElement<'a> for JSRef<'a, Element> {
has_class(self, name)
}
- fn each_class(self, callback: |&Atom|) {
+ fn each_class<F>(self, callback: F)
+ where F: Fn(&Atom)
+ {
match self.get_attribute(ns!(""), &atom!("class")).root() {
None => {}
Some(ref attr) => {
@@ -1415,7 +1419,8 @@ impl<'a> style::TElement<'a> for JSRef<'a, Element> {
}
}
fn has_nonzero_border(self) -> bool {
- match HTMLTableElementCast::to_ref(self) {
+ let table_element: Option<JSRef<HTMLTableElement>> = HTMLTableElementCast::to_ref(self);
+ match table_element {
None => false,
Some(this) => {
match this.get_border() {
@@ -1466,7 +1471,10 @@ impl<'a> ActivationElementHelpers<'a> for JSRef<'a, Element> {
None => {
let node: JSRef<Node> = NodeCast::from_ref(self);
node.ancestors()
- .filter_map(|node| ElementCast::to_ref(node))
+ .filter_map(|node| {
+ let e: Option<JSRef<Element>> = ElementCast::to_ref(node);
+ e
+ })
.filter(|e| e.as_maybe_activatable().is_some()).next()
.map(|r| Temporary::from_rooted(r))
}