Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement SubmitEvent #25636

Merged
merged 1 commit into from Jan 31, 2020
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

SubmitEvent and test changes

  • Loading branch information
pshaughn committed Jan 30, 2020
commit 9cc218d0b064cb517d6963bcd3ffa746ba447976
@@ -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;
@@ -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))
}
}
@@ -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;
};
"testharness"
],
"html/semantics/forms/form-submission-0/form-double-submit-2.html": [
"f0c9471a704d4c0c0742d7ed8e8f13a789514d69",
"4c715de250e22bf48c225f5337ff38736f3fa80b",
"testharness"
],
"html/semantics/forms/form-submission-0/form-double-submit-3.html": [
"1bad23260d054b8f60e255de4d1a074803db4b2f",
"cdb50d226a893de2250a19a93c0b5a0f72bbcfee",
"testharness"
],
"html/semantics/forms/form-submission-0/form-double-submit.html": [
"1102e304174eeec18b65b54deec74a328d998be0",
"005f393bfd42fb850a81eb1d87bae048b7cad30b",
"testharness"
],
"html/semantics/forms/form-submission-0/form-echo.py": [
@@ -1376,27 +1376,6 @@
[SVGAElement includes HTMLHyperlinkElementUtils: member names are unique]
expected: FAIL

[SubmitEvent interface object name]
expected: FAIL

[SubmitEvent interface object length]
expected: FAIL

[SubmitEvent interface: existence and properties of interface prototype object]
expected: FAIL

[SubmitEvent interface: existence and properties of interface prototype object's @@unscopables property]
expected: FAIL
[SubmitEvent interface: attribute submitter]
expected: FAIL
[SubmitEvent interface: existence and properties of interface object]
expected: FAIL
[SubmitEvent interface: existence and properties of interface prototype object's "constructor" property]
expected: FAIL

[SVGElement interface: attribute onwebkitanimationend]
expected: FAIL

This file was deleted.

@@ -1,5 +1,4 @@
[form-double-submit-2.html]
expected: ERROR
[preventDefault should allow onclick submit() to succeed]
expected: FAIL

@@ -1,5 +1,4 @@
[form-double-submit-3.html]
expected: ERROR
[<button> should have the same double-submit protection as <input type=submit>]
expected: FAIL

@@ -1,5 +1,4 @@
[form-double-submit.html]
expected: ERROR
[default submit action should supersede onclick submit()]
expected: FAIL

@@ -5,9 +5,6 @@
[firing an event named submit; form.requestSubmit(submitter)]
expected: FAIL
[firing an event named submit; clicking a submit button]
expected: FAIL
[firing an event named submit; form.requestSubmit(null)]
expected: FAIL
@@ -19032,7 +19032,7 @@
"testharness"
],
"mozilla/interfaces.html": [
"114ec29df620cc0526d39a41928f72d9359890a9",
"fc82a7e82e936811024cbefadaa9cc396511942b",
"testharness"
],
"mozilla/interfaces.js": [
@@ -218,6 +218,7 @@
"StorageEvent",
"StyleSheet",
"StyleSheetList",
"SubmitEvent",
"Text",
"TextTrack",
"TextTrackCue",
@@ -25,6 +25,8 @@
<script>
let frame1 = document.getElementById('frame1');
let frame2 = document.getElementById('frame2');
let form1 = document.getElementById('form1');
let submitbutton = document.getElementById('submitbutton');

async_test(t => {
window.addEventListener('load', () => {
@@ -25,6 +25,8 @@
<script>
let frame1 = document.getElementById('frame1');
let frame2 = document.getElementById('frame2');
let form1 = document.getElementById('form1');
let submitbutton = document.getElementById('submitbutton');

async_test(t => {
window.addEventListener('load', () => {
@@ -25,6 +25,8 @@
<script>
let frame1 = document.getElementById('frame1');
let frame2 = document.getElementById('frame2');
let form1 = document.getElementById('form1');
let submitbutton = document.getElementById('submitbutton');

async_test(t => {
window.addEventListener('load', () => {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.