aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/element.rs
diff options
context:
space:
mode:
authorSimon Sapin <simon.sapin@exyr.org>2015-09-01 18:39:16 +0200
committerSimon Sapin <simon.sapin@exyr.org>2015-09-01 18:39:16 +0200
commit80d471d5cf82e2dab2f8c2c0c7ea496e8ce29a72 (patch)
tree003349216b9f38ebd451376a02cf5a5761a18b0a /components/script/dom/element.rs
parent2591a89a91945629cee5ea5df8598eff5334f24e (diff)
parent4404809e6d591ca7903e43deb693745300560d13 (diff)
downloadservo-80d471d5cf82e2dab2f8c2c0c7ea496e8ce29a72.tar.gz
servo-80d471d5cf82e2dab2f8c2c0c7ea496e8ce29a72.zip
Merge branch 'master' into calc
Diffstat (limited to 'components/script/dom/element.rs')
-rw-r--r--components/script/dom/element.rs362
1 files changed, 139 insertions, 223 deletions
diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs
index 859a38ba282..f16ca2bbb28 100644
--- a/components/script/dom/element.rs
+++ b/components/script/dom/element.rs
@@ -6,7 +6,7 @@
use dom::activation::Activatable;
use dom::attr::AttrValue;
-use dom::attr::{Attr, AttrSettingType, AttrHelpers, AttrHelpersForLayout};
+use dom::attr::{Attr, AttrSettingType, AttrHelpersForLayout};
use dom::bindings::cell::DOMRefCell;
use dom::bindings::codegen::Bindings::AttrBinding::AttrMethods;
use dom::bindings::codegen::Bindings::ElementBinding;
@@ -35,27 +35,26 @@ use dom::bindings::js::{Root, RootedReference};
use dom::bindings::trace::RootedVec;
use dom::bindings::utils::XMLName::InvalidXMLName;
use dom::bindings::utils::{namespace_from_domstring, xml_name_type, validate_and_extract};
-use dom::characterdata::CharacterDataHelpers;
use dom::create::create_element;
-use dom::document::{Document, DocumentHelpers, LayoutDocumentHelpers};
+use dom::document::{Document, LayoutDocumentHelpers};
use dom::domrect::DOMRect;
use dom::domrectlist::DOMRectList;
use dom::domtokenlist::DOMTokenList;
-use dom::event::{Event, EventHelpers};
+use dom::event::Event;
use dom::eventtarget::{EventTarget, EventTargetTypeId};
-use dom::htmlbodyelement::{HTMLBodyElement, HTMLBodyElementHelpers};
+use dom::htmlbodyelement::HTMLBodyElement;
use dom::htmlcollection::HTMLCollection;
use dom::htmlelement::HTMLElementTypeId;
-use dom::htmlfontelement::{HTMLFontElement, HTMLFontElementHelpers};
-use dom::htmliframeelement::{HTMLIFrameElement, RawHTMLIFrameElementHelpers};
-use dom::htmlinputelement::{HTMLInputElement, RawLayoutHTMLInputElementHelpers, HTMLInputElementHelpers};
-use dom::htmltablecellelement::{HTMLTableCellElement, HTMLTableCellElementHelpers};
-use dom::htmltableelement::{HTMLTableElement, HTMLTableElementHelpers};
-use dom::htmltablerowelement::{HTMLTableRowElement, HTMLTableRowElementHelpers};
-use dom::htmltablesectionelement::{HTMLTableSectionElement, HTMLTableSectionElementHelpers};
+use dom::htmlfontelement::HTMLFontElement;
+use dom::htmliframeelement::HTMLIFrameElement;
+use dom::htmlinputelement::{HTMLInputElement, RawLayoutHTMLInputElementHelpers};
+use dom::htmltablecellelement::HTMLTableCellElement;
+use dom::htmltableelement::HTMLTableElement;
+use dom::htmltablerowelement::HTMLTableRowElement;
+use dom::htmltablesectionelement::HTMLTableSectionElement;
use dom::htmltextareaelement::{HTMLTextAreaElement, RawLayoutHTMLTextAreaElementHelpers};
use dom::namednodemap::NamedNodeMap;
-use dom::node::{CLICK_IN_PROGRESS, LayoutNodeHelpers, Node, NodeHelpers, NodeTypeId, SEQUENTIALLY_FOCUSABLE};
+use dom::node::{CLICK_IN_PROGRESS, LayoutNodeHelpers, Node, NodeTypeId, SEQUENTIALLY_FOCUSABLE};
use dom::node::{document_from_node, NodeDamage};
use dom::node::{window_from_node};
use dom::nodelist::NodeList;
@@ -92,7 +91,6 @@ use std::mem;
use std::sync::Arc;
#[dom_struct]
-#[derive(HeapSizeOf)]
pub struct Element {
node: Node,
local_name: Atom,
@@ -571,38 +569,18 @@ pub enum StylePriority {
Normal,
}
-pub trait ElementHelpers<'a> {
- fn html_element_in_html_document(self) -> bool;
- fn local_name(self) -> &'a Atom;
- fn parsed_name(self, name: DOMString) -> Atom;
- fn namespace(self) -> &'a Namespace;
- fn prefix(self) -> &'a Option<DOMString>;
- fn attrs(&self) -> Ref<Vec<JS<Attr>>>;
- fn attrs_mut(&self) -> RefMut<Vec<JS<Attr>>>;
- fn style_attribute(self) -> &'a DOMRefCell<Option<PropertyDeclarationBlock>>;
- fn summarize(self) -> Vec<AttrInfo>;
- fn is_void(self) -> bool;
- fn remove_inline_style_property(self, property: &str);
- fn update_inline_style(self, property_decl: PropertyDeclaration, style_priority: StylePriority);
- fn set_inline_style_property_priority(self, properties: &[&str], style_priority: StylePriority);
- fn get_inline_style_declaration(self, property: &Atom) -> Option<Ref<'a, PropertyDeclaration>>;
- fn get_important_inline_style_declaration(self, property: &Atom) -> Option<Ref<'a, PropertyDeclaration>>;
- fn serialize(self, traversal_scope: TraversalScope) -> Fallible<DOMString>;
- fn get_root_element(self) -> Root<Element>;
- fn lookup_prefix(self, namespace: Namespace) -> Option<DOMString>;
-}
-impl<'a> ElementHelpers<'a> for &'a Element {
- fn html_element_in_html_document(self) -> bool {
+impl Element {
+ pub fn html_element_in_html_document(&self) -> bool {
let node = NodeCast::from_ref(self);
self.namespace == ns!(HTML) && node.is_in_html_doc()
}
- fn local_name(self) -> &'a Atom {
+ pub fn local_name(&self) -> &Atom {
&self.local_name
}
- fn parsed_name(self, name: DOMString) -> Atom {
+ pub fn parsed_name(&self, name: DOMString) -> Atom {
if self.html_element_in_html_document() {
Atom::from_slice(&name.to_ascii_lowercase())
} else {
@@ -610,27 +588,27 @@ impl<'a> ElementHelpers<'a> for &'a Element {
}
}
- fn namespace(self) -> &'a Namespace {
+ pub fn namespace(&self) -> &Namespace {
&self.namespace
}
- fn prefix(self) -> &'a Option<DOMString> {
+ pub fn prefix(&self) -> &Option<DOMString> {
&self.prefix
}
- fn attrs(&self) -> Ref<Vec<JS<Attr>>> {
+ pub fn attrs(&self) -> Ref<Vec<JS<Attr>>> {
self.attrs.borrow()
}
- fn attrs_mut(&self) -> RefMut<Vec<JS<Attr>>> {
+ pub fn attrs_mut(&self) -> RefMut<Vec<JS<Attr>>> {
self.attrs.borrow_mut()
}
- fn style_attribute(self) -> &'a DOMRefCell<Option<PropertyDeclarationBlock>> {
+ pub fn style_attribute(&self) -> &DOMRefCell<Option<PropertyDeclarationBlock>> {
&self.style_attribute
}
- fn summarize(self) -> Vec<AttrInfo> {
+ pub fn summarize(&self) -> Vec<AttrInfo> {
let attrs = self.Attributes();
let mut summarized = vec!();
for i in 0..attrs.r().Length() {
@@ -640,7 +618,7 @@ impl<'a> ElementHelpers<'a> for &'a Element {
summarized
}
- fn is_void(self) -> bool {
+ pub fn is_void(&self) -> bool {
if self.namespace != ns!(HTML) {
return false
}
@@ -654,7 +632,7 @@ impl<'a> ElementHelpers<'a> for &'a Element {
}
}
- fn remove_inline_style_property(self, property: &str) {
+ pub fn remove_inline_style_property(&self, property: &str) {
let mut inline_declarations = self.style_attribute.borrow_mut();
if let &mut Some(ref mut declarations) = &mut *inline_declarations {
let index = declarations.normal
@@ -675,7 +653,7 @@ impl<'a> ElementHelpers<'a> for &'a Element {
}
}
- fn update_inline_style(self, property_decl: PropertyDeclaration, style_priority: StylePriority) {
+ pub fn update_inline_style(&self, property_decl: PropertyDeclaration, style_priority: StylePriority) {
let mut inline_declarations = self.style_attribute().borrow_mut();
if let &mut Some(ref mut declarations) = &mut *inline_declarations {
let existing_declarations = if style_priority == StylePriority::Important {
@@ -709,7 +687,7 @@ impl<'a> ElementHelpers<'a> for &'a Element {
});
}
- fn set_inline_style_property_priority(self, properties: &[&str], style_priority: StylePriority) {
+ pub fn set_inline_style_property_priority(&self, properties: &[&str], style_priority: StylePriority) {
let mut inline_declarations = self.style_attribute().borrow_mut();
if let &mut Some(ref mut declarations) = &mut *inline_declarations {
let (from, to) = if style_priority == StylePriority::Important {
@@ -734,7 +712,7 @@ impl<'a> ElementHelpers<'a> for &'a Element {
}
}
- fn get_inline_style_declaration(self, property: &Atom) -> Option<Ref<'a, PropertyDeclaration>> {
+ pub fn get_inline_style_declaration(&self, property: &Atom) -> Option<Ref<PropertyDeclaration>> {
Ref::filter_map(self.style_attribute.borrow(), |inline_declarations| {
inline_declarations.as_ref().and_then(|declarations| {
declarations.normal
@@ -745,7 +723,8 @@ impl<'a> ElementHelpers<'a> for &'a Element {
})
}
- fn get_important_inline_style_declaration(self, property: &Atom) -> Option<Ref<'a, PropertyDeclaration>> {
+ pub fn get_important_inline_style_declaration(&self, property: &Atom)
+ -> Option<Ref<PropertyDeclaration>> {
Ref::filter_map(self.style_attribute.borrow(), |inline_declarations| {
inline_declarations.as_ref().and_then(|declarations| {
declarations.important
@@ -755,7 +734,7 @@ impl<'a> ElementHelpers<'a> for &'a Element {
})
}
- fn serialize(self, traversal_scope: TraversalScope) -> Fallible<DOMString> {
+ pub fn serialize(&self, traversal_scope: TraversalScope) -> Fallible<DOMString> {
let node = NodeCast::from_ref(self);
let mut writer = vec![];
match serialize(&mut writer, &node,
@@ -769,7 +748,7 @@ impl<'a> ElementHelpers<'a> for &'a Element {
}
// https://html.spec.whatwg.org/multipage/#root-element
- fn get_root_element(self) -> Root<Element> {
+ pub fn get_root_element(&self) -> Root<Element> {
let node = NodeCast::from_ref(self);
node.inclusive_ancestors()
.filter_map(ElementCast::to_root)
@@ -778,7 +757,7 @@ impl<'a> ElementHelpers<'a> for &'a Element {
}
// https://dom.spec.whatwg.org/#locate-a-namespace-prefix
- fn lookup_prefix(self, namespace: Namespace) -> Option<DOMString> {
+ pub fn lookup_prefix(&self, namespace: Namespace) -> Option<DOMString> {
for node in NodeCast::from_ref(self).inclusive_ancestors() {
match ElementCast::to_ref(node.r()) {
Some(element) => {
@@ -806,16 +785,9 @@ impl<'a> ElementHelpers<'a> for &'a Element {
}
}
-pub trait FocusElementHelpers {
- /// https://html.spec.whatwg.org/multipage/#focusable-area
- fn is_focusable_area(self) -> bool;
-
- /// https://html.spec.whatwg.org/multipage/#concept-element-disabled
- fn is_actually_disabled(self) -> bool;
-}
-impl<'a> FocusElementHelpers for &'a Element {
- fn is_focusable_area(self) -> bool {
+impl Element {
+ pub fn is_focusable_area(&self) -> bool {
if self.is_actually_disabled() {
return false;
}
@@ -836,7 +808,7 @@ impl<'a> FocusElementHelpers for &'a Element {
}
}
- fn is_actually_disabled(self) -> bool {
+ pub fn is_actually_disabled(&self) -> bool {
let node = NodeCast::from_ref(self);
match node.type_id() {
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLButtonElement)) |
@@ -855,58 +827,9 @@ impl<'a> FocusElementHelpers for &'a Element {
}
}
-pub trait AttributeHandlers {
- /// Returns the attribute with given namespace and case-sensitive local
- /// name, if any.
- fn get_attribute(self, namespace: &Namespace, local_name: &Atom)
- -> Option<Root<Attr>>;
- /// Returns the first attribute with any namespace and given case-sensitive
- /// name, if any.
- fn get_attribute_by_name(self, name: DOMString) -> Option<Root<Attr>>;
- fn get_attributes(self, local_name: &Atom, attributes: &mut RootedVec<JS<Attr>>);
- fn set_attribute_from_parser(self,
- name: QualName,
- value: DOMString,
- prefix: Option<Atom>);
- fn set_attribute(self, name: &Atom, value: AttrValue);
- fn set_custom_attribute(self, name: DOMString, value: DOMString) -> ErrorResult;
- fn do_set_attribute<F>(self, local_name: Atom, value: AttrValue,
- name: Atom, namespace: Namespace,
- prefix: Option<Atom>, cb: F)
- where F: Fn(&Attr) -> bool;
- fn parse_attribute(self, namespace: &Namespace, local_name: &Atom,
- value: DOMString) -> AttrValue;
-
- /// Removes the first attribute with any given namespace and case-sensitive local
- /// name, if any.
- fn remove_attribute(self, namespace: &Namespace, local_name: &Atom)
- -> Option<Root<Attr>>;
- /// Removes the first attribute with any namespace and given case-sensitive name.
- fn remove_attribute_by_name(self, name: &Atom) -> Option<Root<Attr>>;
- /// Removes the first attribute that satisfies `find`.
- fn do_remove_attribute<F>(self, find: F) -> Option<Root<Attr>>
- where F: Fn(&Attr) -> bool;
-
- fn has_class(self, name: &Atom) -> bool;
-
- fn set_atomic_attribute(self, local_name: &Atom, value: DOMString);
-
- // https://www.whatwg.org/html/#reflecting-content-attributes-in-idl-attributes
- fn has_attribute(self, local_name: &Atom) -> bool;
- fn set_bool_attribute(self, local_name: &Atom, value: bool);
- fn get_url_attribute(self, local_name: &Atom) -> DOMString;
- fn set_url_attribute(self, local_name: &Atom, value: DOMString);
- fn get_string_attribute(self, local_name: &Atom) -> DOMString;
- fn set_string_attribute(self, local_name: &Atom, value: DOMString);
- fn get_tokenlist_attribute(self, local_name: &Atom) -> Vec<Atom>;
- fn set_tokenlist_attribute(self, local_name: &Atom, value: DOMString);
- fn set_atomic_tokenlist_attribute(self, local_name: &Atom, tokens: Vec<Atom>);
- fn get_uint_attribute(self, local_name: &Atom, default: u32) -> u32;
- fn set_uint_attribute(self, local_name: &Atom, value: u32);
-}
-impl<'a> AttributeHandlers for &'a Element {
- fn get_attribute(self, namespace: &Namespace, local_name: &Atom) -> Option<Root<Attr>> {
+impl Element {
+ pub fn get_attribute(&self, namespace: &Namespace, local_name: &Atom) -> Option<Root<Attr>> {
let mut attributes = RootedVec::new();
self.get_attributes(local_name, &mut attributes);
attributes.r().iter()
@@ -915,14 +838,14 @@ impl<'a> AttributeHandlers for &'a Element {
}
// https://dom.spec.whatwg.org/#concept-element-attributes-get-by-name
- fn get_attribute_by_name(self, name: DOMString) -> Option<Root<Attr>> {
+ pub fn get_attribute_by_name(&self, name: DOMString) -> Option<Root<Attr>> {
let name = &self.parsed_name(name);
self.attrs.borrow().iter().map(|attr| attr.root())
.find(|a| a.r().name() == name)
}
// https://dom.spec.whatwg.org/#concept-element-attributes-get-by-name
- fn get_attributes(self, local_name: &Atom, attributes: &mut RootedVec<JS<Attr>>) {
+ pub fn get_attributes(&self, local_name: &Atom, attributes: &mut RootedVec<JS<Attr>>) {
for ref attr in self.attrs.borrow().iter() {
let attr = attr.root();
if attr.r().local_name() == local_name {
@@ -931,7 +854,7 @@ impl<'a> AttributeHandlers for &'a Element {
}
}
- fn set_attribute_from_parser(self,
+ pub fn set_attribute_from_parser(&self,
qname: QualName,
value: DOMString,
prefix: Option<Atom>) {
@@ -952,7 +875,7 @@ impl<'a> AttributeHandlers for &'a Element {
self.do_set_attribute(qname.local, value, name, qname.ns, prefix, |_| false)
}
- fn set_attribute(self, name: &Atom, value: AttrValue) {
+ pub fn set_attribute(&self, name: &Atom, value: AttrValue) {
assert!(&**name == name.to_ascii_lowercase());
assert!(!name.contains(":"));
@@ -961,7 +884,7 @@ impl<'a> AttributeHandlers for &'a Element {
}
// https://html.spec.whatwg.org/multipage/#attr-data-*
- fn set_custom_attribute(self, name: DOMString, value: DOMString) -> ErrorResult {
+ pub fn set_custom_attribute(&self, name: DOMString, value: DOMString) -> ErrorResult {
// Step 1.
match xml_name_type(&name) {
InvalidXMLName => return Err(InvalidCharacter),
@@ -977,7 +900,7 @@ impl<'a> AttributeHandlers for &'a Element {
Ok(())
}
- fn do_set_attribute<F>(self,
+ pub fn do_set_attribute<F>(&self,
local_name: Atom,
value: AttrValue,
name: Atom,
@@ -1003,7 +926,7 @@ impl<'a> AttributeHandlers for &'a Element {
(*self.attrs.borrow())[idx].root().r().set_value(set_type, value, self);
}
- fn parse_attribute(self, namespace: &Namespace, local_name: &Atom,
+ pub fn parse_attribute(&self, namespace: &Namespace, local_name: &Atom,
value: DOMString) -> AttrValue {
if *namespace == ns!("") {
vtable_for(&NodeCast::from_ref(self))
@@ -1013,18 +936,18 @@ impl<'a> AttributeHandlers for &'a Element {
}
}
- fn remove_attribute(self, namespace: &Namespace, local_name: &Atom)
+ pub fn remove_attribute(&self, namespace: &Namespace, local_name: &Atom)
-> Option<Root<Attr>> {
self.do_remove_attribute(|attr| {
attr.namespace() == namespace && attr.local_name() == local_name
})
}
- fn remove_attribute_by_name(self, name: &Atom) -> Option<Root<Attr>> {
+ pub fn remove_attribute_by_name(&self, name: &Atom) -> Option<Root<Attr>> {
self.do_remove_attribute(|attr| attr.name() == name)
}
- fn do_remove_attribute<F>(self, find: F) -> Option<Root<Attr>>
+ pub fn do_remove_attribute<F>(&self, find: F) -> Option<Root<Attr>>
where F: Fn(&Attr) -> bool
{
let idx = self.attrs.borrow().iter()
@@ -1057,7 +980,7 @@ impl<'a> AttributeHandlers for &'a Element {
})
}
- fn has_class(self, name: &Atom) -> bool {
+ pub fn has_class(&self, name: &Atom) -> bool {
let quirks_mode = {
let node = NodeCast::from_ref(self);
let owner_doc = node.owner_doc();
@@ -1074,20 +997,20 @@ impl<'a> AttributeHandlers for &'a Element {
}).unwrap_or(false)
}
- fn set_atomic_attribute(self, local_name: &Atom, value: DOMString) {
+ pub fn set_atomic_attribute(&self, local_name: &Atom, value: DOMString) {
assert!(&**local_name == local_name.to_ascii_lowercase());
let value = AttrValue::from_atomic(value);
self.set_attribute(local_name, value);
}
- fn has_attribute(self, local_name: &Atom) -> bool {
+ pub fn has_attribute(&self, local_name: &Atom) -> bool {
assert!(local_name.bytes().all(|b| b.to_ascii_lowercase() == b));
self.attrs.borrow().iter().map(|attr| attr.root()).any(|attr| {
attr.r().local_name() == local_name && attr.r().namespace() == &ns!("")
})
}
- fn set_bool_attribute(self, local_name: &Atom, value: bool) {
+ pub fn set_bool_attribute(&self, local_name: &Atom, value: bool) {
if self.has_attribute(local_name) == value { return; }
if value {
self.set_string_attribute(local_name, String::new());
@@ -1096,7 +1019,7 @@ impl<'a> AttributeHandlers for &'a Element {
}
}
- fn get_url_attribute(self, local_name: &Atom) -> DOMString {
+ pub fn get_url_attribute(&self, local_name: &Atom) -> DOMString {
assert!(&**local_name == local_name.to_ascii_lowercase());
if !self.has_attribute(local_name) {
return "".to_owned();
@@ -1111,22 +1034,22 @@ impl<'a> AttributeHandlers for &'a Element {
Err(_) => "".to_owned()
}
}
- fn set_url_attribute(self, local_name: &Atom, value: DOMString) {
+ pub fn set_url_attribute(&self, local_name: &Atom, value: DOMString) {
self.set_string_attribute(local_name, value);
}
- fn get_string_attribute(self, local_name: &Atom) -> DOMString {
+ pub fn get_string_attribute(&self, local_name: &Atom) -> DOMString {
match self.get_attribute(&ns!(""), local_name) {
Some(x) => x.r().Value(),
None => "".to_owned()
}
}
- fn set_string_attribute(self, local_name: &Atom, value: DOMString) {
+ pub fn set_string_attribute(&self, local_name: &Atom, value: DOMString) {
assert!(&**local_name == local_name.to_ascii_lowercase());
self.set_attribute(local_name, AttrValue::String(value));
}
- fn get_tokenlist_attribute(self, local_name: &Atom) -> Vec<Atom> {
+ pub fn get_tokenlist_attribute(&self, local_name: &Atom) -> Vec<Atom> {
self.get_attribute(&ns!(""), local_name).map(|attr| {
attr.r()
.value()
@@ -1136,17 +1059,17 @@ impl<'a> AttributeHandlers for &'a Element {
}).unwrap_or(vec!())
}
- fn set_tokenlist_attribute(self, local_name: &Atom, value: DOMString) {
+ pub fn set_tokenlist_attribute(&self, local_name: &Atom, value: DOMString) {
assert!(&**local_name == local_name.to_ascii_lowercase());
self.set_attribute(local_name, AttrValue::from_serialized_tokenlist(value));
}
- fn set_atomic_tokenlist_attribute(self, local_name: &Atom, tokens: Vec<Atom>) {
+ pub fn set_atomic_tokenlist_attribute(&self, local_name: &Atom, tokens: Vec<Atom>) {
assert!(&**local_name == local_name.to_ascii_lowercase());
self.set_attribute(local_name, AttrValue::from_atomic_tokens(tokens));
}
- fn get_uint_attribute(self, local_name: &Atom, default: u32) -> u32 {
+ pub fn get_uint_attribute(&self, local_name: &Atom, default: u32) -> u32 {
assert!(local_name.chars().all(|ch| {
!ch.is_ascii() || ch.to_ascii_lowercase() == ch
}));
@@ -1162,30 +1085,30 @@ impl<'a> AttributeHandlers for &'a Element {
None => default,
}
}
- fn set_uint_attribute(self, local_name: &Atom, value: u32) {
+ pub fn set_uint_attribute(&self, local_name: &Atom, value: u32) {
assert!(&**local_name == local_name.to_ascii_lowercase());
self.set_attribute(local_name, AttrValue::UInt(value.to_string(), value));
}
}
-impl<'a> ElementMethods for &'a Element {
+impl ElementMethods for Element {
// https://dom.spec.whatwg.org/#dom-element-namespaceuri
- fn GetNamespaceURI(self) -> Option<DOMString> {
+ fn GetNamespaceURI(&self) -> Option<DOMString> {
Node::namespace_to_string(self.namespace.clone())
}
// https://dom.spec.whatwg.org/#dom-element-localname
- fn LocalName(self) -> DOMString {
+ fn LocalName(&self) -> DOMString {
(*self.local_name).to_owned()
}
// https://dom.spec.whatwg.org/#dom-element-prefix
- fn GetPrefix(self) -> Option<DOMString> {
+ fn GetPrefix(&self) -> Option<DOMString> {
self.prefix.clone()
}
// https://dom.spec.whatwg.org/#dom-element-tagname
- fn TagName(self) -> DOMString {
+ fn TagName(&self) -> DOMString {
let qualified_name = match self.prefix {
Some(ref prefix) => {
Cow::Owned(format!("{}:{}", &**prefix, &*self.local_name))
@@ -1200,32 +1123,32 @@ impl<'a> ElementMethods for &'a Element {
}
// https://dom.spec.whatwg.org/#dom-element-id
- fn Id(self) -> DOMString {
+ fn Id(&self) -> DOMString {
self.get_string_attribute(&atom!("id"))
}
// https://dom.spec.whatwg.org/#dom-element-id
- fn SetId(self, id: DOMString) {
+ fn SetId(&self, id: DOMString) {
self.set_atomic_attribute(&atom!("id"), id);
}
// https://dom.spec.whatwg.org/#dom-element-classname
- fn ClassName(self) -> DOMString {
+ fn ClassName(&self) -> DOMString {
self.get_string_attribute(&atom!("class"))
}
// https://dom.spec.whatwg.org/#dom-element-classname
- fn SetClassName(self, class: DOMString) {
+ fn SetClassName(&self, class: DOMString) {
self.set_tokenlist_attribute(&atom!("class"), class);
}
// https://dom.spec.whatwg.org/#dom-element-classlist
- fn ClassList(self) -> Root<DOMTokenList> {
+ fn ClassList(&self) -> Root<DOMTokenList> {
self.class_list.or_init(|| DOMTokenList::new(self, &atom!("class")))
}
// https://dom.spec.whatwg.org/#dom-element-attributes
- fn Attributes(self) -> Root<NamedNodeMap> {
+ fn Attributes(&self) -> Root<NamedNodeMap> {
self.attr_list.or_init(|| {
let doc = {
let node = NodeCast::from_ref(self);
@@ -1237,13 +1160,13 @@ impl<'a> ElementMethods for &'a Element {
}
// https://dom.spec.whatwg.org/#dom-element-getattribute
- fn GetAttribute(self, name: DOMString) -> Option<DOMString> {
+ fn GetAttribute(&self, name: DOMString) -> Option<DOMString> {
self.get_attribute_by_name(name)
.map(|s| s.r().Value())
}
// https://dom.spec.whatwg.org/#dom-element-getattributens
- fn GetAttributeNS(self,
+ fn GetAttributeNS(&self,
namespace: Option<DOMString>,
local_name: DOMString) -> Option<DOMString> {
let namespace = &namespace_from_domstring(namespace);
@@ -1252,7 +1175,7 @@ impl<'a> ElementMethods for &'a Element {
}
// https://dom.spec.whatwg.org/#dom-element-setattribute
- fn SetAttribute(self,
+ fn SetAttribute(&self,
name: DOMString,
value: DOMString) -> ErrorResult {
// Step 1.
@@ -1272,7 +1195,7 @@ impl<'a> ElementMethods for &'a Element {
}
// https://dom.spec.whatwg.org/#dom-element-setattributens
- fn SetAttributeNS(self,
+ fn SetAttributeNS(&self,
namespace: Option<DOMString>,
qualified_name: DOMString,
value: DOMString) -> ErrorResult {
@@ -1289,13 +1212,13 @@ impl<'a> ElementMethods for &'a Element {
}
// https://dom.spec.whatwg.org/#dom-element-removeattribute
- fn RemoveAttribute(self, name: DOMString) {
+ fn RemoveAttribute(&self, name: DOMString) {
let name = self.parsed_name(name);
self.remove_attribute_by_name(&name);
}
// https://dom.spec.whatwg.org/#dom-element-removeattributens
- fn RemoveAttributeNS(self,
+ fn RemoveAttributeNS(&self,
namespace: Option<DOMString>,
local_name: DOMString) {
let namespace = namespace_from_domstring(namespace);
@@ -1304,38 +1227,38 @@ impl<'a> ElementMethods for &'a Element {
}
// https://dom.spec.whatwg.org/#dom-element-hasattribute
- fn HasAttribute(self, name: DOMString) -> bool {
+ fn HasAttribute(&self, name: DOMString) -> bool {
self.GetAttribute(name).is_some()
}
// https://dom.spec.whatwg.org/#dom-element-hasattributens
- fn HasAttributeNS(self,
+ fn HasAttributeNS(&self,
namespace: Option<DOMString>,
local_name: DOMString) -> bool {
self.GetAttributeNS(namespace, local_name).is_some()
}
// https://dom.spec.whatwg.org/#dom-element-getelementsbytagname
- fn GetElementsByTagName(self, localname: DOMString) -> Root<HTMLCollection> {
+ fn GetElementsByTagName(&self, localname: DOMString) -> Root<HTMLCollection> {
let window = window_from_node(self);
HTMLCollection::by_tag_name(window.r(), NodeCast::from_ref(self), localname)
}
// https://dom.spec.whatwg.org/#dom-element-getelementsbytagnamens
- fn GetElementsByTagNameNS(self, maybe_ns: Option<DOMString>,
+ fn GetElementsByTagNameNS(&self, maybe_ns: Option<DOMString>,
localname: DOMString) -> Root<HTMLCollection> {
let window = window_from_node(self);
HTMLCollection::by_tag_name_ns(window.r(), NodeCast::from_ref(self), localname, maybe_ns)
}
// https://dom.spec.whatwg.org/#dom-element-getelementsbyclassname
- fn GetElementsByClassName(self, classes: DOMString) -> Root<HTMLCollection> {
+ fn GetElementsByClassName(&self, classes: DOMString) -> Root<HTMLCollection> {
let window = window_from_node(self);
HTMLCollection::by_class_name(window.r(), NodeCast::from_ref(self), classes)
}
// https://drafts.csswg.org/cssom-view/#dom-element-getclientrects
- fn GetClientRects(self) -> Root<DOMRectList> {
+ fn GetClientRects(&self) -> Root<DOMRectList> {
let win = window_from_node(self);
let node = NodeCast::from_ref(self);
let raw_rects = node.get_content_boxes();
@@ -1348,7 +1271,7 @@ impl<'a> ElementMethods for &'a Element {
}
// https://drafts.csswg.org/cssom-view/#dom-element-getboundingclientrect
- fn GetBoundingClientRect(self) -> Root<DOMRect> {
+ fn GetBoundingClientRect(&self) -> Root<DOMRect> {
let win = window_from_node(self);
let node = NodeCast::from_ref(self);
let rect = node.get_bounding_content_box();
@@ -1361,37 +1284,37 @@ impl<'a> ElementMethods for &'a Element {
}
// https://drafts.csswg.org/cssom-view/#dom-element-clienttop
- fn ClientTop(self) -> i32 {
+ fn ClientTop(&self) -> i32 {
let node = NodeCast::from_ref(self);
node.get_client_rect().origin.y
}
// https://drafts.csswg.org/cssom-view/#dom-element-clientleft
- fn ClientLeft(self) -> i32 {
+ fn ClientLeft(&self) -> i32 {
let node = NodeCast::from_ref(self);
node.get_client_rect().origin.x
}
// https://drafts.csswg.org/cssom-view/#dom-element-clientwidth
- fn ClientWidth(self) -> i32 {
+ fn ClientWidth(&self) -> i32 {
let node = NodeCast::from_ref(self);
node.get_client_rect().size.width
}
// https://drafts.csswg.org/cssom-view/#dom-element-clientheight
- fn ClientHeight(self) -> i32 {
+ fn ClientHeight(&self) -> i32 {
let node = NodeCast::from_ref(self);
node.get_client_rect().size.height
}
// https://dvcs.w3.org/hg/innerhtml/raw-file/tip/index.html#widl-Element-innerHTML
- fn GetInnerHTML(self) -> Fallible<DOMString> {
+ fn GetInnerHTML(&self) -> Fallible<DOMString> {
//XXX TODO: XML case
self.serialize(ChildrenOnly)
}
// https://dvcs.w3.org/hg/innerhtml/raw-file/tip/index.html#widl-Element-innerHTML
- fn SetInnerHTML(self, value: DOMString) -> Fallible<()> {
+ fn SetInnerHTML(&self, value: DOMString) -> Fallible<()> {
let context_node = NodeCast::from_ref(self);
// Step 1.
let frag = try!(context_node.parse_fragment(value));
@@ -1401,12 +1324,12 @@ impl<'a> ElementMethods for &'a Element {
}
// https://dvcs.w3.org/hg/innerhtml/raw-file/tip/index.html#widl-Element-outerHTML
- fn GetOuterHTML(self) -> Fallible<DOMString> {
+ fn GetOuterHTML(&self) -> Fallible<DOMString> {
self.serialize(IncludeNode)
}
// https://dvcs.w3.org/hg/innerhtml/raw-file/tip/index.html#widl-Element-outerHTML
- fn SetOuterHTML(self, value: DOMString) -> Fallible<()> {
+ fn SetOuterHTML(&self, value: DOMString) -> Fallible<()> {
let context_document = document_from_node(self);
let context_node = NodeCast::from_ref(self);
// Step 1.
@@ -1441,83 +1364,83 @@ impl<'a> ElementMethods for &'a Element {
}
// https://dom.spec.whatwg.org/#dom-nondocumenttypechildnode-previouselementsibling
- fn GetPreviousElementSibling(self) -> Option<Root<Element>> {
+ fn GetPreviousElementSibling(&self) -> Option<Root<Element>> {
NodeCast::from_ref(self).preceding_siblings()
.filter_map(ElementCast::to_root).next()
}
// https://dom.spec.whatwg.org/#dom-nondocumenttypechildnode-nextelementsibling
- fn GetNextElementSibling(self) -> Option<Root<Element>> {
+ fn GetNextElementSibling(&self) -> Option<Root<Element>> {
NodeCast::from_ref(self).following_siblings()
.filter_map(ElementCast::to_root).next()
}
// https://dom.spec.whatwg.org/#dom-parentnode-children
- fn Children(self) -> Root<HTMLCollection> {
+ fn Children(&self) -> Root<HTMLCollection> {
let window = window_from_node(self);
HTMLCollection::children(window.r(), NodeCast::from_ref(self))
}
// https://dom.spec.whatwg.org/#dom-parentnode-firstelementchild
- fn GetFirstElementChild(self) -> Option<Root<Element>> {
+ fn GetFirstElementChild(&self) -> Option<Root<Element>> {
NodeCast::from_ref(self).child_elements().next()
}
// https://dom.spec.whatwg.org/#dom-parentnode-lastelementchild
- fn GetLastElementChild(self) -> Option<Root<Element>> {
+ fn GetLastElementChild(&self) -> Option<Root<Element>> {
NodeCast::from_ref(self).rev_children().filter_map(ElementCast::to_root).next()
}
// https://dom.spec.whatwg.org/#dom-parentnode-childelementcount
- fn ChildElementCount(self) -> u32 {
+ fn ChildElementCount(&self) -> u32 {
NodeCast::from_ref(self).child_elements().count() as u32
}
// https://dom.spec.whatwg.org/#dom-parentnode-prepend
- fn Prepend(self, nodes: Vec<NodeOrString>) -> ErrorResult {
+ fn Prepend(&self, nodes: Vec<NodeOrString>) -> ErrorResult {
NodeCast::from_ref(self).prepend(nodes)
}
// https://dom.spec.whatwg.org/#dom-parentnode-append
- fn Append(self, nodes: Vec<NodeOrString>) -> ErrorResult {
+ fn Append(&self, nodes: Vec<NodeOrString>) -> ErrorResult {
NodeCast::from_ref(self).append(nodes)
}
// https://dom.spec.whatwg.org/#dom-parentnode-queryselector
- fn QuerySelector(self, selectors: DOMString) -> Fallible<Option<Root<Element>>> {
+ fn QuerySelector(&self, selectors: DOMString) -> Fallible<Option<Root<Element>>> {
let root = NodeCast::from_ref(self);
root.query_selector(selectors)
}
// https://dom.spec.whatwg.org/#dom-parentnode-queryselectorall
- fn QuerySelectorAll(self, selectors: DOMString) -> Fallible<Root<NodeList>> {
+ fn QuerySelectorAll(&self, selectors: DOMString) -> Fallible<Root<NodeList>> {
let root = NodeCast::from_ref(self);
root.query_selector_all(selectors)
}
// https://dom.spec.whatwg.org/#dom-childnode-before
- fn Before(self, nodes: Vec<NodeOrString>) -> ErrorResult {
+ fn Before(&self, nodes: Vec<NodeOrString>) -> ErrorResult {
NodeCast::from_ref(self).before(nodes)
}
// https://dom.spec.whatwg.org/#dom-childnode-after
- fn After(self, nodes: Vec<NodeOrString>) -> ErrorResult {
+ fn After(&self, nodes: Vec<NodeOrString>) -> ErrorResult {
NodeCast::from_ref(self).after(nodes)
}
// https://dom.spec.whatwg.org/#dom-childnode-replacewith
- fn ReplaceWith(self, nodes: Vec<NodeOrString>) -> ErrorResult {
+ fn ReplaceWith(&self, nodes: Vec<NodeOrString>) -> ErrorResult {
NodeCast::from_ref(self).replace_with(nodes)
}
// https://dom.spec.whatwg.org/#dom-childnode-remove
- fn Remove(self) {
+ fn Remove(&self) {
let node = NodeCast::from_ref(self);
node.remove_self();
}
// https://dom.spec.whatwg.org/#dom-element-matches
- fn Matches(self, selectors: DOMString) -> Fallible<bool> {
+ fn Matches(&self, selectors: DOMString) -> Fallible<bool> {
match parse_author_origin_selector_list_from_str(&selectors) {
Err(()) => Err(Syntax),
Ok(ref selectors) => {
@@ -1527,7 +1450,7 @@ impl<'a> ElementMethods for &'a Element {
}
// https://dom.spec.whatwg.org/#dom-element-closest
- fn Closest(self, selectors: DOMString) -> Fallible<Option<Root<Element>>> {
+ fn Closest(&self, selectors: DOMString) -> Fallible<Option<Root<Element>>> {
match parse_author_origin_selector_list_from_str(&selectors) {
Err(()) => Err(Syntax),
Ok(ref selectors) => {
@@ -1545,9 +1468,9 @@ impl<'a> ElementMethods for &'a Element {
}
}
-impl<'a> VirtualMethods for &'a Element {
+impl VirtualMethods for Element {
fn super_type<'b>(&'b self) -> Option<&'b VirtualMethods> {
- let node: &&Node = NodeCast::from_borrowed_ref(self);
+ let node: &Node = NodeCast::from_ref(self);
Some(node as &VirtualMethods)
}
@@ -1556,11 +1479,11 @@ impl<'a> VirtualMethods for &'a Element {
s.after_set_attr(attr);
}
- let node = NodeCast::from_ref(*self);
+ let node = NodeCast::from_ref(self);
match attr.local_name() {
&atom!("style") => {
// Modifying the `style` attribute might change style.
- let doc = document_from_node(*self);
+ let doc = document_from_node(self);
let base_url = doc.r().base_url();
let value = attr.value();
let style = Some(parse_style_attribute(&value, &base_url));
@@ -1573,7 +1496,7 @@ impl<'a> VirtualMethods for &'a Element {
&atom!("class") => {
// Modifying a class can change style.
if node.is_in_doc() {
- let document = document_from_node(*self);
+ let document = document_from_node(self);
document.r().content_changed(node, NodeDamage::NodeStyleDamaged);
}
}
@@ -1581,10 +1504,10 @@ impl<'a> VirtualMethods for &'a Element {
// Modifying an ID might change style.
let value = attr.value();
if node.is_in_doc() {
- let doc = document_from_node(*self);
+ let doc = document_from_node(self);
if !value.is_empty() {
let value = value.atom().unwrap().clone();
- doc.r().register_named_element(*self, value);
+ doc.r().register_named_element(self, value);
}
doc.r().content_changed(node, NodeDamage::NodeStyleDamaged);
}
@@ -1592,7 +1515,7 @@ impl<'a> VirtualMethods for &'a Element {
_ => {
// Modifying any other attribute might change arbitrary things.
if node.is_in_doc() {
- let document = document_from_node(*self);
+ let document = document_from_node(self);
document.r().content_changed(node, NodeDamage::OtherNodeDamage);
}
}
@@ -1604,14 +1527,14 @@ impl<'a> VirtualMethods for &'a Element {
s.before_remove_attr(attr);
}
- let node = NodeCast::from_ref(*self);
+ let node = NodeCast::from_ref(self);
match attr.local_name() {
&atom!("style") => {
// Modifying the `style` attribute might change style.
*self.style_attribute.borrow_mut() = None;
if node.is_in_doc() {
- let doc = document_from_node(*self);
+ let doc = document_from_node(self);
doc.r().content_changed(node, NodeDamage::NodeStyleDamaged);
}
}
@@ -1619,10 +1542,10 @@ impl<'a> VirtualMethods for &'a Element {
// Modifying an ID can change style.
let value = attr.value();
if node.is_in_doc() {
- let doc = document_from_node(*self);
+ let doc = document_from_node(self);
if !value.is_empty() {
let value = value.atom().unwrap().clone();
- doc.r().unregister_named_element(*self, value);
+ doc.r().unregister_named_element(self, value);
}
doc.r().content_changed(node, NodeDamage::NodeStyleDamaged);
}
@@ -1630,14 +1553,14 @@ impl<'a> VirtualMethods for &'a Element {
&atom!("class") => {
// Modifying a class can change style.
if node.is_in_doc() {
- let document = document_from_node(*self);
+ let document = document_from_node(self);
document.r().content_changed(node, NodeDamage::NodeStyleDamaged);
}
}
_ => {
// Modifying any other attribute might change arbitrary things.
if node.is_in_doc() {
- let doc = document_from_node(*self);
+ let doc = document_from_node(self);
doc.r().content_changed(node, NodeDamage::OtherNodeDamage);
}
}
@@ -1660,11 +1583,11 @@ impl<'a> VirtualMethods for &'a Element {
if !tree_in_doc { return; }
if let Some(ref attr) = self.get_attribute(&ns!(""), &atom!("id")) {
- let doc = document_from_node(*self);
+ let doc = document_from_node(self);
let value = attr.r().Value();
if !value.is_empty() {
let value = Atom::from_slice(&value);
- doc.r().register_named_element(*self, value);
+ doc.r().register_named_element(self, value);
}
}
}
@@ -1677,11 +1600,11 @@ impl<'a> VirtualMethods for &'a Element {
if !tree_in_doc { return; }
if let Some(ref attr) = self.get_attribute(&ns!(""), &atom!("id")) {
- let doc = document_from_node(*self);
+ let doc = document_from_node(self);
let value = attr.r().Value();
if !value.is_empty() {
let value = Atom::from_slice(&value);
- doc.r().unregister_named_element(*self, value);
+ doc.r().unregister_named_element(self, value);
}
}
}
@@ -1747,7 +1670,7 @@ impl<'a> ::selectors::Element for Root<Element> {
}
fn get_local_name<'b>(&'b self) -> &'b Atom {
- ElementHelpers::local_name(&**self)
+ self.local_name()
}
fn get_namespace<'b>(&'b self) -> &'b Namespace {
self.namespace()
@@ -1798,7 +1721,7 @@ impl<'a> ::selectors::Element for Root<Element> {
}
}
fn has_class(&self, name: &Atom) -> bool {
- AttributeHandlers::has_class(&**self, name)
+ Element::has_class(&**self, name)
}
fn each_class<F>(&self, mut callback: F)
where F: FnMut(&Atom)
@@ -1859,24 +1782,17 @@ impl<'a> ::selectors::Element for Root<Element> {
}
}
-pub trait ActivationElementHelpers<'a> {
- fn as_maybe_activatable(&'a self) -> Option<&'a (Activatable + 'a)>;
- fn click_in_progress(self) -> bool;
- fn set_click_in_progress(self, click: bool);
- fn nearest_activable_element(self) -> Option<Root<Element>>;
- fn authentic_click_activation<'b>(self, event: &'b Event);
-}
-impl<'a> ActivationElementHelpers<'a> for &'a Element {
- fn as_maybe_activatable(&'a self) -> Option<&'a (Activatable + 'a)> {
- let node = NodeCast::from_ref(*self);
+impl Element {
+ pub fn as_maybe_activatable<'a>(&'a self) -> Option<&'a (Activatable + 'a)> {
+ let node = NodeCast::from_ref(self);
let element = match node.type_id() {
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLInputElement)) => {
- let element = HTMLInputElementCast::to_borrowed_ref(self).unwrap();
+ let element = HTMLInputElementCast::to_ref(self).unwrap();
Some(element as &'a (Activatable + 'a))
},
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAnchorElement)) => {
- let element = HTMLAnchorElementCast::to_borrowed_ref(self).unwrap();
+ let element = HTMLAnchorElementCast::to_ref(self).unwrap();
Some(element as &'a (Activatable + 'a))
},
_ => {
@@ -1892,18 +1808,18 @@ impl<'a> ActivationElementHelpers<'a> for &'a Element {
})
}
- fn click_in_progress(self) -> bool {
+ pub fn click_in_progress(&self) -> bool {
let node = NodeCast::from_ref(self);
node.get_flag(CLICK_IN_PROGRESS)
}
- fn set_click_in_progress(self, click: bool) {
+ pub fn set_click_in_progress(&self, click: bool) {
let node = NodeCast::from_ref(self);
node.set_flag(CLICK_IN_PROGRESS, click)
}
// https://html.spec.whatwg.org/multipage/#nearest-activatable-element
- fn nearest_activable_element(self) -> Option<Root<Element>> {
+ pub fn nearest_activable_element(&self) -> Option<Root<Element>> {
match self.as_maybe_activatable() {
Some(el) => Some(Root::from_ref(el.as_element())),
None => {
@@ -1926,7 +1842,7 @@ impl<'a> ActivationElementHelpers<'a> for &'a Element {
///
/// Use an element's synthetic click activation (or handle_event) for any script-triggered clicks.
/// If the spec says otherwise, check with Manishearth first
- fn authentic_click_activation<'b>(self, event: &'b Event) {
+ pub fn authentic_click_activation<'b>(&self, event: &'b Event) {
// Not explicitly part of the spec, however this helps enforce the invariants
// required to save state between pre-activation and post-activation
// since we cannot nest authentic clicks (unlike synthetic click activation, where
@@ -1953,10 +1869,10 @@ impl<'a> ActivationElementHelpers<'a> for &'a Element {
}
}
// Step 6
- None => {event.fire(target);}
+ None => { event.fire(target); }
},
// Step 6
- None => {event.fire(target);}
+ None => { event.fire(target); }
}
// Step 7
self.set_click_in_progress(false);