mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Move InputSubmit to Activatable
This commit is contained in:
parent
2ed9626f1a
commit
d1547e3a7c
2 changed files with 54 additions and 16 deletions
|
@ -1202,9 +1202,8 @@ impl<'a> ActivationElementHelpers<'a> for JSRef<'a, Element> {
|
|||
let node: JSRef<Node> = NodeCast::from_ref(*self);
|
||||
match node.type_id() {
|
||||
ElementNodeTypeId(HTMLInputElementTypeId) => {
|
||||
let _element: &'a JSRef<'a, HTMLInputElement> = HTMLInputElementCast::to_borrowed_ref(self).unwrap();
|
||||
// Some(element as &'a Activatable + 'a)
|
||||
None
|
||||
let element: &'a JSRef<'a, HTMLInputElement> = HTMLInputElementCast::to_borrowed_ref(self).unwrap();
|
||||
Some(element as &'a Activatable + 'a)
|
||||
},
|
||||
_ => {
|
||||
None
|
||||
|
@ -1222,10 +1221,15 @@ impl<'a> ActivationElementHelpers<'a> for JSRef<'a, Element> {
|
|||
|
||||
// https://html.spec.whatwg.org/multipage/interaction.html#nearest-activatable-element
|
||||
fn nearest_activable_element(self) -> Option<JSRef<'a, Element>> {
|
||||
let node: JSRef<Node> = NodeCast::from_ref(self);
|
||||
node.ancestors()
|
||||
.filter_map(|node| ElementCast::to_ref(node))
|
||||
.filter(|e| e.as_maybe_activatable().is_some()).next()
|
||||
match self.as_maybe_activatable() {
|
||||
Some(el) => Some(*el.as_element().root()),
|
||||
None => {
|
||||
let node: JSRef<Node> = NodeCast::from_ref(self);
|
||||
node.ancestors()
|
||||
.filter_map(|node| ElementCast::to_ref(node))
|
||||
.filter(|e| e.as_maybe_activatable().is_some()).next()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Please call this method *only* for real click events
|
||||
|
@ -1252,11 +1256,8 @@ impl<'a> ActivationElementHelpers<'a> for JSRef<'a, Element> {
|
|||
// Step 6
|
||||
target.dispatch_event_with_target(None, event).ok();
|
||||
e.map(|el| {
|
||||
if NodeCast::from_ref(el).is_in_doc() {
|
||||
return; // XXXManishearth do we need this check?
|
||||
}
|
||||
el.as_maybe_activatable().map(|a| {
|
||||
if event.DefaultPrevented() {
|
||||
if !event.DefaultPrevented() {
|
||||
// post click activation
|
||||
a.activation_behavior();
|
||||
} else {
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
* 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/. */
|
||||
|
||||
use dom::activation::Activatable;
|
||||
use dom::attr::{Attr, AttrValue, UIntAttrValue};
|
||||
use dom::attr::AttrHelpers;
|
||||
use dom::bindings::cell::DOMRefCell;
|
||||
|
@ -429,11 +430,6 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLInputElement> {
|
|||
match self.input_type.get() {
|
||||
InputCheckbox => self.SetChecked(!self.checked.get()),
|
||||
InputRadio => self.SetChecked(true),
|
||||
InputSubmit => {
|
||||
self.form_owner().map(|o| {
|
||||
o.root().submit(NotFromFormSubmitMethod, InputElement(self.clone()))
|
||||
});
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
|
@ -499,3 +495,44 @@ impl<'a> FormControl<'a> for JSRef<'a, HTMLInputElement> {
|
|||
!(self.Disabled() || self.ReadOnly())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl<'a> Activatable for JSRef<'a, HTMLInputElement> {
|
||||
fn as_element(&self) -> Temporary<Element> {
|
||||
Temporary::from_rooted(ElementCast::from_ref(*self))
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/interaction.html#run-pre-click-activation-steps
|
||||
fn pre_click_activation(&self) {
|
||||
match self.input_type.get() {
|
||||
// https://html.spec.whatwg.org/multipage/forms.html#submit-button-state-%28type=submit%29
|
||||
// InputSubmit => (), // No behavior defined
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/interaction.html#run-canceled-activation-steps
|
||||
fn canceled_activation(&self) {
|
||||
match self.input_type.get() {
|
||||
// https://html.spec.whatwg.org/multipage/forms.html#submit-button-state-%28type=submit%29
|
||||
// InputSubmit => (), // No behavior defined
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/interaction.html#run-post-click-activation-steps
|
||||
fn activation_behavior(&self) {
|
||||
match self.input_type.get() {
|
||||
InputSubmit => {
|
||||
// https://html.spec.whatwg.org/multipage/forms.html#submit-button-state-%28type=submit%29
|
||||
// FIXME (Manishearth):
|
||||
if self.mutable() /* and document owner is fully active */ {
|
||||
self.form_owner().map(|o| {
|
||||
o.root().submit(NotFromFormSubmitMethod, InputElement(self.clone()))
|
||||
});
|
||||
}
|
||||
},
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue