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 "nsRadioVisitor.h"
8 #include "mozilla/dom/HTMLInputElement.h"
9 #include "nsIConstraintValidation.h"
10 
11 using namespace mozilla::dom;
12 
NS_IMPL_ISUPPORTS(nsRadioVisitor,nsIRadioVisitor)13 NS_IMPL_ISUPPORTS(nsRadioVisitor, nsIRadioVisitor)
14 
15 bool nsRadioSetCheckedChangedVisitor::Visit(nsIFormControl* aRadio) {
16   RefPtr<HTMLInputElement> radio = static_cast<HTMLInputElement*>(aRadio);
17   NS_ASSERTION(radio, "Visit() passed a null button!");
18 
19   radio->SetCheckedChangedInternal(mCheckedChanged);
20   return true;
21 }
22 
Visit(nsIFormControl * aRadio)23 bool nsRadioGetCheckedChangedVisitor::Visit(nsIFormControl* aRadio) {
24   if (aRadio == mExcludeElement) {
25     return true;
26   }
27 
28   RefPtr<HTMLInputElement> radio = static_cast<HTMLInputElement*>(aRadio);
29   NS_ASSERTION(radio, "Visit() passed a null button!");
30 
31   *mCheckedChanged = radio->GetCheckedChanged();
32   return false;
33 }
34 
Visit(nsIFormControl * aRadio)35 bool nsRadioSetValueMissingState::Visit(nsIFormControl* aRadio) {
36   if (aRadio == mExcludeElement) {
37     return true;
38   }
39 
40   HTMLInputElement* input = static_cast<HTMLInputElement*>(aRadio);
41 
42   input->SetValidityState(nsIConstraintValidation::VALIDITY_STATE_VALUE_MISSING,
43                           mValidity);
44 
45   input->UpdateState(true);
46 
47   return true;
48 }
49 
Visit(nsIFormControl * aRadio)50 bool nsRadioUpdateStateVisitor::Visit(nsIFormControl* aRadio) {
51   if (aRadio == mExcludeElement) {
52     return true;
53   }
54 
55   HTMLInputElement* input = static_cast<HTMLInputElement*>(aRadio);
56   input->UpdateState(true);
57 
58   return true;
59 }
60