mirror of
https://github.com/servo/servo.git
synced 2025-07-24 15:50:21 +01:00
Implement implicit form submission
This commit is contained in:
parent
c89ec3910f
commit
6482e313d6
3 changed files with 24 additions and 3 deletions
|
@ -25,6 +25,9 @@ pub trait Activatable : Copy {
|
|||
// https://html.spec.whatwg.org/multipage/interaction.html#run-post-click-activation-steps
|
||||
fn activation_behavior(&self);
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/forms.html#implicit-submission
|
||||
fn implicit_submission(&self, ctrlKey: bool, shiftKey: bool, altKey: bool, metaKey: bool);
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/interaction.html#run-synthetic-click-activation-steps
|
||||
fn synthetic_click_activation(&self, ctrlKey: bool, shiftKey: bool, altKey: bool, metaKey: bool) {
|
||||
let element = self.as_element().root();
|
||||
|
|
|
@ -20,7 +20,7 @@ use dom::bindings::js::{JS, JSRef, Root, Temporary, OptionalRootable, ResultRoot
|
|||
use dom::bindings::utils::{Reflectable, Reflector};
|
||||
use dom::document::{Document, DocumentHelpers};
|
||||
use dom::element::{AttributeHandlers, Element, HTMLInputElementTypeId};
|
||||
use dom::element::RawLayoutElementHelpers;
|
||||
use dom::element::{RawLayoutElementHelpers, ActivationElementHelpers};
|
||||
use dom::event::{Event, Bubbles, NotCancelable, EventHelpers};
|
||||
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
|
||||
use dom::htmlelement::HTMLElement;
|
||||
|
@ -695,4 +695,19 @@ impl<'a> Activatable for JSRef<'a, HTMLInputElement> {
|
|||
_ => ()
|
||||
}
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/forms.html#implicit-submission
|
||||
fn implicit_submission(&self, ctrlKey: bool, shiftKey: bool, altKey: bool, metaKey: bool) {
|
||||
let doc = document_from_node(*self).root();
|
||||
// FIXME (#4082) use a custom iterator
|
||||
let submits = doc.QuerySelectorAll("input[type=submit]".to_string()).unwrap().root();
|
||||
// XXXManishearth there may be a more efficient way of doing this (#3553)
|
||||
let owner = self.form_owner();
|
||||
if owner == None || ElementCast::from_ref(*self).click_in_progress() {
|
||||
return;
|
||||
}
|
||||
submits.into_vec().iter()
|
||||
.filter_map(|t| HTMLInputElementCast::to_ref(*t.root()))
|
||||
.find(|r| r.form_owner() == owner).map(|s| s.synthetic_click_activation(ctrlKey, shiftKey, altKey, metaKey));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -915,11 +915,14 @@ impl ScriptTask {
|
|||
// I'm dispatching it after the key event so the script has a chance to cancel it
|
||||
// https://www.w3.org/Bugs/Public/show_bug.cgi?id=27337
|
||||
match key {
|
||||
Key::KeySpace | Key::KeyEnter if !prevented && state == Released => {
|
||||
// TODO handle space and enter slightly differently
|
||||
Key::KeySpace if !prevented && state == Released => {
|
||||
let maybe_elem: Option<JSRef<Element>> = ElementCast::to_ref(target);
|
||||
maybe_elem.map(|el| el.as_maybe_activatable().map(|a| a.synthetic_click_activation(ctrl, alt, shift, meta)));
|
||||
}
|
||||
Key::KeyEnter if !prevented && state == Released => {
|
||||
let maybe_elem: Option<JSRef<Element>> = ElementCast::to_ref(target);
|
||||
maybe_elem.map(|el| el.as_maybe_activatable().map(|a| a.implicit_submission(ctrl, alt, shift, meta)));
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
window.flush_layout();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue