Make button elements activatable. Fixes #4837. Fixes #8101.

This commit is contained in:
Josh Matthews 2015-10-20 21:14:42 -05:00
parent c1cb9403a7
commit 7693b03468
9 changed files with 56 additions and 42 deletions

View file

@ -36,6 +36,7 @@ use dom::domtokenlist::DOMTokenList;
use dom::event::Event;
use dom::htmlanchorelement::HTMLAnchorElement;
use dom::htmlbodyelement::{HTMLBodyElement, HTMLBodyElementLayoutHelpers};
use dom::htmlbuttonelement::HTMLButtonElement;
use dom::htmlcollection::HTMLCollection;
use dom::htmlfieldsetelement::HTMLFieldSetElement;
use dom::htmlfontelement::{HTMLFontElement, HTMLFontElementLayoutHelpers};
@ -1775,6 +1776,10 @@ impl Element {
let element = self.downcast::<HTMLInputElement>().unwrap();
Some(element as &Activatable)
},
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLButtonElement)) => {
let element = self.downcast::<HTMLButtonElement>().unwrap();
Some(element as &Activatable)
},
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAnchorElement)) => {
let element = self.downcast::<HTMLAnchorElement>().unwrap();
Some(element as &Activatable)

View file

@ -14,7 +14,7 @@ use dom::event::Event;
use dom::eventtarget::EventTarget;
use dom::htmlelement::HTMLElement;
use dom::htmlfieldsetelement::HTMLFieldSetElement;
use dom::htmlformelement::{FormControl, FormSubmitter};
use dom::htmlformelement::{FormControl, FormSubmitter, ResetFrom};
use dom::htmlformelement::{SubmittedFrom, HTMLFormElement};
use dom::node::{Node, UnbindContext, document_from_node, window_from_node};
use dom::nodelist::NodeList;
@ -189,7 +189,7 @@ impl VirtualMethods for HTMLButtonElement {
impl FormControl for HTMLButtonElement {}
impl<'a> Activatable for &'a HTMLButtonElement {
impl Activatable for HTMLButtonElement {
fn as_element(&self) -> &Element {
self.upcast()
}
@ -214,19 +214,26 @@ impl<'a> Activatable for &'a HTMLButtonElement {
match ty {
//https://html.spec.whatwg.org/multipage/#attr-button-type-submit-state
ButtonType::Submit => {
self.form_owner().map(|o| {
o.submit(SubmittedFrom::NotFromFormSubmitMethod,
FormSubmitter::ButtonElement(self.clone()))
});
},
_ => ()
// TODO: is document owner fully active?
if let Some(owner) = self.form_owner() {
owner.submit(SubmittedFrom::NotFromFormSubmitMethod,
FormSubmitter::ButtonElement(self.clone()));
}
}
ButtonType::Reset => {
// TODO: is document owner fully active?
if let Some(owner) = self.form_owner() {
owner.reset(ResetFrom::NotFromFormResetMethod);
}
}
_ => (),
}
}
// https://html.spec.whatwg.org/multipage/#implicit-submission
#[allow(unsafe_code)]
fn implicit_submission(&self, ctrlKey: bool, shiftKey: bool, altKey: bool, metaKey: bool) {
let doc = document_from_node(*self);
let doc = document_from_node(self);
let node = doc.upcast::<Node>();
let owner = self.form_owner();
if owner.is_none() || self.upcast::<Element>().click_in_progress() {