2013-04-13 00:08:49 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07: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 11:28:08 -07:00
|
|
|
|
2013-01-06 11:20:02 -08:00
|
|
|
#ifndef mozilla_dom_ValidityState_h
|
|
|
|
#define mozilla_dom_ValidityState_h
|
2010-08-18 11:28:08 -07:00
|
|
|
|
|
|
|
#include "nsIDOMValidityState.h"
|
2010-08-21 11:52:49 -07:00
|
|
|
#include "nsIConstraintValidation.h"
|
2013-01-16 10:01:01 -08:00
|
|
|
#include "nsWrapperCache.h"
|
2013-08-27 19:59:14 -07:00
|
|
|
#include "js/TypeDecls.h"
|
2010-08-18 11:28:08 -07:00
|
|
|
|
2013-01-06 11:20:02 -08:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2010-08-18 11:28:08 -07:00
|
|
|
|
2013-01-16 10:01:01 -08:00
|
|
|
class ValidityState MOZ_FINAL : public nsIDOMValidityState,
|
|
|
|
public nsWrapperCache
|
2010-08-18 11:28:08 -07:00
|
|
|
{
|
2014-06-24 19:09:15 -07:00
|
|
|
~ValidityState() {}
|
|
|
|
|
2010-08-18 11:28:08 -07:00
|
|
|
public:
|
2013-01-16 10:01:01 -08:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(ValidityState)
|
2010-08-18 11:28:08 -07:00
|
|
|
NS_DECL_NSIDOMVALIDITYSTATE
|
|
|
|
|
2013-01-06 11:20:02 -08:00
|
|
|
friend class ::nsIConstraintValidation;
|
2010-08-18 11:28:08 -07:00
|
|
|
|
2013-01-16 10:01:01 -08:00
|
|
|
nsIConstraintValidation* GetParentObject() const {
|
|
|
|
return mConstraintValidation;
|
|
|
|
}
|
|
|
|
|
2014-04-08 15:27:18 -07:00
|
|
|
virtual JSObject* WrapObject(JSContext *aCx) MOZ_OVERRIDE;
|
2013-01-16 10:01:01 -08:00
|
|
|
|
|
|
|
// Web IDL methods
|
|
|
|
bool ValueMissing() const
|
|
|
|
{
|
|
|
|
return GetValidityState(nsIConstraintValidation::VALIDITY_STATE_VALUE_MISSING);
|
|
|
|
}
|
|
|
|
bool TypeMismatch() const
|
|
|
|
{
|
|
|
|
return GetValidityState(nsIConstraintValidation::VALIDITY_STATE_TYPE_MISMATCH);
|
|
|
|
}
|
|
|
|
bool PatternMismatch() const
|
|
|
|
{
|
|
|
|
return GetValidityState(nsIConstraintValidation::VALIDITY_STATE_PATTERN_MISMATCH);
|
|
|
|
}
|
|
|
|
bool TooLong() const
|
|
|
|
{
|
|
|
|
return GetValidityState(nsIConstraintValidation::VALIDITY_STATE_TOO_LONG);
|
|
|
|
}
|
|
|
|
bool RangeUnderflow() const
|
|
|
|
{
|
|
|
|
return GetValidityState(nsIConstraintValidation::VALIDITY_STATE_RANGE_UNDERFLOW);
|
|
|
|
}
|
|
|
|
bool RangeOverflow() const
|
|
|
|
{
|
|
|
|
return GetValidityState(nsIConstraintValidation::VALIDITY_STATE_RANGE_OVERFLOW);
|
|
|
|
}
|
|
|
|
bool StepMismatch() const
|
|
|
|
{
|
|
|
|
return GetValidityState(nsIConstraintValidation::VALIDITY_STATE_STEP_MISMATCH);
|
|
|
|
}
|
2014-01-30 04:54:12 -08:00
|
|
|
bool BadInput() const
|
|
|
|
{
|
|
|
|
return GetValidityState(nsIConstraintValidation::VALIDITY_STATE_BAD_INPUT);
|
|
|
|
}
|
2013-01-16 10:01:01 -08:00
|
|
|
bool CustomError() const
|
|
|
|
{
|
|
|
|
return GetValidityState(nsIConstraintValidation::VALIDITY_STATE_CUSTOM_ERROR);
|
|
|
|
}
|
|
|
|
bool Valid() const
|
|
|
|
{
|
|
|
|
return !mConstraintValidation || mConstraintValidation->IsValid();
|
|
|
|
}
|
|
|
|
|
2010-08-18 11:28:08 -07:00
|
|
|
protected:
|
2014-08-05 06:19:51 -07:00
|
|
|
explicit ValidityState(nsIConstraintValidation* aConstraintValidation);
|
2010-08-21 10:52:57 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper function to get a validity state from constraint validation instance.
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
inline bool GetValidityState(nsIConstraintValidation::ValidityStateType aState) const
|
2010-08-21 10:52:57 -07:00
|
|
|
{
|
|
|
|
return mConstraintValidation &&
|
|
|
|
mConstraintValidation->GetValidityState(aState);
|
|
|
|
}
|
2010-08-18 11:28:08 -07:00
|
|
|
|
2013-05-23 16:07:34 -07:00
|
|
|
nsCOMPtr<nsIConstraintValidation> mConstraintValidation;
|
2010-08-18 11:28:08 -07:00
|
|
|
};
|
|
|
|
|
2013-01-06 11:20:02 -08:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_ValidityState_h
|
2010-08-18 11:28:08 -07:00
|
|
|
|