Line data Source code
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 NumericInputTypes_h__
8 : #define NumericInputTypes_h__
9 :
10 : #include "InputType.h"
11 :
12 : class NumericInputTypeBase : public ::InputType
13 : {
14 : public:
15 0 : ~NumericInputTypeBase() override {}
16 :
17 : bool IsRangeOverflow() const override;
18 : bool IsRangeUnderflow() const override;
19 : bool HasStepMismatch(bool aUseZeroIfValueNaN) const override;
20 :
21 : nsresult GetRangeOverflowMessage(nsXPIDLString& aMessage) override;
22 : nsresult GetRangeUnderflowMessage(nsXPIDLString& aMessage) override;
23 :
24 : bool ConvertStringToNumber(nsAString& aValue,
25 : mozilla::Decimal& aResultValue) const override;
26 : bool ConvertNumberToString(mozilla::Decimal aValue,
27 : nsAString& aResultString) const override;
28 :
29 : protected:
30 0 : explicit NumericInputTypeBase(mozilla::dom::HTMLInputElement* aInputElement)
31 0 : : InputType(aInputElement)
32 0 : {}
33 : };
34 :
35 : // input type=number
36 0 : class NumberInputType : public NumericInputTypeBase
37 : {
38 : public:
39 : static InputType*
40 0 : Create(mozilla::dom::HTMLInputElement* aInputElement, void* aMemory)
41 : {
42 0 : return new (aMemory) NumberInputType(aInputElement);
43 : }
44 :
45 : bool IsValueMissing() const override;
46 : bool HasBadInput() const override;
47 :
48 : nsresult GetValueMissingMessage(nsXPIDLString& aMessage) override;
49 : nsresult GetBadInputMessage(nsXPIDLString& aMessage) override;
50 :
51 : protected:
52 : bool IsMutable() const override;
53 :
54 : private:
55 0 : explicit NumberInputType(mozilla::dom::HTMLInputElement* aInputElement)
56 0 : : NumericInputTypeBase(aInputElement)
57 0 : {}
58 : };
59 :
60 : // input type=range
61 0 : class RangeInputType : public NumericInputTypeBase
62 : {
63 : public:
64 : static InputType*
65 0 : Create(mozilla::dom::HTMLInputElement* aInputElement, void* aMemory)
66 : {
67 0 : return new (aMemory) RangeInputType(aInputElement);
68 : }
69 :
70 : nsresult MinMaxStepAttrChanged() override;
71 :
72 : private:
73 0 : explicit RangeInputType(mozilla::dom::HTMLInputElement* aInputElement)
74 0 : : NumericInputTypeBase(aInputElement)
75 0 : {}
76 : };
77 :
78 : #endif /* NumericInputTypes_h__ */
|