2015-05-03 19:32:37 +00: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 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
|
|
|
|
2013-01-06 19:20:02 +00:00
|
|
|
#ifndef mozilla_dom_ValidityState_h
|
|
|
|
#define mozilla_dom_ValidityState_h
|
2010-08-18 18:28:08 +00:00
|
|
|
|
|
|
|
#include "nsIDOMValidityState.h"
|
2010-08-21 18:52:49 +00:00
|
|
|
#include "nsIConstraintValidation.h"
|
2013-01-16 18:01:01 +00:00
|
|
|
#include "nsWrapperCache.h"
|
2013-08-28 02:59:14 +00:00
|
|
|
#include "js/TypeDecls.h"
|
2010-08-18 18:28:08 +00:00
|
|
|
|
2013-01-06 19:20:02 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2010-08-18 18:28:08 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class ValidityState final : public nsIDOMValidityState,
|
2015-03-27 18:52:19 +00:00
|
|
|
public nsWrapperCache
|
2010-08-18 18:28:08 +00:00
|
|
|
{
|
2014-06-25 02:09:15 +00:00
|
|
|
~ValidityState() {}
|
|
|
|
|
2010-08-18 18:28:08 +00:00
|
|
|
public:
|
2013-01-16 18:01:01 +00:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(ValidityState)
|
2010-08-18 18:28:08 +00:00
|
|
|
NS_DECL_NSIDOMVALIDITYSTATE
|
|
|
|
|
2013-01-06 19:20:02 +00:00
|
|
|
friend class ::nsIConstraintValidation;
|
2010-08-18 18:28:08 +00:00
|
|
|
|
2013-01-16 18:01:01 +00:00
|
|
|
nsIConstraintValidation* GetParentObject() const {
|
|
|
|
return mConstraintValidation;
|
|
|
|
}
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual JSObject* WrapObject(JSContext *aCx, JS::Handle<JSObject*> aGivenProto) override;
|
2013-01-16 18:01:01 +00: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 12:54:12 +00:00
|
|
|
bool BadInput() const
|
|
|
|
{
|
|
|
|
return GetValidityState(nsIConstraintValidation::VALIDITY_STATE_BAD_INPUT);
|
|
|
|
}
|
2013-01-16 18:01:01 +00:00
|
|
|
bool CustomError() const
|
|
|
|
{
|
|
|
|
return GetValidityState(nsIConstraintValidation::VALIDITY_STATE_CUSTOM_ERROR);
|
|
|
|
}
|
|
|
|
bool Valid() const
|
|
|
|
{
|
|
|
|
return !mConstraintValidation || mConstraintValidation->IsValid();
|
|
|
|
}
|
|
|
|
|
2010-08-18 18:28:08 +00:00
|
|
|
protected:
|
2014-08-05 13:19:51 +00:00
|
|
|
explicit ValidityState(nsIConstraintValidation* aConstraintValidation);
|
2010-08-21 17:52:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper function to get a validity state from constraint validation instance.
|
|
|
|
*/
|
2011-09-29 06:19:26 +00:00
|
|
|
inline bool GetValidityState(nsIConstraintValidation::ValidityStateType aState) const
|
2010-08-21 17:52:57 +00:00
|
|
|
{
|
|
|
|
return mConstraintValidation &&
|
|
|
|
mConstraintValidation->GetValidityState(aState);
|
|
|
|
}
|
2010-08-18 18:28:08 +00:00
|
|
|
|
2013-05-23 23:07:34 +00:00
|
|
|
nsCOMPtr<nsIConstraintValidation> mConstraintValidation;
|
2010-08-18 18:28:08 +00:00
|
|
|
};
|
|
|
|
|
2013-01-06 19:20:02 +00:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_ValidityState_h
|
2010-08-18 18:28:08 +00:00
|
|
|
|