Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / dom / html / RadioNodeList.cpp
bloba6c0d559292a6cd10e21ae29986c564c3bc363d6
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 {
17 /* virtual */
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) {
26 return el;
28 return nullptr;
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);
36 return;
39 retval.Truncate();
42 void RadioNodeList::SetValue(const nsAString& value, CallerType aCallerType) {
43 for (uint32_t i = 0; i < Length(); i++) {
44 HTMLInputElement* maybeRadio = GetAsRadio(Item(i));
45 if (!maybeRadio) {
46 continue;
49 nsString curval = nsString();
50 maybeRadio->GetValue(curval, aCallerType);
51 if (curval.Equals(value)) {
52 maybeRadio->SetChecked(true);
53 return;
58 NS_IMPL_ISUPPORTS_INHERITED(RadioNodeList, nsSimpleContentList, RadioNodeList)
60 } // namespace mozilla::dom