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"
19 JSObject
* RadioNodeList::WrapObject(JSContext
* aCx
,
20 JS::Handle
<JSObject
*> aGivenProto
) {
21 return RadioNodeList_Binding::Wrap(aCx
, this, aGivenProto
);
24 HTMLInputElement
* GetAsRadio(nsIContent
* node
) {
25 HTMLInputElement
* el
= HTMLInputElement::FromNode(node
);
26 if (el
&& el
->ControlType() == NS_FORM_INPUT_RADIO
) {
32 void RadioNodeList::GetValue(nsString
& retval
, CallerType aCallerType
) {
33 for (uint32_t i
= 0; i
< Length(); i
++) {
34 HTMLInputElement
* maybeRadio
= GetAsRadio(Item(i
));
35 if (maybeRadio
&& maybeRadio
->Checked()) {
36 maybeRadio
->GetValue(retval
, aCallerType
);
43 void RadioNodeList::SetValue(const nsAString
& value
, CallerType aCallerType
) {
44 for (uint32_t i
= 0; i
< Length(); i
++) {
45 HTMLInputElement
* maybeRadio
= GetAsRadio(Item(i
));
50 nsString curval
= nsString();
51 maybeRadio
->GetValue(curval
, aCallerType
);
52 if (curval
.Equals(value
)) {
53 maybeRadio
->SetChecked(true);
59 NS_IMPL_ISUPPORTS_INHERITED(RadioNodeList
, nsSimpleContentList
, RadioNodeList
)
62 } // namespace mozilla