зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1483738: Part 1 - Change notifyInvalidSubmit to take a plain array. r=mconley
This makes things saner for all consumers, which makes it worth doing on its own. But it also gives me an easy nsTArray to work with, which I can use to dispatch DOM events with array properties. Differential Revision: https://phabricator.services.mozilla.com/D3466 --HG-- extra : rebase_source : e8bcc75e84845e42c932886502f99ca3154df48d
This commit is contained in:
Родитель
870d813b3a
Коммит
319fbff074
|
@ -79,18 +79,10 @@ FormSubmitObserver.prototype =
|
|||
*/
|
||||
|
||||
notifyInvalidSubmit(aFormElement, aInvalidElements) {
|
||||
// We are going to handle invalid form submission attempt by focusing the
|
||||
// first invalid element and show the corresponding validation message in a
|
||||
// panel attached to the element.
|
||||
if (!aInvalidElements.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Show a validation message on the first focusable element.
|
||||
for (let i = 0; i < aInvalidElements.length; i++) {
|
||||
for (let element of aInvalidElements) {
|
||||
// Insure that this is the FormSubmitObserver associated with the
|
||||
// element / window this notification is about.
|
||||
let element = aInvalidElements.queryElementAt(i, Ci.nsISupports);
|
||||
if (this._content != element.ownerGlobal.top.document.defaultView) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1826,7 +1826,7 @@ HTMLFormElement::ForgetCurrentSubmission()
|
|||
}
|
||||
|
||||
bool
|
||||
HTMLFormElement::CheckFormValidity(nsIMutableArray* aInvalidElements) const
|
||||
HTMLFormElement::CheckFormValidity(nsTArray<RefPtr<Element>>* aInvalidElements) const
|
||||
{
|
||||
bool ret = true;
|
||||
|
||||
|
@ -1854,7 +1854,7 @@ HTMLFormElement::CheckFormValidity(nsIMutableArray* aInvalidElements) const
|
|||
// Add all unhandled invalid controls to aInvalidElements if the caller
|
||||
// requested them.
|
||||
if (defaultAction && aInvalidElements) {
|
||||
aInvalidElements->AppendElement(ToSupports(sortedControls[i]));
|
||||
aInvalidElements->AppendElement(sortedControls[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1903,12 +1903,9 @@ HTMLFormElement::CheckValidFormSubmission()
|
|||
// Do not check form validity if there is no observer for
|
||||
// NS_INVALIDFORMSUBMIT_SUBJECT.
|
||||
if (NS_SUCCEEDED(rv) && hasObserver) {
|
||||
nsCOMPtr<nsIMutableArray> invalidElements =
|
||||
do_CreateInstance(NS_ARRAY_CONTRACTID, &rv);
|
||||
// Return true on error here because that's what we always did
|
||||
NS_ENSURE_SUCCESS(rv, true);
|
||||
AutoTArray<RefPtr<Element>, 32> invalidElements;
|
||||
|
||||
if (!CheckFormValidity(invalidElements.get())) {
|
||||
if (!CheckFormValidity(&invalidElements)) {
|
||||
// For the first invalid submission, we should update element states.
|
||||
// We have to do that _before_ calling the observers so we are sure they
|
||||
// will not interfere (like focusing the element).
|
||||
|
@ -1958,8 +1955,7 @@ HTMLFormElement::CheckValidFormSubmission()
|
|||
observer = do_QueryInterface(inst);
|
||||
|
||||
if (observer) {
|
||||
observer->NotifyInvalidSubmit(this,
|
||||
static_cast<nsIArray*>(invalidElements));
|
||||
observer->NotifyInvalidSubmit(this, invalidElements);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -517,7 +517,7 @@ protected:
|
|||
*
|
||||
* @return Whether the form is currently valid.
|
||||
*/
|
||||
bool CheckFormValidity(nsIMutableArray* aInvalidElements) const;
|
||||
bool CheckFormValidity(nsTArray<RefPtr<Element>>* aInvalidElements) const;
|
||||
|
||||
// Clear the mImageNameLookupTable and mImageElements.
|
||||
void Clear();
|
||||
|
|
|
@ -145,6 +145,9 @@ nsIConstraintValidation::ReportValidity()
|
|||
return false;
|
||||
}
|
||||
|
||||
AutoTArray<RefPtr<Element>, 1> invalidElements;
|
||||
invalidElements.AppendElement(element);
|
||||
|
||||
nsCOMPtr<nsIObserverService> service =
|
||||
mozilla::services::GetObserverService();
|
||||
if (!service) {
|
||||
|
@ -162,10 +165,6 @@ nsIConstraintValidation::ReportValidity()
|
|||
bool hasObserver = false;
|
||||
rv = theEnum->HasMoreElements(&hasObserver);
|
||||
|
||||
nsCOMPtr<nsIMutableArray> invalidElements =
|
||||
do_CreateInstance(NS_ARRAY_CONTRACTID, &rv);
|
||||
invalidElements->AppendElement(element);
|
||||
|
||||
NS_ENSURE_SUCCESS(rv, true);
|
||||
nsCOMPtr<nsISupports> inst;
|
||||
nsCOMPtr<nsIFormSubmitObserver> observer;
|
||||
|
|
|
@ -11,6 +11,7 @@ interface nsIURI;
|
|||
interface nsIArray;
|
||||
|
||||
webidl HTMLFormElement;
|
||||
webidl Element;
|
||||
|
||||
[scriptable, uuid(867cb7e7-835d-408b-9788-d2834d284e03)]
|
||||
interface nsIFormSubmitObserver: nsISupports
|
||||
|
@ -18,7 +19,7 @@ interface nsIFormSubmitObserver: nsISupports
|
|||
void notify(in HTMLFormElement formNode, in mozIDOMWindow window, in nsIURI actionURL, out boolean cancelSubmit);
|
||||
|
||||
void notifyInvalidSubmit(in HTMLFormElement formNode,
|
||||
in nsIArray invalidElements);
|
||||
in Array<Element> invalidElements);
|
||||
};
|
||||
|
||||
%{C++
|
||||
|
|
|
@ -94,7 +94,7 @@ var FormAssistant = {
|
|||
}
|
||||
|
||||
// Ignore this notificaiton if the current tab doesn't contain the invalid element
|
||||
let currentElement = aInvalidElements.queryElementAt(0, Ci.nsISupports);
|
||||
let currentElement = aInvalidElements[0];
|
||||
let focused = this.focusedElement;
|
||||
if (focused && focused.ownerGlobal.top !== currentElement.ownerGlobal.top) {
|
||||
return;
|
||||
|
|
Загрузка…
Ссылка в новой задаче