CheckableInputTypes.h (1657B)
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_CheckableInputTypes_h__ 8 #define mozilla_dom_CheckableInputTypes_h__ 9 10 #include "mozilla/dom/InputType.h" 11 12 namespace mozilla::dom { 13 14 class CheckableInputTypeBase : public InputType { 15 public: 16 ~CheckableInputTypeBase() override = default; 17 18 protected: 19 explicit CheckableInputTypeBase(HTMLInputElement* aInputElement) 20 : InputType(aInputElement) {} 21 }; 22 23 // input type=checkbox 24 class CheckboxInputType : public CheckableInputTypeBase { 25 public: 26 static InputType* Create(HTMLInputElement* aInputElement, void* aMemory) { 27 return new (aMemory) CheckboxInputType(aInputElement); 28 } 29 30 bool IsValueMissing() const override; 31 32 nsresult GetValueMissingMessage(nsAString& aMessage) override; 33 34 private: 35 explicit CheckboxInputType(HTMLInputElement* aInputElement) 36 : CheckableInputTypeBase(aInputElement) {} 37 }; 38 39 // input type=radio 40 class RadioInputType : public CheckableInputTypeBase { 41 public: 42 static InputType* Create(HTMLInputElement* aInputElement, void* aMemory) { 43 return new (aMemory) RadioInputType(aInputElement); 44 } 45 46 nsresult GetValueMissingMessage(nsAString& aMessage) override; 47 48 private: 49 explicit RadioInputType(HTMLInputElement* aInputElement) 50 : CheckableInputTypeBase(aInputElement) {} 51 }; 52 53 } // namespace mozilla::dom 54 55 #endif /* mozilla_dom_CheckableInputTypes_h__ */