Bug 1560374 - Set testharness and reftest web-platform-tests to Tier-1; r=jmaher...
[gecko.git] / dom / html / RadioNodeList.cpp
blob1ff2d619e1d84b86ed76910593ac0a0044503118
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 {
16 namespace dom {
18 /* virtual */
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) {
27 return el;
29 return nullptr;
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);
37 return;
40 retval.Truncate();
43 void RadioNodeList::SetValue(const nsAString& value, CallerType aCallerType) {
44 for (uint32_t i = 0; i < Length(); i++) {
45 HTMLInputElement* maybeRadio = GetAsRadio(Item(i));
46 if (!maybeRadio) {
47 continue;
50 nsString curval = nsString();
51 maybeRadio->GetValue(curval, aCallerType);
52 if (curval.Equals(value)) {
53 maybeRadio->SetChecked(true);
54 return;
59 NS_IMPL_ISUPPORTS_INHERITED(RadioNodeList, nsSimpleContentList, RadioNodeList)
61 } // namespace dom
62 } // namespace mozilla