tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

NumericInputTypes.h (2363B)


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