2013-02-08 12:50:30 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-08-18 18:28:08 +00:00
|
|
|
|
2010-08-21 18:52:49 +00:00
|
|
|
#ifndef nsIConstraintValidition_h___
|
|
|
|
#define nsIConstraintValidition_h___
|
2010-08-18 18:28:08 +00:00
|
|
|
|
2010-08-21 18:51:38 +00:00
|
|
|
#include "nsISupports.h"
|
2010-08-18 18:28:08 +00:00
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
|
2010-08-21 17:52:57 +00:00
|
|
|
class nsIDOMValidityState;
|
2010-08-18 18:28:08 +00:00
|
|
|
|
2013-01-06 19:20:02 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
class ValidityState;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-21 18:52:49 +00:00
|
|
|
#define NS_ICONSTRAINTVALIDATION_IID \
|
2014-01-30 12:54:12 +00:00
|
|
|
{ 0x983829da, 0x1aaf, 0x449c, \
|
|
|
|
{ 0xa3, 0x06, 0x85, 0xd4, 0xf0, 0x31, 0x1c, 0xf6 } }
|
2010-08-21 18:51:38 +00:00
|
|
|
|
2010-08-18 18:28:08 +00:00
|
|
|
/**
|
2010-08-21 18:52:49 +00:00
|
|
|
* This interface is for form elements implementing the validity constraint API.
|
2010-08-18 18:28:08 +00:00
|
|
|
* See: http://dev.w3.org/html5/spec/forms.html#the-constraint-validation-api
|
2010-08-21 17:52:57 +00:00
|
|
|
*
|
2010-08-21 18:52:49 +00:00
|
|
|
* This interface has to be implemented by all elements implementing the API
|
|
|
|
* and only them.
|
2010-08-18 18:28:08 +00:00
|
|
|
*/
|
2010-08-21 18:52:49 +00:00
|
|
|
class nsIConstraintValidation : public nsISupports
|
2010-08-18 18:28:08 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2010-08-21 18:52:49 +00:00
|
|
|
NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICONSTRAINTVALIDATION_IID);
|
2010-08-21 18:51:38 +00:00
|
|
|
|
2013-01-06 19:20:02 +00:00
|
|
|
friend class mozilla::dom::ValidityState;
|
2010-08-21 17:52:57 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
static const uint16_t sContentSpecifiedMaxLengthMessage;
|
2010-10-25 22:02:24 +00:00
|
|
|
|
2010-08-21 18:52:49 +00:00
|
|
|
virtual ~nsIConstraintValidation();
|
2010-08-18 18:28:08 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool IsValid() const { return mValidityBitField == 0; }
|
2010-08-21 18:51:38 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool IsCandidateForConstraintValidation() const {
|
2010-09-10 05:08:56 +00:00
|
|
|
return !mBarredFromConstraintValidation;
|
|
|
|
}
|
2010-08-21 18:51:38 +00:00
|
|
|
|
2010-08-27 05:46:17 +00:00
|
|
|
NS_IMETHOD GetValidationMessage(nsAString& aValidationMessage);
|
|
|
|
|
2010-08-21 17:52:57 +00:00
|
|
|
enum ValidityStateType
|
|
|
|
{
|
2014-01-30 12:54:12 +00:00
|
|
|
VALIDITY_STATE_VALUE_MISSING = 0x1 << 0,
|
|
|
|
VALIDITY_STATE_TYPE_MISMATCH = 0x1 << 1,
|
|
|
|
VALIDITY_STATE_PATTERN_MISMATCH = 0x1 << 2,
|
|
|
|
VALIDITY_STATE_TOO_LONG = 0x1 << 3,
|
|
|
|
//VALIDITY_STATE_TOO_SHORT = 0x1 << 4,
|
|
|
|
VALIDITY_STATE_RANGE_UNDERFLOW = 0x1 << 5,
|
|
|
|
VALIDITY_STATE_RANGE_OVERFLOW = 0x1 << 6,
|
|
|
|
VALIDITY_STATE_STEP_MISMATCH = 0x1 << 7,
|
|
|
|
VALIDITY_STATE_BAD_INPUT = 0x1 << 8,
|
|
|
|
VALIDITY_STATE_CUSTOM_ERROR = 0x1 << 9,
|
2010-08-21 17:52:57 +00:00
|
|
|
};
|
|
|
|
|
2010-12-16 19:51:59 +00:00
|
|
|
void SetValidityState(ValidityStateType mState,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mValue);
|
2010-12-16 19:51:59 +00:00
|
|
|
|
2013-01-16 18:01:01 +00:00
|
|
|
// Web IDL binding methods
|
|
|
|
bool WillValidate() const {
|
|
|
|
return IsCandidateForConstraintValidation();
|
|
|
|
}
|
|
|
|
mozilla::dom::ValidityState* Validity();
|
|
|
|
bool CheckValidity();
|
|
|
|
|
2010-12-16 19:51:59 +00:00
|
|
|
protected:
|
|
|
|
|
2010-08-21 17:52:57 +00:00
|
|
|
// You can't instantiate an object from that class.
|
2010-08-21 18:52:49 +00:00
|
|
|
nsIConstraintValidation();
|
2010-08-21 17:52:57 +00:00
|
|
|
|
2010-08-18 18:28:08 +00:00
|
|
|
nsresult GetValidity(nsIDOMValidityState** aValidity);
|
2011-09-29 06:19:26 +00:00
|
|
|
nsresult CheckValidity(bool* aValidity);
|
2010-08-21 18:51:38 +00:00
|
|
|
void SetCustomValidity(const nsAString& aError);
|
2010-08-18 18:28:08 +00:00
|
|
|
|
2010-08-21 17:52:57 +00:00
|
|
|
bool GetValidityState(ValidityStateType mState) const {
|
|
|
|
return mValidityBitField & mState;
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
void SetBarredFromConstraintValidation(bool aBarred);
|
2010-08-18 18:28:08 +00:00
|
|
|
|
|
|
|
virtual nsresult GetValidationMessage(nsAString& aValidationMessage,
|
2010-08-21 17:52:57 +00:00
|
|
|
ValidityStateType aType) {
|
2010-08-18 18:28:08 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-01-16 18:01:01 +00:00
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* A pointer to the ValidityState object.
|
|
|
|
*/
|
|
|
|
nsRefPtr<mozilla::dom::ValidityState> mValidity;
|
|
|
|
|
2010-08-21 17:52:57 +00:00
|
|
|
private:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A bitfield representing the current validity state of the element.
|
|
|
|
* Each bit represent an error. All bits to zero means the element is valid.
|
|
|
|
*/
|
2014-01-30 12:54:12 +00:00
|
|
|
int16_t mValidityBitField;
|
2010-08-21 17:52:57 +00:00
|
|
|
|
2010-09-10 05:08:56 +00:00
|
|
|
/**
|
|
|
|
* Keeps track whether the element is barred from constraint validation.
|
|
|
|
*/
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mBarredFromConstraintValidation;
|
2010-09-10 05:08:56 +00:00
|
|
|
|
2010-08-21 17:52:57 +00:00
|
|
|
/**
|
|
|
|
* The string representing the custom error.
|
|
|
|
*/
|
2010-08-18 18:28:08 +00:00
|
|
|
nsString mCustomValidity;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2010-08-21 18:52:49 +00:00
|
|
|
* Use these macro for class inheriting from nsIConstraintValidation to forward
|
|
|
|
* functions to nsIConstraintValidation.
|
2010-08-18 18:28:08 +00:00
|
|
|
*/
|
2010-08-21 18:52:49 +00:00
|
|
|
#define NS_FORWARD_NSICONSTRAINTVALIDATION_EXCEPT_SETCUSTOMVALIDITY \
|
2010-08-18 18:28:08 +00:00
|
|
|
NS_IMETHOD GetValidity(nsIDOMValidityState** aValidity) { \
|
2010-08-21 18:52:49 +00:00
|
|
|
return nsIConstraintValidation::GetValidity(aValidity); \
|
2010-08-18 18:28:08 +00:00
|
|
|
} \
|
2013-01-16 18:01:01 +00:00
|
|
|
NS_IMETHOD GetWillValidate(bool* aWillValidate) { \
|
|
|
|
*aWillValidate = WillValidate(); \
|
2010-08-21 18:51:38 +00:00
|
|
|
return NS_OK; \
|
2010-08-18 18:28:08 +00:00
|
|
|
} \
|
|
|
|
NS_IMETHOD GetValidationMessage(nsAString& aValidationMessage) { \
|
2010-08-21 18:52:49 +00:00
|
|
|
return nsIConstraintValidation::GetValidationMessage(aValidationMessage); \
|
2010-08-18 18:28:08 +00:00
|
|
|
} \
|
2013-01-16 18:01:01 +00:00
|
|
|
using nsIConstraintValidation::CheckValidity; \
|
|
|
|
NS_IMETHOD CheckValidity(bool* aValidity) { \
|
2010-08-21 18:52:49 +00:00
|
|
|
return nsIConstraintValidation::CheckValidity(aValidity); \
|
2010-08-18 18:28:08 +00:00
|
|
|
}
|
|
|
|
|
2010-08-21 18:52:49 +00:00
|
|
|
#define NS_FORWARD_NSICONSTRAINTVALIDATION \
|
|
|
|
NS_FORWARD_NSICONSTRAINTVALIDATION_EXCEPT_SETCUSTOMVALIDITY \
|
2010-08-21 17:52:57 +00:00
|
|
|
NS_IMETHOD SetCustomValidity(const nsAString& aError) { \
|
2010-08-21 18:52:49 +00:00
|
|
|
nsIConstraintValidation::SetCustomValidity(aError); \
|
2010-08-21 18:51:38 +00:00
|
|
|
return NS_OK; \
|
2010-08-21 17:52:57 +00:00
|
|
|
}
|
2010-08-18 18:28:08 +00:00
|
|
|
|
2010-08-21 17:52:57 +00:00
|
|
|
|
2010-08-21 18:52:49 +00:00
|
|
|
/* Use these macro when class declares functions from nsIConstraintValidation */
|
|
|
|
#define NS_IMPL_NSICONSTRAINTVALIDATION_EXCEPT_SETCUSTOMVALIDITY(_from) \
|
2010-08-18 18:28:08 +00:00
|
|
|
NS_IMETHODIMP _from::GetValidity(nsIDOMValidityState** aValidity) { \
|
2010-08-21 18:52:49 +00:00
|
|
|
return nsIConstraintValidation::GetValidity(aValidity); \
|
2010-08-18 18:28:08 +00:00
|
|
|
} \
|
2013-01-16 18:01:01 +00:00
|
|
|
NS_IMETHODIMP _from::GetWillValidate(bool* aWillValidate) { \
|
|
|
|
*aWillValidate = WillValidate(); \
|
2010-08-21 18:51:38 +00:00
|
|
|
return NS_OK; \
|
2010-08-18 18:28:08 +00:00
|
|
|
} \
|
|
|
|
NS_IMETHODIMP _from::GetValidationMessage(nsAString& aValidationMessage) { \
|
2010-08-21 18:52:49 +00:00
|
|
|
return nsIConstraintValidation::GetValidationMessage(aValidationMessage); \
|
2010-08-18 18:28:08 +00:00
|
|
|
} \
|
2011-09-29 06:19:26 +00:00
|
|
|
NS_IMETHODIMP _from::CheckValidity(bool* aValidity) { \
|
2010-08-21 18:52:49 +00:00
|
|
|
return nsIConstraintValidation::CheckValidity(aValidity); \
|
2010-08-18 18:28:08 +00:00
|
|
|
}
|
|
|
|
|
2010-08-21 18:52:49 +00:00
|
|
|
#define NS_IMPL_NSICONSTRAINTVALIDATION(_from) \
|
|
|
|
NS_IMPL_NSICONSTRAINTVALIDATION_EXCEPT_SETCUSTOMVALIDITY(_from) \
|
2010-08-21 17:52:57 +00:00
|
|
|
NS_IMETHODIMP _from::SetCustomValidity(const nsAString& aError) { \
|
2010-08-21 18:52:49 +00:00
|
|
|
nsIConstraintValidation::SetCustomValidity(aError); \
|
2010-08-21 18:51:38 +00:00
|
|
|
return NS_OK; \
|
2010-08-21 17:52:57 +00:00
|
|
|
}
|
|
|
|
|
2010-08-21 18:52:49 +00:00
|
|
|
NS_DEFINE_STATIC_IID_ACCESSOR(nsIConstraintValidation,
|
|
|
|
NS_ICONSTRAINTVALIDATION_IID)
|
2010-08-18 18:28:08 +00:00
|
|
|
|
2010-08-21 18:52:49 +00:00
|
|
|
#endif // nsIConstraintValidation_h___
|
2010-08-18 18:28:08 +00:00
|
|
|
|