aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/htmlformelement.rs
diff options
context:
space:
mode:
authorAnthony Urena <anthgur@users.noreply.github.com>2015-10-06 11:53:00 -0400
committerAnthony Urena <anthgur@users.noreply.github.com>2015-10-07 10:22:02 -0400
commit31980a7a34fb18ddd637dfacec0d0226e9ac0bd1 (patch)
treedb51cd17315d42da9408b6c2054ea793f1fad4ed /components/script/dom/htmlformelement.rs
parent1f45a736e5685dc35b3a703f332ee0aa05d3b125 (diff)
downloadservo-31980a7a34fb18ddd637dfacec0d0226e9ac0bd1.tar.gz
servo-31980a7a34fb18ddd637dfacec0d0226e9ac0bd1.zip
Refactor html form dataset collection
Factor out FormDatum collection for <input> Improve early return logic for getting the FormDatum from an <input> Condense element type patterns
Diffstat (limited to 'components/script/dom/htmlformelement.rs')
-rw-r--r--components/script/dom/htmlformelement.rs123
1 files changed, 40 insertions, 83 deletions
diff --git a/components/script/dom/htmlformelement.rs b/components/script/dom/htmlformelement.rs
index 632b084c293..2b4edbbdfcb 100644
--- a/components/script/dom/htmlformelement.rs
+++ b/components/script/dom/htmlformelement.rs
@@ -229,7 +229,43 @@ impl HTMLFormElement {
win.r().pipeline(), load_data)).unwrap();
}
- pub fn get_form_dataset<'b>(&self, submitter: Option<FormSubmitter<'b>>) -> Vec<FormDatum> {
+ fn get_unclean_dataset<'a>(&self, submitter: Option<FormSubmitter<'a>>) -> Vec<FormDatum> {
+ let node = NodeCast::from_ref(self);
+ // TODO: This is an incorrect way of getting controls owned
+ // by the form, but good enough until html5ever lands
+ node.traverse_preorder().filter_map(|child| {
+ if child.r().get_disabled_state() {
+ return None;
+ }
+ if child.r().ancestors()
+ .any(|a| HTMLDataListElementCast::to_root(a).is_some()) {
+ return None;
+ }
+ match child.r().type_id() {
+ NodeTypeId::Element(ElementTypeId::HTMLElement(element)) => {
+ match element {
+ HTMLElementTypeId::HTMLInputElement => {
+ let input = HTMLInputElementCast::to_ref(child.r()).unwrap();
+ input.get_form_datum(submitter)
+ }
+ HTMLElementTypeId::HTMLButtonElement |
+ HTMLElementTypeId::HTMLSelectElement |
+ HTMLElementTypeId::HTMLObjectElement |
+ HTMLElementTypeId::HTMLTextAreaElement => {
+ // Unimplemented
+ None
+ }
+ _ => None
+ }
+ }
+ _ => None
+ }
+ }).collect()
+ // TODO: Handle `dirnames` (needs directionality support)
+ // https://html.spec.whatwg.org/multipage/#the-directionality
+ }
+
+ pub fn get_form_dataset<'a>(&self, submitter: Option<FormSubmitter<'a>>) -> Vec<FormDatum> {
fn clean_crlf(s: &str) -> DOMString {
// https://html.spec.whatwg.org/multipage/#constructing-the-form-data-set
// Step 4
@@ -262,88 +298,9 @@ impl HTMLFormElement {
buf
}
- let node = NodeCast::from_ref(self);
- // TODO: This is an incorrect way of getting controls owned
- // by the form, but good enough until html5ever lands
- let data_set = node.traverse_preorder().filter_map(|child| {
- if child.r().get_disabled_state() {
- return None;
- }
- if child.r().ancestors()
- .any(|a| HTMLDataListElementCast::to_root(a).is_some()) {
- return None;
- }
- // XXXManishearth don't include it if it is a button but not the submitter
- match child.r().type_id() {
- NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLInputElement)) => {
- let input = HTMLInputElementCast::to_ref(child.r()).unwrap();
- let ty = input.Type();
- let name = input.Name();
- match &*ty {
- "radio" | "checkbox" => {
- if !input.Checked() || name.is_empty() {
- return None;
- }
- },
- "image" => (),
- _ => {
- if name.is_empty() {
- return None;
- }
- }
- }
-
- let mut value = input.Value();
- let is_submitter = match submitter {
- Some(FormSubmitter::InputElement(s)) => {
- input == s
- },
- _ => false
- };
- match &*ty {
- "image" => None, // Unimplemented
- "radio" | "checkbox" => {
- if value.is_empty() {
- value = "on".to_owned();
- }
- Some(FormDatum {
- ty: ty,
- name: name,
- value: value
- })
- },
- // Discard buttons which are not the submitter
- "submit" | "button" | "reset" if !is_submitter => None,
- "file" => None, // Unimplemented
- _ => Some(FormDatum {
- ty: ty,
- name: name,
- value: value
- })
- }
- }
- NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLButtonElement)) => {
- // Unimplemented
- None
- }
- NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLSelectElement)) => {
- // Unimplemented
- None
- }
- NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLObjectElement)) => {
- // Unimplemented
- None
- }
- NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLTextAreaElement)) => {
- // Unimplemented
- None
- }
- _ => None
- }
- });
- // TODO: Handle `dirnames` (needs directionality support)
- // https://html.spec.whatwg.org/multipage/#the-directionality
- let mut ret: Vec<FormDatum> = data_set.collect();
+ let mut ret = self.get_unclean_dataset(submitter);
+ // https://html.spec.whatwg.org/multipage/#constructing-the-form-data-set
+ // Step 4
for datum in &mut ret {
match &*datum.ty {
"file" | "textarea" => (),