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