Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/html/RadioNodeList.cpp
Line
Count
Source (jump to first uncovered line)
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
#include "mozilla/dom/RadioNodeList.h"
8
9
#include "mozilla/dom/BindingUtils.h"
10
#include "mozilla/dom/RadioNodeListBinding.h"
11
#include "js/TypeDecls.h"
12
13
#include "HTMLInputElement.h"
14
15
namespace mozilla {
16
namespace dom {
17
18
/* virtual */ JSObject*
19
RadioNodeList::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
20
0
{
21
0
  return RadioNodeList_Binding::Wrap(aCx, this, aGivenProto);
22
0
}
23
24
HTMLInputElement*
25
GetAsRadio(nsIContent* node)
26
0
{
27
0
  HTMLInputElement* el = HTMLInputElement::FromNode(node);
28
0
  if (el && el->ControlType() == NS_FORM_INPUT_RADIO) {
29
0
    return el;
30
0
  }
31
0
  return nullptr;
32
0
}
33
34
void
35
RadioNodeList::GetValue(nsString& retval, CallerType aCallerType)
36
0
{
37
0
  for (uint32_t i = 0; i < Length(); i++) {
38
0
    HTMLInputElement* maybeRadio = GetAsRadio(Item(i));
39
0
    if (maybeRadio && maybeRadio->Checked()) {
40
0
      maybeRadio->GetValue(retval, aCallerType);
41
0
      return;
42
0
    }
43
0
  }
44
0
  retval.Truncate();
45
0
}
46
47
void
48
RadioNodeList::SetValue(const nsAString& value, CallerType aCallerType)
49
0
{
50
0
  for (uint32_t i = 0; i < Length(); i++) {
51
0
52
0
    HTMLInputElement* maybeRadio = GetAsRadio(Item(i));
53
0
    if (!maybeRadio) {
54
0
      continue;
55
0
    }
56
0
57
0
    nsString curval = nsString();
58
0
    maybeRadio->GetValue(curval, aCallerType);
59
0
    if (curval.Equals(value)) {
60
0
      maybeRadio->SetChecked(true);
61
0
      return;
62
0
    }
63
0
64
0
  }
65
0
}
66
67
NS_IMPL_ISUPPORTS_INHERITED(RadioNodeList, nsSimpleContentList, RadioNodeList)
68
69
} // namespace dom
70
} // namespace mozilla