Compare commits

...
Author SHA1 Message Date
Moonchild 8de2e49133 WIP: Implement SubmitEvent API 2023-12-12 21:15:35 +01:00
Moonchild 61c87ab9b2 Bug 1552301 - Implement and enable <form>.requestSubmit() 2023-12-12 21:14:42 +01:00
Moonchild 0b842f3569 Bug 1600992 - Remove self header inclusion on generated webidl bindings
These self inclusions are useless so just remove them.
2023-12-12 21:12:05 +01:00
9 changed files with 103 additions and 53 deletions

No files matched your search

+3 -3
View File
@@ -1201,9 +1201,6 @@ class CGHeaders(CGWrapper):
getAllTypes(descriptors + callbackDescriptors, dictionaries,
callbacks))
# Now make sure we're not trying to include the header from inside itself
declareIncludes.discard(prefix + ".h")
def addHeaderForFunc(func, desc):
if func is None:
return
@@ -1287,6 +1284,9 @@ class CGHeaders(CGWrapper):
parentDesc = jsImplemented.getDescriptor(jsParent.identifier.name)
declareIncludes.add(parentDesc.jsImplParentHeader)
# Now make sure we're not trying to include the header from inside itself
declareIncludes.discard(prefix + ".h")
# Let the machinery do its thing.
def _includeString(includes):
return ''.join(['#include "%s"\n' % i for i in includes]) + '\n'
+1
View File
@@ -110,3 +110,4 @@ MSG_DEF(MSG_PMO_INVALID_MEMBERS, 0, JSEXN_TYPEERR, "PerformanceMeasureOptions ca
MSG_DEF(MSG_PMO_CONSTRUCTOR_INACCESSIBLE, 0, JSEXN_TYPEERR, "Can't access PerformanceMark constructor, performance is null.")
MSG_DEF(MSG_PMO_UNEXPECTED_START_TIME, 0, JSEXN_TYPEERR, "Expected startTime >= 0.")
MSG_DEF(MSG_PMO_INVALID_ATTR_FOR_NON_GLOBAL, 1, JSEXN_TYPEERR, "Cannot get PerformanceTiming attribute values for non-Window global object. Given: {0}.")
MSG_DEF(MSG_NOT_SUBMIT_BUTTON, 0, JSEXN_TYPEERR, "The submitter is not a submit button.")
@@ -401,6 +401,10 @@ const kEventConstructors = {
},
chromeOnly: true,
},
SubmitEvent: { create: function (aName, aProps) {
return new SubmitEvent(aName, aProps);
},
},
SVGZoomEvent: { create: function (aName, aProps) {
var e = document.createEvent("svgzoomevent");
e.initUIEvent(aName, aProps.bubbles, aProps.cancelable,
+55 -44
View File
@@ -15,6 +15,7 @@
#include "mozilla/dom/nsCSPContext.h"
#include "mozilla/dom/HTMLFormControlsCollection.h"
#include "mozilla/dom/HTMLFormElementBinding.h"
#include "mozilla/dom/SubmitEventBinding.h"
#include "mozilla/Move.h"
#include "nsIHTMLDocument.h"
#include "nsGkAtoms.h"
@@ -262,7 +263,7 @@ HTMLFormElement::Submit(ErrorResult& aRv)
mPendingSubmission = nullptr;
}
aRv = DoSubmitOrReset(nullptr, eFormSubmit);
aRv = DoSubmit();
}
NS_IMETHODIMP
@@ -273,6 +274,32 @@ HTMLFormElement::Submit()
return rv.StealNSResult();
}
// https://html.spec.whatwg.org/multipage/forms.html#dom-form-requestsubmit
void HTMLFormElement::RequestSubmit(nsGenericHTMLElement* aSubmitter,
ErrorResult& aRv) {
// 1. If submitter is not null, then:
if (aSubmitter) {
nsCOMPtr<nsIFormControl> fc = do_QueryObject(aSubmitter);
// 1.1. If submitter is not a submit button, then throw a TypeError.
if (!fc || !fc->IsSubmitControl()) {
aRv.ThrowTypeError<MSG_NOT_SUBMIT_BUTTON>();
return;
}
// 1.2. If submitter's form owner is not this form element, then throw a
// "NotFoundError" DOMException.
if (fc->GetFormElement() != this) {
aRv.Throw(NS_ERROR_DOM_NOT_FOUND_ERR);
return;
}
}
// 2. Otherwise, set submitter to this form element.
// 3. Submit this form element, from submitter.
MaybeSubmit(aSubmitter);
}
NS_IMETHODIMP
HTMLFormElement::Reset()
{
@@ -548,9 +575,12 @@ HTMLFormElement::PostHandleEvent(EventChainPostVisitor& aVisitor)
if (aVisitor.mEventStatus == nsEventStatus_eIgnore) {
switch (msg) {
case eFormReset:
case eFormReset: {
DoReset();
break;
}
case eFormSubmit: {
if (mPendingSubmission && msg == eFormSubmit) {
if (mPendingSubmission) {
// tell the form to forget a possible pending submission.
// the reason is that the script returned true (the event was
// ignored) so if there is a stored submission, it will miss
@@ -558,7 +588,7 @@ HTMLFormElement::PostHandleEvent(EventChainPostVisitor& aVisitor)
// to forget it and the form element will build a new one
mPendingSubmission = nullptr;
}
DoSubmitOrReset(aVisitor.mEvent, msg);
DoSubmit(aVisitor.mDOMEvent);
break;
}
default:
@@ -584,8 +614,7 @@ HTMLFormElement::PostHandleEvent(EventChainPostVisitor& aVisitor)
}
nsresult
HTMLFormElement::DoSubmitOrReset(WidgetEvent* aEvent,
EventMessage aMessage)
HTMLFormElement::DoReset()
{
// Make sure the presentation is up-to-date
nsIDocument* doc = GetComposedDoc();
@@ -593,29 +622,6 @@ HTMLFormElement::DoSubmitOrReset(WidgetEvent* aEvent,
doc->FlushPendingNotifications(Flush_ContentAndNotify);
}
// JBK Don't get form frames anymore - bug 34297
// Submit or Reset the form
if (eFormReset == aMessage) {
return DoReset();
}
if (eFormSubmit == aMessage) {
// Don't submit if we're not in a document or if we're in
// a sandboxed frame and form submit is disabled.
if (!doc || (doc->GetSandboxFlags() & SANDBOXED_FORMS)) {
return NS_OK;
}
return DoSubmit(aEvent);
}
MOZ_ASSERT(false);
return NS_OK;
}
nsresult
HTMLFormElement::DoReset()
{
// JBK walk the elements[] array instead of form frame controls - bug 34297
uint32_t numElements = GetElementCount();
for (uint32_t elementX = 0; elementX < numElements; ++elementX) {
@@ -635,10 +641,21 @@ HTMLFormElement::DoReset()
return rv; \
}
nsresult
HTMLFormElement::DoSubmit(WidgetEvent* aEvent)
{
NS_ASSERTION(GetComposedDoc(), "Should never get here without a current doc");
nsresult HTMLFormElement::DoSubmit(Event* aEvent) {
nsIDocument* doc = GetComposedDoc();
NS_ASSERTION(doc, "Should never get here without a current doc");
// Make sure the presentation is up-to-date
if (doc) {
doc->FlushPendingNotifications(FlushType::ContentAndNotify);
}
// Don't submit if we're not in a document or if we're in
// a sandboxed frame and form submit is disabled.
if (mIsConstructingEntryList || !doc ||
(doc->GetSandboxFlags() & SANDBOXED_FORMS)) {
return NS_OK;
}
if (mIsSubmitting) {
NS_WARNING("Preventing double form submission");
@@ -691,22 +708,16 @@ HTMLFormElement::DoSubmit(WidgetEvent* aEvent)
nsresult
HTMLFormElement::BuildSubmission(HTMLFormSubmission** aFormSubmission,
WidgetEvent* aEvent)
Event* aEvent)
{
NS_ASSERTION(!mPendingSubmission, "tried to build two submissions!");
// Get the originating frame (failure is non-fatal)
// Get the originating frame
nsGenericHTMLElement* originatingElement = nullptr;
if (aEvent) {
InternalFormEvent* formEvent = aEvent->AsFormEvent();
if (formEvent) {
nsIContent* originator = formEvent->mOriginator;
if (originator) {
if (!originator->IsHTMLElement()) {
return NS_ERROR_UNEXPECTED;
}
originatingElement = static_cast<nsGenericHTMLElement*>(originator);
}
SubmitEvent* submitEvent = aEvent->AsSubmitEvent();
if (submitEvent) {
originatingElement = submitEvent->GetSubmitter();
}
}
+16 -6
View File
@@ -392,6 +392,19 @@ public:
// XPCOM Reset() is OK
/**
* Requests to submit the form. Unlike submit(), this method includes
* interactive constraint validation and firing a submit event,
* either of which can cancel submission.
*
* @param aSubmitter The submitter argument can be used to point to a specific
* submit button.
* @param aRv An ErrorResult.
* @see
* https://html.spec.whatwg.org/multipage/forms.html#dom-form-requestsubmit
*/
void RequestSubmit(nsGenericHTMLElement* aSubmitter, ErrorResult& aRv);
bool CheckValidity()
{
return CheckFormValidity(nullptr);
@@ -448,8 +461,6 @@ protected:
RefPtr<HTMLFormElement> mForm;
};
nsresult DoSubmitOrReset(WidgetEvent* aEvent,
EventMessage aMessage);
nsresult DoReset();
// Async callback to handle removal of our default submit
@@ -461,12 +472,11 @@ protected:
//
/**
* Attempt to submit (submission might be deferred)
* (called by DoSubmitOrReset)
*
* @param aPresContext the presentation context
* @param aEvent the DOM event that was passed to us for the submit
*/
nsresult DoSubmit(WidgetEvent* aEvent);
nsresult DoSubmit(Event* aEvent = nullptr);
/**
* Prepare the submission object (called by DoSubmit)
@@ -474,8 +484,8 @@ protected:
* @param aFormSubmission the submission object
* @param aEvent the DOM event that was passed to us for the submit
*/
nsresult BuildSubmission(HTMLFormSubmission** aFormSubmission,
WidgetEvent* aEvent);
nsresult BuildSubmission(HTMLFormSubmission** aFormSubmission, Event* aEvent);
/**
* Perform the submission (called by DoSubmit and FlushPendingSubmission)
*
+2
View File
@@ -43,6 +43,8 @@ interface HTMLFormElement : HTMLElement {
[Throws]
void submit();
[Pref="dom.forms.requestsubmit.enabled", Throws]
void requestSubmit(optional HTMLElement? submitter = null);
[CEReactions]
void reset();
boolean checkValidity();
+18
View File
@@ -0,0 +1,18 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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 http://mozilla.org/MPL/2.0/.
*
* The origin of this IDL file is
* https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#submitevent
*/
[Exposed=Window,
Constructor(DOMString type, optional SubmitEventInit eventInitDict)]
interface SubmitEvent : Event {
readonly attribute HTMLElement? submitter;
};
dictionary SubmitEventInit : EventInit {
HTMLElement? submitter = null;
};
+1
View File
@@ -393,6 +393,7 @@ WEBIDL_FILES = [
'StorageType.webidl',
'StyleSheet.webidl',
'StyleSheetList.webidl',
'SubmitEvent.webidl',
'SubtleCrypto.webidl',
'SVGAElement.webidl',
'SVGAngle.webidl',
+3
View File
@@ -209,6 +209,9 @@ pref("dom.requestIdleCallback.enabled", true);
// See WD https://www.w3.org/TR/intersection-observer/
pref("dom.intersectionObserver.enabled", true);
// Whether the form.requestSubmit API is enabled
pref("dom.forms.requestsubmit.enabled", true);
#ifdef MOZ_GAMEPAD
// Whether the Gamepad API is enabled
pref("dom.gamepad.enabled", true);