accessible/src/generic/FormControlAccessible.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 // NOTE: alphabetically ordered
michael@0 7
michael@0 8 #include "FormControlAccessible.h"
michael@0 9 #include "Role.h"
michael@0 10
michael@0 11 #include "mozilla/FloatingPoint.h"
michael@0 12 #include "nsIDOMHTMLFormElement.h"
michael@0 13 #include "nsIDOMXULElement.h"
michael@0 14 #include "nsIDOMXULControlElement.h"
michael@0 15
michael@0 16 using namespace mozilla::a11y;
michael@0 17
michael@0 18 ////////////////////////////////////////////////////////////////////////////////
michael@0 19 // ProgressMeterAccessible
michael@0 20 ////////////////////////////////////////////////////////////////////////////////
michael@0 21
michael@0 22 template class mozilla::a11y::ProgressMeterAccessible<1>;
michael@0 23 template class mozilla::a11y::ProgressMeterAccessible<100>;
michael@0 24
michael@0 25 ////////////////////////////////////////////////////////////////////////////////
michael@0 26 // nsISupports
michael@0 27
michael@0 28 template<int Max>
michael@0 29 NS_IMPL_ADDREF_INHERITED(ProgressMeterAccessible<Max>, LeafAccessible)
michael@0 30
michael@0 31 template<int Max>
michael@0 32 NS_IMPL_RELEASE_INHERITED(ProgressMeterAccessible<Max>, LeafAccessible)
michael@0 33
michael@0 34 template<int Max>
michael@0 35 NS_IMPL_QUERY_INTERFACE_INHERITED(ProgressMeterAccessible<Max>,
michael@0 36 LeafAccessible,
michael@0 37 nsIAccessibleValue)
michael@0 38
michael@0 39 ////////////////////////////////////////////////////////////////////////////////
michael@0 40 // Accessible
michael@0 41
michael@0 42 template<int Max>
michael@0 43 role
michael@0 44 ProgressMeterAccessible<Max>::NativeRole()
michael@0 45 {
michael@0 46 return roles::PROGRESSBAR;
michael@0 47 }
michael@0 48
michael@0 49 template<int Max>
michael@0 50 uint64_t
michael@0 51 ProgressMeterAccessible<Max>::NativeState()
michael@0 52 {
michael@0 53 uint64_t state = LeafAccessible::NativeState();
michael@0 54
michael@0 55 // An undetermined progressbar (i.e. without a value) has a mixed state.
michael@0 56 nsAutoString attrValue;
michael@0 57 mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::value, attrValue);
michael@0 58
michael@0 59 if (attrValue.IsEmpty())
michael@0 60 state |= states::MIXED;
michael@0 61
michael@0 62 return state;
michael@0 63 }
michael@0 64
michael@0 65 ////////////////////////////////////////////////////////////////////////////////
michael@0 66 // ProgressMeterAccessible<Max>: Widgets
michael@0 67
michael@0 68 template<int Max>
michael@0 69 bool
michael@0 70 ProgressMeterAccessible<Max>::IsWidget() const
michael@0 71 {
michael@0 72 return true;
michael@0 73 }
michael@0 74
michael@0 75 ////////////////////////////////////////////////////////////////////////////////
michael@0 76 // nsIAccessibleValue
michael@0 77
michael@0 78 template<int Max>
michael@0 79 void
michael@0 80 ProgressMeterAccessible<Max>::Value(nsString& aValue)
michael@0 81 {
michael@0 82 LeafAccessible::Value(aValue);
michael@0 83 if (!aValue.IsEmpty())
michael@0 84 return;
michael@0 85
michael@0 86 double maxValue = MaxValue();
michael@0 87 if (IsNaN(maxValue) || maxValue == 0)
michael@0 88 return;
michael@0 89
michael@0 90 double curValue = CurValue();
michael@0 91 if (IsNaN(curValue))
michael@0 92 return;
michael@0 93
michael@0 94 // Treat the current value bigger than maximum as 100%.
michael@0 95 double percentValue = (curValue < maxValue) ?
michael@0 96 (curValue / maxValue) * 100 : 100;
michael@0 97
michael@0 98 aValue.AppendFloat(percentValue);
michael@0 99 aValue.AppendLiteral("%");
michael@0 100 }
michael@0 101
michael@0 102 template<int Max>
michael@0 103 double
michael@0 104 ProgressMeterAccessible<Max>::MaxValue() const
michael@0 105 {
michael@0 106 double value = LeafAccessible::MaxValue();
michael@0 107 if (!IsNaN(value))
michael@0 108 return value;
michael@0 109
michael@0 110 nsAutoString strValue;
michael@0 111 if (mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::max, strValue)) {
michael@0 112 nsresult result = NS_OK;
michael@0 113 value = strValue.ToDouble(&result);
michael@0 114 if (NS_SUCCEEDED(result))
michael@0 115 return value;
michael@0 116 }
michael@0 117
michael@0 118 return Max;
michael@0 119 }
michael@0 120
michael@0 121 template<int Max>
michael@0 122 double
michael@0 123 ProgressMeterAccessible<Max>::MinValue() const
michael@0 124 {
michael@0 125 double value = LeafAccessible::MinValue();
michael@0 126 return IsNaN(value) ? 0 : value;
michael@0 127 }
michael@0 128
michael@0 129 template<int Max>
michael@0 130 double
michael@0 131 ProgressMeterAccessible<Max>::Step() const
michael@0 132 {
michael@0 133 double value = LeafAccessible::Step();
michael@0 134 return IsNaN(value) ? 0 : value;
michael@0 135 }
michael@0 136
michael@0 137 template<int Max>
michael@0 138 double
michael@0 139 ProgressMeterAccessible<Max>::CurValue() const
michael@0 140 {
michael@0 141 double value = LeafAccessible::CurValue();
michael@0 142 if (!IsNaN(value))
michael@0 143 return value;
michael@0 144
michael@0 145 nsAutoString attrValue;
michael@0 146 if (!mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::value, attrValue))
michael@0 147 return UnspecifiedNaN<double>();
michael@0 148
michael@0 149 nsresult error = NS_OK;
michael@0 150 value = attrValue.ToDouble(&error);
michael@0 151 return NS_FAILED(error) ? UnspecifiedNaN<double>() : value;
michael@0 152 }
michael@0 153
michael@0 154 template<int Max>
michael@0 155 bool
michael@0 156 ProgressMeterAccessible<Max>::SetCurValue(double aValue)
michael@0 157 {
michael@0 158 return false; // progress meters are readonly.
michael@0 159 }
michael@0 160
michael@0 161 ////////////////////////////////////////////////////////////////////////////////
michael@0 162 // RadioButtonAccessible
michael@0 163 ////////////////////////////////////////////////////////////////////////////////
michael@0 164
michael@0 165 RadioButtonAccessible::
michael@0 166 RadioButtonAccessible(nsIContent* aContent, DocAccessible* aDoc) :
michael@0 167 LeafAccessible(aContent, aDoc)
michael@0 168 {
michael@0 169 }
michael@0 170
michael@0 171 uint8_t
michael@0 172 RadioButtonAccessible::ActionCount()
michael@0 173 {
michael@0 174 return 1;
michael@0 175 }
michael@0 176
michael@0 177 NS_IMETHODIMP
michael@0 178 RadioButtonAccessible::GetActionName(uint8_t aIndex, nsAString& aName)
michael@0 179 {
michael@0 180 if (aIndex == eAction_Click) {
michael@0 181 aName.AssignLiteral("select");
michael@0 182 return NS_OK;
michael@0 183 }
michael@0 184 return NS_ERROR_INVALID_ARG;
michael@0 185 }
michael@0 186
michael@0 187 NS_IMETHODIMP
michael@0 188 RadioButtonAccessible::DoAction(uint8_t aIndex)
michael@0 189 {
michael@0 190 if (aIndex != eAction_Click)
michael@0 191 return NS_ERROR_INVALID_ARG;
michael@0 192
michael@0 193 DoCommand();
michael@0 194 return NS_OK;
michael@0 195 }
michael@0 196
michael@0 197 role
michael@0 198 RadioButtonAccessible::NativeRole()
michael@0 199 {
michael@0 200 return roles::RADIOBUTTON;
michael@0 201 }
michael@0 202
michael@0 203 ////////////////////////////////////////////////////////////////////////////////
michael@0 204 // RadioButtonAccessible: Widgets
michael@0 205
michael@0 206 bool
michael@0 207 RadioButtonAccessible::IsWidget() const
michael@0 208 {
michael@0 209 return true;
michael@0 210 }

mercurial