2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
2010-09-10 09:08:56 +04:00
|
|
|
|
2013-06-19 18:24:37 +04:00
|
|
|
#ifndef mozilla_dom_HTMLFormElement_h
|
|
|
|
#define mozilla_dom_HTMLFormElement_h
|
2010-09-10 09:08:56 +04:00
|
|
|
|
2014-03-17 10:56:54 +04:00
|
|
|
#include "mozilla/AsyncEventDispatcher.h"
|
2013-05-30 00:43:41 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2016-06-07 23:10:18 +03:00
|
|
|
#include "nsAutoPtr.h"
|
2009-10-30 04:49:11 +03:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIForm.h"
|
|
|
|
#include "nsIFormControl.h"
|
|
|
|
#include "nsGenericHTMLElement.h"
|
|
|
|
#include "nsIWebProgressListener.h"
|
|
|
|
#include "nsIRadioGroupContainer.h"
|
|
|
|
#include "nsIWeakReferenceUtils.h"
|
|
|
|
#include "nsThreadUtils.h"
|
2010-04-19 19:41:39 +04:00
|
|
|
#include "nsInterfaceHashtable.h"
|
2013-08-10 05:17:51 +04:00
|
|
|
#include "nsRefPtrHashtable.h"
|
2011-02-25 21:12:47 +03:00
|
|
|
#include "nsDataHashtable.h"
|
2013-08-24 06:42:42 +04:00
|
|
|
#include "jsfriendapi.h" // For js::ExpandoAndGeneration
|
2009-10-30 04:49:11 +03:00
|
|
|
|
2010-09-11 08:07:41 +04:00
|
|
|
class nsIMutableArray;
|
2013-03-18 19:38:19 +04:00
|
|
|
class nsIURI;
|
2009-10-30 04:49:11 +03:00
|
|
|
|
2013-06-18 16:53:23 +04:00
|
|
|
namespace mozilla {
|
2014-03-18 08:48:20 +04:00
|
|
|
class EventChainPostVisitor;
|
2014-03-18 08:48:19 +04:00
|
|
|
class EventChainPreVisitor;
|
2013-06-18 16:53:23 +04:00
|
|
|
namespace dom {
|
2013-10-03 11:11:26 +04:00
|
|
|
class HTMLFormControlsCollection;
|
2013-06-18 16:53:23 +04:00
|
|
|
class HTMLImageElement;
|
2019-09-09 16:53:27 +03:00
|
|
|
class FormData;
|
2013-06-19 18:24:37 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class HTMLFormElement final : public nsGenericHTMLElement,
|
2015-03-27 21:52:19 +03:00
|
|
|
public nsIWebProgressListener,
|
|
|
|
public nsIForm,
|
|
|
|
public nsIRadioGroupContainer {
|
2013-10-03 11:11:26 +04:00
|
|
|
friend class HTMLFormControlsCollection;
|
2013-06-19 18:24:37 +04:00
|
|
|
|
2009-10-30 04:49:11 +03:00
|
|
|
public:
|
2018-03-22 00:39:04 +03:00
|
|
|
NS_IMPL_FROMNODE_HTML_WITH_TAG(HTMLFormElement, form)
|
2018-02-23 21:28:08 +03:00
|
|
|
|
2018-09-21 23:45:49 +03:00
|
|
|
explicit HTMLFormElement(
|
|
|
|
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo);
|
2009-10-30 04:49:11 +03:00
|
|
|
|
2014-08-06 17:31:21 +04:00
|
|
|
enum { FORM_CONTROL_LIST_HASHTABLE_LENGTH = 8 };
|
2013-10-03 11:11:26 +04:00
|
|
|
|
2009-10-30 04:49:11 +03:00
|
|
|
// nsISupports
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
|
|
|
|
// nsIWebProgressListener
|
|
|
|
NS_DECL_NSIWEBPROGRESSLISTENER
|
|
|
|
|
|
|
|
// nsIForm
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD_(nsIFormControl*) GetElementAt(int32_t aIndex) const override;
|
|
|
|
NS_IMETHOD_(uint32_t) GetElementCount() const override;
|
|
|
|
NS_IMETHOD_(int32_t) IndexOfControl(nsIFormControl* aControl) override;
|
|
|
|
NS_IMETHOD_(nsIFormControl*) GetDefaultSubmitElement() const override;
|
2009-10-30 04:49:11 +03:00
|
|
|
|
|
|
|
// nsIRadioGroupContainer
|
2012-08-03 14:38:52 +04:00
|
|
|
void SetCurrentRadioButton(const nsAString& aName,
|
2015-03-21 19:28:04 +03:00
|
|
|
HTMLInputElement* aRadio) override;
|
|
|
|
HTMLInputElement* GetCurrentRadioButton(const nsAString& aName) override;
|
2009-10-30 04:49:11 +03:00
|
|
|
NS_IMETHOD GetNextRadioButton(const nsAString& aName, const bool aPrevious,
|
2013-08-10 05:17:51 +04:00
|
|
|
HTMLInputElement* aFocusedRadio,
|
2015-03-21 19:28:04 +03:00
|
|
|
HTMLInputElement** aRadioOut) override;
|
2009-10-30 04:49:11 +03:00
|
|
|
NS_IMETHOD WalkRadioGroup(const nsAString& aName, nsIRadioVisitor* aVisitor,
|
2015-03-21 19:28:04 +03:00
|
|
|
bool aFlushContent) override;
|
2017-08-03 09:39:00 +03:00
|
|
|
void AddToRadioGroup(const nsAString& aName,
|
|
|
|
HTMLInputElement* aRadio) override;
|
|
|
|
void RemoveFromRadioGroup(const nsAString& aName,
|
|
|
|
HTMLInputElement* aRadio) override;
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual uint32_t GetRequiredRadioCount(const nsAString& aName) const override;
|
2014-11-28 04:40:00 +03:00
|
|
|
virtual void RadioRequiredWillChange(const nsAString& aName,
|
2015-03-21 19:28:04 +03:00
|
|
|
bool aRequiredAdded) override;
|
|
|
|
virtual bool GetValueMissingState(const nsAString& aName) const override;
|
|
|
|
virtual void SetValueMissingState(const nsAString& aName,
|
|
|
|
bool aValue) override;
|
2009-10-30 04:49:11 +03:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual EventStates IntrinsicState() const override;
|
2012-02-07 16:51:49 +04:00
|
|
|
|
2016-10-13 09:33:53 +03:00
|
|
|
// EventTarget
|
|
|
|
virtual void AsyncEventRunning(AsyncEventDispatcher* aEvent) override;
|
|
|
|
|
2009-10-30 04:49:11 +03:00
|
|
|
// nsIContent
|
2012-08-22 19:56:38 +04:00
|
|
|
virtual bool ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
|
2009-10-30 04:49:11 +03:00
|
|
|
const nsAString& aValue,
|
2017-11-02 06:35:52 +03:00
|
|
|
nsIPrincipal* aMaybeScriptedPrincipal,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsAttrValue& aResult) override;
|
2018-04-05 20:42:41 +03:00
|
|
|
void GetEventTargetParent(EventChainPreVisitor& aVisitor) override;
|
2018-04-05 20:42:41 +03:00
|
|
|
void WillHandleEvent(EventChainPostVisitor& aVisitor) override;
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual nsresult PostHandleEvent(EventChainPostVisitor& aVisitor) override;
|
2009-10-30 04:49:11 +03:00
|
|
|
|
Bug 1555216 - Change the signature of BindToTree to be (BindContext&, nsINode& aParentNode). r=bzbarsky
BindContext was going to have way more information at first, but then I realized
that most of the things I wanted to know were basically a flag away using the
parent node.
Still I think it's worth it, now experimenting with BindToTree will only mean
adding a field to a struct that's included from a couple cpp files, instead of a
massive pain.
I also think this is clearer, and doing this highlights quite a few
inconsistencies in our code which I've left untouched, but commented with
FIXMEs.
Steps are:
$ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsresult BindToTree(Document\* aDocument, nsIContent\* aParent,#nsresult BindToTree(BindContext\&, nsINode\& aParent)#g' $file; done
$ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's# nsIContent\* aBindingParent) override#override#g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(Document\* aDocument, nsIContent\* aParent,#::BindToTree(BindContext\& aContext, nsINode\& aParent)#g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsIContent\* aBindingParent)##g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(aDocument, aParent, aBindingParent)#::BindToTree(aContext, aParent)#g' $file; done
$ ./mach clang-format
Then manual fixups.
Depends on D32948
Differential Revision: https://phabricator.services.mozilla.com/D32949
2019-05-29 07:27:04 +03:00
|
|
|
virtual nsresult BindToTree(BindContext&, nsINode& aParent) override;
|
2019-05-29 01:47:08 +03:00
|
|
|
virtual void UnbindFromTree(bool aNullParent = true) override;
|
2017-10-03 01:05:19 +03:00
|
|
|
virtual nsresult BeforeSetAttr(int32_t aNamespaceID, nsAtom* aName,
|
2017-06-07 20:28:20 +03:00
|
|
|
const nsAttrValueOrString* aValue,
|
|
|
|
bool aNotify) override;
|
2017-10-03 01:05:19 +03:00
|
|
|
virtual nsresult AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
|
2017-05-19 00:09:01 +03:00
|
|
|
const nsAttrValue* aValue,
|
|
|
|
const nsAttrValue* aOldValue,
|
2017-10-10 00:33:38 +03:00
|
|
|
nsIPrincipal* aSubjectPrincipal,
|
2017-05-19 00:09:01 +03:00
|
|
|
bool aNotify) override;
|
2009-10-30 04:49:11 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Forget all information about the current submission (and the fact that we
|
|
|
|
* are currently submitting at all).
|
|
|
|
*/
|
|
|
|
void ForgetCurrentSubmission();
|
|
|
|
|
2018-08-09 02:58:44 +03:00
|
|
|
virtual nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;
|
2009-10-30 04:49:11 +03:00
|
|
|
|
2016-07-22 23:19:52 +03:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLFormElement,
|
|
|
|
nsGenericHTMLElement)
|
2009-10-30 04:49:11 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove an element from this form's list of elements
|
|
|
|
*
|
|
|
|
* @param aElement the element to remove
|
2010-10-08 17:42:09 +04:00
|
|
|
* @param aUpdateValidity If true, updates the form validity.
|
2009-10-30 04:49:11 +03:00
|
|
|
* @return NS_OK if the element was successfully removed.
|
|
|
|
*/
|
2010-10-08 17:42:09 +04:00
|
|
|
nsresult RemoveElement(nsGenericHTMLFormElement* aElement,
|
2010-11-11 15:36:42 +03:00
|
|
|
bool aUpdateValidity);
|
2009-10-30 04:49:11 +03:00
|
|
|
|
|
|
|
/**
|
2010-05-13 16:19:50 +04:00
|
|
|
* Remove an element from the lookup table maintained by the form.
|
2009-10-30 04:49:11 +03:00
|
|
|
* We can't fold this method into RemoveElement() because when
|
|
|
|
* RemoveElement() is called it doesn't know if the element is
|
2016-11-21 20:34:02 +03:00
|
|
|
* removed because the id attribute has changed, or because the
|
2009-10-30 04:49:11 +03:00
|
|
|
* name attribute has changed.
|
|
|
|
*
|
|
|
|
* @param aElement the element to remove
|
|
|
|
* @param aName the name or id of the element to remove
|
|
|
|
* @return NS_OK if the element was successfully removed.
|
|
|
|
*/
|
|
|
|
nsresult RemoveElementFromTable(nsGenericHTMLFormElement* aElement,
|
2016-11-21 20:34:02 +03:00
|
|
|
const nsAString& aName);
|
2013-06-18 16:54:27 +04:00
|
|
|
|
2009-10-30 04:49:11 +03:00
|
|
|
/**
|
|
|
|
* Add an element to end of this form's list of elements
|
|
|
|
*
|
|
|
|
* @param aElement the element to add
|
2010-10-08 17:42:09 +04:00
|
|
|
* @param aUpdateValidity If true, the form validity will be updated.
|
2019-01-02 16:05:23 +03:00
|
|
|
* @param aNotify If true, send DocumentObserver notifications as needed.
|
2009-10-30 04:49:11 +03:00
|
|
|
* @return NS_OK if the element was successfully added
|
|
|
|
*/
|
2010-10-08 17:42:09 +04:00
|
|
|
nsresult AddElement(nsGenericHTMLFormElement* aElement, bool aUpdateValidity,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aNotify);
|
2009-10-30 04:49:11 +03:00
|
|
|
|
2013-06-18 16:53:23 +04:00
|
|
|
/**
|
2010-05-13 16:19:50 +04:00
|
|
|
* Add an element to the lookup table maintained by the form.
|
2009-10-30 04:49:11 +03:00
|
|
|
*
|
|
|
|
* We can't fold this method into AddElement() because when
|
|
|
|
* AddElement() is called, the form control has no
|
|
|
|
* attributes. The name or id attributes of the form control
|
|
|
|
* are used as a key into the table.
|
|
|
|
*/
|
|
|
|
nsresult AddElementToTable(nsGenericHTMLFormElement* aChild,
|
|
|
|
const nsAString& aName);
|
2013-06-18 16:53:23 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove an image element from this form's list of image elements
|
|
|
|
*
|
|
|
|
* @param aElement the image element to remove
|
|
|
|
* @return NS_OK if the element was successfully removed.
|
|
|
|
*/
|
2016-11-21 20:34:02 +03:00
|
|
|
nsresult RemoveImageElement(HTMLImageElement* aElement);
|
2013-06-18 16:53:23 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove an image element from the lookup table maintained by the form.
|
|
|
|
* We can't fold this method into RemoveImageElement() because when
|
|
|
|
* RemoveImageElement() is called it doesn't know if the element is
|
|
|
|
* removed because the id attribute has changed, or because the
|
|
|
|
* name attribute has changed.
|
|
|
|
*
|
|
|
|
* @param aElement the image element to remove
|
|
|
|
* @param aName the name or id of the element to remove
|
|
|
|
* @return NS_OK if the element was successfully removed.
|
|
|
|
*/
|
2016-11-21 20:34:02 +03:00
|
|
|
nsresult RemoveImageElementFromTable(HTMLImageElement* aElement,
|
|
|
|
const nsAString& aName);
|
2013-06-18 16:53:23 +04:00
|
|
|
/**
|
|
|
|
* Add an image element to the end of this form's list of image elements
|
|
|
|
*
|
|
|
|
* @param aElement the element to add
|
|
|
|
* @return NS_OK if the element was successfully added
|
|
|
|
*/
|
2016-11-21 20:34:02 +03:00
|
|
|
nsresult AddImageElement(HTMLImageElement* aElement);
|
2013-06-18 16:53:23 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add an image element to the lookup table maintained by the form.
|
|
|
|
*
|
|
|
|
* We can't fold this method into AddImageElement() because when
|
|
|
|
* AddImageElement() is called, the image attributes can change.
|
|
|
|
* The name or id attributes of the image are used as a key into the table.
|
|
|
|
*/
|
2016-11-21 20:34:02 +03:00
|
|
|
nsresult AddImageElementToTable(HTMLImageElement* aChild,
|
|
|
|
const nsAString& aName);
|
2013-06-18 16:53:23 +04:00
|
|
|
|
2009-10-30 04:49:11 +03:00
|
|
|
/**
|
2013-10-16 18:39:45 +04:00
|
|
|
* Returns true if implicit submission of this form is disabled. For more
|
|
|
|
* on implicit submission see:
|
2009-10-30 04:49:11 +03:00
|
|
|
*
|
2013-10-16 18:39:45 +04:00
|
|
|
* http://www.whatwg.org/specs/web-apps/current-work/multipage/association-of-controls-and-forms.html#implicit-submission
|
2009-10-30 04:49:11 +03:00
|
|
|
*/
|
2013-10-16 18:39:45 +04:00
|
|
|
bool ImplicitSubmissionIsDisabled() const;
|
2009-10-30 04:49:11 +03:00
|
|
|
|
2017-10-01 16:57:16 +03:00
|
|
|
/**
|
|
|
|
* Check whether a given nsIFormControl is the last single line input control
|
|
|
|
* that is not disabled. aControl is expected to not be null.
|
|
|
|
*/
|
|
|
|
bool IsLastActiveElement(const nsIFormControl* aControl) const;
|
|
|
|
|
2009-10-30 04:49:11 +03:00
|
|
|
/**
|
|
|
|
* Check whether a given nsIFormControl is the default submit
|
|
|
|
* element. This is different from just comparing to
|
|
|
|
* GetDefaultSubmitElement() in certain situations inside an update
|
|
|
|
* when GetDefaultSubmitElement() might not be up to date. aControl
|
|
|
|
* is expected to not be null.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsDefaultSubmitElement(const nsIFormControl* aControl) const;
|
2009-10-30 04:49:11 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Flag the form to know that a button or image triggered scripted form
|
|
|
|
* submission. In that case the form will defer the submission until the
|
|
|
|
* script handler returns and the return value is known.
|
|
|
|
*/
|
2017-12-07 21:13:50 +03:00
|
|
|
void OnSubmitClickBegin(Element* aOriginatingElement);
|
2009-10-30 04:49:11 +03:00
|
|
|
void OnSubmitClickEnd();
|
|
|
|
|
2010-09-10 09:08:56 +04:00
|
|
|
/**
|
|
|
|
* This method will update the form validity so the submit controls states
|
|
|
|
* will be updated (for -moz-submit-invalid pseudo-class).
|
|
|
|
* This method has to be called by form elements whenever their validity state
|
|
|
|
* or status regarding constraint validation changes.
|
|
|
|
*
|
|
|
|
* @note This method isn't used for CheckValidity().
|
|
|
|
* @note If an element becomes barred from constraint validation, it has to be
|
|
|
|
* considered as valid.
|
|
|
|
*
|
|
|
|
* @param aElementValidityState the new validity state of the element
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
void UpdateValidity(bool aElementValidityState);
|
2010-09-10 09:08:56 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the form validity based on the last UpdateValidity() call.
|
|
|
|
*
|
|
|
|
* @return Whether the form was valid the last time UpdateValidity() was
|
|
|
|
* called.
|
|
|
|
*
|
|
|
|
* @note This method may not return the *current* validity state!
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool GetValidity() const { return !mInvalidElementsCount; }
|
2010-09-10 09:08:56 +04:00
|
|
|
|
2010-09-11 08:07:41 +04:00
|
|
|
/**
|
|
|
|
* This method check the form validity and make invalid form elements send
|
|
|
|
* invalid event if needed.
|
|
|
|
*
|
|
|
|
* @return Whether the form is valid.
|
|
|
|
*
|
2010-09-11 08:11:58 +04:00
|
|
|
* @note Do not call this method if novalidate/formnovalidate is used.
|
2010-09-11 08:07:41 +04:00
|
|
|
* @note This method might disappear with bug 592124, hopefuly.
|
2019-11-20 19:14:37 +03:00
|
|
|
* @see
|
|
|
|
* https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#interactively-validate-the-constraints
|
2010-09-11 08:07:41 +04:00
|
|
|
*/
|
|
|
|
bool CheckValidFormSubmission();
|
|
|
|
|
2010-09-16 02:52:02 +04:00
|
|
|
/**
|
2019-09-09 16:53:27 +03:00
|
|
|
* Contruct the entry list to get their data pumped into the FormData and
|
|
|
|
* fire a `formdata` event with the entry list in formData attribute.
|
|
|
|
* <https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#constructing-form-data-set>
|
2010-09-16 02:52:02 +04:00
|
|
|
*
|
2019-09-09 16:53:27 +03:00
|
|
|
* @param aFormData the form data object
|
2010-09-16 02:52:02 +04:00
|
|
|
*/
|
2019-09-09 16:53:27 +03:00
|
|
|
nsresult ConstructEntryList(FormData* aFormData);
|
2010-09-16 02:52:02 +04:00
|
|
|
|
2010-11-24 02:50:19 +03:00
|
|
|
/**
|
|
|
|
* Whether the submission of this form has been ever prevented because of
|
|
|
|
* being invalid.
|
|
|
|
*
|
|
|
|
* @return Whether the submission of this form has been prevented because of
|
|
|
|
* being invalid.
|
|
|
|
*/
|
|
|
|
bool HasEverTriedInvalidSubmit() const { return mEverTriedInvalidSubmit; }
|
|
|
|
|
2013-04-04 11:03:12 +04:00
|
|
|
/**
|
|
|
|
* Implements form[name]. Returns form controls in this form with the correct
|
|
|
|
* value of the name attribute.
|
|
|
|
*/
|
|
|
|
already_AddRefed<nsISupports> FindNamedItem(const nsAString& aName,
|
|
|
|
nsWrapperCache** aCache);
|
|
|
|
|
2013-06-19 18:24:37 +04:00
|
|
|
// WebIDL
|
|
|
|
|
|
|
|
void GetAcceptCharset(DOMString& aValue) {
|
|
|
|
GetHTMLAttr(nsGkAtoms::acceptcharset, aValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetAcceptCharset(const nsAString& aValue, ErrorResult& aRv) {
|
|
|
|
SetHTMLAttr(nsGkAtoms::acceptcharset, aValue, aRv);
|
|
|
|
}
|
|
|
|
|
2017-07-17 09:17:19 +03:00
|
|
|
void GetAction(nsString& aValue);
|
2013-06-19 18:24:37 +04:00
|
|
|
void SetAction(const nsAString& aValue, ErrorResult& aRv) {
|
|
|
|
SetHTMLAttr(nsGkAtoms::action, aValue, aRv);
|
|
|
|
}
|
|
|
|
|
2018-02-23 21:28:08 +03:00
|
|
|
void GetAutocomplete(nsAString& aValue);
|
2013-06-19 18:24:37 +04:00
|
|
|
void SetAutocomplete(const nsAString& aValue, ErrorResult& aRv) {
|
|
|
|
SetHTMLAttr(nsGkAtoms::autocomplete, aValue, aRv);
|
|
|
|
}
|
|
|
|
|
2018-02-23 21:28:08 +03:00
|
|
|
void GetEnctype(nsAString& aValue);
|
2013-06-19 18:24:37 +04:00
|
|
|
void SetEnctype(const nsAString& aValue, ErrorResult& aRv) {
|
|
|
|
SetHTMLAttr(nsGkAtoms::enctype, aValue, aRv);
|
|
|
|
}
|
|
|
|
|
2018-02-23 21:28:08 +03:00
|
|
|
void GetEncoding(nsAString& aValue) { GetEnctype(aValue); }
|
2013-06-19 18:24:37 +04:00
|
|
|
void SetEncoding(const nsAString& aValue, ErrorResult& aRv) {
|
|
|
|
SetEnctype(aValue, aRv);
|
|
|
|
}
|
|
|
|
|
2018-02-23 21:28:08 +03:00
|
|
|
void GetMethod(nsAString& aValue);
|
2013-06-19 18:24:37 +04:00
|
|
|
void SetMethod(const nsAString& aValue, ErrorResult& aRv) {
|
|
|
|
SetHTMLAttr(nsGkAtoms::method, aValue, aRv);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GetName(DOMString& aValue) { GetHTMLAttr(nsGkAtoms::name, aValue); }
|
|
|
|
|
|
|
|
void SetName(const nsAString& aValue, ErrorResult& aRv) {
|
|
|
|
SetHTMLAttr(nsGkAtoms::name, aValue, aRv);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool NoValidate() const { return GetBoolAttr(nsGkAtoms::novalidate); }
|
|
|
|
|
|
|
|
void SetNoValidate(bool aValue, ErrorResult& aRv) {
|
|
|
|
SetHTMLBoolAttr(nsGkAtoms::novalidate, aValue, aRv);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GetTarget(DOMString& aValue) { GetHTMLAttr(nsGkAtoms::target, aValue); }
|
|
|
|
|
|
|
|
void SetTarget(const nsAString& aValue, ErrorResult& aRv) {
|
|
|
|
SetHTMLAttr(nsGkAtoms::target, aValue, aRv);
|
|
|
|
}
|
|
|
|
|
|
|
|
// it's only out-of-line because the class definition is not available in the
|
|
|
|
// header
|
|
|
|
nsIHTMLCollection* Elements();
|
|
|
|
|
|
|
|
int32_t Length();
|
|
|
|
|
2019-11-20 19:14:39 +03:00
|
|
|
/**
|
|
|
|
* Check whether submission can proceed for this form then fire submit event.
|
|
|
|
* This basically implements steps 1-6 (more or less) of
|
|
|
|
* <https://html.spec.whatwg.org/multipage/forms.html#concept-form-submit>.
|
|
|
|
* @param aSubmitter If not null, is the "submitter" from that algorithm.
|
|
|
|
* Therefore it must be a valid submit control.
|
|
|
|
*/
|
|
|
|
MOZ_CAN_RUN_SCRIPT void MaybeSubmit(Element* aSubmitter);
|
|
|
|
MOZ_CAN_RUN_SCRIPT void MaybeReset(Element* aSubmitter);
|
2013-06-19 18:24:37 +04:00
|
|
|
void Submit(ErrorResult& aRv);
|
2019-12-03 13:13:41 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
MOZ_CAN_RUN_SCRIPT void RequestSubmit(nsGenericHTMLElement* aSubmitter,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
2018-02-23 21:28:08 +03:00
|
|
|
void Reset();
|
2013-06-19 18:24:37 +04:00
|
|
|
|
|
|
|
bool CheckValidity() { return CheckFormValidity(nullptr); }
|
|
|
|
|
2016-04-15 11:13:00 +03:00
|
|
|
bool ReportValidity() { return CheckValidFormSubmission(); }
|
|
|
|
|
2013-06-19 18:24:37 +04:00
|
|
|
Element* IndexedGetter(uint32_t aIndex, bool& aFound);
|
|
|
|
|
|
|
|
already_AddRefed<nsISupports> NamedGetter(const nsAString& aName,
|
|
|
|
bool& aFound);
|
|
|
|
|
2016-05-10 05:25:40 +03:00
|
|
|
void GetSupportedNames(nsTArray<nsString>& aRetval);
|
2013-06-19 18:24:37 +04:00
|
|
|
|
2013-10-03 11:11:26 +04:00
|
|
|
static int32_t CompareFormControlPosition(Element* aElement1,
|
|
|
|
Element* aElement2,
|
|
|
|
const nsIContent* aForm);
|
|
|
|
#ifdef DEBUG
|
|
|
|
static void AssertDocumentOrder(
|
|
|
|
const nsTArray<nsGenericHTMLFormElement*>& aControls, nsIContent* aForm);
|
2017-07-28 18:38:26 +03:00
|
|
|
static void AssertDocumentOrder(
|
|
|
|
const nsTArray<RefPtr<nsGenericHTMLFormElement>>& aControls,
|
|
|
|
nsIContent* aForm);
|
2013-10-03 11:11:26 +04:00
|
|
|
#endif
|
|
|
|
|
2013-06-19 18:24:37 +04:00
|
|
|
js::ExpandoAndGeneration mExpandoAndGeneration;
|
|
|
|
|
2009-10-30 04:49:11 +03:00
|
|
|
protected:
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual JSObject* WrapNode(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) override;
|
2013-06-19 18:24:37 +04:00
|
|
|
|
2013-01-31 22:47:00 +04:00
|
|
|
void PostPasswordEvent();
|
|
|
|
|
2016-10-13 09:33:53 +03:00
|
|
|
RefPtr<AsyncEventDispatcher> mFormPasswordEventDispatcher;
|
2013-01-31 22:47:00 +04:00
|
|
|
|
2009-10-30 04:49:11 +03:00
|
|
|
class RemoveElementRunnable;
|
|
|
|
friend class RemoveElementRunnable;
|
|
|
|
|
2016-04-26 03:23:21 +03:00
|
|
|
class RemoveElementRunnable : public Runnable {
|
2009-10-30 04:49:11 +03:00
|
|
|
public:
|
2014-09-02 04:49:25 +04:00
|
|
|
explicit RemoveElementRunnable(HTMLFormElement* aForm)
|
2017-06-12 22:34:10 +03:00
|
|
|
: Runnable("dom::HTMLFormElement::RemoveElementRunnable"),
|
|
|
|
mForm(aForm) {}
|
2009-10-30 04:49:11 +03:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD Run() override {
|
2010-11-11 15:36:42 +03:00
|
|
|
mForm->HandleDefaultSubmitRemoval();
|
2009-10-30 04:49:11 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<HTMLFormElement> mForm;
|
2009-10-30 04:49:11 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
nsresult DoReset();
|
|
|
|
|
|
|
|
// Async callback to handle removal of our default submit
|
2010-11-11 15:36:42 +03:00
|
|
|
void HandleDefaultSubmitRemoval();
|
2009-10-30 04:49:11 +03:00
|
|
|
|
|
|
|
//
|
|
|
|
// Submit Helpers
|
|
|
|
//
|
|
|
|
//
|
|
|
|
/**
|
2013-06-19 18:24:37 +04:00
|
|
|
* Attempt to submit (submission might be deferred)
|
2009-10-30 04:49:11 +03:00
|
|
|
*
|
|
|
|
* @param aPresContext the presentation context
|
|
|
|
* @param aEvent the DOM event that was passed to us for the submit
|
|
|
|
*/
|
2020-02-11 15:46:54 +03:00
|
|
|
nsresult DoSubmit(Event* aEvent = nullptr);
|
2009-10-30 04:49:11 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Prepare the submission object (called by DoSubmit)
|
|
|
|
*
|
|
|
|
* @param aFormSubmission the submission object
|
|
|
|
* @param aEvent the DOM event that was passed to us for the submit
|
|
|
|
*/
|
2020-02-11 15:46:54 +03:00
|
|
|
nsresult BuildSubmission(HTMLFormSubmission** aFormSubmission, Event* aEvent);
|
2009-10-30 04:49:11 +03:00
|
|
|
/**
|
|
|
|
* Perform the submission (called by DoSubmit and FlushPendingSubmission)
|
|
|
|
*
|
|
|
|
* @param aFormSubmission the submission object
|
|
|
|
*/
|
2016-06-16 10:24:16 +03:00
|
|
|
nsresult SubmitSubmission(HTMLFormSubmission* aFormSubmission);
|
2009-10-30 04:49:11 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Notify any submit observers of the submit.
|
|
|
|
*
|
|
|
|
* @param aActionURL the URL being submitted to
|
|
|
|
* @param aCancelSubmit out param where submit observers can specify that the
|
|
|
|
* submit should be cancelled.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
nsresult NotifySubmitObservers(nsIURI* aActionURL, bool* aCancelSubmit,
|
|
|
|
bool aEarlyNotify);
|
2009-10-30 04:49:11 +03:00
|
|
|
|
2015-01-15 22:01:10 +03:00
|
|
|
/**
|
|
|
|
* If this form submission is secure -> insecure, ask the user if they want
|
|
|
|
* to continue.
|
|
|
|
*
|
|
|
|
* @param aActionURL the URL being submitted to
|
|
|
|
* @param aCancelSubmit out param: will be true if the user wants to cancel
|
|
|
|
*/
|
|
|
|
nsresult DoSecureToInsecureSubmitCheck(nsIURI* aActionURL,
|
|
|
|
bool* aCancelSubmit);
|
|
|
|
|
2009-10-30 04:49:11 +03:00
|
|
|
/**
|
2013-04-04 11:03:12 +04:00
|
|
|
* Find form controls in this form with the correct value in the name
|
|
|
|
* attribute.
|
2009-10-30 04:49:11 +03:00
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
already_AddRefed<nsISupports> DoResolveName(const nsAString& aName,
|
|
|
|
bool aFlushContent);
|
2009-10-30 04:49:11 +03:00
|
|
|
|
2010-08-21 22:51:38 +04:00
|
|
|
/**
|
|
|
|
* Check the form validity following this algorithm:
|
2019-11-20 19:14:37 +03:00
|
|
|
* https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#statically-validate-the-constraints
|
2010-08-21 22:51:38 +04:00
|
|
|
*
|
2010-09-11 08:07:41 +04:00
|
|
|
* @param aInvalidElements [out] parameter containing the list of unhandled
|
|
|
|
* invalid controls.
|
2010-08-21 22:51:38 +04:00
|
|
|
*
|
|
|
|
* @return Whether the form is currently valid.
|
|
|
|
*/
|
2018-08-16 22:20:54 +03:00
|
|
|
bool CheckFormValidity(nsTArray<RefPtr<Element>>* aInvalidElements) const;
|
2010-08-21 22:51:38 +04:00
|
|
|
|
2013-06-18 16:53:23 +04:00
|
|
|
// Clear the mImageNameLookupTable and mImageElements.
|
|
|
|
void Clear();
|
|
|
|
|
2013-06-18 16:54:27 +04:00
|
|
|
// Insert a element into the past names map.
|
|
|
|
void AddToPastNamesMap(const nsAString& aName, nsISupports* aChild);
|
|
|
|
|
2016-11-21 20:34:02 +03:00
|
|
|
// Remove the given element from the past names map. The element must be an
|
|
|
|
// nsGenericHTMLFormElement or HTMLImageElement.
|
|
|
|
void RemoveElementFromPastNamesMap(Element* aElement);
|
|
|
|
|
2013-06-19 18:24:37 +04:00
|
|
|
nsresult AddElementToTableInternal(
|
|
|
|
nsInterfaceHashtable<nsStringHashKey, nsISupports>& aTable,
|
|
|
|
nsIContent* aChild, const nsAString& aName);
|
|
|
|
|
|
|
|
nsresult RemoveElementFromTableInternal(
|
|
|
|
nsInterfaceHashtable<nsStringHashKey, nsISupports>& aTable,
|
|
|
|
nsIContent* aChild, const nsAString& aName);
|
|
|
|
|
2009-10-30 04:49:11 +03:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Flush a possible pending submission. If there was a scripted submission
|
|
|
|
* triggered by a button or image, the submission was defered. This method
|
|
|
|
* forces the pending submission to be submitted. (happens when the handler
|
|
|
|
* returns false or there is an action/target change in the script)
|
|
|
|
*/
|
|
|
|
void FlushPendingSubmission();
|
2018-07-22 12:11:27 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the full URL to submit to. Do not submit if the returned URL is null.
|
|
|
|
*
|
|
|
|
* @param aActionURL the full, unadulterated URL you'll be submitting to [OUT]
|
|
|
|
* @param aOriginatingElement the originating element of the form submission
|
|
|
|
* [IN]
|
|
|
|
*/
|
|
|
|
nsresult GetActionURL(nsIURI** aActionURL, Element* aOriginatingElement);
|
2009-10-30 04:49:11 +03:00
|
|
|
|
2019-07-01 13:06:16 +03:00
|
|
|
// Returns a number for this form that is unique within its owner document.
|
|
|
|
// This is used by nsContentUtils::GenerateStateKey to identify form controls
|
|
|
|
// that are inserted into the document by the parser.
|
|
|
|
int32_t GetFormNumberForStateKey();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when we have been cloned and adopted, and the information of the
|
|
|
|
* node has been changed.
|
|
|
|
*/
|
|
|
|
void NodeInfoChanged(Document* aOldDoc) override;
|
|
|
|
|
2009-10-30 04:49:11 +03:00
|
|
|
protected:
|
|
|
|
//
|
|
|
|
// Data members
|
|
|
|
//
|
|
|
|
/** The list of controls (form.elements as well as stuff not in elements) */
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<HTMLFormControlsCollection> mControls;
|
2009-10-30 04:49:11 +03:00
|
|
|
/** The currently selected radio button of each group */
|
2017-01-05 07:22:00 +03:00
|
|
|
nsRefPtrHashtable<nsStringHashKey, HTMLInputElement> mSelectedRadioButtons;
|
2011-02-25 21:12:47 +03:00
|
|
|
/** The number of required radio button of each group */
|
2012-08-22 19:56:38 +04:00
|
|
|
nsDataHashtable<nsStringCaseInsensitiveHashKey, uint32_t>
|
|
|
|
mRequiredRadioButtonCounts;
|
2011-02-25 21:16:04 +03:00
|
|
|
/** The value missing state of each group */
|
|
|
|
nsDataHashtable<nsStringCaseInsensitiveHashKey, bool>
|
|
|
|
mValueMissingRadioGroups;
|
2009-10-30 04:49:11 +03:00
|
|
|
|
|
|
|
/** The pending submission object */
|
2016-06-16 10:24:16 +03:00
|
|
|
nsAutoPtr<HTMLFormSubmission> mPendingSubmission;
|
2009-10-30 04:49:11 +03:00
|
|
|
/** The request currently being submitted */
|
|
|
|
nsCOMPtr<nsIRequest> mSubmittingRequest;
|
|
|
|
/** The web progress object we are currently listening to */
|
|
|
|
nsWeakPtr mWebProgress;
|
|
|
|
|
|
|
|
/** The default submit element -- WEAK */
|
|
|
|
nsGenericHTMLFormElement* mDefaultSubmitElement;
|
|
|
|
|
|
|
|
/** The first submit element in mElements -- WEAK */
|
|
|
|
nsGenericHTMLFormElement* mFirstSubmitInElements;
|
|
|
|
|
|
|
|
/** The first submit element in mNotInElements -- WEAK */
|
|
|
|
nsGenericHTMLFormElement* mFirstSubmitNotInElements;
|
|
|
|
|
2013-06-18 16:53:23 +04:00
|
|
|
// This array holds on to all HTMLImageElement(s).
|
|
|
|
// This is needed to properly clean up the bi-directional references
|
|
|
|
// (both weak and strong) between the form and its HTMLImageElements.
|
|
|
|
|
2016-11-21 20:34:02 +03:00
|
|
|
nsTArray<HTMLImageElement*> mImageElements; // Holds WEAK references
|
2013-06-18 16:53:23 +04:00
|
|
|
|
|
|
|
// A map from an ID or NAME attribute to the HTMLImageElement(s), this
|
|
|
|
// hash holds strong references either to the named HTMLImageElement, or
|
|
|
|
// to a list of named HTMLImageElement(s), in the case where this hash
|
|
|
|
// holds on to a list of named HTMLImageElement(s) the list has weak
|
|
|
|
// references to the HTMLImageElement.
|
|
|
|
|
|
|
|
nsInterfaceHashtable<nsStringHashKey, nsISupports> mImageNameLookupTable;
|
|
|
|
|
2013-06-18 16:54:27 +04:00
|
|
|
// A map from names to elements that were gotten by those names from this
|
|
|
|
// form in that past. See "past names map" in the HTML5 specification.
|
|
|
|
|
|
|
|
nsInterfaceHashtable<nsStringHashKey, nsISupports> mPastNameLookupTable;
|
|
|
|
|
2017-07-06 23:57:24 +03:00
|
|
|
/** Keep track of what the popup state was when the submit was initiated */
|
2018-12-16 12:21:16 +03:00
|
|
|
PopupBlocker::PopupControlState mSubmitPopupState;
|
2017-07-06 23:57:24 +03:00
|
|
|
|
2010-09-10 09:08:56 +04:00
|
|
|
/**
|
|
|
|
* Number of invalid and candidate for constraint validation elements in the
|
|
|
|
* form the last time UpdateValidity has been called.
|
|
|
|
* @note Should only be used by UpdateValidity() and GetValidity()!
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t mInvalidElementsCount;
|
2010-09-10 09:08:56 +04:00
|
|
|
|
2019-07-01 13:06:16 +03:00
|
|
|
// See GetFormNumberForStateKey.
|
|
|
|
int32_t mFormNumber;
|
|
|
|
|
2017-07-06 23:57:24 +03:00
|
|
|
/** Whether we are currently processing a submit event or not */
|
|
|
|
bool mGeneratingSubmit;
|
|
|
|
/** Whether we are currently processing a reset event or not */
|
|
|
|
bool mGeneratingReset;
|
|
|
|
/** Whether we are submitting currently */
|
|
|
|
bool mIsSubmitting;
|
|
|
|
/** Whether the submission is to be deferred in case a script triggers it */
|
|
|
|
bool mDeferSubmission;
|
|
|
|
/** Whether we notified NS_FORMSUBMIT_SUBJECT listeners already */
|
|
|
|
bool mNotifiedObservers;
|
|
|
|
/** If we notified the listeners early, what was the result? */
|
|
|
|
bool mNotifiedObserversResult;
|
2010-11-24 02:50:19 +03:00
|
|
|
/**
|
|
|
|
* Whether the submission of this form has been ever prevented because of
|
|
|
|
* being invalid.
|
|
|
|
*/
|
|
|
|
bool mEverTriedInvalidSubmit;
|
2019-09-09 16:53:27 +03:00
|
|
|
/** Whether we are constructing entry list */
|
|
|
|
bool mIsConstructingEntryList;
|
2019-11-20 22:39:38 +03:00
|
|
|
/** Whether we are firing submission event */
|
|
|
|
bool mIsFiringSubmissionEvents;
|
2010-11-24 02:50:19 +03:00
|
|
|
|
2014-08-01 21:02:30 +04:00
|
|
|
private:
|
2019-09-09 16:53:27 +03:00
|
|
|
NotNull<const Encoding*> GetSubmitEncoding();
|
2014-08-01 21:02:30 +04:00
|
|
|
~HTMLFormElement();
|
2009-10-30 04:49:11 +03:00
|
|
|
};
|
2010-09-10 09:08:56 +04:00
|
|
|
|
2013-06-19 18:24:37 +04:00
|
|
|
} // namespace dom
|
2014-07-09 01:23:16 +04:00
|
|
|
|
2013-06-19 18:24:37 +04:00
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_HTMLFormElement_h
|