RadioGroupContainer.h (2513B)
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_nsRadioGroupStruct_h 8 #define mozilla_dom_nsRadioGroupStruct_h 9 10 #include "nsClassHashtable.h" 11 12 class nsIContent; 13 14 namespace mozilla::dom { 15 16 class HTMLInputElement; 17 struct nsRadioGroupStruct; 18 19 class RadioGroupContainer final { 20 public: 21 RadioGroupContainer(); 22 ~RadioGroupContainer(); 23 24 static void Traverse(RadioGroupContainer* tmp, 25 nsCycleCollectionTraversalCallback& cb); 26 size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const; 27 28 template <typename VisitCallback> 29 void WalkRadioGroup(const nsAString& aName, VisitCallback&& aCallback, 30 const HTMLInputElement* aExcludedElement) { 31 nsRadioGroupStruct* radioGroup = GetOrCreateRadioGroup(aName); 32 for (HTMLInputElement* button : GetButtonsInGroup(radioGroup)) { 33 if (button != aExcludedElement && !aCallback(button)) { 34 return; 35 } 36 } 37 } 38 39 void SetCurrentRadioButton(const nsAString& aName, HTMLInputElement* aRadio); 40 HTMLInputElement* GetCurrentRadioButton(const nsAString& aName); 41 nsresult GetNextRadioButton(const nsAString& aName, const bool aPrevious, 42 HTMLInputElement* aFocusedRadio, 43 HTMLInputElement** aRadioOut); 44 HTMLInputElement* GetFirstRadioButton(const nsAString& aName); 45 void AddToRadioGroup(const nsAString& aName, HTMLInputElement* aRadio, 46 nsIContent* aAncestor); 47 void RemoveFromRadioGroup(const nsAString& aName, HTMLInputElement* aRadio); 48 uint32_t GetRequiredRadioCount(const nsAString& aName) const; 49 void RadioRequiredWillChange(const nsAString& aName, bool aRequiredAdded); 50 bool GetValueMissingState(const nsAString& aName) const; 51 void SetValueMissingState(const nsAString& aName, bool aValue); 52 53 // for radio group 54 nsRadioGroupStruct* GetRadioGroup(const nsAString& aName) const; 55 nsRadioGroupStruct* GetOrCreateRadioGroup(const nsAString& aName); 56 57 private: 58 Span<const RefPtr<HTMLInputElement>> GetButtonsInGroup( 59 nsRadioGroupStruct* aGroup) const; 60 61 nsClassHashtable<nsStringHashKey, nsRadioGroupStruct> mRadioGroups; 62 }; 63 64 } // namespace mozilla::dom 65 66 #endif // mozilla_dom_nsRadioGroupStruct_h