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/. */
7 #include "mozilla/dom/RadioNodeList.h"
9 #include "mozilla/dom/BindingUtils.h"
10 #include "mozilla/dom/RadioNodeListBinding.h"
11 #include "js/TypeDecls.h"
13 #include "HTMLInputElement.h"
15 namespace mozilla::dom
{
18 JSObject
* RadioNodeList::WrapObject(JSContext
* aCx
,
19 JS::Handle
<JSObject
*> aGivenProto
) {
20 return RadioNodeList_Binding::Wrap(aCx
, this, aGivenProto
);
23 HTMLInputElement
* GetAsRadio(nsIContent
* node
) {
24 auto* el
= HTMLInputElement::FromNode(node
);
25 if (el
&& el
->ControlType() == FormControlType::InputRadio
) {
31 void RadioNodeList::GetValue(nsString
& retval
, CallerType aCallerType
) {
32 for (uint32_t i
= 0; i
< Length(); i
++) {
33 HTMLInputElement
* maybeRadio
= GetAsRadio(Item(i
));
34 if (maybeRadio
&& maybeRadio
->Checked()) {
35 maybeRadio
->GetValue(retval
, aCallerType
);
42 void RadioNodeList::SetValue(const nsAString
& value
, CallerType aCallerType
) {
43 for (uint32_t i
= 0; i
< Length(); i
++) {
44 HTMLInputElement
* maybeRadio
= GetAsRadio(Item(i
));
49 nsString curval
= nsString();
50 maybeRadio
->GetValue(curval
, aCallerType
);
51 if (curval
.Equals(value
)) {
52 maybeRadio
->SetChecked(true);
58 NS_IMPL_ISUPPORTS_INHERITED(RadioNodeList
, nsSimpleContentList
, RadioNodeList
)
60 } // namespace mozilla::dom