1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef mozilla_dom_NumericInputTypes_h__ 8 #define mozilla_dom_NumericInputTypes_h__ 9 10 #include "mozilla/dom/InputType.h" 11 12 namespace mozilla { 13 namespace dom { 14 15 class NumericInputTypeBase : public InputType { 16 public: 17 ~NumericInputTypeBase() override = default; 18 19 bool IsRangeOverflow() const override; 20 bool IsRangeUnderflow() const override; 21 bool HasStepMismatch(bool aUseZeroIfValueNaN) const override; 22 23 nsresult GetRangeOverflowMessage(nsAString& aMessage) override; 24 nsresult GetRangeUnderflowMessage(nsAString& aMessage) override; 25 26 bool ConvertStringToNumber(nsAString& aValue, 27 Decimal& aResultValue) const override; 28 bool ConvertNumberToString(Decimal aValue, 29 nsAString& aResultString) const override; 30 31 protected: NumericInputTypeBase(HTMLInputElement * aInputElement)32 explicit NumericInputTypeBase(HTMLInputElement* aInputElement) 33 : InputType(aInputElement) {} 34 }; 35 36 // input type=number 37 class NumberInputType final : public NumericInputTypeBase { 38 public: Create(HTMLInputElement * aInputElement,void * aMemory)39 static InputType* Create(HTMLInputElement* aInputElement, void* aMemory) { 40 return new (aMemory) NumberInputType(aInputElement); 41 } 42 43 bool IsValueMissing() const override; 44 bool HasBadInput() const override; 45 46 nsresult GetValueMissingMessage(nsAString& aMessage) override; 47 nsresult GetBadInputMessage(nsAString& aMessage) override; 48 49 bool ConvertNumberToString(Decimal aValue, 50 nsAString& aResultString) const override; 51 52 protected: 53 bool IsMutable() const override; 54 55 private: NumberInputType(HTMLInputElement * aInputElement)56 explicit NumberInputType(HTMLInputElement* aInputElement) 57 : NumericInputTypeBase(aInputElement) {} 58 }; 59 60 // input type=range 61 class RangeInputType : public NumericInputTypeBase { 62 public: Create(HTMLInputElement * aInputElement,void * aMemory)63 static InputType* Create(HTMLInputElement* aInputElement, void* aMemory) { 64 return new (aMemory) RangeInputType(aInputElement); 65 } 66 67 MOZ_CAN_RUN_SCRIPT 68 nsresult MinMaxStepAttrChanged() override; 69 70 private: RangeInputType(HTMLInputElement * aInputElement)71 explicit RangeInputType(HTMLInputElement* aInputElement) 72 : NumericInputTypeBase(aInputElement) {} 73 }; 74 75 } // namespace dom 76 } // namespace mozilla 77 78 #endif /* mozilla_dom_NumericInputTypes_h__ */ 79