Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / dom / html / nsIConstraintValidation.h
blob14f7cee77fb5d9eec64136552c226b8f27291399
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 nsIConstraintValidition_h___
8 #define nsIConstraintValidition_h___
10 #include "nsISupports.h"
12 class nsIContent;
14 namespace mozilla::dom {
15 class ValidityState;
16 } // namespace mozilla::dom
18 #define NS_ICONSTRAINTVALIDATION_IID \
19 { \
20 0x983829da, 0x1aaf, 0x449c, { \
21 0xa3, 0x06, 0x85, 0xd4, 0xf0, 0x31, 0x1c, 0xf6 \
22 } \
25 /**
26 * This interface is for form elements implementing the validity constraint API.
27 * See: http://dev.w3.org/html5/spec/forms.html#the-constraint-validation-api
29 * This interface has to be implemented by all elements implementing the API
30 * and only them.
32 class nsIConstraintValidation : public nsISupports {
33 public:
34 NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICONSTRAINTVALIDATION_IID);
36 friend class mozilla::dom::ValidityState;
38 static const uint16_t sContentSpecifiedMaxLengthMessage;
40 virtual ~nsIConstraintValidation();
42 bool IsValid() const { return mValidityBitField == 0; }
44 bool IsCandidateForConstraintValidation() const {
45 return !mBarredFromConstraintValidation;
48 enum ValidityStateType {
49 VALIDITY_STATE_VALUE_MISSING = 0x1 << 0,
50 VALIDITY_STATE_TYPE_MISMATCH = 0x1 << 1,
51 VALIDITY_STATE_PATTERN_MISMATCH = 0x1 << 2,
52 VALIDITY_STATE_TOO_LONG = 0x1 << 3,
53 VALIDITY_STATE_TOO_SHORT = 0x1 << 4,
54 VALIDITY_STATE_RANGE_UNDERFLOW = 0x1 << 5,
55 VALIDITY_STATE_RANGE_OVERFLOW = 0x1 << 6,
56 VALIDITY_STATE_STEP_MISMATCH = 0x1 << 7,
57 VALIDITY_STATE_BAD_INPUT = 0x1 << 8,
58 VALIDITY_STATE_CUSTOM_ERROR = 0x1 << 9,
61 void SetValidityState(ValidityStateType aState, bool aValue);
63 /**
64 * Check the validity of this object. If it is not valid, file a "invalid"
65 * event on the aEventTarget.
67 * @param aEventTarget The target of the event.
68 * @param aDefaultAction Set to true if default action should be taken,
69 * see EventTarget::DispatchEvent.
70 * @return whether it's valid.
72 bool CheckValidity(nsIContent& aEventTarget,
73 bool* aEventDefaultAction = nullptr) const;
75 // Web IDL binding methods
76 bool WillValidate() const { return IsCandidateForConstraintValidation(); }
77 mozilla::dom::ValidityState* Validity();
78 bool ReportValidity();
80 protected:
81 // You can't instantiate an object from that class.
82 nsIConstraintValidation();
84 bool GetValidityState(ValidityStateType aState) const {
85 return mValidityBitField & aState;
88 void SetBarredFromConstraintValidation(bool aBarred);
90 /**
91 * A pointer to the ValidityState object.
93 RefPtr<mozilla::dom::ValidityState> mValidity;
95 private:
96 /**
97 * A bitfield representing the current validity state of the element.
98 * Each bit represent an error. All bits to zero means the element is valid.
100 int16_t mValidityBitField;
103 * Keeps track whether the element is barred from constraint validation.
105 bool mBarredFromConstraintValidation;
108 NS_DEFINE_STATIC_IID_ACCESSOR(nsIConstraintValidation,
109 NS_ICONSTRAINTVALIDATION_IID)
111 #endif // nsIConstraintValidation_h___