mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
SubmitEvent and test changes
This commit is contained in:
parent
1352e7188a
commit
9cc218d0b0
18 changed files with 131 additions and 58 deletions
|
@ -307,7 +307,7 @@ impl Activatable for HTMLButtonElement {
|
|||
if let Some(owner) = self.form_owner() {
|
||||
owner.submit(
|
||||
SubmittedFrom::NotFromForm,
|
||||
FormSubmitter::ButtonElement(self.clone()),
|
||||
FormSubmitter::ButtonElement(self),
|
||||
);
|
||||
}
|
||||
},
|
||||
|
|
|
@ -48,6 +48,7 @@ use crate::dom::node::{Node, NodeFlags, ShadowIncluding};
|
|||
use crate::dom::node::{UnbindContext, VecPreOrderInsertionHelper};
|
||||
use crate::dom::nodelist::{NodeList, RadioListMode};
|
||||
use crate::dom::radionodelist::RadioNodeList;
|
||||
use crate::dom::submitevent::SubmitEvent;
|
||||
use crate::dom::validitystate::ValidationFlags;
|
||||
use crate::dom::virtualmethods::VirtualMethods;
|
||||
use crate::dom::window::Window;
|
||||
|
@ -604,10 +605,29 @@ impl HTMLFormElement {
|
|||
}
|
||||
}
|
||||
// Step 7
|
||||
// spec calls this "submitterButton" but it doesn't have to be a button,
|
||||
// just not be the form itself
|
||||
let submitter_button = match submitter {
|
||||
FormSubmitter::FormElement(f) => {
|
||||
if f == self {
|
||||
None
|
||||
} else {
|
||||
Some(f.upcast::<HTMLElement>())
|
||||
}
|
||||
},
|
||||
FormSubmitter::InputElement(i) => Some(i.upcast::<HTMLElement>()),
|
||||
FormSubmitter::ButtonElement(b) => Some(b.upcast::<HTMLElement>()),
|
||||
};
|
||||
if submit_method_flag == SubmittedFrom::NotFromForm {
|
||||
let event = self
|
||||
.upcast::<EventTarget>()
|
||||
.fire_bubbling_cancelable_event(atom!("submit"));
|
||||
let event = SubmitEvent::new(
|
||||
&self.global(),
|
||||
atom!("submit"),
|
||||
true,
|
||||
true,
|
||||
submitter_button.map(|s| DomRoot::from_ref(s)),
|
||||
);
|
||||
let event = event.upcast::<Event>();
|
||||
event.fire(self.upcast::<EventTarget>());
|
||||
if event.DefaultPrevented() {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -2470,7 +2470,7 @@ impl Activatable for HTMLInputElement {
|
|||
self.form_owner().map(|o| {
|
||||
o.submit(
|
||||
SubmittedFrom::NotFromForm,
|
||||
FormSubmitter::InputElement(self.clone()),
|
||||
FormSubmitter::InputElement(self),
|
||||
)
|
||||
});
|
||||
},
|
||||
|
|
|
@ -484,6 +484,7 @@ pub mod storageevent;
|
|||
pub mod stylepropertymapreadonly;
|
||||
pub mod stylesheet;
|
||||
pub mod stylesheetlist;
|
||||
pub mod submitevent;
|
||||
pub mod svgelement;
|
||||
pub mod svggraphicselement;
|
||||
pub mod svgsvgelement;
|
||||
|
|
79
components/script/dom/submitevent.rs
Normal file
79
components/script/dom/submitevent.rs
Normal file
|
@ -0,0 +1,79 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use crate::dom::bindings::codegen::Bindings::EventBinding::EventMethods;
|
||||
use crate::dom::bindings::codegen::Bindings::SubmitEventBinding;
|
||||
use crate::dom::bindings::codegen::Bindings::SubmitEventBinding::SubmitEventMethods;
|
||||
use crate::dom::bindings::inheritance::Castable;
|
||||
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject};
|
||||
use crate::dom::bindings::root::DomRoot;
|
||||
use crate::dom::bindings::str::DOMString;
|
||||
use crate::dom::event::Event;
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
use crate::dom::htmlelement::HTMLElement;
|
||||
use crate::dom::window::Window;
|
||||
use dom_struct::dom_struct;
|
||||
use servo_atoms::Atom;
|
||||
|
||||
#[dom_struct]
|
||||
#[allow(non_snake_case)]
|
||||
pub struct SubmitEvent {
|
||||
event: Event,
|
||||
submitter: Option<DomRoot<HTMLElement>>,
|
||||
}
|
||||
|
||||
impl SubmitEvent {
|
||||
fn new_inherited(submitter: Option<DomRoot<HTMLElement>>) -> SubmitEvent {
|
||||
SubmitEvent {
|
||||
event: Event::new_inherited(),
|
||||
submitter: submitter,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new(
|
||||
global: &GlobalScope,
|
||||
type_: Atom,
|
||||
bubbles: bool,
|
||||
cancelable: bool,
|
||||
submitter: Option<DomRoot<HTMLElement>>,
|
||||
) -> DomRoot<SubmitEvent> {
|
||||
let ev = reflect_dom_object(
|
||||
Box::new(SubmitEvent::new_inherited(submitter)),
|
||||
global,
|
||||
SubmitEventBinding::Wrap,
|
||||
);
|
||||
{
|
||||
let event = ev.upcast::<Event>();
|
||||
event.init_event(type_, bubbles, cancelable);
|
||||
}
|
||||
ev
|
||||
}
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
pub fn Constructor(
|
||||
window: &Window,
|
||||
type_: DOMString,
|
||||
init: &SubmitEventBinding::SubmitEventInit,
|
||||
) -> DomRoot<SubmitEvent> {
|
||||
SubmitEvent::new(
|
||||
&window.global(),
|
||||
Atom::from(type_),
|
||||
init.parent.bubbles,
|
||||
init.parent.cancelable,
|
||||
init.submitter.as_ref().map(|s| DomRoot::from_ref(&**s)),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl SubmitEventMethods for SubmitEvent {
|
||||
/// <https://dom.spec.whatwg.org/#dom-event-istrusted>
|
||||
fn IsTrusted(&self) -> bool {
|
||||
self.event.IsTrusted()
|
||||
}
|
||||
|
||||
/// https://html.spec.whatwg.org/multipage/#dom-submitevent-submitter
|
||||
fn GetSubmitter(&self) -> Option<DomRoot<HTMLElement>> {
|
||||
self.submitter.as_ref().map(|s| DomRoot::from_ref(&**s))
|
||||
}
|
||||
}
|
15
components/script/dom/webidls/SubmitEvent.webidl
Normal file
15
components/script/dom/webidls/SubmitEvent.webidl
Normal file
|
@ -0,0 +1,15 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#submitevent
|
||||
[Exposed=Window]
|
||||
interface SubmitEvent : Event {
|
||||
constructor(DOMString typeArg, optional SubmitEventInit eventInitDict = {});
|
||||
|
||||
readonly attribute HTMLElement? submitter;
|
||||
};
|
||||
|
||||
dictionary SubmitEventInit : EventInit {
|
||||
HTMLElement? submitter = null;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue