mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
Refactor FormControl trait
The trait is now implemented for HTMLFooElement instead of &HTMLFooElement and does no longer require an impl body.
This commit is contained in:
parent
a72d7a4f52
commit
bae4abd388
9 changed files with 24 additions and 54 deletions
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue