aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom
diff options
context:
space:
mode:
Diffstat (limited to 'components/script/dom')
-rwxr-xr-xcomponents/script/dom/htmlbuttonelement.rs2
-rw-r--r--components/script/dom/htmlformelement.rs26
-rwxr-xr-xcomponents/script/dom/htmlinputelement.rs2
-rw-r--r--components/script/dom/mod.rs1
-rw-r--r--components/script/dom/submitevent.rs79
-rw-r--r--components/script/dom/webidls/SubmitEvent.webidl15
6 files changed, 120 insertions, 5 deletions
diff --git a/components/script/dom/htmlbuttonelement.rs b/components/script/dom/htmlbuttonelement.rs
index b7c7da1e9bf..49541a2d4a0 100755
--- a/components/script/dom/htmlbuttonelement.rs
+++ b/components/script/dom/htmlbuttonelement.rs
@@ -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),
);
}
},
diff --git a/components/script/dom/htmlformelement.rs b/components/script/dom/htmlformelement.rs
index ebbe1d49615..bf59dc0280b 100644
--- a/components/script/dom/htmlformelement.rs
+++ b/components/script/dom/htmlformelement.rs
@@ -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;
}
diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs
index a8587b58ed0..88b2e688d65 100755
--- a/components/script/dom/htmlinputelement.rs
+++ b/components/script/dom/htmlinputelement.rs
@@ -2470,7 +2470,7 @@ impl Activatable for HTMLInputElement {
self.form_owner().map(|o| {
o.submit(
SubmittedFrom::NotFromForm,
- FormSubmitter::InputElement(self.clone()),
+ FormSubmitter::InputElement(self),
)
});
},
diff --git a/components/script/dom/mod.rs b/components/script/dom/mod.rs
index 282d3b66d60..c1a1ab72354 100644
--- a/components/script/dom/mod.rs
+++ b/components/script/dom/mod.rs
@@ -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;
diff --git a/components/script/dom/submitevent.rs b/components/script/dom/submitevent.rs
new file mode 100644
index 00000000000..17f8e7fd003
--- /dev/null
+++ b/components/script/dom/submitevent.rs
@@ -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))
+ }
+}
diff --git a/components/script/dom/webidls/SubmitEvent.webidl b/components/script/dom/webidls/SubmitEvent.webidl
new file mode 100644
index 00000000000..f5b2c49257d
--- /dev/null
+++ b/components/script/dom/webidls/SubmitEvent.webidl
@@ -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;
+};