Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove helper traits #7401

Merged
merged 5 commits into from Aug 27, 2015
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Prev

Remove AttributeHandlers

On components/script/*.rs:

    # Remove imports.
    /^ *use dom::element::\{.*AttributeHandlers/ {
        s/\{AttributeHandlers, /\{/
        s/, AttributeHandlers//g
        s/\{([a-zA-Z]+)\}/\1/
        /\{\}/d
        s/::self;$/;/
    }
    /^ *use dom::element::\{?AttributeHandlers\}?;$/d

    # Remove AttributeHandlers.
    /^pub trait AttributeHandlers \{$/,/^\}$/D

    # Patch AttributeHandlers methods.
    /^impl<'a> AttributeHandlers for &'a Element \{/,/^\}$/ {
        s/^impl<'a> AttributeHandlers for &'a Element \{/impl Element {/
        /^ *fn /s/\(self([,)])/\(\&self\1/
	/^ *fn.*\(&self/s/fn/pub fn/
    }

The few error cases were then fixed by hand.
  • Loading branch information
nox committed Aug 27, 2015
commit 2a028f66a2e7ab56094cf856ebdc20bc49ab7d4d
@@ -9,7 +9,7 @@ use dom::bindings::global::GlobalRef;
use dom::bindings::js::{JS, MutNullableHeap};
use dom::bindings::js::{Root, RootedReference, LayoutJS};
use dom::bindings::utils::{Reflector, reflect_dom_object};
use dom::element::{Element, AttributeHandlers};
use dom::element::Element;
use dom::virtualmethods::vtable_for;
use dom::window::Window;

@@ -41,7 +41,7 @@ use dom::customevent::CustomEvent;
use dom::documentfragment::DocumentFragment;
use dom::documenttype::DocumentType;
use dom::domimplementation::DOMImplementation;
use dom::element::{AttributeHandlers, Element, ElementCreator, ElementTypeId};
use dom::element::{Element, ElementCreator, ElementTypeId};
use dom::event::{Event, EventBubbles, EventCancelable};
use dom::eventtarget::{EventTarget, EventTargetTypeId};
use dom::htmlanchorelement::HTMLAnchorElement;
@@ -10,7 +10,7 @@ use dom::bindings::error::{ErrorResult, Fallible};
use dom::bindings::global::GlobalRef;
use dom::bindings::js::{JS, Root};
use dom::bindings::utils::{Reflector, reflect_dom_object};
use dom::element::{Element, AttributeHandlers};
use dom::element::Element;
use dom::node::window_from_node;

use string_cache::Atom;
@@ -825,58 +825,9 @@ impl 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()
@@ -885,14 +836,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 {
@@ -901,7 +852,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>) {
@@ -922,7 +873,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(":"));

@@ -931,7 +882,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),
@@ -947,7 +898,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,
@@ -973,7 +924,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))
@@ -983,18 +934,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()
@@ -1027,7 +978,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();
@@ -1044,20 +995,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());
@@ -1066,7 +1017,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();
@@ -1081,22 +1032,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()
@@ -1106,17 +1057,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
}));
@@ -1132,7 +1083,7 @@ 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));
}
@@ -1768,7 +1719,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)
@@ -16,7 +16,7 @@ use dom::bindings::codegen::InheritTypes::{MouseEventCast, NodeCast};
use dom::bindings::js::{JS, MutNullableHeap, Root};
use dom::document::Document;
use dom::domtokenlist::DOMTokenList;
use dom::element::{Element, AttributeHandlers, ElementTypeId};
use dom::element::{Element, ElementTypeId};
use dom::event::Event;
use dom::eventtarget::{EventTarget, EventTargetTypeId};
use dom::htmlelement::{HTMLElement, HTMLElementTypeId};
@@ -10,7 +10,7 @@ use dom::bindings::codegen::InheritTypes::HTMLAppletElementDerived;
use dom::bindings::codegen::InheritTypes::HTMLElementCast;
use dom::bindings::js::Root;
use dom::document::Document;
use dom::element::{AttributeHandlers, ElementTypeId};
use dom::element::ElementTypeId;
use dom::eventtarget::{EventTarget, EventTargetTypeId};
use dom::htmlelement::{HTMLElement, HTMLElementTypeId};
use dom::node::{Node, NodeTypeId};
@@ -9,7 +9,7 @@ use dom::bindings::codegen::InheritTypes::HTMLBaseElementDerived;
use dom::bindings::codegen::InheritTypes::HTMLElementCast;
use dom::bindings::js::Root;
use dom::document::Document;
use dom::element::{ElementTypeId, AttributeHandlers};
use dom::element::ElementTypeId;
use dom::eventtarget::{EventTarget, EventTargetTypeId};
use dom::htmlelement::{HTMLElement, HTMLElementTypeId};
use dom::node::{Node, NodeTypeId, document_from_node};
@@ -10,7 +10,7 @@ use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLElementCast, HTMLBut
use dom::bindings::codegen::InheritTypes::{HTMLButtonElementDerived, HTMLFieldSetElementDerived};
use dom::bindings::js::Root;
use dom::document::Document;
use dom::element::{AttributeHandlers, Element, ElementTypeId};
use dom::element::{Element, ElementTypeId};
use dom::event::Event;
use dom::eventtarget::{EventTarget, EventTargetTypeId};
use dom::htmlelement::{HTMLElement, HTMLElementTypeId};
@@ -14,7 +14,6 @@ use dom::bindings::js::{JS, LayoutJS, MutNullableHeap, HeapGCValue, Root};
use dom::bindings::utils::{Reflectable};
use dom::canvasrenderingcontext2d::{CanvasRenderingContext2D, LayoutCanvasRenderingContext2DHelpers};
use dom::document::Document;
use dom::element::AttributeHandlers;
use dom::element::ElementTypeId;
use dom::eventtarget::{EventTarget, EventTargetTypeId};
use dom::htmlelement::{HTMLElement, HTMLElementTypeId};
@@ -9,7 +9,7 @@ use dom::bindings::global::GlobalRef;
use dom::bindings::js::{JS, Root};
use dom::bindings::trace::JSTraceable;
use dom::bindings::utils::{namespace_from_domstring, Reflector, reflect_dom_object};
use dom::element::{Element, AttributeHandlers};
use dom::element::Element;
use dom::node::{Node, TreeIterator};
use dom::window::Window;
use util::str::{DOMString, split_html_space_chars};
@@ -19,7 +19,7 @@ use dom::bindings::utils::Reflectable;
use dom::cssstyledeclaration::{CSSStyleDeclaration, CSSModificationAccess};
use dom::document::Document;
use dom::domstringmap::DOMStringMap;
use dom::element::{Element, ElementTypeId, AttributeHandlers};
use dom::element::{Element, ElementTypeId};
use dom::eventtarget::{EventTarget, EventTargetTypeId};
use dom::htmlinputelement::HTMLInputElement;
use dom::htmlmediaelement::HTMLMediaElementTypeId;
@@ -9,8 +9,7 @@ use dom::bindings::codegen::InheritTypes::{HTMLElementCast, HTMLLegendElementDer
use dom::bindings::codegen::InheritTypes::{HTMLFieldSetElementDerived, NodeCast};
use dom::bindings::js::{Root, RootedReference};
use dom::document::Document;
use dom::element::ElementTypeId;
use dom::element::{AttributeHandlers, Element};
use dom::element::{Element, ElementTypeId};
use dom::eventtarget::{EventTarget, EventTargetTypeId};
use dom::htmlcollection::{HTMLCollection, CollectionFilter};
use dom::htmlelement::{HTMLElement, HTMLElementTypeId};
@@ -19,8 +19,7 @@ use dom::bindings::codegen::InheritTypes::{HTMLTextAreaElementCast, NodeCast};
use dom::bindings::global::GlobalRef;
use dom::bindings::js::{Root};
use dom::document::Document;
use dom::element::ElementTypeId;
use dom::element::{Element, AttributeHandlers};
use dom::element::{Element, ElementTypeId};
use dom::event::{Event, EventBubbles, EventCancelable};
use dom::eventtarget::{EventTarget, EventTargetTypeId};
use dom::htmlbuttonelement::{HTMLButtonElement};
@@ -17,8 +17,7 @@ use dom::bindings::js::{Root};
use dom::bindings::utils::Reflectable;
use dom::customevent::CustomEvent;
use dom::document::Document;
use dom::element::ElementTypeId;
use dom::element::{self, AttributeHandlers};
use dom::element::{ElementTypeId, self};
use dom::eventtarget::{EventTarget, EventTargetTypeId};
use dom::htmlelement::{HTMLElement, HTMLElementTypeId};
use dom::node::{Node, NodeTypeId, window_from_node};
@@ -15,7 +15,6 @@ use dom::bindings::global::GlobalRef;
use dom::bindings::js::{LayoutJS, Root};
use dom::bindings::refcounted::Trusted;
use dom::document::Document;
use dom::element::AttributeHandlers;
use dom::element::ElementTypeId;
use dom::event::{Event, EventBubbles, EventCancelable};
use dom::eventtarget::{EventTarget, EventTargetTypeId};
@@ -16,7 +16,7 @@ use dom::bindings::codegen::InheritTypes::{HTMLInputElementDerived, HTMLFieldSet
use dom::bindings::global::GlobalRef;
use dom::bindings::js::{JS, LayoutJS, Root, RootedReference};
use dom::document::Document;
use dom::element::{AttributeHandlers, Element, ElementTypeId, RawLayoutElementHelpers};
use dom::element::{Element, ElementTypeId, RawLayoutElementHelpers};
use dom::event::{Event, EventBubbles, EventCancelable};
use dom::eventtarget::{EventTarget, EventTargetTypeId};
use dom::htmlelement::{HTMLElement, HTMLElementTypeId};
@@ -16,8 +16,7 @@ use dom::bindings::js::{RootedReference};
use dom::bindings::refcounted::Trusted;
use dom::document::Document;
use dom::domtokenlist::DOMTokenList;
use dom::element::ElementTypeId;
use dom::element::{AttributeHandlers, Element};
use dom::element::{Element, ElementTypeId};
use dom::event::{EventBubbles, EventCancelable, Event};
use dom::eventtarget::{EventTarget, EventTargetTypeId};
use dom::htmlelement::{HTMLElement, HTMLElementTypeId};
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.