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