mirror of
https://github.com/servo/servo.git
synced 2025-07-24 15:50:21 +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() {
|
if let Some(owner) = self.form_owner() {
|
||||||
owner.submit(
|
owner.submit(
|
||||||
SubmittedFrom::NotFromForm,
|
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::node::{UnbindContext, VecPreOrderInsertionHelper};
|
||||||
use crate::dom::nodelist::{NodeList, RadioListMode};
|
use crate::dom::nodelist::{NodeList, RadioListMode};
|
||||||
use crate::dom::radionodelist::RadioNodeList;
|
use crate::dom::radionodelist::RadioNodeList;
|
||||||
|
use crate::dom::submitevent::SubmitEvent;
|
||||||
use crate::dom::validitystate::ValidationFlags;
|
use crate::dom::validitystate::ValidationFlags;
|
||||||
use crate::dom::virtualmethods::VirtualMethods;
|
use crate::dom::virtualmethods::VirtualMethods;
|
||||||
use crate::dom::window::Window;
|
use crate::dom::window::Window;
|
||||||
|
@ -604,10 +605,29 @@ impl HTMLFormElement {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Step 7
|
// 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 {
|
if submit_method_flag == SubmittedFrom::NotFromForm {
|
||||||
let event = self
|
let event = SubmitEvent::new(
|
||||||
.upcast::<EventTarget>()
|
&self.global(),
|
||||||
.fire_bubbling_cancelable_event(atom!("submit"));
|
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() {
|
if event.DefaultPrevented() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2470,7 +2470,7 @@ impl Activatable for HTMLInputElement {
|
||||||
self.form_owner().map(|o| {
|
self.form_owner().map(|o| {
|
||||||
o.submit(
|
o.submit(
|
||||||
SubmittedFrom::NotFromForm,
|
SubmittedFrom::NotFromForm,
|
||||||
FormSubmitter::InputElement(self.clone()),
|
FormSubmitter::InputElement(self),
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
|
@ -484,6 +484,7 @@ pub mod storageevent;
|
||||||
pub mod stylepropertymapreadonly;
|
pub mod stylepropertymapreadonly;
|
||||||
pub mod stylesheet;
|
pub mod stylesheet;
|
||||||
pub mod stylesheetlist;
|
pub mod stylesheetlist;
|
||||||
|
pub mod submitevent;
|
||||||
pub mod svgelement;
|
pub mod svgelement;
|
||||||
pub mod svggraphicselement;
|
pub mod svggraphicselement;
|
||||||
pub mod svgsvgelement;
|
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;
|
||||||
|
};
|
|
@ -692159,15 +692159,15 @@
|
||||||
"testharness"
|
"testharness"
|
||||||
],
|
],
|
||||||
"html/semantics/forms/form-submission-0/form-double-submit-2.html": [
|
"html/semantics/forms/form-submission-0/form-double-submit-2.html": [
|
||||||
"f0c9471a704d4c0c0742d7ed8e8f13a789514d69",
|
"4c715de250e22bf48c225f5337ff38736f3fa80b",
|
||||||
"testharness"
|
"testharness"
|
||||||
],
|
],
|
||||||
"html/semantics/forms/form-submission-0/form-double-submit-3.html": [
|
"html/semantics/forms/form-submission-0/form-double-submit-3.html": [
|
||||||
"1bad23260d054b8f60e255de4d1a074803db4b2f",
|
"cdb50d226a893de2250a19a93c0b5a0f72bbcfee",
|
||||||
"testharness"
|
"testharness"
|
||||||
],
|
],
|
||||||
"html/semantics/forms/form-submission-0/form-double-submit.html": [
|
"html/semantics/forms/form-submission-0/form-double-submit.html": [
|
||||||
"1102e304174eeec18b65b54deec74a328d998be0",
|
"005f393bfd42fb850a81eb1d87bae048b7cad30b",
|
||||||
"testharness"
|
"testharness"
|
||||||
],
|
],
|
||||||
"html/semantics/forms/form-submission-0/form-echo.py": [
|
"html/semantics/forms/form-submission-0/form-echo.py": [
|
||||||
|
|
|
@ -1376,27 +1376,6 @@
|
||||||
[SVGAElement includes HTMLHyperlinkElementUtils: member names are unique]
|
[SVGAElement includes HTMLHyperlinkElementUtils: member names are unique]
|
||||||
expected: FAIL
|
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]
|
[SVGElement interface: attribute onwebkitanimationend]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
[SubmitEvent.window.html]
|
|
||||||
[Successful SubmitEvent constructor]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Failing SubmitEvent constructor]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Successful SubmitEvent constructor; empty dictionary]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Successful SubmitEvent constructor; null submitter]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Successful SubmitEvent constructor; missing dictionary]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Successful SubmitEvent constructor; null/undefined submitter]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Successful SubmitEvent constructor; null/undefined dictionary]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
[form-double-submit-2.html]
|
[form-double-submit-2.html]
|
||||||
expected: ERROR
|
|
||||||
[preventDefault should allow onclick submit() to succeed]
|
[preventDefault should allow onclick submit() to succeed]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
[form-double-submit-3.html]
|
[form-double-submit-3.html]
|
||||||
expected: ERROR
|
|
||||||
[<button> should have the same double-submit protection as <input type=submit>]
|
[<button> should have the same double-submit protection as <input type=submit>]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
[form-double-submit.html]
|
[form-double-submit.html]
|
||||||
expected: ERROR
|
|
||||||
[default submit action should supersede onclick submit()]
|
[default submit action should supersede onclick submit()]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
|
|
@ -5,9 +5,6 @@
|
||||||
[firing an event named submit; form.requestSubmit(submitter)]
|
[firing an event named submit; form.requestSubmit(submitter)]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[firing an event named submit; clicking a submit button]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[firing an event named submit; form.requestSubmit(null)]
|
[firing an event named submit; form.requestSubmit(null)]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
|
|
@ -19032,7 +19032,7 @@
|
||||||
"testharness"
|
"testharness"
|
||||||
],
|
],
|
||||||
"mozilla/interfaces.html": [
|
"mozilla/interfaces.html": [
|
||||||
"114ec29df620cc0526d39a41928f72d9359890a9",
|
"fc82a7e82e936811024cbefadaa9cc396511942b",
|
||||||
"testharness"
|
"testharness"
|
||||||
],
|
],
|
||||||
"mozilla/interfaces.js": [
|
"mozilla/interfaces.js": [
|
||||||
|
|
|
@ -218,6 +218,7 @@ test_interfaces([
|
||||||
"StorageEvent",
|
"StorageEvent",
|
||||||
"StyleSheet",
|
"StyleSheet",
|
||||||
"StyleSheetList",
|
"StyleSheetList",
|
||||||
|
"SubmitEvent",
|
||||||
"Text",
|
"Text",
|
||||||
"TextTrack",
|
"TextTrack",
|
||||||
"TextTrackCue",
|
"TextTrackCue",
|
||||||
|
|
|
@ -25,6 +25,8 @@
|
||||||
<script>
|
<script>
|
||||||
let frame1 = document.getElementById('frame1');
|
let frame1 = document.getElementById('frame1');
|
||||||
let frame2 = document.getElementById('frame2');
|
let frame2 = document.getElementById('frame2');
|
||||||
|
let form1 = document.getElementById('form1');
|
||||||
|
let submitbutton = document.getElementById('submitbutton');
|
||||||
|
|
||||||
async_test(t => {
|
async_test(t => {
|
||||||
window.addEventListener('load', () => {
|
window.addEventListener('load', () => {
|
||||||
|
|
|
@ -25,6 +25,8 @@
|
||||||
<script>
|
<script>
|
||||||
let frame1 = document.getElementById('frame1');
|
let frame1 = document.getElementById('frame1');
|
||||||
let frame2 = document.getElementById('frame2');
|
let frame2 = document.getElementById('frame2');
|
||||||
|
let form1 = document.getElementById('form1');
|
||||||
|
let submitbutton = document.getElementById('submitbutton');
|
||||||
|
|
||||||
async_test(t => {
|
async_test(t => {
|
||||||
window.addEventListener('load', () => {
|
window.addEventListener('load', () => {
|
||||||
|
|
|
@ -25,6 +25,8 @@
|
||||||
<script>
|
<script>
|
||||||
let frame1 = document.getElementById('frame1');
|
let frame1 = document.getElementById('frame1');
|
||||||
let frame2 = document.getElementById('frame2');
|
let frame2 = document.getElementById('frame2');
|
||||||
|
let form1 = document.getElementById('form1');
|
||||||
|
let submitbutton = document.getElementById('submitbutton');
|
||||||
|
|
||||||
async_test(t => {
|
async_test(t => {
|
||||||
window.addEventListener('load', () => {
|
window.addEventListener('load', () => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue