/src/mozilla-central/dom/html/nsIConstraintValidation.h
Line | Count | Source (jump to first uncovered line) |
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/. */ |
6 | | |
7 | | #ifndef nsIConstraintValidition_h___ |
8 | | #define nsIConstraintValidition_h___ |
9 | | |
10 | | #include "nsISupports.h" |
11 | | #include "nsString.h" |
12 | | |
13 | | namespace mozilla { |
14 | | class ErrorResult; |
15 | | namespace dom { |
16 | | class ValidityState; |
17 | | } // namespace dom |
18 | | } // namespace mozilla |
19 | | |
20 | | #define NS_ICONSTRAINTVALIDATION_IID \ |
21 | | { 0x983829da, 0x1aaf, 0x449c, \ |
22 | | { 0xa3, 0x06, 0x85, 0xd4, 0xf0, 0x31, 0x1c, 0xf6 } } |
23 | | |
24 | | /** |
25 | | * This interface is for form elements implementing the validity constraint API. |
26 | | * See: http://dev.w3.org/html5/spec/forms.html#the-constraint-validation-api |
27 | | * |
28 | | * This interface has to be implemented by all elements implementing the API |
29 | | * and only them. |
30 | | */ |
31 | | class nsIConstraintValidation : public nsISupports |
32 | | { |
33 | | public: |
34 | | |
35 | | NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICONSTRAINTVALIDATION_IID); |
36 | | |
37 | | friend class mozilla::dom::ValidityState; |
38 | | |
39 | | static const uint16_t sContentSpecifiedMaxLengthMessage; |
40 | | |
41 | | virtual ~nsIConstraintValidation(); |
42 | | |
43 | 0 | bool IsValid() const { return mValidityBitField == 0; } |
44 | | |
45 | 0 | bool IsCandidateForConstraintValidation() const { |
46 | 0 | return !mBarredFromConstraintValidation; |
47 | 0 | } |
48 | | |
49 | | void GetValidationMessage(nsAString& aValidationMessage, |
50 | | mozilla::ErrorResult& aError); |
51 | | |
52 | | enum ValidityStateType |
53 | | { |
54 | | VALIDITY_STATE_VALUE_MISSING = 0x1 << 0, |
55 | | VALIDITY_STATE_TYPE_MISMATCH = 0x1 << 1, |
56 | | VALIDITY_STATE_PATTERN_MISMATCH = 0x1 << 2, |
57 | | VALIDITY_STATE_TOO_LONG = 0x1 << 3, |
58 | | VALIDITY_STATE_TOO_SHORT = 0x1 << 4, |
59 | | VALIDITY_STATE_RANGE_UNDERFLOW = 0x1 << 5, |
60 | | VALIDITY_STATE_RANGE_OVERFLOW = 0x1 << 6, |
61 | | VALIDITY_STATE_STEP_MISMATCH = 0x1 << 7, |
62 | | VALIDITY_STATE_BAD_INPUT = 0x1 << 8, |
63 | | VALIDITY_STATE_CUSTOM_ERROR = 0x1 << 9, |
64 | | }; |
65 | | |
66 | | void SetValidityState(ValidityStateType aState, |
67 | | bool aValue); |
68 | | |
69 | | // Web IDL binding methods |
70 | 0 | bool WillValidate() const { |
71 | 0 | return IsCandidateForConstraintValidation(); |
72 | 0 | } |
73 | | mozilla::dom::ValidityState* Validity(); |
74 | | bool CheckValidity(); |
75 | | bool ReportValidity(); |
76 | | |
77 | | protected: |
78 | | |
79 | | // You can't instantiate an object from that class. |
80 | | nsIConstraintValidation(); |
81 | | |
82 | | nsresult CheckValidity(bool* aValidity); |
83 | | void SetCustomValidity(const nsAString& aError); |
84 | | |
85 | | bool GetValidityState(ValidityStateType aState) const |
86 | 0 | { |
87 | 0 | return mValidityBitField & aState; |
88 | 0 | } |
89 | | |
90 | | void SetBarredFromConstraintValidation(bool aBarred); |
91 | | |
92 | | virtual nsresult GetValidationMessage(nsAString& aValidationMessage, |
93 | 0 | ValidityStateType aType) { |
94 | 0 | return NS_OK; |
95 | 0 | } |
96 | | |
97 | | protected: |
98 | | /** |
99 | | * A pointer to the ValidityState object. |
100 | | */ |
101 | | RefPtr<mozilla::dom::ValidityState> mValidity; |
102 | | |
103 | | private: |
104 | | |
105 | | /** |
106 | | * A bitfield representing the current validity state of the element. |
107 | | * Each bit represent an error. All bits to zero means the element is valid. |
108 | | */ |
109 | | int16_t mValidityBitField; |
110 | | |
111 | | /** |
112 | | * Keeps track whether the element is barred from constraint validation. |
113 | | */ |
114 | | bool mBarredFromConstraintValidation; |
115 | | |
116 | | /** |
117 | | * The string representing the custom error. |
118 | | */ |
119 | | nsString mCustomValidity; |
120 | | }; |
121 | | |
122 | | NS_DEFINE_STATIC_IID_ACCESSOR(nsIConstraintValidation, |
123 | | NS_ICONSTRAINTVALIDATION_IID) |
124 | | |
125 | | #endif // nsIConstraintValidation_h___ |
126 | | |