mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
parent
8ecbed9e42
commit
7ce40080bf
7 changed files with 85 additions and 159 deletions
|
@ -1221,6 +1221,75 @@ impl HTMLInputElement {
|
|||
fn selection(&self) -> TextControlSelection<Self> {
|
||||
TextControlSelection::new(&self, &self.textinput)
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#implicit-submission
|
||||
#[allow(unsafe_code)]
|
||||
fn implicit_submission(&self, ctrl_key: bool, shift_key: bool, alt_key: bool, meta_key: bool) {
|
||||
let doc = document_from_node(self);
|
||||
let node = doc.upcast::<Node>();
|
||||
let owner = self.form_owner();
|
||||
let form = match owner {
|
||||
None => return,
|
||||
Some(ref f) => f,
|
||||
};
|
||||
|
||||
if self.upcast::<Element>().click_in_progress() {
|
||||
return;
|
||||
}
|
||||
let submit_button;
|
||||
submit_button = node
|
||||
.query_selector_iter(DOMString::from("input[type=submit]"))
|
||||
.unwrap()
|
||||
.filter_map(DomRoot::downcast::<HTMLInputElement>)
|
||||
.find(|r| r.form_owner() == owner);
|
||||
match submit_button {
|
||||
Some(ref button) => {
|
||||
if button.is_instance_activatable() {
|
||||
synthetic_click_activation(
|
||||
button.as_element(),
|
||||
ctrl_key,
|
||||
shift_key,
|
||||
alt_key,
|
||||
meta_key,
|
||||
ActivationSource::NotFromClick,
|
||||
)
|
||||
}
|
||||
},
|
||||
None => {
|
||||
let inputs = node
|
||||
.query_selector_iter(DOMString::from("input"))
|
||||
.unwrap()
|
||||
.filter_map(DomRoot::downcast::<HTMLInputElement>)
|
||||
.filter(|input| {
|
||||
input.form_owner() == owner &&
|
||||
match input.input_type() {
|
||||
InputType::Text |
|
||||
InputType::Search |
|
||||
InputType::Url |
|
||||
InputType::Tel |
|
||||
InputType::Email |
|
||||
InputType::Password |
|
||||
InputType::Date |
|
||||
InputType::Month |
|
||||
InputType::Week |
|
||||
InputType::Time |
|
||||
InputType::DatetimeLocal |
|
||||
InputType::Number => true,
|
||||
_ => false,
|
||||
}
|
||||
});
|
||||
|
||||
if inputs.skip(1).next().is_some() {
|
||||
// lazily test for > 1 submission-blocking inputs
|
||||
return;
|
||||
}
|
||||
form.submit(
|
||||
SubmittedFrom::NotFromForm,
|
||||
FormSubmitter::FormElement(&form),
|
||||
);
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl VirtualMethods for HTMLInputElement {
|
||||
|
@ -1746,75 +1815,6 @@ impl Activatable for HTMLInputElement {
|
|||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#implicit-submission
|
||||
#[allow(unsafe_code)]
|
||||
fn implicit_submission(&self, ctrl_key: bool, shift_key: bool, alt_key: bool, meta_key: bool) {
|
||||
let doc = document_from_node(self);
|
||||
let node = doc.upcast::<Node>();
|
||||
let owner = self.form_owner();
|
||||
let form = match owner {
|
||||
None => return,
|
||||
Some(ref f) => f,
|
||||
};
|
||||
|
||||
if self.upcast::<Element>().click_in_progress() {
|
||||
return;
|
||||
}
|
||||
let submit_button;
|
||||
submit_button = node
|
||||
.query_selector_iter(DOMString::from("input[type=submit]"))
|
||||
.unwrap()
|
||||
.filter_map(DomRoot::downcast::<HTMLInputElement>)
|
||||
.find(|r| r.form_owner() == owner);
|
||||
match submit_button {
|
||||
Some(ref button) => {
|
||||
if button.is_instance_activatable() {
|
||||
synthetic_click_activation(
|
||||
button.as_element(),
|
||||
ctrl_key,
|
||||
shift_key,
|
||||
alt_key,
|
||||
meta_key,
|
||||
ActivationSource::NotFromClick,
|
||||
)
|
||||
}
|
||||
},
|
||||
None => {
|
||||
let inputs = node
|
||||
.query_selector_iter(DOMString::from("input"))
|
||||
.unwrap()
|
||||
.filter_map(DomRoot::downcast::<HTMLInputElement>)
|
||||
.filter(|input| {
|
||||
input.form_owner() == owner &&
|
||||
match input.input_type() {
|
||||
InputType::Text |
|
||||
InputType::Search |
|
||||
InputType::Url |
|
||||
InputType::Tel |
|
||||
InputType::Email |
|
||||
InputType::Password |
|
||||
InputType::Date |
|
||||
InputType::Month |
|
||||
InputType::Week |
|
||||
InputType::Time |
|
||||
InputType::DatetimeLocal |
|
||||
InputType::Number => true,
|
||||
_ => false,
|
||||
}
|
||||
});
|
||||
|
||||
if inputs.skip(1).next().is_some() {
|
||||
// lazily test for > 1 submission-blocking inputs
|
||||
return;
|
||||
}
|
||||
form.submit(
|
||||
SubmittedFrom::NotFromForm,
|
||||
FormSubmitter::FormElement(&form),
|
||||
);
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#attr-input-accept
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue