aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/htmlformelement.rs
diff options
context:
space:
mode:
authorRohan Prinja <rohan.prinja@gmail.com>2014-10-11 17:29:15 +0530
committerManish Goregaokar <manishsmail@gmail.com>2014-10-14 21:24:36 +0530
commit05134e6d1fa93c1068322b0cf3b548ba4b98e849 (patch)
treea7f03773c1f73f8bc68fa98d78be96596389d246 /components/script/dom/htmlformelement.rs
parentc92d58980cd8eb6a1b267fe195213fc2354b1773 (diff)
downloadservo-05134e6d1fa93c1068322b0cf3b548ba4b98e849.tar.gz
servo-05134e6d1fa93c1068322b0cf3b548ba4b98e849.zip
Add form submission via input element
Diffstat (limited to 'components/script/dom/htmlformelement.rs')
-rw-r--r--components/script/dom/htmlformelement.rs65
1 files changed, 48 insertions, 17 deletions
diff --git a/components/script/dom/htmlformelement.rs b/components/script/dom/htmlformelement.rs
index d8b0ad76695..678a090e69b 100644
--- a/components/script/dom/htmlformelement.rs
+++ b/components/script/dom/htmlformelement.rs
@@ -367,46 +367,77 @@ pub enum FormMethod {
}
pub enum FormSubmitter<'a> {
- FormElement(JSRef<'a, HTMLFormElement>)
+ FormElement(JSRef<'a, HTMLFormElement>),
+ InputElement(JSRef<'a, HTMLInputElement>)
// TODO: Submit buttons, image submit, etc etc
}
impl<'a> FormSubmitter<'a> {
fn action(&self) -> DOMString {
match *self {
- FormElement(form) => form.Action()
+ FormElement(form) => form.Action(),
+ InputElement(input_element) => {
+ let element: JSRef<Element> = ElementCast::from_ref(input_element);
+ if element.has_attribute("formaction") {
+ input_element.FormAction()
+ } else {
+ input_element.form_owner().map_or("".to_string(), |f_o| f_o.Action())
+ }
+ }
}
}
fn enctype(&self) -> FormEncType {
- match *self {
- FormElement(form) => {
- match form.Enctype().as_slice() {
- "multipart/form-data" => FormDataEncoded,
- "text/plain" => TextPlainEncoded,
- // https://html.spec.whatwg.org/multipage/forms.html#attr-fs-enctype
- // urlencoded is the default
- _ => UrlEncoded
+ let attr = match *self {
+ FormElement(form) => form.Enctype(),
+ InputElement(input_element) => {
+ let element: JSRef<Element> = ElementCast::from_ref(input_element);
+ if element.has_attribute("formenctype") {
+ input_element.FormEnctype()
+ } else {
+ input_element.form_owner().map_or("".to_string(), |f_o| f_o.Enctype())
}
}
+ };
+ match attr.as_slice() {
+ "multipart/form-data" => FormDataEncoded,
+ "text/plain" => TextPlainEncoded,
+ // https://html.spec.whatwg.org/multipage/forms.html#attr-fs-enctype
+ // urlencoded is the default
+ _ => UrlEncoded
}
}
fn method(&self) -> FormMethod {
- match *self {
- FormElement(form) => {
- match form.Method().as_slice() {
- "dialog" => FormDialog,
- "post" => FormPost,
- _ => FormGet
+ let attr = match *self {
+ FormElement(form) => form.Method(),
+ InputElement(input_element) => {
+ let element: JSRef<Element> = ElementCast::from_ref(input_element);
+ if element.has_attribute("formmethod") {
+ input_element.FormMethod()
+ } else {
+ input_element.form_owner().map_or("".to_string(), |f_o| f_o.Method())
}
}
+ };
+ match attr.as_slice() {
+ "dialog" => FormDialog,
+ "post" => FormPost,
+ _ => FormGet
}
}
fn target(&self) -> DOMString {
match *self {
- FormElement(form) => form.Target()
+ FormElement(form) => form.Target(),
+ InputElement(input_element) => {
+ let element: JSRef<Element> = ElementCast::from_ref(input_element);
+ if element.has_attribute("formtarget") {
+ input_element.FormTarget()
+ } else {
+ input_element.form_owner().map_or("".to_string(), |f_o| f_o.Target())
+ }
+ }
}
}
}