Skip to content
Permalink
Browse files

Refactor FormControl trait

The trait is now implemented for HTMLFooElement instead of
&HTMLFooElement and does no longer require an impl body.
  • Loading branch information...
aopicier committed Sep 30, 2015
1 parent a72d7a4 commit bae4abd388fd4f27335704f8dfe590809691f765
@@ -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 {
@@ -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 {}
@@ -9,6 +9,7 @@ use dom::bindings::codegen::Bindings::HTMLButtonElementBinding::HTMLButtonElemen
use dom::bindings::codegen::Bindings::HTMLFormElementBinding;
use dom::bindings::codegen::Bindings::HTMLFormElementBinding::HTMLFormElementMethods;
use dom::bindings::codegen::Bindings::HTMLInputElementBinding::HTMLInputElementMethods;
use dom::bindings::codegen::InheritTypes::{ElementBase, ElementCast};
use dom::bindings::codegen::InheritTypes::EventTargetCast;
use dom::bindings::codegen::InheritTypes::HTMLDataListElementCast;
use dom::bindings::codegen::InheritTypes::HTMLElementCast;
@@ -18,6 +19,7 @@ use dom::bindings::codegen::InheritTypes::HTMLInputElementCast;
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 {
@@ -629,11 +629,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 {
@@ -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 {}
@@ -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 {}
@@ -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 {}
@@ -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 {}
@@ -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>,

0 comments on commit bae4abd

Please sign in to comment.
You can’t perform that action at this time.