1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_HTMLInputElement_h
8 #define mozilla_dom_HTMLInputElement_h
10 #include "mozilla/Attributes.h"
11 #include "nsGenericHTMLElement.h"
12 #include "nsImageLoadingContent.h"
13 #include "nsITextControlElement.h"
16 #include "nsIConstraintValidation.h"
17 #include "mozilla/UniquePtr.h"
18 #include "mozilla/dom/BindingDeclarations.h"
19 #include "mozilla/dom/HTMLFormElement.h" // for HasEverTriedInvalidSubmit()
20 #include "mozilla/dom/HTMLInputElementBinding.h"
21 #include "mozilla/dom/Promise.h"
22 #include "mozilla/dom/UnionTypes.h"
23 #include "nsIFilePicker.h"
24 #include "nsIContentPrefService2.h"
25 #include "mozilla/Decimal.h"
26 #include "nsContentUtils.h"
27 #include "nsTextEditorState.h"
28 #include "mozilla/Variant.h"
29 #include "SingleLineTextInputTypes.h"
30 #include "NumericInputTypes.h"
31 #include "CheckableInputTypes.h"
32 #include "ButtonInputTypes.h"
33 #include "DateTimeInputTypes.h"
34 #include "ColorInputType.h"
35 #include "FileInputType.h"
36 #include "HiddenInputType.h"
38 static constexpr size_t INPUT_TYPE_SIZE
= sizeof(
39 mozilla::Variant
<TextInputType
, SearchInputType
, TelInputType
, URLInputType
,
40 EmailInputType
, PasswordInputType
, NumberInputType
,
41 RangeInputType
, RadioInputType
, CheckboxInputType
,
42 ButtonInputType
, ImageInputType
, ResetInputType
,
43 SubmitInputType
, DateInputType
, TimeInputType
,
44 WeekInputType
, MonthInputType
, DateTimeLocalInputType
,
45 FileInputType
, ColorInputType
, HiddenInputType
>);
49 class nsIRadioGroupContainer
;
50 class nsIRadioVisitor
;
54 class EventChainPostVisitor
;
55 class EventChainPreVisitor
;
59 class AfterSetFilesOrDirectoriesRunnable
;
61 class DispatchChangeEventCallback
;
64 class FileSystemEntry
;
68 * A class we use to create a singleton object that is used to keep track of
69 * the last directory from which the user has picked files (via
70 * <input type=file>) on a per-domain basis. The implementation uses
71 * nsIContentPrefService2/NS_CONTENT_PREF_SERVICE_CONTRACTID to store the last
72 * directory per-domain, and to ensure that whether the directories are
73 * persistently saved (saved across sessions) or not honors whether or not the
74 * page is being viewed in private browsing.
76 class UploadLastDir final
: public nsIObserver
, public nsSupportsWeakReference
{
84 * Fetch the last used directory for this location from the content
85 * pref service, and display the file picker opened in that directory.
87 * @param aDoc current document
88 * @param aFilePicker the file picker to open
89 * @param aFpCallback the callback object to be run when the file is shown.
91 nsresult
FetchDirectoryAndDisplayPicker(
92 Document
* aDoc
, nsIFilePicker
* aFilePicker
,
93 nsIFilePickerShownCallback
* aFpCallback
);
96 * Store the last used directory for this location using the
97 * content pref service, if it is available
98 * @param aURI URI of the current page
99 * @param aDir Parent directory of the file(s)/directory chosen by the user
101 nsresult
StoreLastUsedDirectory(Document
* aDoc
, nsIFile
* aDir
);
103 class ContentPrefCallback final
: public nsIContentPrefCallback2
{
104 virtual ~ContentPrefCallback() {}
107 ContentPrefCallback(nsIFilePicker
* aFilePicker
,
108 nsIFilePickerShownCallback
* aFpCallback
)
109 : mFilePicker(aFilePicker
), mFpCallback(aFpCallback
) {}
112 NS_DECL_NSICONTENTPREFCALLBACK2
114 nsCOMPtr
<nsIFilePicker
> mFilePicker
;
115 nsCOMPtr
<nsIFilePickerShownCallback
> mFpCallback
;
116 nsCOMPtr
<nsIContentPref
> mResult
;
120 class HTMLInputElement final
: public nsGenericHTMLFormElementWithState
,
121 public nsImageLoadingContent
,
122 public nsITextControlElement
,
123 public nsIConstraintValidation
{
124 friend class AfterSetFilesOrDirectoriesCallback
;
125 friend class DispatchChangeEventCallback
;
126 friend class ::InputType
;
129 using nsGenericHTMLFormElementWithState::GetForm
;
130 using nsGenericHTMLFormElementWithState::GetFormAction
;
131 using nsIConstraintValidation::GetValidationMessage
;
133 enum class FromClone
{ no
, yes
};
135 HTMLInputElement(already_AddRefed
<mozilla::dom::NodeInfo
>&& aNodeInfo
,
136 mozilla::dom::FromParser aFromParser
,
137 FromClone aFromClone
= FromClone::no
);
139 NS_IMPL_FROMNODE_HTML_WITH_TAG(HTMLInputElement
, input
)
142 NS_DECL_ISUPPORTS_INHERITED
144 virtual int32_t TabIndexDefault() override
;
145 using nsGenericHTMLElement::Focus
;
146 virtual void Blur(ErrorResult
& aError
) override
;
147 virtual void Focus(const FocusOptions
& aOptions
,
148 ErrorResult
& aError
) override
;
151 #if !defined(ANDROID) && !defined(XP_MACOSX)
152 virtual bool IsNodeApzAwareInternal() const override
;
156 virtual bool IsInteractiveHTMLContent(bool aIgnoreTabindex
) const override
;
159 virtual void AsyncEventRunning(AsyncEventDispatcher
* aEvent
) override
;
161 // Overriden nsIFormControl methods
162 MOZ_CAN_RUN_SCRIPT_BOUNDARY
163 NS_IMETHOD
Reset() override
;
164 NS_IMETHOD
SubmitNamesValues(HTMLFormSubmission
* aFormSubmission
) override
;
165 NS_IMETHOD
SaveState() override
;
166 MOZ_CAN_RUN_SCRIPT_BOUNDARY
167 virtual bool RestoreState(PresState
* aState
) override
;
168 virtual bool AllowDrop() override
;
169 virtual bool IsDisabledForEvents(WidgetEvent
* aEvent
) override
;
171 virtual void FieldSetDisabledChanged(bool aNotify
) override
;
174 virtual bool IsHTMLFocusable(bool aWithMouse
, bool* aIsFocusable
,
175 int32_t* aTabIndex
) override
;
177 virtual bool ParseAttribute(int32_t aNamespaceID
, nsAtom
* aAttribute
,
178 const nsAString
& aValue
,
179 nsIPrincipal
* aMaybeScriptedPrincipal
,
180 nsAttrValue
& aResult
) override
;
181 virtual nsChangeHint
GetAttributeChangeHint(const nsAtom
* aAttribute
,
182 int32_t aModType
) const override
;
183 NS_IMETHOD_(bool) IsAttributeMapped(const nsAtom
* aAttribute
) const override
;
184 virtual nsMapRuleToAttributesFunc
GetAttributeMappingFunction()
187 void GetEventTargetParent(EventChainPreVisitor
& aVisitor
) override
;
188 MOZ_CAN_RUN_SCRIPT_BOUNDARY
189 virtual nsresult
PreHandleEvent(EventChainVisitor
& aVisitor
) override
;
190 MOZ_CAN_RUN_SCRIPT_BOUNDARY
191 virtual nsresult
PostHandleEvent(EventChainPostVisitor
& aVisitor
) override
;
192 MOZ_CAN_RUN_SCRIPT_BOUNDARY
193 void PostHandleEventForRangeThumb(EventChainPostVisitor
& aVisitor
);
195 void StartRangeThumbDrag(WidgetGUIEvent
* aEvent
);
197 void FinishRangeThumbDrag(WidgetGUIEvent
* aEvent
= nullptr);
199 void CancelRangeThumbDrag(bool aIsForUserEvent
= true);
201 void SetValueOfRangeForUserEvent(Decimal aValue
);
203 virtual nsresult
BindToTree(BindContext
&, nsINode
& aParent
) override
;
204 virtual void UnbindFromTree(bool aNullParent
= true) override
;
206 MOZ_CAN_RUN_SCRIPT_BOUNDARY
207 virtual void DoneCreatingElement() override
;
209 virtual EventStates
IntrinsicState() const override
;
213 virtual void AddStates(EventStates aStates
) override
;
214 virtual void RemoveStates(EventStates aStates
) override
;
217 // nsITextControlElement
218 NS_IMETHOD
SetValueChanged(bool aValueChanged
) override
;
219 NS_IMETHOD_(bool) IsSingleLineTextControl() const override
;
220 NS_IMETHOD_(bool) IsTextArea() const override
;
221 NS_IMETHOD_(bool) IsPasswordTextControl() const override
;
222 NS_IMETHOD_(int32_t) GetCols() override
;
223 NS_IMETHOD_(int32_t) GetWrapCols() override
;
224 NS_IMETHOD_(int32_t) GetRows() override
;
225 NS_IMETHOD_(void) GetDefaultValueFromContent(nsAString
& aValue
) override
;
226 NS_IMETHOD_(bool) ValueChanged() const override
;
228 GetTextEditorValue(nsAString
& aValue
, bool aIgnoreWrap
) const override
;
229 NS_IMETHOD_(mozilla::TextEditor
*) GetTextEditor() override
;
230 NS_IMETHOD_(mozilla::TextEditor
*) GetTextEditorWithoutCreation() override
;
231 NS_IMETHOD_(nsISelectionController
*) GetSelectionController() override
;
232 NS_IMETHOD_(nsFrameSelection
*) GetConstFrameSelection() override
;
233 NS_IMETHOD
BindToFrame(nsTextControlFrame
* aFrame
) override
;
234 MOZ_CAN_RUN_SCRIPT_BOUNDARY
235 NS_IMETHOD_(void) UnbindFromFrame(nsTextControlFrame
* aFrame
) override
;
236 MOZ_CAN_RUN_SCRIPT_BOUNDARY
237 NS_IMETHOD
CreateEditor() override
;
238 NS_IMETHOD_(void) UpdateOverlayTextVisibility(bool aNotify
) override
;
239 NS_IMETHOD_(void) SetPreviewValue(const nsAString
& aValue
) override
;
240 NS_IMETHOD_(void) GetPreviewValue(nsAString
& aValue
) override
;
241 NS_IMETHOD_(void) EnablePreview() override
;
242 NS_IMETHOD_(bool) IsPreviewEnabled() override
;
243 NS_IMETHOD_(bool) GetPlaceholderVisibility() override
;
244 NS_IMETHOD_(bool) GetPreviewVisibility() override
;
245 NS_IMETHOD_(void) InitializeKeyboardEventListeners() override
;
246 NS_IMETHOD_(void) OnValueChanged(bool aNotify
, ValueChangeKind
) override
;
247 virtual void GetValueFromSetRangeText(nsAString
& aValue
) override
;
248 MOZ_CAN_RUN_SCRIPT_BOUNDARY
249 virtual nsresult
SetValueFromSetRangeText(const nsAString
& aValue
) override
;
250 NS_IMETHOD_(bool) HasCachedSelection() override
;
252 // Methods for nsFormFillController so it can do selection operations on input
253 // types the HTML spec doesn't support them on, like "email".
254 uint32_t GetSelectionStartIgnoringType(ErrorResult
& aRv
);
255 uint32_t GetSelectionEndIgnoringType(ErrorResult
& aRv
);
257 void GetDisplayFileName(nsAString
& aFileName
) const;
259 const nsTArray
<OwningFileOrDirectory
>& GetFilesOrDirectoriesInternal() const;
261 void SetFilesOrDirectories(
262 const nsTArray
<OwningFileOrDirectory
>& aFilesOrDirectories
,
263 bool aSetValueChanged
);
264 void SetFiles(FileList
* aFiles
, bool aSetValueChanged
);
266 // This method is used for test only. Onces the data is set, a 'change' event
268 void MozSetDndFilesAndDirectories(
269 const nsTArray
<OwningFileOrDirectory
>& aSequence
);
271 // Called when a nsIFilePicker or a nsIColorPicker terminate.
274 void SetCheckedChangedInternal(bool aCheckedChanged
);
275 bool GetCheckedChanged() const { return mCheckedChanged
; }
276 void AddedToRadioGroup();
277 void WillRemoveFromRadioGroup();
280 * Helper function returning the currently selected button in the radio group.
281 * Returning null if the element is not a button or if there is no selectied
282 * button in the group.
284 * @return the selected button (or null).
286 HTMLInputElement
* GetSelectedRadioButton() const;
288 MOZ_CAN_RUN_SCRIPT_BOUNDARY
289 virtual nsresult
Clone(dom::NodeInfo
*, nsINode
** aResult
) const override
;
291 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLInputElement
,
292 nsGenericHTMLFormElementWithState
)
294 static UploadLastDir
* gUploadLastDir
;
295 // create and destroy the static UploadLastDir object for remembering
296 // which directory was last used on a site-by-site basis
297 static void InitUploadLastDir();
298 static void DestroyUploadLastDir();
300 // If the valueAsDate attribute should be enabled in webIDL
301 static bool ValueAsDateEnabled(JSContext
* cx
, JSObject
* obj
);
303 void MaybeLoadImage();
305 void SetSelectionCached() {
306 MOZ_ASSERT(mType
== NS_FORM_INPUT_NUMBER
);
307 mSelectionCached
= true;
309 bool IsSelectionCached() const {
310 MOZ_ASSERT(mType
== NS_FORM_INPUT_NUMBER
);
311 return mSelectionCached
;
313 void ClearSelectionCached() {
314 MOZ_ASSERT(mType
== NS_FORM_INPUT_NUMBER
);
315 mSelectionCached
= false;
317 nsTextEditorState::SelectionProperties
& GetSelectionProperties() {
318 MOZ_ASSERT(mType
== NS_FORM_INPUT_NUMBER
);
319 return mSelectionProperties
;
322 bool HasPatternAttribute() const { return mHasPatternAttribute
; }
324 // nsIConstraintValidation
327 bool IsValueMissing() const;
328 bool HasTypeMismatch() const;
329 bool HasPatternMismatch() const;
330 bool IsRangeOverflow() const;
331 bool IsRangeUnderflow() const;
332 bool HasStepMismatch(bool aUseZeroIfValueNaN
= false) const;
333 bool HasBadInput() const;
334 void UpdateTooLongValidityState();
335 void UpdateTooShortValidityState();
336 void UpdateValueMissingValidityState();
337 void UpdateTypeMismatchValidityState();
338 void UpdatePatternMismatchValidityState();
339 void UpdateRangeOverflowValidityState();
340 void UpdateRangeUnderflowValidityState();
341 void UpdateStepMismatchValidityState();
342 void UpdateBadInputValidityState();
343 // Update all our validity states and then update our element state
344 // as needed. aNotify controls whether the element state update
346 void UpdateAllValidityStates(bool aNotify
);
348 void MaybeUpdateAllValidityStates(bool aNotify
) {
349 // If you need to add new type which supports validationMessage, you should
350 // add test cases into test_MozEditableElement_setUserInput.html.
351 if (mType
== NS_FORM_INPUT_EMAIL
) {
352 UpdateAllValidityStates(aNotify
);
356 // Update all our validity states without updating element state.
357 // This should be called instead of UpdateAllValidityStates any time
358 // we're guaranteed that element state will be updated anyway.
359 void UpdateAllValidityStatesButNotElementState();
360 void UpdateBarredFromConstraintValidation();
361 nsresult
GetValidationMessage(nsAString
& aValidationMessage
,
362 ValidityStateType aType
) override
;
364 // Override SetCustomValidity so we update our state properly when it's called
366 void SetCustomValidity(const nsAString
& aError
);
369 * Update the value missing validity state for radio elements when they have
372 * @param aIgnoreSelf Whether the required attribute and the checked state
373 * of the current radio should be ignored.
374 * @note This method shouldn't be called if the radio element hasn't a group.
376 void UpdateValueMissingValidityStateForRadio(bool aIgnoreSelf
);
379 * Set filters to the filePicker according to the accept attribute value.
382 * http://dev.w3.org/html5/spec/forms.html#attr-input-accept
384 * @note You should not call this function if the element has no @accept.
385 * @note "All Files" filter is always set, no matter if there is a valid
386 * filter specified or not.
387 * @note If more than one valid filter is found, the "All Supported Types"
388 * filter is added, which is the concatenation of all valid filters.
389 * @note Duplicate filters and similar filters (i.e. filters whose file
390 * extensions already exist in another filter) are ignored.
391 * @note "All Files" filter will be selected by default if unknown mime types
392 * have been specified and no file extension filter has been specified.
393 * Otherwise, specified filter or "All Supported Types" filter will be
394 * selected by default.
395 * The logic behind is that having unknown mime type means we might restrict
396 * user's input too much, as some filters will be missing.
397 * However, if author has also specified some file extension filters, it's
398 * likely those are fallback for the unusual mime type we haven't been able
399 * to resolve; so it's better to select author specified filters in that case.
401 void SetFilePickerFiltersFromAccept(nsIFilePicker
* filePicker
);
404 * The form might need to request an update of the UI bits
405 * (BF_CAN_SHOW_INVALID_UI and BF_CAN_SHOW_VALID_UI) when an invalid form
406 * submission is tried.
408 * @param aIsFocused Whether the element is currently focused.
410 * @note The caller is responsible to call ContentStatesChanged.
412 void UpdateValidityUIBits(bool aIsFocused
);
415 * Fires change event if mFocusedValue and current value held are unequal and
416 * if a change event may be fired on bluring.
417 * Sets mFocusedValue to value, if a change event is fired.
419 void FireChangeEventIfNeeded();
422 * Returns the input element's value as a Decimal.
423 * Returns NaN if the current element's value is not a floating point number.
425 * @return the input element's value as a Decimal.
427 Decimal
GetValueAsDecimal() const;
430 * Returns the input's "minimum" (as defined by the HTML5 spec) as a double.
431 * Note this takes account of any default minimum that the type may have.
432 * Returns NaN if the min attribute isn't a valid floating point number and
433 * the input's type does not have a default minimum.
435 * NOTE: Only call this if you know DoesMinMaxApply() returns true.
437 Decimal
GetMinimum() const;
440 * Returns the input's "maximum" (as defined by the HTML5 spec) as a double.
441 * Note this takes account of any default maximum that the type may have.
442 * Returns NaN if the max attribute isn't a valid floating point number and
443 * the input's type does not have a default maximum.
445 * NOTE:Only call this if you know DoesMinMaxApply() returns true.
447 Decimal
GetMaximum() const;
451 void GetAccept(nsAString
& aValue
) { GetHTMLAttr(nsGkAtoms::accept
, aValue
); }
452 void SetAccept(const nsAString
& aValue
, ErrorResult
& aRv
) {
453 SetHTMLAttr(nsGkAtoms::accept
, aValue
, aRv
);
456 void GetAlt(nsAString
& aValue
) { GetHTMLAttr(nsGkAtoms::alt
, aValue
); }
457 void SetAlt(const nsAString
& aValue
, ErrorResult
& aRv
) {
458 SetHTMLAttr(nsGkAtoms::alt
, aValue
, aRv
);
461 void GetAutocomplete(nsAString
& aValue
);
462 void SetAutocomplete(const nsAString
& aValue
, ErrorResult
& aRv
) {
463 SetHTMLAttr(nsGkAtoms::autocomplete
, aValue
, aRv
);
466 void GetAutocompleteInfo(Nullable
<AutocompleteInfo
>& aInfo
);
468 bool Autofocus() const { return GetBoolAttr(nsGkAtoms::autofocus
); }
470 void SetAutofocus(bool aValue
, ErrorResult
& aRv
) {
471 SetHTMLBoolAttr(nsGkAtoms::autofocus
, aValue
, aRv
);
474 bool DefaultChecked() const {
475 return HasAttr(kNameSpaceID_None
, nsGkAtoms::checked
);
478 void SetDefaultChecked(bool aValue
, ErrorResult
& aRv
) {
479 SetHTMLBoolAttr(nsGkAtoms::checked
, aValue
, aRv
);
482 bool Checked() const { return mChecked
; }
483 void SetChecked(bool aChecked
);
485 bool Disabled() const { return GetBoolAttr(nsGkAtoms::disabled
); }
487 void SetDisabled(bool aValue
, ErrorResult
& aRv
) {
488 SetHTMLBoolAttr(nsGkAtoms::disabled
, aValue
, aRv
);
491 FileList
* GetFiles();
492 void SetFiles(FileList
* aFiles
);
494 void SetFormAction(const nsAString
& aValue
, ErrorResult
& aRv
) {
495 SetHTMLAttr(nsGkAtoms::formaction
, aValue
, aRv
);
498 void GetFormEnctype(nsAString
& aValue
);
499 void SetFormEnctype(const nsAString
& aValue
, ErrorResult
& aRv
) {
500 SetHTMLAttr(nsGkAtoms::formenctype
, aValue
, aRv
);
503 void GetFormMethod(nsAString
& aValue
);
504 void SetFormMethod(const nsAString
& aValue
, ErrorResult
& aRv
) {
505 SetHTMLAttr(nsGkAtoms::formmethod
, aValue
, aRv
);
508 bool FormNoValidate() const { return GetBoolAttr(nsGkAtoms::formnovalidate
); }
510 void SetFormNoValidate(bool aValue
, ErrorResult
& aRv
) {
511 SetHTMLBoolAttr(nsGkAtoms::formnovalidate
, aValue
, aRv
);
514 void GetFormTarget(nsAString
& aValue
) {
515 GetHTMLAttr(nsGkAtoms::formtarget
, aValue
);
517 void SetFormTarget(const nsAString
& aValue
, ErrorResult
& aRv
) {
518 SetHTMLAttr(nsGkAtoms::formtarget
, aValue
, aRv
);
521 MOZ_CAN_RUN_SCRIPT
uint32_t Height();
523 void SetHeight(uint32_t aValue
, ErrorResult
& aRv
) {
524 SetUnsignedIntAttr(nsGkAtoms::height
, aValue
, 0, aRv
);
527 bool Indeterminate() const { return mIndeterminate
; }
529 bool IsDraggingRange() const { return mIsDraggingRange
; }
530 void SetIndeterminate(bool aValue
);
532 void GetInputMode(nsAString
& aValue
);
533 void SetInputMode(const nsAString
& aValue
, ErrorResult
& aRv
) {
534 SetHTMLAttr(nsGkAtoms::inputmode
, aValue
, aRv
);
537 nsGenericHTMLElement
* GetList() const;
539 void GetMax(nsAString
& aValue
) { GetHTMLAttr(nsGkAtoms::max
, aValue
); }
540 void SetMax(const nsAString
& aValue
, ErrorResult
& aRv
) {
541 SetHTMLAttr(nsGkAtoms::max
, aValue
, aRv
);
544 int32_t MaxLength() const { return GetIntAttr(nsGkAtoms::maxlength
, -1); }
546 void SetMaxLength(int32_t aValue
, ErrorResult
& aRv
) {
547 int32_t minLength
= MinLength();
548 if (aValue
< 0 || (minLength
>= 0 && aValue
< minLength
)) {
549 aRv
.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR
);
553 SetHTMLIntAttr(nsGkAtoms::maxlength
, aValue
, aRv
);
556 int32_t MinLength() const { return GetIntAttr(nsGkAtoms::minlength
, -1); }
558 void SetMinLength(int32_t aValue
, ErrorResult
& aRv
) {
559 int32_t maxLength
= MaxLength();
560 if (aValue
< 0 || (maxLength
>= 0 && aValue
> maxLength
)) {
561 aRv
.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR
);
565 SetHTMLIntAttr(nsGkAtoms::minlength
, aValue
, aRv
);
568 void GetMin(nsAString
& aValue
) { GetHTMLAttr(nsGkAtoms::min
, aValue
); }
569 void SetMin(const nsAString
& aValue
, ErrorResult
& aRv
) {
570 SetHTMLAttr(nsGkAtoms::min
, aValue
, aRv
);
573 bool Multiple() const { return GetBoolAttr(nsGkAtoms::multiple
); }
575 void SetMultiple(bool aValue
, ErrorResult
& aRv
) {
576 SetHTMLBoolAttr(nsGkAtoms::multiple
, aValue
, aRv
);
579 void GetName(nsAString
& aValue
) { GetHTMLAttr(nsGkAtoms::name
, aValue
); }
580 void SetName(const nsAString
& aValue
, ErrorResult
& aRv
) {
581 SetHTMLAttr(nsGkAtoms::name
, aValue
, aRv
);
584 void GetPattern(nsAString
& aValue
) {
585 GetHTMLAttr(nsGkAtoms::pattern
, aValue
);
587 void SetPattern(const nsAString
& aValue
, ErrorResult
& aRv
) {
588 SetHTMLAttr(nsGkAtoms::pattern
, aValue
, aRv
);
591 void GetPlaceholder(nsAString
& aValue
) {
592 GetHTMLAttr(nsGkAtoms::placeholder
, aValue
);
594 void SetPlaceholder(const nsAString
& aValue
, ErrorResult
& aRv
) {
595 SetHTMLAttr(nsGkAtoms::placeholder
, aValue
, aRv
);
598 bool ReadOnly() const { return GetBoolAttr(nsGkAtoms::readonly
); }
600 void SetReadOnly(bool aValue
, ErrorResult
& aRv
) {
601 SetHTMLBoolAttr(nsGkAtoms::readonly
, aValue
, aRv
);
604 bool Required() const { return GetBoolAttr(nsGkAtoms::required
); }
606 void SetRequired(bool aValue
, ErrorResult
& aRv
) {
607 SetHTMLBoolAttr(nsGkAtoms::required
, aValue
, aRv
);
610 uint32_t Size() const {
611 return GetUnsignedIntAttr(nsGkAtoms::size
, DEFAULT_COLS
);
614 void SetSize(uint32_t aValue
, ErrorResult
& aRv
) {
616 aRv
.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR
);
620 SetUnsignedIntAttr(nsGkAtoms::size
, aValue
, DEFAULT_COLS
, aRv
);
623 void GetSrc(nsAString
& aValue
) {
624 GetURIAttr(nsGkAtoms::src
, nullptr, aValue
);
626 void SetSrc(const nsAString
& aValue
, nsIPrincipal
* aTriggeringPrincipal
,
628 SetHTMLAttr(nsGkAtoms::src
, aValue
, aTriggeringPrincipal
, aRv
);
631 void GetStep(nsAString
& aValue
) { GetHTMLAttr(nsGkAtoms::step
, aValue
); }
632 void SetStep(const nsAString
& aValue
, ErrorResult
& aRv
) {
633 SetHTMLAttr(nsGkAtoms::step
, aValue
, aRv
);
636 void GetType(nsAString
& aValue
);
637 void SetType(const nsAString
& aValue
, ErrorResult
& aRv
) {
638 SetHTMLAttr(nsGkAtoms::type
, aValue
, aRv
);
641 void GetDefaultValue(nsAString
& aValue
) {
642 GetHTMLAttr(nsGkAtoms::value
, aValue
);
644 void SetDefaultValue(const nsAString
& aValue
, ErrorResult
& aRv
) {
645 SetHTMLAttr(nsGkAtoms::value
, aValue
, aRv
);
648 MOZ_CAN_RUN_SCRIPT_BOUNDARY
649 void SetValue(const nsAString
& aValue
, CallerType aCallerType
,
651 void GetValue(nsAString
& aValue
, CallerType aCallerType
);
653 Nullable
<Date
> GetValueAsDate(ErrorResult
& aRv
);
655 void SetValueAsDate(const Nullable
<Date
>& aDate
, ErrorResult
& aRv
);
657 double ValueAsNumber() const {
658 return DoesValueAsNumberApply() ? GetValueAsDecimal().toDouble()
659 : UnspecifiedNaN
<double>();
662 void SetValueAsNumber(double aValue
, ErrorResult
& aRv
);
664 MOZ_CAN_RUN_SCRIPT
uint32_t Width();
666 void SetWidth(uint32_t aValue
, ErrorResult
& aRv
) {
667 SetUnsignedIntAttr(nsGkAtoms::width
, aValue
, 0, aRv
);
670 void StepUp(int32_t aN
, ErrorResult
& aRv
) { aRv
= ApplyStep(aN
); }
672 void StepDown(int32_t aN
, ErrorResult
& aRv
) { aRv
= ApplyStep(-aN
); }
675 * Returns the current step value.
676 * Returns kStepAny if the current step is "any" string.
678 * @return the current step value.
680 Decimal
GetStep() const;
682 already_AddRefed
<nsINodeList
> GetLabels();
686 Nullable
<uint32_t> GetSelectionStart(ErrorResult
& aRv
);
687 void SetSelectionStart(const Nullable
<uint32_t>& aValue
, ErrorResult
& aRv
);
689 Nullable
<uint32_t> GetSelectionEnd(ErrorResult
& aRv
);
690 void SetSelectionEnd(const Nullable
<uint32_t>& aValue
, ErrorResult
& aRv
);
692 void GetSelectionDirection(nsAString
& aValue
, ErrorResult
& aRv
);
693 void SetSelectionDirection(const nsAString
& aValue
, ErrorResult
& aRv
);
695 void SetSelectionRange(uint32_t aStart
, uint32_t aEnd
,
696 const Optional
<nsAString
>& direction
,
699 void SetRangeText(const nsAString
& aReplacement
, ErrorResult
& aRv
);
701 void SetRangeText(const nsAString
& aReplacement
, uint32_t aStart
,
702 uint32_t aEnd
, SelectionMode aSelectMode
, ErrorResult
& aRv
);
704 bool Allowdirs() const {
705 return HasAttr(kNameSpaceID_None
, nsGkAtoms::allowdirs
);
708 void SetAllowdirs(bool aValue
, ErrorResult
& aRv
) {
709 SetHTMLBoolAttr(nsGkAtoms::allowdirs
, aValue
, aRv
);
712 bool WebkitDirectoryAttr() const {
713 return HasAttr(kNameSpaceID_None
, nsGkAtoms::webkitdirectory
);
716 void SetWebkitDirectoryAttr(bool aValue
, ErrorResult
& aRv
) {
717 SetHTMLBoolAttr(nsGkAtoms::webkitdirectory
, aValue
, aRv
);
720 void GetWebkitEntries(nsTArray
<RefPtr
<FileSystemEntry
>>& aSequence
);
722 bool IsFilesAndDirectoriesSupported() const;
724 already_AddRefed
<Promise
> GetFilesAndDirectories(ErrorResult
& aRv
);
726 already_AddRefed
<Promise
> GetFiles(bool aRecursiveFlag
, ErrorResult
& aRv
);
728 void ChooseDirectory(ErrorResult
& aRv
);
730 void GetAlign(nsAString
& aValue
) { GetHTMLAttr(nsGkAtoms::align
, aValue
); }
731 void SetAlign(const nsAString
& aValue
, ErrorResult
& aRv
) {
732 SetHTMLAttr(nsGkAtoms::align
, aValue
, aRv
);
735 void GetUseMap(nsAString
& aValue
) { GetHTMLAttr(nsGkAtoms::usemap
, aValue
); }
736 void SetUseMap(const nsAString
& aValue
, ErrorResult
& aRv
) {
737 SetHTMLAttr(nsGkAtoms::usemap
, aValue
, aRv
);
740 nsIControllers
* GetControllers(ErrorResult
& aRv
);
741 // XPCOM adapter function widely used throughout code, leaving it as is.
742 nsresult
GetControllers(nsIControllers
** aResult
);
744 int32_t InputTextLength(CallerType aCallerType
);
746 void MozGetFileNameArray(nsTArray
<nsString
>& aFileNames
, ErrorResult
& aRv
);
748 void MozSetFileNameArray(const Sequence
<nsString
>& aFileNames
,
750 void MozSetFileArray(const Sequence
<OwningNonNull
<File
>>& aFiles
);
751 void MozSetDirectory(const nsAString
& aDirectoryPath
, ErrorResult
& aRv
);
754 * The following functions are called from datetime picker to let input box
755 * know the current state of the picker or to update the input box on changes.
757 void GetDateTimeInputBoxValue(DateTimeValue
& aValue
);
760 * This allows chrome JavaScript to dispatch event to the inner datetimebox
761 * anonymous or UA Widget element.
763 Element
* GetDateTimeBoxElement();
766 * The following functions are called from datetime input box XBL to control
767 * and update the picker.
769 void OpenDateTimePicker(const DateTimeValue
& aInitialValue
);
770 void UpdateDateTimePicker(const DateTimeValue
& aValue
);
771 void CloseDateTimePicker();
774 * Called from datetime input box binding when inner text fields are focused
777 void SetFocusState(bool aIsFocused
);
780 * Called from datetime input box binding when the the user entered value
781 * becomes valid/invalid.
783 void UpdateValidityState();
786 * The following are called from datetime input box binding to get the
787 * corresponding computed values.
789 double GetStepAsDouble() { return GetStep().toDouble(); }
790 double GetStepBaseAsDouble() { return GetStepBase().toDouble(); }
791 double GetMinimumAsDouble() { return GetMinimum().toDouble(); }
792 double GetMaximumAsDouble() { return GetMaximum().toDouble(); }
794 HTMLInputElement
* GetOwnerNumberControl();
796 void StartNumberControlSpinnerSpin();
797 enum SpinnerStopState
{ eAllowDispatchingEvents
, eDisallowDispatchingEvents
};
798 void StopNumberControlSpinnerSpin(
799 SpinnerStopState aState
= eAllowDispatchingEvents
);
801 void StepNumberControlForUserEvent(int32_t aDirection
);
804 * The callback function used by the nsRepeatService that we use to spin the
805 * spinner for <input type=number>.
807 MOZ_CAN_RUN_SCRIPT_BOUNDARY
808 static void HandleNumberControlSpin(void* aData
);
810 bool NumberSpinnerUpButtonIsDepressed() const {
811 return mNumberControlSpinnerIsSpinning
&& mNumberControlSpinnerSpinsUp
;
814 bool NumberSpinnerDownButtonIsDepressed() const {
815 return mNumberControlSpinnerIsSpinning
&& !mNumberControlSpinnerSpinsUp
;
818 bool MozIsTextField(bool aExcludePassword
);
821 * GetEditor() is for webidl bindings.
823 nsIEditor
* GetEditor();
825 bool IsInputEventTarget() const { return IsSingleLineTextControl(false); }
827 MOZ_CAN_RUN_SCRIPT_BOUNDARY
828 void SetUserInput(const nsAString
& aInput
, nsIPrincipal
& aSubjectPrincipal
);
831 * If aValue contains a valid floating-point number in the format specified
832 * by the HTML 5 spec:
834 * http://www.whatwg.org/specs/web-apps/current-work/multipage/common-microsyntaxes.html#floating-point-numbers
836 * then this function will return the number parsed as a Decimal, otherwise
837 * it will return a Decimal for which Decimal::isFinite() will return false.
839 static Decimal
StringToDecimal(const nsAString
& aValue
);
842 const nsTArray
<OwningFileOrDirectory
>& aFilesOrDirectories
);
844 static void Shutdown();
847 * Returns if the required attribute applies for the current type.
849 bool DoesRequiredApply() const;
852 * Returns the current required state of the element. This function differs
853 * from Required() in that this function only returns true for input types
854 * that @required attribute applies and the attribute is set; in contrast,
855 * Required() returns true whenever @required attribute is set.
857 bool IsRequired() const { return State().HasState(NS_EVENT_STATE_REQUIRED
); }
859 bool HasBeenTypePassword() { return mHasBeenTypePassword
; }
862 virtual ~HTMLInputElement();
864 virtual JSObject
* WrapNode(JSContext
* aCx
,
865 JS::Handle
<JSObject
*> aGivenProto
) override
;
867 // Pull IsSingleLineTextControl into our scope, otherwise it'd be hidden
868 // by the nsITextControlElement version.
869 using nsGenericHTMLFormElementWithState::IsSingleLineTextControl
;
872 * The ValueModeType specifies how the value IDL attribute should behave.
874 * See: http://dev.w3.org/html5/spec/forms.html#dom-input-value
877 // On getting, returns the value.
878 // On setting, sets value.
880 // On getting, returns the value if present or the empty string.
881 // On setting, sets the value.
883 // On getting, returns the value if present or "on".
884 // On setting, sets the value.
885 VALUE_MODE_DEFAULT_ON
,
886 // On getting, returns "C:\fakepath\" followed by the file name of the
887 // first file of the selected files if any.
888 // On setting the empty string, empties the selected files list, otherwise
889 // throw the INVALID_STATE_ERR exception.
894 * This helper method convert a sub-string that contains only digits to a
895 * number (unsigned int given that it can't contain a minus sign).
896 * This method will return whether the sub-string is correctly formatted
897 * (ie. contains only digit) and it can be successfuly parsed to generate a
899 * If the method returns true, |aResult| will contained the parsed number.
901 * @param aValue the string on which the sub-string will be extracted and
903 * @param aStart the beginning of the sub-string in aValue.
904 * @param aLen the length of the sub-string.
905 * @param aResult the parsed number.
906 * @return whether the sub-string has been parsed successfully.
908 static bool DigitSubStringToNumber(const nsAString
& aValue
, uint32_t aStart
,
909 uint32_t aLen
, uint32_t* aResult
);
916 * @param aValue String to set.
917 * @param aOldValue Previous value before setting aValue.
918 If previous value is unknown, aOldValue can be nullptr.
919 * @param aFlags See nsTextEditorState::SetValueFlags.
922 nsresult
SetValueInternal(const nsAString
& aValue
, const nsAString
* aOldValue
,
926 nsresult
SetValueInternal(const nsAString
& aValue
, uint32_t aFlags
) {
927 return SetValueInternal(aValue
, nullptr, aFlags
);
930 // Generic getter for the value that doesn't do experimental control type
932 void GetValueInternal(nsAString
& aValue
, CallerType aCallerType
) const;
934 // A getter for callers that know we're not dealing with a file input, so they
935 // don't have to think about the caller type.
936 void GetNonFileValueInternal(nsAString
& aValue
) const;
939 * Returns whether the current value is the empty string. This only makes
940 * sense for some input types; does NOT make sense for file inputs.
942 * @return whether the current value is the empty string.
944 bool IsValueEmpty() const;
947 * Returns whether the current placeholder value should be shown.
949 bool ShouldShowPlaceholder() const;
951 void ClearFiles(bool aSetValueChanged
);
953 void SetIndeterminateInternal(bool aValue
, bool aShouldInvalidate
);
956 * Called when an attribute is about to be changed
958 virtual nsresult
BeforeSetAttr(int32_t aNameSpaceID
, nsAtom
* aName
,
959 const nsAttrValueOrString
* aValue
,
960 bool aNotify
) override
;
962 * Called when an attribute has just been changed
964 MOZ_CAN_RUN_SCRIPT_BOUNDARY
965 virtual nsresult
AfterSetAttr(int32_t aNameSpaceID
, nsAtom
* aName
,
966 const nsAttrValue
* aValue
,
967 const nsAttrValue
* aOldValue
,
968 nsIPrincipal
* aSubjectPrincipal
,
969 bool aNotify
) override
;
971 virtual void BeforeSetForm(bool aBindToTree
) override
;
973 virtual void AfterClearForm(bool aUnbindOrDelete
) override
;
976 * Dispatch a select event. Returns true if the event was not cancelled.
978 bool DispatchSelectEvent(nsPresContext
* aPresContext
);
980 void SelectAll(nsPresContext
* aPresContext
);
981 bool IsImage() const {
982 return AttrValueIs(kNameSpaceID_None
, nsGkAtoms::type
, nsGkAtoms::image
,
987 * Visit the group of radio buttons this radio belongs to
988 * @param aVisitor the visitor to visit with
990 nsresult
VisitGroup(nsIRadioVisitor
* aVisitor
, bool aFlushContent
);
993 * Do all the work that |SetChecked| does (radio button handling, etc.), but
994 * take an |aNotify| parameter.
996 void DoSetChecked(bool aValue
, bool aNotify
, bool aSetValueChanged
);
999 * Do all the work that |SetCheckedChanged| does (radio button handling,
1000 * etc.), but take an |aNotify| parameter that lets it avoid flushing content
1003 void DoSetCheckedChanged(bool aCheckedChanged
, bool aNotify
);
1006 * Actually set checked and notify the frame of the change.
1007 * @param aValue the value of checked to set
1009 void SetCheckedInternal(bool aValue
, bool aNotify
);
1011 void RadioSetChecked(bool aNotify
);
1012 void SetCheckedChanged(bool aCheckedChanged
);
1015 * MaybeSubmitForm looks for a submit input or a single text control
1016 * and submits the form if either is present.
1018 MOZ_CAN_RUN_SCRIPT nsresult
MaybeSubmitForm(nsPresContext
* aPresContext
);
1021 * Update mFileList with the currently selected file.
1023 void UpdateFileList();
1026 * Called after calling one of the SetFilesOrDirectories() functions.
1027 * This method can explore the directory recursively if needed.
1029 void AfterSetFilesOrDirectories(bool aSetValueChanged
);
1032 * Recursively explore the directory and populate mFileOrDirectories correctly
1033 * for webkitdirectory.
1035 void ExploreDirectoryRecursively(bool aSetValuechanged
);
1038 * Determine whether the editor needs to be initialized explicitly for
1039 * a particular event.
1041 bool NeedToInitializeEditorForEvent(EventChainPreVisitor
& aVisitor
) const;
1044 * Get the value mode of the element, depending of the type.
1046 ValueModeType
GetValueMode() const;
1049 * Get the mutable state of the element.
1050 * When the element isn't mutable (immutable), the value or checkedness
1051 * should not be changed by the user.
1053 * See: http://dev.w3.org/html5/spec/forms.html#concept-input-mutable
1055 bool IsMutable() const;
1058 * Returns if the min and max attributes apply for the current type.
1060 bool DoesMinMaxApply() const;
1063 * Returns if the step attribute apply for the current type.
1065 bool DoesStepApply() const { return DoesMinMaxApply(); }
1068 * Returns if stepDown and stepUp methods apply for the current type.
1070 bool DoStepDownStepUpApply() const { return DoesStepApply(); }
1073 * Returns if valueAsNumber attribute applies for the current type.
1075 bool DoesValueAsNumberApply() const { return DoesMinMaxApply(); }
1078 * Returns if autocomplete attribute applies for the current type.
1080 bool DoesAutocompleteApply() const;
1083 nsTextEditorState
* GetEditorState() const;
1085 mozilla::TextEditor
* GetTextEditorFromState();
1088 * Manages the internal data storage across type changes.
1091 void HandleTypeChange(uint8_t aNewType
, bool aNotify
);
1094 * Sanitize the value of the element depending of its current type.
1096 * http://www.whatwg.org/specs/web-apps/current-work/#value-sanitization-algorithm
1098 void SanitizeValue(nsAString
& aValue
);
1101 * Returns whether the placeholder attribute applies for the current type.
1103 bool PlaceholderApplies() const;
1106 * Set the current default value to the value of the input element.
1107 * @note You should not call this method if GetValueMode() doesn't return
1111 nsresult
SetDefaultValueAsValue();
1113 void SetDirectionFromValue(bool aNotify
);
1116 * Return if an element should have a specific validity UI
1117 * (with :-moz-ui-invalid and :-moz-ui-valid pseudo-classes).
1119 * @return Whether the element should have a validity UI.
1121 bool ShouldShowValidityUI() const {
1123 * Always show the validity UI if the form has already tried to be submitted
1126 * Otherwise, show the validity UI if the element's value has been changed.
1128 if (mForm
&& mForm
->HasEverTriedInvalidSubmit()) {
1132 switch (GetValueMode()) {
1133 case VALUE_MODE_DEFAULT
:
1135 case VALUE_MODE_DEFAULT_ON
:
1136 return GetCheckedChanged();
1137 case VALUE_MODE_VALUE
:
1138 case VALUE_MODE_FILENAME
:
1139 return mValueChanged
;
1142 MOZ_ASSERT_UNREACHABLE("We should not be there: there are no other modes.");
1147 * Returns the radio group container if the element has one, null otherwise.
1148 * The radio group container will be the form owner if there is one.
1149 * The current document otherwise.
1150 * @return the radio group container if the element has one, null otherwise.
1152 nsIRadioGroupContainer
* GetRadioGroupContainer() const;
1155 * Parse a color string of the form #XXXXXX where X should be hexa characters
1156 * @param the string to be parsed.
1157 * @return whether the string is a valid simple color.
1158 * Note : this function does not consider the empty string as valid.
1160 bool IsValidSimpleColor(const nsAString
& aValue
) const;
1163 * Parse a week string of the form yyyy-Www
1164 * @param the string to be parsed.
1165 * @return whether the string is a valid week.
1166 * Note : this function does not consider the empty string as valid.
1168 bool IsValidWeek(const nsAString
& aValue
) const;
1171 * Parse a month string of the form yyyy-mm
1172 * @param the string to be parsed.
1173 * @return whether the string is a valid month.
1174 * Note : this function does not consider the empty string as valid.
1176 bool IsValidMonth(const nsAString
& aValue
) const;
1179 * Parse a date string of the form yyyy-mm-dd
1180 * @param the string to be parsed.
1181 * @return whether the string is a valid date.
1182 * Note : this function does not consider the empty string as valid.
1184 bool IsValidDate(const nsAString
& aValue
) const;
1187 * Parse a datetime-local string of the form yyyy-mm-ddThh:mm[:ss.s] or
1188 * yyyy-mm-dd hh:mm[:ss.s], where fractions of seconds can be 1 to 3 digits.
1190 * @param the string to be parsed.
1191 * @return whether the string is a valid datetime-local string.
1192 * Note : this function does not consider the empty string as valid.
1194 bool IsValidDateTimeLocal(const nsAString
& aValue
) const;
1197 * Parse a year string of the form yyyy
1199 * @param the string to be parsed.
1201 * @return the year in aYear.
1202 * @return whether the parsing was successful.
1204 bool ParseYear(const nsAString
& aValue
, uint32_t* aYear
) const;
1207 * Parse a month string of the form yyyy-mm
1209 * @param the string to be parsed.
1210 * @return the year and month in aYear and aMonth.
1211 * @return whether the parsing was successful.
1213 bool ParseMonth(const nsAString
& aValue
, uint32_t* aYear
,
1214 uint32_t* aMonth
) const;
1217 * Parse a week string of the form yyyy-Www
1219 * @param the string to be parsed.
1220 * @return the year and week in aYear and aWeek.
1221 * @return whether the parsing was successful.
1223 bool ParseWeek(const nsAString
& aValue
, uint32_t* aYear
,
1224 uint32_t* aWeek
) const;
1226 * Parse a date string of the form yyyy-mm-dd
1228 * @param the string to be parsed.
1229 * @return the date in aYear, aMonth, aDay.
1230 * @return whether the parsing was successful.
1232 bool ParseDate(const nsAString
& aValue
, uint32_t* aYear
, uint32_t* aMonth
,
1233 uint32_t* aDay
) const;
1236 * Parse a datetime-local string of the form yyyy-mm-ddThh:mm[:ss.s] or
1237 * yyyy-mm-dd hh:mm[:ss.s], where fractions of seconds can be 1 to 3 digits.
1239 * @param the string to be parsed.
1240 * @return the date in aYear, aMonth, aDay and time expressed in milliseconds
1242 * @return whether the parsing was successful.
1244 bool ParseDateTimeLocal(const nsAString
& aValue
, uint32_t* aYear
,
1245 uint32_t* aMonth
, uint32_t* aDay
,
1246 uint32_t* aTime
) const;
1249 * Normalize the datetime-local string following the HTML specifications:
1250 * https://html.spec.whatwg.org/multipage/infrastructure.html#valid-normalised-local-date-and-time-string
1252 void NormalizeDateTimeLocal(nsAString
& aValue
) const;
1255 * This methods returns the number of days since epoch for a given year and
1258 double DaysSinceEpochFromWeek(uint32_t aYear
, uint32_t aWeek
) const;
1261 * This methods returns the number of days in a given month, for a given year.
1263 uint32_t NumberOfDaysInMonth(uint32_t aMonth
, uint32_t aYear
) const;
1266 * This methods returns the number of months between January 1970 and the
1267 * given year and month.
1269 int32_t MonthsSinceJan1970(uint32_t aYear
, uint32_t aMonth
) const;
1272 * This methods returns the day of the week given a date. If @isoWeek is true,
1273 * 7=Sunday, otherwise, 0=Sunday.
1275 uint32_t DayOfWeek(uint32_t aYear
, uint32_t aMonth
, uint32_t aDay
,
1276 bool isoWeek
) const;
1279 * This methods returns the maximum number of week in a given year, the
1280 * result is either 52 or 53.
1282 uint32_t MaximumWeekInYear(uint32_t aYear
) const;
1285 * This methods returns true if it's a leap year.
1287 bool IsLeapYear(uint32_t aYear
) const;
1290 * Returns whether aValue is a valid time as described by HTML specifications:
1291 * http://www.whatwg.org/specs/web-apps/current-work/multipage/common-microsyntaxes.html#valid-time-string
1293 * @param aValue the string to be tested.
1294 * @return Whether the string is a valid time per HTML specifications.
1296 bool IsValidTime(const nsAString
& aValue
) const;
1299 * Returns the time expressed in milliseconds of |aValue| being parsed as a
1300 * time following the HTML specifications:
1301 * http://www.whatwg.org/specs/web-apps/current-work/#parse-a-time-string
1303 * Note: |aResult| can be null.
1305 * @param aValue the string to be parsed.
1306 * @param aResult the time expressed in milliseconds representing the time
1308 * @return Whether the parsing was successful.
1310 static bool ParseTime(const nsAString
& aValue
, uint32_t* aResult
);
1313 * Sets the value of the element to the string representation of the Decimal.
1315 * @param aValue The Decimal that will be used to set the value.
1317 void SetValue(Decimal aValue
, CallerType aCallerType
);
1320 * Update the HAS_RANGE bit field value.
1322 void UpdateHasRange();
1325 * Get the step scale value for the current type.
1327 * http://www.whatwg.org/specs/web-apps/current-work/multipage/common-input-element-attributes.html#concept-input-step-scale
1329 Decimal
GetStepScaleFactor() const;
1332 * Return the base used to compute if a value matches step.
1333 * Basically, it's the min attribute if present and a default value otherwise.
1335 * @return The step base.
1337 Decimal
GetStepBase() const;
1340 * Returns the default step for the current type.
1341 * @return the default step for the current type.
1343 Decimal
GetDefaultStep() const;
1345 enum StepCallerType
{ CALLED_FOR_USER_EVENT
, CALLED_FOR_SCRIPT
};
1348 * Sets the aValue outparam to the value that this input would take if
1349 * someone tries to step aStep steps and this input's value would change as
1350 * a result. Leaves aValue untouched if this inputs value would not change
1351 * (e.g. already at max, and asking for the next step up).
1353 * Negative aStep means step down, positive means step up.
1355 * Returns NS_OK or else the error values that should be thrown if this call
1356 * was initiated by a stepUp()/stepDown() call from script under conditions
1357 * that such a call should throw.
1359 nsresult
GetValueIfStepped(int32_t aStepCount
, StepCallerType aCallerType
,
1360 Decimal
* aNextStep
);
1363 * Apply a step change from stepUp or stepDown by multiplying aStep by the
1364 * current step value.
1366 * @param aStep The value used to be multiplied against the step value.
1368 nsresult
ApplyStep(int32_t aStep
);
1371 * Returns if the current type is an experimental mobile type.
1373 static bool IsExperimentalMobileType(uint8_t aType
);
1376 * Returns if the current type is one of the date/time input types: date,
1377 * time and month. TODO: week and datetime-local.
1379 static bool IsDateTimeInputType(uint8_t aType
);
1382 * Returns true if the element should prevent dispatching another DOMActivate.
1383 * This is used in situations where the anonymous subtree should already have
1384 * sent a DOMActivate and prevents firing more than once.
1386 bool ShouldPreventDOMActivateDispatch(EventTarget
* aOriginalTarget
);
1389 * Some input type (color and file) let user choose a value using a picker:
1390 * this function checks if it is needed, and if so, open the corresponding
1391 * picker (color picker or file picker).
1393 nsresult
MaybeInitPickers(EventChainPostVisitor
& aVisitor
);
1395 enum FilePickerType
{ FILE_PICKER_FILE
, FILE_PICKER_DIRECTORY
};
1396 nsresult
InitFilePicker(FilePickerType aType
);
1397 nsresult
InitColorPicker();
1400 * Use this function before trying to open a picker.
1401 * It checks if the page is allowed to open a new pop-up.
1402 * If it returns true, you should not create the picker.
1404 * @return true if popup should be blocked, false otherwise
1406 bool IsPopupBlocked() const;
1408 GetFilesHelper
* GetOrCreateGetFilesHelper(bool aRecursiveFlag
,
1411 void ClearGetFilesHelpers();
1414 * nsINode::SetMayBeApzAware() will be invoked in this function if necessary
1415 * to prevent default action of APZC so that we can increase/decrease the
1416 * value of this InputElement when mouse wheel event comes without scrolling
1419 * SetMayBeApzAware() will set flag MayBeApzAware which is checked by apzc to
1420 * decide whether to add this element into its dispatch-to-content region.
1422 void UpdateApzAwareFlag();
1425 * A helper to get the current selection range. Will throw on the ErrorResult
1426 * if we have no editor state.
1428 void GetSelectionRange(uint32_t* aSelectionStart
, uint32_t* aSelectionEnd
,
1432 * Override for nsImageLoadingContent.
1434 nsIContent
* AsContent() override
{ return this; }
1436 nsCOMPtr
<nsIControllers
> mControllers
;
1439 * In mInputData, the mState field is used if IsSingleLineTextControl returns
1440 * true and mValue is used otherwise. We have to be careful when handling it
1443 * Accessing the mState member should be done using the GetEditorState
1444 * function, which returns null if the state is not present.
1448 * The current value of the input if it has been changed from the default
1452 * The state of the text editor associated with the text/password input
1454 nsTextEditorState
* mState
;
1458 UniquePtr
<FileData
> mFileData
;
1461 * The value of the input element when first initialized and it is updated
1462 * when the element is either changed through a script, focused or dispatches
1463 * a change event. This is to ensure correct future change event firing.
1464 * NB: This is ONLY applicable where the element is a text control. ie,
1465 * where type= "date", "time", "text", "email", "search", "tel", "url" or
1468 nsString mFocusedValue
;
1471 * If mIsDraggingRange is true, this is the value that the input had before
1472 * the drag started. Used to reset the input to its old value if the drag is
1475 Decimal mRangeThumbDragStartValue
;
1478 * Current value in the input box, in DateTimeValue dictionary format, see
1479 * HTMLInputElement.webidl for details.
1481 nsAutoPtr
<DateTimeValue
> mDateTimeInputBoxValue
;
1484 * The selection properties cache for number controls. This is needed because
1485 * the number controls don't recycle their text field, so the normal cache in
1486 * nsTextEditorState cannot do its job.
1488 nsTextEditorState::SelectionProperties mSelectionProperties
;
1491 * The triggering principal for the src attribute.
1493 nsCOMPtr
<nsIPrincipal
> mSrcTriggeringPrincipal
;
1496 * InputType object created based on input type.
1498 UniquePtr
<InputType
, DoNotDelete
> mInputType
;
1500 // Memory allocated for mInputType, reused when type changes.
1501 char mInputTypeMem
[INPUT_TYPE_SIZE
];
1503 // Step scale factor values, for input types that have one.
1504 static const Decimal kStepScaleFactorDate
;
1505 static const Decimal kStepScaleFactorNumberRange
;
1506 static const Decimal kStepScaleFactorTime
;
1507 static const Decimal kStepScaleFactorMonth
;
1508 static const Decimal kStepScaleFactorWeek
;
1510 // Default step base value when a type do not have specific one.
1511 static const Decimal kDefaultStepBase
;
1512 // Default step base value when type=week does not not have a specific one,
1513 // which is −259200000, the start of week 1970-W01.
1514 static const Decimal kDefaultStepBaseWeek
;
1516 // Default step used when there is no specified step.
1517 static const Decimal kDefaultStep
;
1518 static const Decimal kDefaultStepTime
;
1520 // Float value returned by GetStep() when the step attribute is set to 'any'.
1521 static const Decimal kStepAny
;
1523 // Minimum year limited by HTML standard, year >= 1.
1524 static const double kMinimumYear
;
1525 // Maximum year limited by ECMAScript date object range, year <= 275760.
1526 static const double kMaximumYear
;
1527 // Maximum valid week is 275760-W37.
1528 static const double kMaximumWeekInMaximumYear
;
1529 // Maximum valid day is 275760-09-13.
1530 static const double kMaximumDayInMaximumYear
;
1531 // Maximum valid month is 275760-09.
1532 static const double kMaximumMonthInMaximumYear
;
1533 // Long years in a ISO calendar have 53 weeks in them.
1534 static const double kMaximumWeekInYear
;
1535 // Milliseconds in a day.
1536 static const double kMsPerDay
;
1538 nsContentUtils::AutocompleteAttrState mAutocompleteAttrState
;
1539 nsContentUtils::AutocompleteAttrState mAutocompleteInfoState
;
1540 bool mDisabledChanged
: 1;
1541 bool mValueChanged
: 1;
1542 bool mLastValueChangeWasInteractive
: 1;
1543 bool mCheckedChanged
: 1;
1545 bool mHandlingSelectEvent
: 1;
1546 bool mShouldInitChecked
: 1;
1547 bool mDoneCreating
: 1;
1548 bool mInInternalActivate
: 1;
1549 bool mCheckedIsToggled
: 1;
1550 bool mIndeterminate
: 1;
1551 bool mInhibitRestoration
: 1;
1552 bool mCanShowValidUI
: 1;
1553 bool mCanShowInvalidUI
: 1;
1555 bool mIsDraggingRange
: 1;
1556 bool mNumberControlSpinnerIsSpinning
: 1;
1557 bool mNumberControlSpinnerSpinsUp
: 1;
1558 bool mPickerRunning
: 1;
1559 bool mSelectionCached
: 1;
1560 bool mIsPreviewEnabled
: 1;
1561 bool mHasBeenTypePassword
: 1;
1562 bool mHasPatternAttribute
: 1;
1565 static void ImageInputMapAttributesIntoRule(
1566 const nsMappedAttributes
* aAttributes
, MappedDeclarations
&);
1569 * Returns true if this input's type will fire a DOM "change" event when it
1570 * loses focus if its value has changed since it gained focus.
1572 bool MayFireChangeOnBlur() const { return MayFireChangeOnBlur(mType
); }
1575 * Returns true if selection methods can be called on element
1577 bool SupportsTextSelection() const {
1578 return mType
== NS_FORM_INPUT_TEXT
|| mType
== NS_FORM_INPUT_SEARCH
||
1579 mType
== NS_FORM_INPUT_URL
|| mType
== NS_FORM_INPUT_TEL
||
1580 mType
== NS_FORM_INPUT_PASSWORD
;
1583 static bool MayFireChangeOnBlur(uint8_t aType
) {
1584 return IsSingleLineTextControl(false, aType
) ||
1585 aType
== NS_FORM_INPUT_RANGE
|| aType
== NS_FORM_INPUT_NUMBER
||
1586 aType
== NS_FORM_INPUT_TIME
|| aType
== NS_FORM_INPUT_DATE
;
1590 * Checks if aDateTimeInputType should be supported based on
1591 * "dom.forms.datetime", and "dom.experimental_forms".
1593 static bool IsDateTimeTypeSupported(uint8_t aDateTimeInputType
);
1596 * Checks preference "dom.experimental_forms" to determine if experimental
1597 * implementation of input element should be enabled.
1599 static bool IsExperimentalFormsEnabled();
1602 * Checks preference "dom.forms.datetime.others" to determine if input week,
1603 * month and datetime-local should be supported.
1605 static bool IsInputDateTimeOthersEnabled();
1608 * Checks preference "dom.forms.color" to determine if date/time related
1609 * types should be supported.
1611 static bool IsInputColorEnabled();
1613 struct nsFilePickerFilter
{
1614 nsFilePickerFilter() : mFilterMask(0) {}
1616 explicit nsFilePickerFilter(int32_t aFilterMask
)
1617 : mFilterMask(aFilterMask
) {}
1619 nsFilePickerFilter(const nsString
& aTitle
, const nsString
& aFilter
)
1620 : mFilterMask(0), mTitle(aTitle
), mFilter(aFilter
) {}
1622 nsFilePickerFilter(const nsFilePickerFilter
& other
) {
1623 mFilterMask
= other
.mFilterMask
;
1624 mTitle
= other
.mTitle
;
1625 mFilter
= other
.mFilter
;
1628 bool operator==(const nsFilePickerFilter
& other
) const {
1629 if ((mFilter
== other
.mFilter
) && (mFilterMask
== other
.mFilterMask
)) {
1636 // Filter mask, using values defined in nsIFilePicker
1637 int32_t mFilterMask
;
1638 // If mFilterMask is defined, mTitle and mFilter are useless and should be
1644 class nsFilePickerShownCallback
: public nsIFilePickerShownCallback
{
1645 virtual ~nsFilePickerShownCallback() {}
1648 nsFilePickerShownCallback(HTMLInputElement
* aInput
,
1649 nsIFilePicker
* aFilePicker
);
1652 NS_IMETHOD
Done(int16_t aResult
) override
;
1655 nsCOMPtr
<nsIFilePicker
> mFilePicker
;
1656 RefPtr
<HTMLInputElement
> mInput
;
1659 static void ReleaseTextEditorState(nsTextEditorState
* aState
);
1661 static nsTextEditorState
* sCachedTextEditorState
;
1662 static bool sShutdown
;
1666 } // namespace mozilla