mirror of
https://github.com/servo/servo.git
synced 2025-07-24 15:50:21 +01:00
Address review comments
This commit is contained in:
parent
10d9a66ce1
commit
76219df816
2 changed files with 27 additions and 30 deletions
|
@ -2,6 +2,8 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
use dom::bindings::codegen::Bindings::EventBinding::EventMethods;
|
||||||
|
use dom::bindings::codegen::Bindings::EventTargetBinding::EventTargetMethods;
|
||||||
use dom::bindings::codegen::Bindings::HTMLFormElementBinding;
|
use dom::bindings::codegen::Bindings::HTMLFormElementBinding;
|
||||||
use dom::bindings::codegen::Bindings::HTMLFormElementBinding::HTMLFormElementMethods;
|
use dom::bindings::codegen::Bindings::HTMLFormElementBinding::HTMLFormElementMethods;
|
||||||
use dom::bindings::codegen::Bindings::HTMLInputElementBinding::HTMLInputElementMethods;
|
use dom::bindings::codegen::Bindings::HTMLInputElementBinding::HTMLInputElementMethods;
|
||||||
|
@ -14,7 +16,7 @@ use dom::document::{Document, DocumentHelpers};
|
||||||
use dom::element::{Element, AttributeHandlers, HTMLFormElementTypeId, HTMLTextAreaElementTypeId, HTMLDataListElementTypeId};
|
use dom::element::{Element, AttributeHandlers, HTMLFormElementTypeId, HTMLTextAreaElementTypeId, HTMLDataListElementTypeId};
|
||||||
use dom::element::{HTMLInputElementTypeId, HTMLButtonElementTypeId, HTMLObjectElementTypeId, HTMLSelectElementTypeId};
|
use dom::element::{HTMLInputElementTypeId, HTMLButtonElementTypeId, HTMLObjectElementTypeId, HTMLSelectElementTypeId};
|
||||||
use dom::event::Event;
|
use dom::event::Event;
|
||||||
use dom::eventtarget::{EventTarget, EventTargetHelpers, NodeTargetTypeId};
|
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
|
||||||
use dom::htmlelement::HTMLElement;
|
use dom::htmlelement::HTMLElement;
|
||||||
use dom::htmlinputelement::HTMLInputElement;
|
use dom::htmlinputelement::HTMLInputElement;
|
||||||
use dom::node::{Node, NodeHelpers, ElementNodeTypeId, document_from_node, window_from_node};
|
use dom::node::{Node, NodeHelpers, ElementNodeTypeId, document_from_node, window_from_node};
|
||||||
|
@ -163,24 +165,24 @@ pub trait HTMLFormElementHelpers {
|
||||||
impl<'a> HTMLFormElementHelpers for JSRef<'a, HTMLFormElement> {
|
impl<'a> HTMLFormElementHelpers for JSRef<'a, HTMLFormElement> {
|
||||||
fn submit(self, _from_submit_method: bool, submitter: FormSubmitter) {
|
fn submit(self, _from_submit_method: bool, submitter: FormSubmitter) {
|
||||||
// Step 1
|
// Step 1
|
||||||
let doc = *document_from_node(self).root();
|
let doc = document_from_node(self).root();
|
||||||
let win = *window_from_node(self).root();
|
let win = window_from_node(self).root();
|
||||||
let base = doc.url();
|
let base = doc.url();
|
||||||
// TODO: Handle browsing contexts
|
// TODO: Handle browsing contexts
|
||||||
// TODO: Handle validation
|
// TODO: Handle validation
|
||||||
let event = Event::new(&Window(win),
|
let event = Event::new(&Window(*win),
|
||||||
"submit".to_string(),
|
"submit".to_string(),
|
||||||
true, true).root();
|
true, true).root();
|
||||||
let target: JSRef<EventTarget> = EventTargetCast::from_ref(self);
|
let target: JSRef<EventTarget> = EventTargetCast::from_ref(self);
|
||||||
target.dispatch_event_with_target(None, *event).ok();
|
target.DispatchEvent(*event).ok();
|
||||||
if event.canceled.get() {
|
if event.DefaultPrevented() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Step 6
|
// Step 6
|
||||||
let form_data = self.get_form_dataset(Some(submitter));
|
let form_data = self.get_form_dataset(Some(submitter));
|
||||||
// Step 7-8
|
// Step 7-8
|
||||||
let mut action = submitter.action();
|
let mut action = submitter.action();
|
||||||
if action.len() == 0 {
|
if action.is_empty() {
|
||||||
action = base.serialize();
|
action = base.serialize();
|
||||||
}
|
}
|
||||||
// TODO: Resolve the url relative to the submitter element
|
// TODO: Resolve the url relative to the submitter element
|
||||||
|
@ -194,9 +196,7 @@ impl<'a> HTMLFormElementHelpers for JSRef<'a, HTMLFormElement> {
|
||||||
// TODO: Handle browsing contexts, partially loaded documents (step 16-17)
|
// TODO: Handle browsing contexts, partially loaded documents (step 16-17)
|
||||||
|
|
||||||
let parsed_data = match enctype {
|
let parsed_data = match enctype {
|
||||||
UrlEncoded => {
|
UrlEncoded => serialize(form_data.iter().map(|d| (d.name.as_slice(), d.value.as_slice())), None),
|
||||||
serialize(form_data.iter().map(|d| (d.name.as_slice(), d.value.as_slice())), None)
|
|
||||||
}
|
|
||||||
_ => "".to_string() // TODO: Add serializers for the other encoding types
|
_ => "".to_string() // TODO: Add serializers for the other encoding types
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -204,7 +204,9 @@ impl<'a> HTMLFormElementHelpers for JSRef<'a, HTMLFormElement> {
|
||||||
// Step 18
|
// Step 18
|
||||||
match (scheme.as_slice(), method) {
|
match (scheme.as_slice(), method) {
|
||||||
(_, FormDialog) => return, // Unimplemented
|
(_, FormDialog) => return, // Unimplemented
|
||||||
("http", FormGet) | ("https", FormGet) => { load_data.url.query = Some(parsed_data); },
|
("http", FormGet) | ("https", FormGet) => {
|
||||||
|
load_data.url.query = Some(parsed_data);
|
||||||
|
},
|
||||||
("http", FormPost) | ("https", FormPost) => {
|
("http", FormPost) | ("https", FormPost) => {
|
||||||
load_data.method = Post;
|
load_data.method = Post;
|
||||||
load_data.data = Some(parsed_data.into_bytes());
|
load_data.data = Some(parsed_data.into_bytes());
|
||||||
|
@ -266,33 +268,33 @@ impl<'a> HTMLFormElementHelpers for JSRef<'a, HTMLFormElement> {
|
||||||
match child.type_id() {
|
match child.type_id() {
|
||||||
ElementNodeTypeId(HTMLInputElementTypeId) => {
|
ElementNodeTypeId(HTMLInputElementTypeId) => {
|
||||||
let input: JSRef<HTMLInputElement> = HTMLInputElementCast::to_ref(child).unwrap();
|
let input: JSRef<HTMLInputElement> = HTMLInputElementCast::to_ref(child).unwrap();
|
||||||
let elem: JSRef<Element> = ElementCast::from_ref(input);
|
let ty = input.Type();
|
||||||
match elem.get_string_attribute("type").as_slice() {
|
let name = input.Name();
|
||||||
|
match ty.as_slice() {
|
||||||
"radio" | "checkbox" => {
|
"radio" | "checkbox" => {
|
||||||
if !input.Checked() {
|
if !input.Checked() || name.is_empty() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"image" => (),
|
"image" => (),
|
||||||
_ => {
|
_ => {
|
||||||
if elem.get_string_attribute("name").len() == 0 {
|
if name.is_empty() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let ty = input.Type(); // IDL attr, not HTML attr
|
|
||||||
let mut value_attr = elem.get_string_attribute("value");
|
let mut value = input.Value();
|
||||||
let name = elem.get_string_attribute("name");
|
|
||||||
match ty.as_slice() {
|
match ty.as_slice() {
|
||||||
"image" => None, // Unimplemented
|
"image" => None, // Unimplemented
|
||||||
"radio" | "checkbox" => {
|
"radio" | "checkbox" => {
|
||||||
if value_attr.len() == 0 {
|
if value.is_empty() {
|
||||||
value_attr = "on".to_string();
|
value = "on".to_string();
|
||||||
}
|
}
|
||||||
Some(FormDatum {
|
Some(FormDatum {
|
||||||
ty: ty,
|
ty: ty,
|
||||||
name: name,
|
name: name,
|
||||||
value: value_attr
|
value: value
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
"file" => None, // Unimplemented
|
"file" => None, // Unimplemented
|
||||||
|
@ -371,18 +373,14 @@ pub enum FormSubmitter<'a> {
|
||||||
impl<'a> FormSubmitter<'a> {
|
impl<'a> FormSubmitter<'a> {
|
||||||
fn action(&self) -> DOMString {
|
fn action(&self) -> DOMString {
|
||||||
match *self {
|
match *self {
|
||||||
FormElement(form) => {
|
FormElement(form) => form.Action()
|
||||||
let element: JSRef<Element> = ElementCast::from_ref(form);
|
|
||||||
element.get_url_attribute("action")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn enctype(&self) -> FormEncType {
|
fn enctype(&self) -> FormEncType {
|
||||||
match *self {
|
match *self {
|
||||||
FormElement(form) => {
|
FormElement(form) => {
|
||||||
let element: JSRef<Element> = ElementCast::from_ref(form);
|
match form.Enctype().as_slice() {
|
||||||
match element.get_string_attribute("enctype").into_ascii_lower().as_slice() {
|
|
||||||
"multipart/form-data" => FormDataEncoded,
|
"multipart/form-data" => FormDataEncoded,
|
||||||
"text/plain" => TextPlainEncoded,
|
"text/plain" => TextPlainEncoded,
|
||||||
// https://html.spec.whatwg.org/multipage/forms.html#attr-fs-enctype
|
// https://html.spec.whatwg.org/multipage/forms.html#attr-fs-enctype
|
||||||
|
@ -396,8 +394,7 @@ impl<'a> FormSubmitter<'a> {
|
||||||
fn method(&self) -> FormMethod {
|
fn method(&self) -> FormMethod {
|
||||||
match *self {
|
match *self {
|
||||||
FormElement(form) => {
|
FormElement(form) => {
|
||||||
let element: JSRef<Element> = ElementCast::from_ref(form);
|
match form.Method().as_slice() {
|
||||||
match element.get_string_attribute("method").into_ascii_lower().as_slice() {
|
|
||||||
"dialog" => FormDialog,
|
"dialog" => FormDialog,
|
||||||
"post" => FormPost,
|
"post" => FormPost,
|
||||||
_ => FormGet
|
_ => FormGet
|
||||||
|
|
|
@ -37,7 +37,7 @@ interface HTMLInputElement : HTMLElement {
|
||||||
attribute unsigned long size;
|
attribute unsigned long size;
|
||||||
// attribute DOMString src;
|
// attribute DOMString src;
|
||||||
// attribute DOMString step;
|
// attribute DOMString step;
|
||||||
attribute DOMString type; //XXXjdm need binaryName
|
attribute DOMString type;
|
||||||
// attribute DOMString defaultValue;
|
// attribute DOMString defaultValue;
|
||||||
[TreatNullAs=EmptyString] attribute DOMString value;
|
[TreatNullAs=EmptyString] attribute DOMString value;
|
||||||
// attribute Date? valueAsDate;
|
// attribute Date? valueAsDate;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue