mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
implment activation of buttonelement
ignore button type first
This commit is contained in:
parent
6d0e9a6c9d
commit
a026ccd4bb
1 changed files with 61 additions and 4 deletions
|
@ -2,20 +2,21 @@
|
|||
* 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;
|
||||
use dom::attr::AttrHelpers;
|
||||
use dom::bindings::codegen::Bindings::HTMLButtonElementBinding;
|
||||
use dom::bindings::codegen::Bindings::HTMLButtonElementBinding::HTMLButtonElementMethods;
|
||||
use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLElementCast, NodeCast};
|
||||
use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLElementCast, HTMLButtonElementCast, NodeCast};
|
||||
use dom::bindings::codegen::InheritTypes::{HTMLButtonElementDerived, HTMLFieldSetElementDerived};
|
||||
use dom::bindings::js::{JSRef, Temporary};
|
||||
use dom::document::Document;
|
||||
use dom::element::{AttributeHandlers, Element};
|
||||
use dom::element::{AttributeHandlers, Element, ElementTypeId};
|
||||
use dom::element::ActivationElementHelpers;
|
||||
use dom::eventtarget::{EventTarget, EventTargetTypeId};
|
||||
use dom::element::ElementTypeId;
|
||||
use dom::htmlelement::{HTMLElement, HTMLElementTypeId};
|
||||
use dom::htmlformelement::{FormControl};
|
||||
use dom::node::{DisabledStateHelpers, Node, NodeHelpers, NodeTypeId, window_from_node};
|
||||
use dom::node::{DisabledStateHelpers, Node, NodeHelpers, NodeTypeId, document_from_node, window_from_node};
|
||||
use dom::validitystate::ValidityState;
|
||||
use dom::virtualmethods::VirtualMethods;
|
||||
|
||||
|
@ -159,3 +160,59 @@ impl<'a> FormControl<'a> for JSRef<'a, HTMLButtonElement> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> Activatable for JSRef<'a, HTMLButtonElement> {
|
||||
fn as_element(&self) -> Temporary<Element> {
|
||||
Temporary::from_rooted(ElementCast::from_ref(*self))
|
||||
}
|
||||
|
||||
fn is_instance_activatable(&self) -> bool {
|
||||
match self.button_type.get() {
|
||||
//https://html.spec.whatwg.org/multipage/forms.html#the-button-element
|
||||
_ => {
|
||||
let node: JSRef<Node> = NodeCast::from_ref(*self);
|
||||
!(node.get_disabled_state())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/interaction.html#run-pre-click-activation-steps
|
||||
// https://html.spec.whatwg.org/multipage/forms.html#the-button-element:activation-behavior
|
||||
fn pre_click_activation(&self) {
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/interaction.html#run-canceled-activation-steps
|
||||
fn canceled_activation(&self) {
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/interaction.html#run-post-click-activation-steps
|
||||
fn activation_behavior(&self) {
|
||||
let ty = self.button_type.get();
|
||||
match ty {
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/forms.html#implicit-submission
|
||||
#[allow(unsafe_blocks)]
|
||||
fn implicit_submission(&self, ctrlKey: bool, shiftKey: bool, altKey: bool, metaKey: bool) {
|
||||
let doc = document_from_node(*self).root();
|
||||
let node: JSRef<Node> = NodeCast::from_ref(doc.r());
|
||||
let owner = self.form_owner();
|
||||
let elem: JSRef<Element> = ElementCast::from_ref(*self);
|
||||
if owner.is_none() || elem.click_in_progress() {
|
||||
return;
|
||||
}
|
||||
// This is safe because we are stopping after finding the first element
|
||||
// and only then performing actions which may modify the DOM tree
|
||||
unsafe {
|
||||
node.query_selector_iter("button[type=submit]".to_owned()).unwrap()
|
||||
.filter_map(|t| {
|
||||
let h: Option<JSRef<HTMLButtonElement>> = HTMLButtonElementCast::to_ref(t);
|
||||
h
|
||||
})
|
||||
.find(|r| r.form_owner() == owner)
|
||||
.map(|&:s| s.synthetic_click_activation(ctrlKey, shiftKey, altKey, metaKey));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue