Auto merge of #7801 - aopicier:refactor_formcontrol, r=Manishearth

Refactor FormControl trait

The trait is now implemented for HTMLFooElement instead of
&HTMLFooElement and does no longer require an impl body.

Suggested by @Manishearth

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/7801)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2015-09-30 19:06:18 -06:00
commit 94e85a5226
9 changed files with 24 additions and 54 deletions

View file

@ -191,11 +191,7 @@ impl VirtualMethods for HTMLButtonElement {
}
}
impl<'a> FormControl<'a> for &'a HTMLButtonElement {
fn to_element(self) -> &'a Element {
ElementCast::from_ref(self)
}
}
impl FormControl for HTMLButtonElement {}
impl<'a> Activatable for &'a HTMLButtonElement {
fn as_element<'b>(&'b self) -> &'b Element {

View file

@ -5,7 +5,7 @@
use dom::attr::Attr;
use dom::bindings::codegen::Bindings::HTMLFieldSetElementBinding;
use dom::bindings::codegen::Bindings::HTMLFieldSetElementBinding::HTMLFieldSetElementMethods;
use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLElementCast, HTMLLegendElementDerived};
use dom::bindings::codegen::InheritTypes::{HTMLElementCast, HTMLLegendElementDerived};
use dom::bindings::codegen::InheritTypes::{HTMLFieldSetElementDerived, NodeCast};
use dom::bindings::js::{Root, RootedReference};
use dom::document::Document;
@ -157,8 +157,4 @@ impl VirtualMethods for HTMLFieldSetElement {
}
}
impl<'a> FormControl<'a> for &'a HTMLFieldSetElement {
fn to_element(self) -> &'a Element {
ElementCast::from_ref(self)
}
}
impl FormControl for HTMLFieldSetElement {}

View file

@ -15,9 +15,11 @@ use dom::bindings::codegen::InheritTypes::HTMLElementCast;
use dom::bindings::codegen::InheritTypes::HTMLFormElementCast;
use dom::bindings::codegen::InheritTypes::HTMLFormElementDerived;
use dom::bindings::codegen::InheritTypes::HTMLInputElementCast;
use dom::bindings::codegen::InheritTypes::{ElementBase, ElementCast};
use dom::bindings::codegen::InheritTypes::{HTMLTextAreaElementCast, NodeCast};
use dom::bindings::global::GlobalRef;
use dom::bindings::js::{Root};
use dom::bindings::utils::Reflectable;
use dom::document::Document;
use dom::element::{Element, ElementTypeId};
use dom::event::{Event, EventBubbles, EventCancelable};
@ -515,10 +517,10 @@ impl<'a> FormSubmitter<'a> {
}
}
pub trait FormControl<'a> : Copy + Sized {
pub trait FormControl: ElementBase + Reflectable {
// FIXME: This is wrong (https://github.com/servo/servo/issues/3553)
// but we need html5ever to do it correctly
fn form_owner(self) -> Option<Root<HTMLFormElement>> {
fn form_owner(&self) -> Option<Root<HTMLFormElement>> {
// https://html.spec.whatwg.org/multipage/#reset-the-form-owner
let elem = self.to_element();
let owner = elem.get_string_attribute(&atom!("form"));
@ -544,12 +546,12 @@ pub trait FormControl<'a> : Copy + Sized {
None
}
fn get_form_attribute<InputFn, OwnerFn>(self,
fn get_form_attribute<InputFn, OwnerFn>(&self,
attr: &Atom,
input: InputFn,
owner: OwnerFn)
-> DOMString
where InputFn: Fn(Self) -> DOMString,
where InputFn: Fn(&Self) -> DOMString,
OwnerFn: Fn(&HTMLFormElement) -> DOMString
{
if self.to_element().has_attribute(attr) {
@ -559,7 +561,9 @@ pub trait FormControl<'a> : Copy + Sized {
}
}
fn to_element(self) -> &'a Element;
fn to_element(&self) -> &Element {
ElementCast::from_ref(self)
}
}
impl VirtualMethods for HTMLFormElement {

View file

@ -633,11 +633,7 @@ impl VirtualMethods for HTMLInputElement {
}
}
impl<'a> FormControl<'a> for &'a HTMLInputElement {
fn to_element(self) -> &'a Element {
ElementCast::from_ref(self)
}
}
impl FormControl for HTMLInputElement {}
impl Activatable for HTMLInputElement {
fn as_element<'b>(&'b self) -> &'b Element {

View file

@ -4,11 +4,10 @@
use dom::bindings::codegen::Bindings::HTMLLabelElementBinding;
use dom::bindings::codegen::Bindings::HTMLLabelElementBinding::HTMLLabelElementMethods;
use dom::bindings::codegen::InheritTypes::ElementCast;
use dom::bindings::codegen::InheritTypes::HTMLLabelElementDerived;
use dom::bindings::js::Root;
use dom::document::Document;
use dom::element::{Element, ElementTypeId};
use dom::element::ElementTypeId;
use dom::eventtarget::{EventTarget, EventTargetTypeId};
use dom::htmlelement::{HTMLElement, HTMLElementTypeId};
use dom::htmlformelement::{FormControl, HTMLFormElement};
@ -54,8 +53,4 @@ impl HTMLLabelElementMethods for HTMLLabelElement {
}
}
impl<'a> FormControl<'a> for &'a HTMLLabelElement {
fn to_element(self) -> &'a Element {
ElementCast::from_ref(self)
}
}
impl FormControl for HTMLLabelElement {}

View file

@ -10,7 +10,7 @@ use dom::bindings::codegen::InheritTypes::HTMLObjectElementDerived;
use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLElementCast};
use dom::bindings::js::Root;
use dom::document::Document;
use dom::element::{AttributeMutation, Element, ElementTypeId};
use dom::element::{AttributeMutation, ElementTypeId};
use dom::eventtarget::{EventTarget, EventTargetTypeId};
use dom::htmlelement::{HTMLElement, HTMLElementTypeId};
use dom::htmlformelement::{FormControl, HTMLFormElement};
@ -119,8 +119,4 @@ impl VirtualMethods for HTMLObjectElement {
}
}
impl<'a> FormControl<'a> for &'a HTMLObjectElement {
fn to_element(self) -> &'a Element {
ElementCast::from_ref(self)
}
}
impl FormControl for HTMLObjectElement {}

View file

@ -4,11 +4,10 @@
use dom::bindings::codegen::Bindings::HTMLOutputElementBinding;
use dom::bindings::codegen::Bindings::HTMLOutputElementBinding::HTMLOutputElementMethods;
use dom::bindings::codegen::InheritTypes::ElementCast;
use dom::bindings::codegen::InheritTypes::HTMLOutputElementDerived;
use dom::bindings::js::Root;
use dom::document::Document;
use dom::element::{Element, ElementTypeId};
use dom::element::ElementTypeId;
use dom::eventtarget::{EventTarget, EventTargetTypeId};
use dom::htmlelement::{HTMLElement, HTMLElementTypeId};
use dom::htmlformelement::{FormControl, HTMLFormElement};
@ -61,8 +60,4 @@ impl HTMLOutputElementMethods for HTMLOutputElement {
}
}
impl<'a> FormControl<'a> for &'a HTMLOutputElement {
fn to_element(self) -> &'a Element {
ElementCast::from_ref(self)
}
}
impl FormControl for HTMLOutputElement {}

View file

@ -5,13 +5,13 @@
use dom::attr::{Attr, AttrValue};
use dom::bindings::codegen::Bindings::HTMLSelectElementBinding;
use dom::bindings::codegen::Bindings::HTMLSelectElementBinding::HTMLSelectElementMethods;
use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLElementCast, NodeCast};
use dom::bindings::codegen::InheritTypes::{HTMLElementCast, NodeCast};
use dom::bindings::codegen::InheritTypes::{HTMLFieldSetElementDerived, HTMLSelectElementDerived};
use dom::bindings::codegen::UnionTypes::HTMLElementOrLong;
use dom::bindings::codegen::UnionTypes::HTMLOptionElementOrHTMLOptGroupElement;
use dom::bindings::js::Root;
use dom::document::Document;
use dom::element::{AttributeMutation, Element, ElementTypeId};
use dom::element::{AttributeMutation, ElementTypeId};
use dom::eventtarget::{EventTarget, EventTargetTypeId};
use dom::htmlelement::{HTMLElement, HTMLElementTypeId};
use dom::htmlformelement::{FormControl, HTMLFormElement};
@ -161,8 +161,4 @@ impl VirtualMethods for HTMLSelectElement {
}
}
impl<'a> FormControl<'a> for &'a HTMLSelectElement {
fn to_element(self) -> &'a Element {
ElementCast::from_ref(self)
}
}
impl FormControl for HTMLSelectElement {}

View file

@ -15,7 +15,7 @@ use dom::bindings::global::GlobalRef;
use dom::bindings::js::{LayoutJS, Root};
use dom::bindings::refcounted::Trusted;
use dom::document::Document;
use dom::element::{AttributeMutation, Element, ElementTypeId};
use dom::element::{AttributeMutation, ElementTypeId};
use dom::event::{Event, EventBubbles, EventCancelable};
use dom::eventtarget::{EventTarget, EventTargetTypeId};
use dom::htmlelement::{HTMLElement, HTMLElementTypeId};
@ -363,11 +363,7 @@ impl VirtualMethods for HTMLTextAreaElement {
}
}
impl<'a> FormControl<'a> for &'a HTMLTextAreaElement {
fn to_element(self) -> &'a Element {
ElementCast::from_ref(self)
}
}
impl FormControl for HTMLTextAreaElement {}
pub struct ChangeEventRunnable {
element: Trusted<HTMLTextAreaElement>,