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/. */
|
1998-09-23 21:16:51 +04:00
|
|
|
#ifndef nsIFormControl_h___
|
|
|
|
#define nsIFormControl_h___
|
|
|
|
|
2015-08-26 15:56:59 +03:00
|
|
|
#include "mozilla/EventForwards.h"
|
1998-09-23 21:16:51 +04:00
|
|
|
#include "nsISupports.h"
|
2015-08-26 15:56:59 +03:00
|
|
|
|
2010-05-09 22:32:57 +04:00
|
|
|
namespace mozilla {
|
2018-03-02 21:18:35 +03:00
|
|
|
class PresState;
|
2010-05-09 22:32:57 +04:00
|
|
|
namespace dom {
|
|
|
|
class Element;
|
2013-08-17 04:32:47 +04:00
|
|
|
class HTMLFieldSetElement;
|
2016-06-16 10:24:16 +03:00
|
|
|
class HTMLFormSubmission;
|
2018-03-14 23:42:25 +03:00
|
|
|
class HTMLFormElement;
|
2010-05-09 22:32:57 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2010-05-20 06:30:04 +04:00
|
|
|
enum FormControlsTypes {
|
|
|
|
NS_FORM_FIELDSET = 1,
|
|
|
|
NS_FORM_OUTPUT,
|
|
|
|
NS_FORM_SELECT,
|
|
|
|
NS_FORM_TEXTAREA,
|
|
|
|
NS_FORM_OBJECT,
|
|
|
|
eFormControlsWithoutSubTypesMax,
|
|
|
|
// After this, all types will have sub-types which introduce new enum lists.
|
|
|
|
// eFormControlsWithoutSubTypesMax let us know if the previous types values
|
|
|
|
// are not overlapping with sub-types/masks.
|
|
|
|
|
|
|
|
// Elements with different types, the value is used as a mask.
|
|
|
|
// When changing the order, adding or removing elements, be sure to update
|
2013-11-11 12:03:59 +04:00
|
|
|
// the static_assert checks accordingly.
|
2010-05-20 06:30:04 +04:00
|
|
|
NS_FORM_BUTTON_ELEMENT = 0x40, // 0b01000000
|
|
|
|
NS_FORM_INPUT_ELEMENT = 0x80 // 0b10000000
|
|
|
|
};
|
|
|
|
|
2016-09-07 05:20:17 +03:00
|
|
|
enum ButtonElementTypes : uint8_t {
|
2010-05-20 06:30:04 +04:00
|
|
|
NS_FORM_BUTTON_BUTTON = NS_FORM_BUTTON_ELEMENT + 1,
|
|
|
|
NS_FORM_BUTTON_RESET,
|
|
|
|
NS_FORM_BUTTON_SUBMIT,
|
|
|
|
eButtonElementTypesMax
|
|
|
|
};
|
|
|
|
|
2016-09-07 05:20:17 +03:00
|
|
|
enum InputElementTypes : uint8_t {
|
2010-05-20 06:30:04 +04:00
|
|
|
NS_FORM_INPUT_BUTTON = NS_FORM_INPUT_ELEMENT + 1,
|
|
|
|
NS_FORM_INPUT_CHECKBOX,
|
2013-05-23 17:02:23 +04:00
|
|
|
NS_FORM_INPUT_COLOR,
|
2012-12-27 20:06:53 +04:00
|
|
|
NS_FORM_INPUT_DATE,
|
2010-08-18 22:31:54 +04:00
|
|
|
NS_FORM_INPUT_EMAIL,
|
2010-05-20 06:30:04 +04:00
|
|
|
NS_FORM_INPUT_FILE,
|
|
|
|
NS_FORM_INPUT_HIDDEN,
|
|
|
|
NS_FORM_INPUT_RESET,
|
|
|
|
NS_FORM_INPUT_IMAGE,
|
2016-07-04 00:19:00 +03:00
|
|
|
NS_FORM_INPUT_MONTH,
|
2012-06-11 00:23:17 +04:00
|
|
|
NS_FORM_INPUT_NUMBER,
|
2010-05-20 06:30:04 +04:00
|
|
|
NS_FORM_INPUT_PASSWORD,
|
|
|
|
NS_FORM_INPUT_RADIO,
|
|
|
|
NS_FORM_INPUT_SEARCH,
|
|
|
|
NS_FORM_INPUT_SUBMIT,
|
|
|
|
NS_FORM_INPUT_TEL,
|
|
|
|
NS_FORM_INPUT_TEXT,
|
2013-01-08 21:10:00 +04:00
|
|
|
NS_FORM_INPUT_TIME,
|
2010-08-18 22:33:37 +04:00
|
|
|
NS_FORM_INPUT_URL,
|
2013-02-16 16:35:57 +04:00
|
|
|
NS_FORM_INPUT_RANGE,
|
2016-08-16 06:15:00 +03:00
|
|
|
NS_FORM_INPUT_WEEK,
|
2016-10-24 04:35:00 +03:00
|
|
|
NS_FORM_INPUT_DATETIME_LOCAL,
|
2010-05-20 06:30:04 +04:00
|
|
|
eInputElementTypesMax
|
|
|
|
};
|
|
|
|
|
2013-11-11 12:03:59 +04:00
|
|
|
static_assert(static_cast<uint32_t>(eFormControlsWithoutSubTypesMax) <
|
|
|
|
static_cast<uint32_t>(NS_FORM_BUTTON_ELEMENT),
|
|
|
|
"Too many FormControlsTypes without sub-types");
|
|
|
|
static_assert(static_cast<uint32_t>(eButtonElementTypesMax) <
|
|
|
|
static_cast<uint32_t>(NS_FORM_INPUT_ELEMENT),
|
|
|
|
"Too many ButtonElementTypes");
|
|
|
|
static_assert(static_cast<uint32_t>(eInputElementTypesMax) < 1 << 8,
|
|
|
|
"Too many form control types");
|
1998-09-23 21:16:51 +04:00
|
|
|
|
|
|
|
#define NS_IFORMCONTROL_IID \
|
2018-11-30 13:46:48 +03:00
|
|
|
{ \
|
2013-01-03 19:17:36 +04:00
|
|
|
0x4b89980c, 0x4dcd, 0x428f, { \
|
|
|
|
0xb7, 0xad, 0x43, 0x5b, 0x93, 0x29, 0x79, 0xec \
|
|
|
|
} \
|
|
|
|
}
|
1998-09-23 21:16:51 +04:00
|
|
|
|
|
|
|
/**
|
2001-11-02 10:40:01 +03:00
|
|
|
* Interface which all form controls (e.g. buttons, checkboxes, text,
|
|
|
|
* radio buttons, select, etc) implement in addition to their dom specific
|
|
|
|
* interface.
|
|
|
|
*/
|
|
|
|
class nsIFormControl : public nsISupports {
|
1998-09-23 21:16:51 +04:00
|
|
|
public:
|
2017-04-01 05:49:00 +03:00
|
|
|
nsIFormControl(uint8_t aType) : mType(aType) {}
|
1999-05-20 10:39:37 +04:00
|
|
|
|
2005-11-11 17:36:26 +03:00
|
|
|
NS_DECLARE_STATIC_IID_ACCESSOR(NS_IFORMCONTROL_IID)
|
1999-05-20 10:39:37 +04:00
|
|
|
|
2013-08-17 04:32:47 +04:00
|
|
|
/**
|
|
|
|
* Get the fieldset for this form control.
|
|
|
|
* @return the fieldset
|
|
|
|
*/
|
|
|
|
virtual mozilla::dom::HTMLFieldSetElement* GetFieldSet() = 0;
|
|
|
|
|
1998-09-23 21:16:51 +04:00
|
|
|
/**
|
2001-11-02 10:40:01 +03:00
|
|
|
* Get the form for this form control.
|
2010-05-09 22:32:57 +04:00
|
|
|
* @return the form
|
2001-11-02 10:40:01 +03:00
|
|
|
*/
|
2019-07-01 13:06:16 +03:00
|
|
|
virtual mozilla::dom::HTMLFormElement* GetFormElement() = 0;
|
1998-09-23 21:16:51 +04:00
|
|
|
|
|
|
|
/**
|
2001-11-02 10:40:01 +03:00
|
|
|
* Set the form for this form control.
|
2008-09-11 07:21:33 +04:00
|
|
|
* @param aForm the form. This must not be null.
|
|
|
|
*
|
|
|
|
* @note that when setting the form the control is not added to the
|
|
|
|
* form. It adds itself when it gets bound to the tree thereafter,
|
|
|
|
* so that it can be properly sorted with the other controls in the
|
|
|
|
* form.
|
|
|
|
*/
|
2018-03-14 23:42:25 +03:00
|
|
|
virtual void SetForm(mozilla::dom::HTMLFormElement* aForm) = 0;
|
2008-09-11 07:21:33 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Tell the control to forget about its form.
|
2008-09-08 17:19:49 +04:00
|
|
|
*
|
2002-02-16 04:19:24 +03:00
|
|
|
* @param aRemoveFromForm set false if you do not want this element removed
|
2002-05-09 04:29:23 +04:00
|
|
|
* from the form. (Used by nsFormControlList::Clear())
|
2017-05-02 00:10:00 +03:00
|
|
|
* @param aUnbindOrDelete set true if the element is being deleted or unbound
|
|
|
|
* from tree.
|
2001-11-02 10:40:01 +03:00
|
|
|
*/
|
2017-05-02 00:10:00 +03:00
|
|
|
virtual void ClearForm(bool aRemoveFromForm, bool aUnbindOrDelete) = 0;
|
1998-09-23 21:16:51 +04:00
|
|
|
|
|
|
|
/**
|
2002-07-24 23:40:03 +04:00
|
|
|
* Get the type of this control as an int (see NS_FORM_* above)
|
2002-12-19 02:38:09 +03:00
|
|
|
* @return the type of this control
|
2001-11-02 10:40:01 +03:00
|
|
|
*/
|
2017-04-01 05:49:00 +03:00
|
|
|
uint32_t ControlType() const { return mType; }
|
1998-09-23 21:16:51 +04:00
|
|
|
|
2002-02-16 04:19:24 +03:00
|
|
|
/**
|
2002-07-24 23:40:03 +04:00
|
|
|
* Reset this form control (as it should be when the user clicks the Reset
|
|
|
|
* button)
|
2002-02-16 04:19:24 +03:00
|
|
|
*/
|
2001-11-02 10:40:01 +03:00
|
|
|
NS_IMETHOD Reset() = 0;
|
1998-09-23 21:16:51 +04:00
|
|
|
|
2002-02-16 04:19:24 +03:00
|
|
|
/**
|
|
|
|
* Tells the form control to submit its names and values to the form
|
|
|
|
* submission object
|
|
|
|
* @param aFormSubmission the form submission to notify of names/values/files
|
|
|
|
* to submit
|
|
|
|
*/
|
2016-06-16 10:24:16 +03:00
|
|
|
NS_IMETHOD
|
|
|
|
SubmitNamesValues(mozilla::dom::HTMLFormSubmission* aFormSubmission) = 0;
|
2001-11-02 10:40:01 +03:00
|
|
|
|
|
|
|
/**
|
2002-07-24 23:40:03 +04:00
|
|
|
* Save to presentation state. The form control will determine whether it
|
|
|
|
* has anything to save and if so, create an entry in the layout history for
|
|
|
|
* its pres context.
|
2001-11-02 10:40:01 +03:00
|
|
|
*/
|
2002-03-31 14:14:01 +04:00
|
|
|
NS_IMETHOD SaveState() = 0;
|
2001-11-02 10:40:01 +03:00
|
|
|
|
|
|
|
/**
|
2002-07-24 23:40:03 +04:00
|
|
|
* Restore from presentation state. You pass in the presentation state for
|
|
|
|
* this form control (generated with GenerateStateKey() + "-C") and the form
|
|
|
|
* control will grab its state from there.
|
|
|
|
*
|
2002-03-31 14:14:01 +04:00
|
|
|
* @param aState the pres state to use to restore the control
|
2011-10-17 18:59:28 +04:00
|
|
|
* @return true if the form control was a checkbox and its
|
|
|
|
* checked state was restored, false otherwise.
|
2001-11-02 10:40:01 +03:00
|
|
|
*/
|
2018-03-02 21:18:35 +03:00
|
|
|
virtual bool RestoreState(mozilla::PresState* aState) = 0;
|
2004-02-12 00:31:53 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
virtual bool AllowDrop() = 0;
|
2006-08-16 07:20:19 +04:00
|
|
|
|
|
|
|
/**
|
2011-03-24 19:06:58 +03:00
|
|
|
* Returns whether this is a control which submits the form when activated by
|
|
|
|
* the user.
|
|
|
|
* @return whether this is a submit control.
|
2006-08-16 07:20:19 +04:00
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
inline bool IsSubmitControl() const;
|
2010-05-12 11:17:07 +04:00
|
|
|
|
|
|
|
/**
|
2011-03-24 19:06:58 +03:00
|
|
|
* Returns whether this is a text control.
|
2010-05-12 11:17:07 +04:00
|
|
|
* @param aExcludePassword to have NS_FORM_INPUT_PASSWORD returning false.
|
2011-03-24 19:06:58 +03:00
|
|
|
* @return whether this is a text control.
|
2010-05-12 11:17:07 +04:00
|
|
|
*/
|
2016-03-03 01:39:34 +03:00
|
|
|
inline bool IsTextControl(bool aExcludePassword) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if this is a text control or a number control.
|
|
|
|
* @param aExcludePassword to have NS_FORM_INPUT_PASSWORD returning false.
|
|
|
|
* @return true if this is a text control or a number control.
|
|
|
|
*/
|
|
|
|
inline bool IsTextOrNumberControl(bool aExcludePassword) const;
|
2010-05-12 11:17:07 +04:00
|
|
|
|
|
|
|
/**
|
2011-03-24 19:06:58 +03:00
|
|
|
* Returns whether this is a single line text control.
|
2010-05-12 11:17:07 +04:00
|
|
|
* @param aExcludePassword to have NS_FORM_INPUT_PASSWORD returning false.
|
2011-03-24 19:06:58 +03:00
|
|
|
* @return whether this is a single line text control.
|
2010-05-12 11:17:07 +04:00
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
inline bool IsSingleLineTextControl(bool aExcludePassword) const;
|
2010-05-20 06:28:10 +04:00
|
|
|
|
2017-10-01 16:57:16 +03:00
|
|
|
/**
|
|
|
|
* Returns true if this is a single line text control or a number control.
|
|
|
|
* @param aExcludePassword to have NS_FORM_INPUT_PASSWORD returning false.
|
|
|
|
* @return true if this is a single line text control or a number control.
|
|
|
|
*/
|
|
|
|
inline bool IsSingleLineTextOrNumberControl(bool aExcludePassword) const;
|
|
|
|
|
2010-08-21 22:51:38 +04:00
|
|
|
/**
|
2011-03-24 19:06:58 +03:00
|
|
|
* Returns whether this is a submittable form control.
|
|
|
|
* @return whether this is a submittable form control.
|
2010-08-21 22:51:38 +04:00
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
inline bool IsSubmittableControl() const;
|
2011-03-24 19:06:58 +03:00
|
|
|
|
2011-03-24 17:55:32 +03:00
|
|
|
/**
|
|
|
|
* Returns whether this form control can have draggable children.
|
|
|
|
* @return whether this form control can have draggable children.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
inline bool AllowDraggableChildren() const;
|
2011-03-24 17:55:32 +03:00
|
|
|
|
2018-10-31 11:55:33 +03:00
|
|
|
virtual bool IsDisabledForEvents(mozilla::WidgetEvent* aEvent) {
|
2013-01-03 19:17:36 +04:00
|
|
|
return false;
|
|
|
|
}
|
2011-03-24 19:06:58 +03:00
|
|
|
|
2019-07-01 13:06:16 +03:00
|
|
|
// Returns a number for this form control 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. -1 is returned for form controls with no state or
|
|
|
|
// which were inserted into the document by some other means than
|
|
|
|
// the parser from the network.
|
|
|
|
virtual int32_t GetParserInsertedControlNumberForStateKey() const {
|
|
|
|
return -1;
|
|
|
|
};
|
|
|
|
|
2011-03-24 19:06:58 +03:00
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* Returns whether mType corresponds to a single line text control type.
|
|
|
|
* @param aExcludePassword to have NS_FORM_INPUT_PASSWORD ignored.
|
|
|
|
* @param aType the type to be tested.
|
|
|
|
* @return whether mType corresponds to a single line text control type.
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
inline static bool IsSingleLineTextControl(bool aExcludePassword,
|
|
|
|
uint32_t aType);
|
2011-03-24 18:10:42 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns whether this is a auto-focusable form control.
|
|
|
|
* @return whether this is a auto-focusable form control.
|
|
|
|
*/
|
|
|
|
inline bool IsAutofocusable() const;
|
2017-04-01 05:49:00 +03:00
|
|
|
|
|
|
|
uint8_t mType;
|
1998-09-23 21:16:51 +04:00
|
|
|
};
|
|
|
|
|
2011-03-24 19:06:58 +03:00
|
|
|
bool nsIFormControl::IsSubmitControl() const {
|
2017-04-01 05:49:00 +03:00
|
|
|
uint32_t type = ControlType();
|
2011-03-24 19:06:58 +03:00
|
|
|
return type == NS_FORM_INPUT_SUBMIT || type == NS_FORM_INPUT_IMAGE ||
|
|
|
|
type == NS_FORM_BUTTON_SUBMIT;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool nsIFormControl::IsTextControl(bool aExcludePassword) const {
|
2017-04-01 05:49:00 +03:00
|
|
|
uint32_t type = ControlType();
|
2011-03-24 19:06:58 +03:00
|
|
|
return type == NS_FORM_TEXTAREA ||
|
|
|
|
IsSingleLineTextControl(aExcludePassword, type);
|
|
|
|
}
|
|
|
|
|
2016-03-03 01:39:34 +03:00
|
|
|
bool nsIFormControl::IsTextOrNumberControl(bool aExcludePassword) const {
|
2017-04-01 05:49:00 +03:00
|
|
|
return IsTextControl(aExcludePassword) ||
|
|
|
|
ControlType() == NS_FORM_INPUT_NUMBER;
|
2016-03-03 01:39:34 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool nsIFormControl::IsSingleLineTextControl(bool aExcludePassword) const {
|
2017-04-01 05:49:00 +03:00
|
|
|
return IsSingleLineTextControl(aExcludePassword, ControlType());
|
2011-03-24 19:06:58 +03:00
|
|
|
}
|
|
|
|
|
2017-10-01 16:57:16 +03:00
|
|
|
bool nsIFormControl::IsSingleLineTextOrNumberControl(
|
|
|
|
bool aExcludePassword) const {
|
|
|
|
return IsSingleLineTextControl(aExcludePassword) ||
|
|
|
|
ControlType() == NS_FORM_INPUT_NUMBER;
|
|
|
|
}
|
|
|
|
|
2011-03-24 19:06:58 +03:00
|
|
|
/*static*/
|
2012-08-22 19:56:38 +04:00
|
|
|
bool nsIFormControl::IsSingleLineTextControl(bool aExcludePassword,
|
|
|
|
uint32_t aType) {
|
2011-03-24 19:06:58 +03:00
|
|
|
return aType == NS_FORM_INPUT_TEXT || aType == NS_FORM_INPUT_EMAIL ||
|
|
|
|
aType == NS_FORM_INPUT_SEARCH || aType == NS_FORM_INPUT_TEL ||
|
|
|
|
aType == NS_FORM_INPUT_URL ||
|
2013-01-08 21:10:00 +04:00
|
|
|
// TODO: those are temporary until bug 773205 is fixed.
|
2016-07-04 00:19:00 +03:00
|
|
|
aType == NS_FORM_INPUT_MONTH || aType == NS_FORM_INPUT_WEEK ||
|
2016-10-24 04:35:00 +03:00
|
|
|
aType == NS_FORM_INPUT_DATETIME_LOCAL ||
|
2011-03-24 19:06:58 +03:00
|
|
|
(!aExcludePassword && aType == NS_FORM_INPUT_PASSWORD);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool nsIFormControl::IsSubmittableControl() const {
|
2017-04-01 05:49:00 +03:00
|
|
|
uint32_t type = ControlType();
|
2011-03-24 19:06:58 +03:00
|
|
|
return type == NS_FORM_OBJECT || type == NS_FORM_TEXTAREA ||
|
2019-07-06 11:18:28 +03:00
|
|
|
type == NS_FORM_SELECT || type & NS_FORM_BUTTON_ELEMENT ||
|
|
|
|
type & NS_FORM_INPUT_ELEMENT;
|
2011-03-24 19:06:58 +03:00
|
|
|
}
|
|
|
|
|
2011-03-24 17:55:32 +03:00
|
|
|
bool nsIFormControl::AllowDraggableChildren() const {
|
2017-04-01 05:49:00 +03:00
|
|
|
uint32_t type = ControlType();
|
2011-03-24 17:55:32 +03:00
|
|
|
return type == NS_FORM_OBJECT || type == NS_FORM_FIELDSET ||
|
|
|
|
type == NS_FORM_OUTPUT;
|
|
|
|
}
|
|
|
|
|
2011-03-24 18:10:42 +03:00
|
|
|
bool nsIFormControl::IsAutofocusable() const {
|
2017-04-01 05:49:00 +03:00
|
|
|
uint32_t type = ControlType();
|
2011-03-24 18:10:42 +03:00
|
|
|
return type & NS_FORM_INPUT_ELEMENT || type & NS_FORM_BUTTON_ELEMENT ||
|
|
|
|
type == NS_FORM_TEXTAREA || type == NS_FORM_SELECT;
|
|
|
|
}
|
|
|
|
|
2005-11-11 17:36:26 +03:00
|
|
|
NS_DEFINE_STATIC_IID_ACCESSOR(nsIFormControl, NS_IFORMCONTROL_IID)
|
|
|
|
|
1998-09-23 21:16:51 +04:00
|
|
|
#endif /* nsIFormControl_h___ */
|