Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 bae4abd
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 54 deletions.
6 changes: 1 addition & 5 deletions components/script/dom/htmlbuttonelement.rs
Expand Up @@ -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 {
Expand Down
8 changes: 2 additions & 6 deletions components/script/dom/htmlfieldsetelement.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {}
14 changes: 9 additions & 5 deletions components/script/dom/htmlformelement.rs
Expand Up @@ -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;
Expand All @@ -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};
Expand Down Expand Up @@ -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"));
Expand All @@ -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) {
Expand All @@ -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 {
Expand Down
6 changes: 1 addition & 5 deletions components/script/dom/htmlinputelement.rs
Expand Up @@ -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 {
Expand Down
9 changes: 2 additions & 7 deletions components/script/dom/htmllabelelement.rs
Expand Up @@ -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};
Expand Down Expand Up @@ -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 {}
8 changes: 2 additions & 6 deletions components/script/dom/htmlobjectelement.rs
Expand Up @@ -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};
Expand Down Expand Up @@ -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 {}
9 changes: 2 additions & 7 deletions components/script/dom/htmloutputelement.rs
Expand Up @@ -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};
Expand Down Expand Up @@ -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 {}
10 changes: 3 additions & 7 deletions components/script/dom/htmlselectelement.rs
Expand Up @@ -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};
Expand Down Expand Up @@ -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 {}
8 changes: 2 additions & 6 deletions components/script/dom/htmltextareaelement.rs
Expand Up @@ -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};
Expand Down Expand Up @@ -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>,
Expand Down

0 comments on commit bae4abd

Please sign in to comment.