forked from roytam1/UXP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHTMLInputElement.h
1769 lines (1482 loc) · 56.4 KB
/
HTMLInputElement.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
#ifndef mozilla_dom_HTMLInputElement_h
#define mozilla_dom_HTMLInputElement_h
#include "mozilla/Attributes.h"
#include "nsGenericHTMLElement.h"
#include "nsImageLoadingContent.h"
#include "nsIDOMHTMLInputElement.h"
#include "nsITextControlElement.h"
#include "nsITimer.h"
#include "nsIPhonetic.h"
#include "nsIDOMNSEditableElement.h"
#include "nsCOMPtr.h"
#include "nsIConstraintValidation.h"
#include "mozilla/dom/HTMLFormElement.h" // for HasEverTriedInvalidSubmit()
#include "mozilla/dom/HTMLInputElementBinding.h"
#include "mozilla/dom/Promise.h"
#include "mozilla/dom/UnionTypes.h"
#include "nsIFilePicker.h"
#include "nsIContentPrefService2.h"
#include "mozilla/Decimal.h"
#include "nsContentUtils.h"
#include "nsTextEditorState.h"
class nsIRadioGroupContainer;
class nsIRadioVisitor;
namespace mozilla {
class EventChainPostVisitor;
class EventChainPreVisitor;
namespace dom {
class AfterSetFilesOrDirectoriesRunnable;
class Date;
class DispatchChangeEventCallback;
class File;
class FileList;
class FileSystemEntry;
class GetFilesHelper;
/**
* A class we use to create a singleton object that is used to keep track of
* the last directory from which the user has picked files (via
* <input type=file>) on a per-domain basis. The implementation uses
* nsIContentPrefService2/NS_CONTENT_PREF_SERVICE_CONTRACTID to store the last
* directory per-domain, and to ensure that whether the directories are
* persistently saved (saved across sessions) or not honors whether or not the
* page is being viewed in private browsing.
*/
class UploadLastDir final : public nsIObserver, public nsSupportsWeakReference
{
~UploadLastDir() {}
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
/**
* Fetch the last used directory for this location from the content
* pref service, and display the file picker opened in that directory.
*
* @param aDoc current document
* @param aFilePicker the file picker to open
* @param aFpCallback the callback object to be run when the file is shown.
*/
nsresult FetchDirectoryAndDisplayPicker(nsIDocument* aDoc,
nsIFilePicker* aFilePicker,
nsIFilePickerShownCallback* aFpCallback);
/**
* Store the last used directory for this location using the
* content pref service, if it is available
* @param aURI URI of the current page
* @param aDir Parent directory of the file(s)/directory chosen by the user
*/
nsresult StoreLastUsedDirectory(nsIDocument* aDoc, nsIFile* aDir);
class ContentPrefCallback final : public nsIContentPrefCallback2
{
virtual ~ContentPrefCallback()
{ }
public:
ContentPrefCallback(nsIFilePicker* aFilePicker, nsIFilePickerShownCallback* aFpCallback)
: mFilePicker(aFilePicker)
, mFpCallback(aFpCallback)
{ }
NS_DECL_ISUPPORTS
NS_DECL_NSICONTENTPREFCALLBACK2
nsCOMPtr<nsIFilePicker> mFilePicker;
nsCOMPtr<nsIFilePickerShownCallback> mFpCallback;
nsCOMPtr<nsIContentPref> mResult;
};
};
class HTMLInputElement final : public nsGenericHTMLFormElementWithState,
public nsImageLoadingContent,
public nsIDOMHTMLInputElement,
public nsITextControlElement,
public nsIPhonetic,
public nsIDOMNSEditableElement,
public nsIConstraintValidation
{
friend class AfterSetFilesOrDirectoriesCallback;
friend class DispatchChangeEventCallback;
public:
using nsIConstraintValidation::GetValidationMessage;
using nsIConstraintValidation::CheckValidity;
using nsIConstraintValidation::ReportValidity;
using nsIConstraintValidation::WillValidate;
using nsIConstraintValidation::Validity;
using nsGenericHTMLFormElementWithState::GetForm;
enum class FromClone { no, yes };
HTMLInputElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo,
mozilla::dom::FromParser aFromParser,
FromClone aFromClone = FromClone::no);
NS_IMPL_FROMCONTENT_HTML_WITH_TAG(HTMLInputElement, input)
// nsISupports
NS_DECL_ISUPPORTS_INHERITED
virtual int32_t TabIndexDefault() override;
using nsGenericHTMLElement::Focus;
virtual void Blur(ErrorResult& aError) override;
virtual void Focus(ErrorResult& aError) override;
// nsINode
#if !defined(ANDROID) && !defined(XP_MACOSX)
virtual bool IsNodeApzAwareInternal() const override;
#endif
// Element
virtual bool IsInteractiveHTMLContent(bool aIgnoreTabindex) const override;
// EventTarget
virtual void AsyncEventRunning(AsyncEventDispatcher* aEvent) override;
// nsIDOMHTMLInputElement
NS_DECL_NSIDOMHTMLINPUTELEMENT
// nsIPhonetic
NS_DECL_NSIPHONETIC
// nsIDOMNSEditableElement
NS_IMETHOD GetEditor(nsIEditor** aEditor) override
{
return nsGenericHTMLElement::GetEditor(aEditor);
}
NS_IMETHOD SetUserInput(const nsAString& aInput) override;
// Overriden nsIFormControl methods
NS_IMETHOD_(uint32_t) GetType() const override { return mType; }
NS_IMETHOD Reset() override;
NS_IMETHOD SubmitNamesValues(HTMLFormSubmission* aFormSubmission) override;
NS_IMETHOD SaveState() override;
virtual bool RestoreState(nsPresState* aState) override;
virtual bool AllowDrop() override;
virtual bool IsDisabledForEvents(EventMessage aMessage) override;
virtual void FieldSetDisabledChanged(bool aNotify) override;
// nsIContent
virtual bool IsHTMLFocusable(bool aWithMouse, bool *aIsFocusable, int32_t *aTabIndex) override;
virtual bool ParseAttribute(int32_t aNamespaceID,
nsIAtom* aAttribute,
const nsAString& aValue,
nsAttrValue& aResult) override;
virtual nsChangeHint GetAttributeChangeHint(const nsIAtom* aAttribute,
int32_t aModType) const override;
NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* aAttribute) const override;
virtual nsMapRuleToAttributesFunc GetAttributeMappingFunction() const override;
virtual nsresult GetEventTargetParent(
EventChainPreVisitor& aVisitor) override;
virtual nsresult PreHandleEvent(EventChainVisitor& aVisitor) override;
virtual nsresult PostHandleEvent(
EventChainPostVisitor& aVisitor) override;
void PostHandleEventForRangeThumb(EventChainPostVisitor& aVisitor);
void StartRangeThumbDrag(WidgetGUIEvent* aEvent);
void FinishRangeThumbDrag(WidgetGUIEvent* aEvent = nullptr);
void CancelRangeThumbDrag(bool aIsForUserEvent = true);
void SetValueOfRangeForUserEvent(Decimal aValue);
virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
nsIContent* aBindingParent,
bool aCompileEventHandlers) override;
virtual void UnbindFromTree(bool aDeep = true,
bool aNullParent = true) override;
virtual void DoneCreatingElement() override;
virtual EventStates IntrinsicState() const override;
// Element
private:
virtual void AddStates(EventStates aStates) override;
virtual void RemoveStates(EventStates aStates) override;
public:
// nsITextControlElement
NS_IMETHOD SetValueChanged(bool aValueChanged) override;
NS_IMETHOD_(bool) IsSingleLineTextControl() const override;
NS_IMETHOD_(bool) IsTextArea() const override;
NS_IMETHOD_(bool) IsPlainTextControl() const override;
NS_IMETHOD_(bool) IsPasswordTextControl() const override;
NS_IMETHOD_(int32_t) GetCols() override;
NS_IMETHOD_(int32_t) GetWrapCols() override;
NS_IMETHOD_(int32_t) GetRows() override;
NS_IMETHOD_(void) GetDefaultValueFromContent(nsAString& aValue) override;
NS_IMETHOD_(bool) ValueChanged() const override;
NS_IMETHOD_(void) GetTextEditorValue(nsAString& aValue, bool aIgnoreWrap) const override;
NS_IMETHOD_(nsIEditor*) GetTextEditor() override;
NS_IMETHOD_(nsISelectionController*) GetSelectionController() override;
NS_IMETHOD_(nsFrameSelection*) GetConstFrameSelection() override;
NS_IMETHOD BindToFrame(nsTextControlFrame* aFrame) override;
NS_IMETHOD_(void) UnbindFromFrame(nsTextControlFrame* aFrame) override;
NS_IMETHOD CreateEditor() override;
NS_IMETHOD_(nsIContent*) GetRootEditorNode() override;
NS_IMETHOD_(Element*) CreatePlaceholderNode() override;
NS_IMETHOD_(Element*) GetPlaceholderNode() override;
NS_IMETHOD_(void) UpdatePlaceholderVisibility(bool aNotify) override;
NS_IMETHOD_(bool) GetPlaceholderVisibility() override;
NS_IMETHOD_(void) InitializeKeyboardEventListeners() override;
NS_IMETHOD_(void) OnValueChanged(bool aNotify, bool aWasInteractiveUserChange) override;
NS_IMETHOD_(bool) HasCachedSelection() override;
void GetDisplayFileName(nsAString& aFileName) const;
const nsTArray<OwningFileOrDirectory>& GetFilesOrDirectoriesInternal() const
{
return mFilesOrDirectories;
}
void SetFilesOrDirectories(const nsTArray<OwningFileOrDirectory>& aFilesOrDirectories,
bool aSetValueChanged);
void SetFiles(nsIDOMFileList* aFiles, bool aSetValueChanged);
// This method is used for test only. Onces the data is set, a 'change' event
// is dispatched.
void MozSetDndFilesAndDirectories(const nsTArray<OwningFileOrDirectory>& aSequence);
// Called when a nsIFilePicker or a nsIColorPicker terminate.
void PickerClosed();
void SetCheckedChangedInternal(bool aCheckedChanged);
bool GetCheckedChanged() const {
return mCheckedChanged;
}
void AddedToRadioGroup();
void WillRemoveFromRadioGroup();
/**
* Helper function returning the currently selected button in the radio group.
* Returning null if the element is not a button or if there is no selectied
* button in the group.
*
* @return the selected button (or null).
*/
already_AddRefed<nsIDOMHTMLInputElement> GetSelectedRadioButton() const;
virtual nsresult Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult) const override;
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLInputElement,
nsGenericHTMLFormElementWithState)
static UploadLastDir* gUploadLastDir;
// create and destroy the static UploadLastDir object for remembering
// which directory was last used on a site-by-site basis
static void InitUploadLastDir();
static void DestroyUploadLastDir();
//If the valueAsDate attribute should be enabled in webIDL
static bool ValueAsDateEnabled(JSContext* cx, JSObject* obj);
void MaybeLoadImage();
void SetSelectionProperties(const nsTextEditorState::SelectionProperties& aProps)
{
MOZ_ASSERT(mType == NS_FORM_INPUT_NUMBER);
mSelectionCached = true;
mSelectionProperties = aProps;
}
bool IsSelectionCached() const
{
MOZ_ASSERT(mType == NS_FORM_INPUT_NUMBER);
return mSelectionCached;
}
void ClearSelectionCached()
{
MOZ_ASSERT(mType == NS_FORM_INPUT_NUMBER);
mSelectionCached = false;
}
nsTextEditorState::SelectionProperties& GetSelectionProperties()
{
MOZ_ASSERT(mType == NS_FORM_INPUT_NUMBER);
return mSelectionProperties;
}
// nsIConstraintValidation
bool IsTooLong();
bool IsTooShort();
bool IsValueMissing() const;
bool HasTypeMismatch() const;
bool HasPatternMismatch() const;
bool IsRangeOverflow() const;
bool IsRangeUnderflow() const;
bool HasStepMismatch(bool aUseZeroIfValueNaN = false) const;
bool HasBadInput() const;
void UpdateTooLongValidityState();
void UpdateTooShortValidityState();
void UpdateValueMissingValidityState();
void UpdateTypeMismatchValidityState();
void UpdatePatternMismatchValidityState();
void UpdateRangeOverflowValidityState();
void UpdateRangeUnderflowValidityState();
void UpdateStepMismatchValidityState();
void UpdateBadInputValidityState();
void UpdateAllValidityStates(bool aNotify);
void UpdateBarredFromConstraintValidation();
nsresult GetValidationMessage(nsAString& aValidationMessage,
ValidityStateType aType) override;
/**
* Update the value missing validity state for radio elements when they have
* a group.
*
* @param aIgnoreSelf Whether the required attribute and the checked state
* of the current radio should be ignored.
* @note This method shouldn't be called if the radio element hasn't a group.
*/
void UpdateValueMissingValidityStateForRadio(bool aIgnoreSelf);
/**
* Set filters to the filePicker according to the accept attribute value.
*
* See:
* http://dev.w3.org/html5/spec/forms.html#attr-input-accept
*
* @note You should not call this function if the element has no @accept.
* @note "All Files" filter is always set, no matter if there is a valid
* filter specified or not.
* @note If more than one valid filter is found, the "All Supported Types"
* filter is added, which is the concatenation of all valid filters.
* @note Duplicate filters and similar filters (i.e. filters whose file
* extensions already exist in another filter) are ignored.
* @note "All Files" filter will be selected by default if unknown mime types
* have been specified and no file extension filter has been specified.
* Otherwise, specified filter or "All Supported Types" filter will be
* selected by default.
* The logic behind is that having unknown mime type means we might restrict
* user's input too much, as some filters will be missing.
* However, if author has also specified some file extension filters, it's
* likely those are fallback for the unusual mime type we haven't been able
* to resolve; so it's better to select author specified filters in that case.
*/
void SetFilePickerFiltersFromAccept(nsIFilePicker* filePicker);
/**
* The form might need to request an update of the UI bits
* (BF_CAN_SHOW_INVALID_UI and BF_CAN_SHOW_VALID_UI) when an invalid form
* submission is tried.
*
* @param aIsFocused Whether the element is currently focused.
*
* @note The caller is responsible to call ContentStatesChanged.
*/
void UpdateValidityUIBits(bool aIsFocused);
/**
* Fires change event if mFocusedValue and current value held are unequal.
*/
void FireChangeEventIfNeeded();
/**
* Returns the input element's value as a Decimal.
* Returns NaN if the current element's value is not a floating point number.
*
* @return the input element's value as a Decimal.
*/
Decimal GetValueAsDecimal() const;
/**
* Returns the input's "minimum" (as defined by the HTML5 spec) as a double.
* Note this takes account of any default minimum that the type may have.
* Returns NaN if the min attribute isn't a valid floating point number and
* the input's type does not have a default minimum.
*
* NOTE: Only call this if you know DoesMinMaxApply() returns true.
*/
Decimal GetMinimum() const;
/**
* Returns the input's "maximum" (as defined by the HTML5 spec) as a double.
* Note this takes account of any default maximum that the type may have.
* Returns NaN if the max attribute isn't a valid floating point number and
* the input's type does not have a default maximum.
*
* NOTE:Only call this if you know DoesMinMaxApply() returns true.
*/
Decimal GetMaximum() const;
// WebIDL
// XPCOM GetAccept() is OK
void SetAccept(const nsAString& aValue, ErrorResult& aRv)
{
SetHTMLAttr(nsGkAtoms::accept, aValue, aRv);
}
// XPCOM GetAlt() is OK
void SetAlt(const nsAString& aValue, ErrorResult& aRv)
{
SetHTMLAttr(nsGkAtoms::alt, aValue, aRv);
}
// XPCOM GetAutocomplete() is OK
void SetAutocomplete(const nsAString& aValue, ErrorResult& aRv)
{
SetHTMLAttr(nsGkAtoms::autocomplete, aValue, aRv);
}
void GetAutocompleteInfo(Nullable<AutocompleteInfo>& aInfo);
bool Autofocus() const
{
return GetBoolAttr(nsGkAtoms::autofocus);
}
void SetAutofocus(bool aValue, ErrorResult& aRv)
{
SetHTMLBoolAttr(nsGkAtoms::autofocus, aValue, aRv);
}
bool DefaultChecked() const
{
return HasAttr(kNameSpaceID_None, nsGkAtoms::checked);
}
void SetDefaultChecked(bool aValue, ErrorResult& aRv)
{
SetHTMLBoolAttr(nsGkAtoms::checked, aValue, aRv);
}
bool Checked() const
{
return mChecked;
}
// XPCOM SetChecked() is OK
bool Disabled() const
{
return GetBoolAttr(nsGkAtoms::disabled);
}
void SetDisabled(bool aValue,ErrorResult& aRv)
{
SetHTMLBoolAttr(nsGkAtoms::disabled, aValue, aRv);
}
// XPCOM GetForm() is OK
FileList* GetFiles();
// XPCOM GetFormAction() is OK
void SetFormAction(const nsAString& aValue, ErrorResult& aRv)
{
SetHTMLAttr(nsGkAtoms::formaction, aValue, aRv);
}
// XPCOM GetFormEnctype() is OK
void SetFormEnctype(const nsAString& aValue, ErrorResult& aRv)
{
SetHTMLAttr(nsGkAtoms::formenctype, aValue, aRv);
}
// XPCOM GetFormMethod() is OK
void SetFormMethod(const nsAString& aValue, ErrorResult& aRv)
{
SetHTMLAttr(nsGkAtoms::formmethod, aValue, aRv);
}
bool FormNoValidate() const
{
return GetBoolAttr(nsGkAtoms::formnovalidate);
}
void SetFormNoValidate(bool aValue, ErrorResult& aRv)
{
SetHTMLBoolAttr(nsGkAtoms::formnovalidate, aValue, aRv);
}
// XPCOM GetFormTarget() is OK
void SetFormTarget(const nsAString& aValue, ErrorResult& aRv)
{
SetHTMLAttr(nsGkAtoms::formtarget, aValue, aRv);
}
uint32_t Height();
void SetHeight(uint32_t aValue, ErrorResult& aRv)
{
SetUnsignedIntAttr(nsGkAtoms::height, aValue, 0, aRv);
}
bool Indeterminate() const
{
return mIndeterminate;
}
// XPCOM SetIndeterminate() is OK
// XPCOM GetInputMode() is OK
void SetInputMode(const nsAString& aValue, ErrorResult& aRv)
{
SetHTMLAttr(nsGkAtoms::inputmode, aValue, aRv);
}
nsGenericHTMLElement* GetList() const;
// XPCOM GetMax() is OK
void SetMax(const nsAString& aValue, ErrorResult& aRv)
{
SetHTMLAttr(nsGkAtoms::max, aValue, aRv);
}
int32_t MaxLength() const
{
return GetIntAttr(nsGkAtoms::maxlength, -1);
}
void SetMaxLength(int32_t aValue, ErrorResult& aRv)
{
int32_t minLength = MinLength();
if (aValue < 0 || (minLength >= 0 && aValue < minLength)) {
aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
return;
}
SetHTMLIntAttr(nsGkAtoms::maxlength, aValue, aRv);
}
int32_t MinLength() const
{
return GetIntAttr(nsGkAtoms::minlength, -1);
}
void SetMinLength(int32_t aValue, ErrorResult& aRv)
{
int32_t maxLength = MaxLength();
if (aValue < 0 || (maxLength >= 0 && aValue > maxLength)) {
aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
return;
}
SetHTMLIntAttr(nsGkAtoms::minlength, aValue, aRv);
}
// XPCOM GetMin() is OK
void SetMin(const nsAString& aValue, ErrorResult& aRv)
{
SetHTMLAttr(nsGkAtoms::min, aValue, aRv);
}
bool Multiple() const
{
return GetBoolAttr(nsGkAtoms::multiple);
}
void SetMultiple(bool aValue, ErrorResult& aRv)
{
SetHTMLBoolAttr(nsGkAtoms::multiple, aValue, aRv);
}
// XPCOM GetName() is OK
void SetName(const nsAString& aValue, ErrorResult& aRv)
{
SetHTMLAttr(nsGkAtoms::name, aValue, aRv);
}
// XPCOM GetPattern() is OK
void SetPattern(const nsAString& aValue, ErrorResult& aRv)
{
SetHTMLAttr(nsGkAtoms::pattern, aValue, aRv);
}
// XPCOM GetPlaceholder() is OK
void SetPlaceholder(const nsAString& aValue, ErrorResult& aRv)
{
SetHTMLAttr(nsGkAtoms::placeholder, aValue, aRv);
}
bool ReadOnly() const
{
return GetBoolAttr(nsGkAtoms::readonly);
}
void SetReadOnly(bool aValue, ErrorResult& aRv)
{
SetHTMLBoolAttr(nsGkAtoms::readonly, aValue, aRv);
}
bool Required() const
{
return GetBoolAttr(nsGkAtoms::required);
}
void SetRequired(bool aValue, ErrorResult& aRv)
{
SetHTMLBoolAttr(nsGkAtoms::required, aValue, aRv);
}
uint32_t Size() const
{
return GetUnsignedIntAttr(nsGkAtoms::size, DEFAULT_COLS);
}
void SetSize(uint32_t aValue, ErrorResult& aRv)
{
if (aValue == 0) {
aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
return;
}
SetUnsignedIntAttr(nsGkAtoms::size, aValue, DEFAULT_COLS, aRv);
}
// XPCOM GetSrc() is OK
void SetSrc(const nsAString& aValue, ErrorResult& aRv)
{
SetHTMLAttr(nsGkAtoms::src, aValue, aRv);
}
// XPCOM GetStep() is OK
void SetStep(const nsAString& aValue, ErrorResult& aRv)
{
SetHTMLAttr(nsGkAtoms::step, aValue, aRv);
}
// XPCOM GetType() is OK
void SetType(const nsAString& aValue, ErrorResult& aRv)
{
SetHTMLAttr(nsGkAtoms::type, aValue, aRv);
}
// XPCOM GetDefaultValue() is OK
void SetDefaultValue(const nsAString& aValue, ErrorResult& aRv)
{
SetHTMLAttr(nsGkAtoms::value, aValue, aRv);
}
void GetValue(nsAString& aValue, ErrorResult& aRv);
void SetValue(const nsAString& aValue, ErrorResult& aRv);
Nullable<Date> GetValueAsDate(ErrorResult& aRv);
void SetValueAsDate(Nullable<Date>, ErrorResult& aRv);
double ValueAsNumber() const
{
return DoesValueAsNumberApply() ? GetValueAsDecimal().toDouble()
: UnspecifiedNaN<double>();
}
void SetValueAsNumber(double aValue, ErrorResult& aRv);
uint32_t Width();
void SetWidth(uint32_t aValue, ErrorResult& aRv)
{
SetUnsignedIntAttr(nsGkAtoms::width, aValue, 0, aRv);
}
void StepUp(int32_t aN, ErrorResult& aRv)
{
aRv = ApplyStep(aN);
}
void StepDown(int32_t aN, ErrorResult& aRv)
{
aRv = ApplyStep(-aN);
}
/**
* Returns the current step value.
* Returns kStepAny if the current step is "any" string.
*
* @return the current step value.
*/
Decimal GetStep() const;
void GetValidationMessage(nsAString& aValidationMessage, ErrorResult& aRv);
// XPCOM GetCustomVisibility() is OK
already_AddRefed<nsINodeList> GetLabels();
// XPCOM Select() is OK
Nullable<int32_t> GetSelectionStart(ErrorResult& aRv);
void SetSelectionStart(const Nullable<int32_t>& aValue, ErrorResult& aRv);
Nullable<int32_t> GetSelectionEnd(ErrorResult& aRv);
void SetSelectionEnd(const Nullable<int32_t>& aValue, ErrorResult& aRv);
void GetSelectionDirection(nsAString& aValue, ErrorResult& aRv);
void SetSelectionDirection(const nsAString& aValue, ErrorResult& aRv);
void SetSelectionRange(int32_t aStart, int32_t aEnd,
const Optional< nsAString >& direction,
ErrorResult& aRv);
void SetRangeText(const nsAString& aReplacement, ErrorResult& aRv);
void SetRangeText(const nsAString& aReplacement, uint32_t aStart,
uint32_t aEnd, const SelectionMode& aSelectMode,
ErrorResult& aRv, int32_t aSelectionStart = -1,
int32_t aSelectionEnd = -1);
bool Allowdirs() const
{
return HasAttr(kNameSpaceID_None, nsGkAtoms::allowdirs);
}
void SetAllowdirs(bool aValue, ErrorResult& aRv)
{
SetHTMLBoolAttr(nsGkAtoms::allowdirs, aValue, aRv);
}
bool WebkitDirectoryAttr() const
{
return HasAttr(kNameSpaceID_None, nsGkAtoms::webkitdirectory);
}
void SetWebkitDirectoryAttr(bool aValue, ErrorResult& aRv)
{
SetHTMLBoolAttr(nsGkAtoms::webkitdirectory, aValue, aRv);
}
void GetWebkitEntries(nsTArray<RefPtr<FileSystemEntry>>& aSequence);
bool IsFilesAndDirectoriesSupported() const;
already_AddRefed<Promise> GetFilesAndDirectories(ErrorResult& aRv);
already_AddRefed<Promise> GetFiles(bool aRecursiveFlag, ErrorResult& aRv);
void ChooseDirectory(ErrorResult& aRv);
// XPCOM GetAlign() is OK
void SetAlign(const nsAString& aValue, ErrorResult& aRv)
{
SetHTMLAttr(nsGkAtoms::align, aValue, aRv);
}
// XPCOM GetUseMap() is OK
void SetUseMap(const nsAString& aValue, ErrorResult& aRv)
{
SetHTMLAttr(nsGkAtoms::usemap, aValue, aRv);
}
nsIControllers* GetControllers(ErrorResult& aRv);
int32_t GetTextLength(ErrorResult& aRv);
void MozGetFileNameArray(nsTArray<nsString>& aFileNames, ErrorResult& aRv);
void MozSetFileNameArray(const Sequence< nsString >& aFileNames, ErrorResult& aRv);
void MozSetFileArray(const Sequence<OwningNonNull<File>>& aFiles);
void MozSetDirectory(const nsAString& aDirectoryPath, ErrorResult& aRv);
/*
* The following functions are called from datetime picker to let input box
* know the current state of the picker or to update the input box on changes.
*/
void GetDateTimeInputBoxValue(DateTimeValue& aValue);
void UpdateDateTimeInputBox(const DateTimeValue& aValue);
void SetDateTimePickerState(bool aOpen);
/*
* The following functions are called from datetime input box XBL to control
* and update the picker.
*/
void OpenDateTimePicker(const DateTimeValue& aInitialValue);
void UpdateDateTimePicker(const DateTimeValue& aValue);
void CloseDateTimePicker();
/*
* The following are called from datetime input box binding to get the
* corresponding computed values.
*/
double GetStepAsDouble() { return GetStep().toDouble(); }
double GetStepBaseAsDouble() { return GetStepBase().toDouble(); }
double GetMinimumAsDouble() { return GetMinimum().toDouble(); }
double GetMaximumAsDouble() { return GetMaximum().toDouble(); }
HTMLInputElement* GetOwnerNumberControl();
HTMLInputElement* GetOwnerDateTimeControl();
void StartNumberControlSpinnerSpin();
enum SpinnerStopState {
eAllowDispatchingEvents,
eDisallowDispatchingEvents
};
void StopNumberControlSpinnerSpin(SpinnerStopState aState =
eAllowDispatchingEvents);
void StepNumberControlForUserEvent(int32_t aDirection);
/**
* The callback function used by the nsRepeatService that we use to spin the
* spinner for <input type=number>.
*/
static void HandleNumberControlSpin(void* aData);
bool NumberSpinnerUpButtonIsDepressed() const
{
return mNumberControlSpinnerIsSpinning && mNumberControlSpinnerSpinsUp;
}
bool NumberSpinnerDownButtonIsDepressed() const
{
return mNumberControlSpinnerIsSpinning && !mNumberControlSpinnerSpinsUp;
}
bool MozIsTextField(bool aExcludePassword);
nsIEditor* GetEditor();
void SetUserInput(const nsAString& aInput,
nsIPrincipal& aSubjectPrincipal);
// XPCOM GetPhonetic() is OK
/**
* If aValue contains a valid floating-point number in the format specified
* by the HTML 5 spec:
*
* http://www.whatwg.org/specs/web-apps/current-work/multipage/common-microsyntaxes.html#floating-point-numbers
*
* then this function will return the number parsed as a Decimal, otherwise
* it will return a Decimal for which Decimal::isFinite() will return false.
*/
static Decimal StringToDecimal(const nsAString& aValue);
void UpdateEntries(const nsTArray<OwningFileOrDirectory>& aFilesOrDirectories);
protected:
virtual ~HTMLInputElement();
virtual JSObject* WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
// Pull IsSingleLineTextControl into our scope, otherwise it'd be hidden
// by the nsITextControlElement version.
using nsGenericHTMLFormElementWithState::IsSingleLineTextControl;
/**
* The ValueModeType specifies how the value IDL attribute should behave.
*
* See: http://dev.w3.org/html5/spec/forms.html#dom-input-value
*/
enum ValueModeType
{
// On getting, returns the value.
// On setting, sets value.
VALUE_MODE_VALUE,
// On getting, returns the value if present or the empty string.
// On setting, sets the value.
VALUE_MODE_DEFAULT,
// On getting, returns the value if present or "on".
// On setting, sets the value.
VALUE_MODE_DEFAULT_ON,
// On getting, returns "C:\fakepath\" followed by the file name of the
// first file of the selected files if any.
// On setting the empty string, empties the selected files list, otherwise
// throw the INVALID_STATE_ERR exception.
VALUE_MODE_FILENAME
};
/**
* This helper method returns true if aValue is a valid email address.
* This is following the HTML5 specification:
* http://dev.w3.org/html5/spec/forms.html#valid-e-mail-address
*
* @param aValue the email address to check.
* @result whether the given string is a valid email address.
*/
static bool IsValidEmailAddress(const nsAString& aValue);
/**
* This helper method returns true if aValue is a valid email address list.
* Email address list is a list of email address separated by comas (,) which
* can be surrounded by space charecters.
* This is following the HTML5 specification:
* http://dev.w3.org/html5/spec/forms.html#valid-e-mail-address-list
*
* @param aValue the email address list to check.
* @result whether the given string is a valid email address list.
*/
static bool IsValidEmailAddressList(const nsAString& aValue);
/**
* This helper method convert a sub-string that contains only digits to a
* number (unsigned int given that it can't contain a minus sign).
* This method will return whether the sub-string is correctly formatted
* (ie. contains only digit) and it can be successfuly parsed to generate a
* number).
* If the method returns true, |aResult| will contained the parsed number.
*
* @param aValue the string on which the sub-string will be extracted and parsed.
* @param aStart the beginning of the sub-string in aValue.
* @param aLen the length of the sub-string.
* @param aResult the parsed number.
* @return whether the sub-string has been parsed successfully.
*/
static bool DigitSubStringToNumber(const nsAString& aValue, uint32_t aStart,
uint32_t aLen, uint32_t* aResult);
// Helper method
/**
* Setting the value.
*
* @param aValue String to set.
* @param aFlags See nsTextEditorState::SetValueFlags.
*/
nsresult SetValueInternal(const nsAString& aValue, uint32_t aFlags);
nsresult GetValueInternal(nsAString& aValue) const;
/**
* Returns whether the current value is the empty string.
*
* @return whether the current value is the empty string.
*/
bool IsValueEmpty() const;
void ClearFiles(bool aSetValueChanged);
void SetIndeterminateInternal(bool aValue,
bool aShouldInvalidate);
nsresult GetSelectionRange(int32_t* aSelectionStart, int32_t* aSelectionEnd);
/**
* Called when an attribute is about to be changed
*/
virtual nsresult BeforeSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
const nsAttrValueOrString* aValue,
bool aNotify) override;
/**
* Called when an attribute has just been changed
*/
virtual nsresult AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue,
bool aNotify) override;
/**
* Dispatch a select event. Returns true if the event was not cancelled.
*/
bool DispatchSelectEvent(nsPresContext* aPresContext);
void SelectAll(nsPresContext* aPresContext);
bool IsImage() const
{
return AttrValueIs(kNameSpaceID_None, nsGkAtoms::type,
nsGkAtoms::image, eIgnoreCase);
}
/**
* Visit the group of radio buttons this radio belongs to
* @param aVisitor the visitor to visit with
*/
nsresult VisitGroup(nsIRadioVisitor* aVisitor, bool aFlushContent);
/**
* Do all the work that |SetChecked| does (radio button handling, etc.), but
* take an |aNotify| parameter.
*/
void DoSetChecked(bool aValue, bool aNotify, bool aSetValueChanged);
/**
* Do all the work that |SetCheckedChanged| does (radio button handling,
* etc.), but take an |aNotify| parameter that lets it avoid flushing content
* when it can.
*/
void DoSetCheckedChanged(bool aCheckedChanged, bool aNotify);