2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04: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 22:28:08 +04:00
|
|
|
|
2010-08-21 22:52:49 +04:00
|
|
|
#ifndef nsIConstraintValidition_h___
|
|
|
|
#define nsIConstraintValidition_h___
|
2010-08-18 22:28:08 +04:00
|
|
|
|
2010-08-21 22:51:38 +04:00
|
|
|
#include "nsISupports.h"
|
2010-08-18 22:28:08 +04:00
|
|
|
#include "nsString.h"
|
|
|
|
|
2010-08-21 21:52:57 +04:00
|
|
|
class nsIDOMValidityState;
|
2010-08-18 22:28:08 +04:00
|
|
|
|
2013-01-06 23:20:02 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
class ValidityState;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2013-01-06 23:20:02 +04:00
|
|
|
|
2010-08-21 22:52:49 +04:00
|
|
|
#define NS_ICONSTRAINTVALIDATION_IID \
|
2014-01-30 16:54:12 +04:00
|
|
|
{ 0x983829da, 0x1aaf, 0x449c, \
|
|
|
|
{ 0xa3, 0x06, 0x85, 0xd4, 0xf0, 0x31, 0x1c, 0xf6 } }
|
2010-08-21 22:51:38 +04:00
|
|
|
|
2010-08-18 22:28:08 +04:00
|
|
|
/**
|
2010-08-21 22:52:49 +04:00
|
|
|
* This interface is for form elements implementing the validity constraint API.
|
2010-08-18 22:28:08 +04:00
|
|
|
* See: http://dev.w3.org/html5/spec/forms.html#the-constraint-validation-api
|
2010-08-21 21:52:57 +04:00
|
|
|
*
|
2010-08-21 22:52:49 +04:00
|
|
|
* This interface has to be implemented by all elements implementing the API
|
|
|
|
* and only them.
|
2010-08-18 22:28:08 +04:00
|
|
|
*/
|
2010-08-21 22:52:49 +04:00
|
|
|
class nsIConstraintValidation : public nsISupports
|
2010-08-18 22:28:08 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2010-08-21 22:52:49 +04:00
|
|
|
NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICONSTRAINTVALIDATION_IID);
|
2010-08-21 22:51:38 +04:00
|
|
|
|
2013-01-06 23:20:02 +04:00
|
|
|
friend class mozilla::dom::ValidityState;
|
2010-08-21 21:52:57 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
static const uint16_t sContentSpecifiedMaxLengthMessage;
|
2010-10-26 02:02:24 +04:00
|
|
|
|
2010-08-21 22:52:49 +04:00
|
|
|
virtual ~nsIConstraintValidation();
|
2010-08-18 22:28:08 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsValid() const { return mValidityBitField == 0; }
|
2010-08-21 22:51:38 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsCandidateForConstraintValidation() const {
|
2010-09-10 09:08:56 +04:00
|
|
|
return !mBarredFromConstraintValidation;
|
|
|
|
}
|
2010-08-21 22:51:38 +04:00
|
|
|
|
2010-08-27 09:46:17 +04:00
|
|
|
NS_IMETHOD GetValidationMessage(nsAString& aValidationMessage);
|
|
|
|
|
2010-08-21 21:52:57 +04:00
|
|
|
enum ValidityStateType
|
|
|
|
{
|
2014-01-30 16:54:12 +04: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 21:52:57 +04:00
|
|
|
};
|
|
|
|
|
2016-01-27 19:14:16 +03:00
|
|
|
void SetValidityState(ValidityStateType aState,
|
|
|
|
bool aValue);
|
2010-12-16 22:51:59 +03:00
|
|
|
|
2013-01-16 22:01:01 +04:00
|
|
|
// Web IDL binding methods
|
|
|
|
bool WillValidate() const {
|
|
|
|
return IsCandidateForConstraintValidation();
|
|
|
|
}
|
|
|
|
mozilla::dom::ValidityState* Validity();
|
|
|
|
bool CheckValidity();
|
2016-04-15 11:13:00 +03:00
|
|
|
bool ReportValidity();
|
2013-01-16 22:01:01 +04:00
|
|
|
|
2010-12-16 22:51:59 +03:00
|
|
|
protected:
|
|
|
|
|
2010-08-21 21:52:57 +04:00
|
|
|
// You can't instantiate an object from that class.
|
2010-08-21 22:52:49 +04:00
|
|
|
nsIConstraintValidation();
|
2010-08-21 21:52:57 +04:00
|
|
|
|
2010-08-18 22:28:08 +04:00
|
|
|
nsresult GetValidity(nsIDOMValidityState** aValidity);
|
2011-09-29 10:19:26 +04:00
|
|
|
nsresult CheckValidity(bool* aValidity);
|
2010-08-21 22:51:38 +04:00
|
|
|
void SetCustomValidity(const nsAString& aError);
|
2010-08-18 22:28:08 +04:00
|
|
|
|
2016-01-27 19:14:16 +03:00
|
|
|
bool GetValidityState(ValidityStateType aState) const
|
|
|
|
{
|
|
|
|
return mValidityBitField & aState;
|
|
|
|
}
|
2010-08-21 21:52:57 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
void SetBarredFromConstraintValidation(bool aBarred);
|
2010-08-18 22:28:08 +04:00
|
|
|
|
|
|
|
virtual nsresult GetValidationMessage(nsAString& aValidationMessage,
|
2010-08-21 21:52:57 +04:00
|
|
|
ValidityStateType aType) {
|
2010-08-18 22:28:08 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-01-16 22:01:01 +04:00
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* A pointer to the ValidityState object.
|
|
|
|
*/
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<mozilla::dom::ValidityState> mValidity;
|
2013-01-16 22:01:01 +04:00
|
|
|
|
2010-08-21 21:52:57 +04: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 16:54:12 +04:00
|
|
|
int16_t mValidityBitField;
|
2010-08-21 21:52:57 +04:00
|
|
|
|
2010-09-10 09:08:56 +04:00
|
|
|
/**
|
|
|
|
* Keeps track whether the element is barred from constraint validation.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mBarredFromConstraintValidation;
|
2010-09-10 09:08:56 +04:00
|
|
|
|
2010-08-21 21:52:57 +04:00
|
|
|
/**
|
|
|
|
* The string representing the custom error.
|
|
|
|
*/
|
2010-08-18 22:28:08 +04:00
|
|
|
nsString mCustomValidity;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2010-08-21 22:52:49 +04:00
|
|
|
* Use these macro for class inheriting from nsIConstraintValidation to forward
|
|
|
|
* functions to nsIConstraintValidation.
|
2010-08-18 22:28:08 +04:00
|
|
|
*/
|
2010-08-21 22:52:49 +04:00
|
|
|
#define NS_FORWARD_NSICONSTRAINTVALIDATION_EXCEPT_SETCUSTOMVALIDITY \
|
2010-08-18 22:28:08 +04:00
|
|
|
NS_IMETHOD GetValidity(nsIDOMValidityState** aValidity) { \
|
2010-08-21 22:52:49 +04:00
|
|
|
return nsIConstraintValidation::GetValidity(aValidity); \
|
2010-08-18 22:28:08 +04:00
|
|
|
} \
|
2013-01-16 22:01:01 +04:00
|
|
|
NS_IMETHOD GetWillValidate(bool* aWillValidate) { \
|
|
|
|
*aWillValidate = WillValidate(); \
|
2010-08-21 22:51:38 +04:00
|
|
|
return NS_OK; \
|
2010-08-18 22:28:08 +04:00
|
|
|
} \
|
|
|
|
NS_IMETHOD GetValidationMessage(nsAString& aValidationMessage) { \
|
2010-08-21 22:52:49 +04:00
|
|
|
return nsIConstraintValidation::GetValidationMessage(aValidationMessage); \
|
2010-08-18 22:28:08 +04:00
|
|
|
} \
|
2013-01-16 22:01:01 +04:00
|
|
|
using nsIConstraintValidation::CheckValidity; \
|
|
|
|
NS_IMETHOD CheckValidity(bool* aValidity) { \
|
2010-08-21 22:52:49 +04:00
|
|
|
return nsIConstraintValidation::CheckValidity(aValidity); \
|
2010-08-18 22:28:08 +04:00
|
|
|
}
|
|
|
|
|
2010-08-21 22:52:49 +04:00
|
|
|
#define NS_FORWARD_NSICONSTRAINTVALIDATION \
|
|
|
|
NS_FORWARD_NSICONSTRAINTVALIDATION_EXCEPT_SETCUSTOMVALIDITY \
|
2010-08-21 21:52:57 +04:00
|
|
|
NS_IMETHOD SetCustomValidity(const nsAString& aError) { \
|
2010-08-21 22:52:49 +04:00
|
|
|
nsIConstraintValidation::SetCustomValidity(aError); \
|
2010-08-21 22:51:38 +04:00
|
|
|
return NS_OK; \
|
2010-08-21 21:52:57 +04:00
|
|
|
}
|
2010-08-18 22:28:08 +04:00
|
|
|
|
2010-08-21 21:52:57 +04:00
|
|
|
|
2010-08-21 22:52:49 +04:00
|
|
|
/* Use these macro when class declares functions from nsIConstraintValidation */
|
|
|
|
#define NS_IMPL_NSICONSTRAINTVALIDATION_EXCEPT_SETCUSTOMVALIDITY(_from) \
|
2010-08-18 22:28:08 +04:00
|
|
|
NS_IMETHODIMP _from::GetValidity(nsIDOMValidityState** aValidity) { \
|
2010-08-21 22:52:49 +04:00
|
|
|
return nsIConstraintValidation::GetValidity(aValidity); \
|
2010-08-18 22:28:08 +04:00
|
|
|
} \
|
2013-01-16 22:01:01 +04:00
|
|
|
NS_IMETHODIMP _from::GetWillValidate(bool* aWillValidate) { \
|
|
|
|
*aWillValidate = WillValidate(); \
|
2010-08-21 22:51:38 +04:00
|
|
|
return NS_OK; \
|
2010-08-18 22:28:08 +04:00
|
|
|
} \
|
|
|
|
NS_IMETHODIMP _from::GetValidationMessage(nsAString& aValidationMessage) { \
|
2010-08-21 22:52:49 +04:00
|
|
|
return nsIConstraintValidation::GetValidationMessage(aValidationMessage); \
|
2010-08-18 22:28:08 +04:00
|
|
|
} \
|
2011-09-29 10:19:26 +04:00
|
|
|
NS_IMETHODIMP _from::CheckValidity(bool* aValidity) { \
|
2010-08-21 22:52:49 +04:00
|
|
|
return nsIConstraintValidation::CheckValidity(aValidity); \
|
2010-08-18 22:28:08 +04:00
|
|
|
}
|
|
|
|
|
2010-08-21 22:52:49 +04:00
|
|
|
#define NS_IMPL_NSICONSTRAINTVALIDATION(_from) \
|
|
|
|
NS_IMPL_NSICONSTRAINTVALIDATION_EXCEPT_SETCUSTOMVALIDITY(_from) \
|
2010-08-21 21:52:57 +04:00
|
|
|
NS_IMETHODIMP _from::SetCustomValidity(const nsAString& aError) { \
|
2010-08-21 22:52:49 +04:00
|
|
|
nsIConstraintValidation::SetCustomValidity(aError); \
|
2010-08-21 22:51:38 +04:00
|
|
|
return NS_OK; \
|
2010-08-21 21:52:57 +04:00
|
|
|
}
|
|
|
|
|
2010-08-21 22:52:49 +04:00
|
|
|
NS_DEFINE_STATIC_IID_ACCESSOR(nsIConstraintValidation,
|
|
|
|
NS_ICONSTRAINTVALIDATION_IID)
|
2010-08-18 22:28:08 +04:00
|
|
|
|
2010-08-21 22:52:49 +04:00
|
|
|
#endif // nsIConstraintValidation_h___
|
2010-08-18 22:28:08 +04:00
|
|
|
|