activation behavior for Button type Submit

This commit is contained in:
yodalee 2015-01-28 03:36:09 +08:00
parent 15231db7d3
commit 0f2b1c4856
2 changed files with 34 additions and 3 deletions

View file

@ -15,7 +15,8 @@ use dom::element::{AttributeHandlers, Element, ElementTypeId};
use dom::element::ActivationElementHelpers;
use dom::eventtarget::{EventTarget, EventTargetTypeId};
use dom::htmlelement::{HTMLElement, HTMLElementTypeId};
use dom::htmlformelement::{FormControl};
use dom::htmlformelement::{FormSubmitter, FormControl, HTMLFormElementHelpers};
use dom::htmlformelement::{SubmittedFrom};
use dom::node::{DisabledStateHelpers, Node, NodeHelpers, NodeTypeId, document_from_node, window_from_node};
use dom::validitystate::ValidityState;
use dom::virtualmethods::VirtualMethods;
@ -205,6 +206,13 @@ impl<'a> Activatable for JSRef<'a, HTMLButtonElement> {
fn activation_behavior(&self) {
let ty = self.button_type.get();
match ty {
//https://html.spec.whatwg.org/multipage/forms.html#attr-button-type-submit-state
ButtonType::ButtonSubmit => {
self.form_owner().map(|o| {
o.root().r().submit(SubmittedFrom::NotFromFormSubmitMethod,
FormSubmitter::ButtonElement(self.clone()))
});
}
_ => ()
}
}

View file

@ -8,6 +8,7 @@ use dom::bindings::codegen::Bindings::EventTargetBinding::EventTargetMethods;
use dom::bindings::codegen::Bindings::HTMLFormElementBinding;
use dom::bindings::codegen::Bindings::HTMLFormElementBinding::HTMLFormElementMethods;
use dom::bindings::codegen::Bindings::HTMLInputElementBinding::HTMLInputElementMethods;
use dom::bindings::codegen::Bindings::HTMLButtonElementBinding::HTMLButtonElementMethods;
use dom::bindings::codegen::InheritTypes::{EventTargetCast, HTMLFormElementDerived, NodeCast};
use dom::bindings::codegen::InheritTypes::{HTMLInputElementCast, HTMLTextAreaElementCast, HTMLFormElementCast};
use dom::bindings::global::GlobalRef;
@ -19,6 +20,7 @@ use dom::eventtarget::{EventTarget, EventTargetTypeId};
use dom::element::ElementTypeId;
use dom::htmlelement::{HTMLElement, HTMLElementTypeId};
use dom::htmlinputelement::{HTMLInputElement, HTMLInputElementHelpers};
use dom::htmlbuttonelement::{HTMLButtonElement};
use dom::htmltextareaelement::{HTMLTextAreaElement, HTMLTextAreaElementHelpers};
use dom::node::{Node, NodeHelpers, NodeTypeId, document_from_node, window_from_node};
use hyper::method::Method;
@ -416,8 +418,9 @@ pub enum FormMethod {
#[derive(Copy)]
pub enum FormSubmitter<'a> {
FormElement(JSRef<'a, HTMLFormElement>),
InputElement(JSRef<'a, HTMLInputElement>)
// TODO: Submit buttons, image submit, etc etc
InputElement(JSRef<'a, HTMLInputElement>),
ButtonElement(JSRef<'a, HTMLButtonElement>)
// TODO: image submit, etc etc
}
impl<'a> FormSubmitter<'a> {
@ -429,6 +432,11 @@ impl<'a> FormSubmitter<'a> {
input_element.get_form_attribute(&Atom::from_slice("formaction"),
|i| i.FormAction(),
|f| f.Action())
},
FormSubmitter::ButtonElement(button_element) => {
button_element.get_form_attribute(&Atom::from_slice("formaction"),
|i| i.FormAction(),
|f| f.Action())
}
}
}
@ -441,6 +449,11 @@ impl<'a> FormSubmitter<'a> {
input_element.get_form_attribute(&Atom::from_slice("formenctype"),
|i| i.FormEnctype(),
|f| f.Enctype())
},
FormSubmitter::ButtonElement(button_element) => {
button_element.get_form_attribute(&Atom::from_slice("formenctype"),
|i| i.FormAction(),
|f| f.Action())
}
};
match attr.as_slice() {
@ -460,6 +473,11 @@ impl<'a> FormSubmitter<'a> {
input_element.get_form_attribute(&Atom::from_slice("formmethod"),
|i| i.FormMethod(),
|f| f.Method())
},
FormSubmitter::ButtonElement(button_element) => {
button_element.get_form_attribute(&Atom::from_slice("formmethod"),
|i| i.FormAction(),
|f| f.Action())
}
};
match attr.as_slice() {
@ -477,6 +495,11 @@ impl<'a> FormSubmitter<'a> {
input_element.get_form_attribute(&Atom::from_slice("formtarget"),
|i| i.FormTarget(),
|f| f.Target())
},
FormSubmitter::ButtonElement(button_element) => {
button_element.get_form_attribute(&Atom::from_slice("formtarget"),
|i| i.FormAction(),
|f| f.Action())
}
}
}