2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// NOTE: alphabetically ordered
|
2012-01-11 19:07:35 -08:00
|
|
|
|
2012-04-12 04:11:40 -07:00
|
|
|
#include "FormControlAccessible.h"
|
2012-01-11 19:07:35 -08:00
|
|
|
#include "Role.h"
|
|
|
|
|
2013-11-19 13:01:15 -08:00
|
|
|
#include "mozilla/FloatingPoint.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIDOMHTMLFormElement.h"
|
|
|
|
#include "nsIDOMXULElement.h"
|
|
|
|
#include "nsIDOMXULControlElement.h"
|
|
|
|
|
2012-01-11 19:07:35 -08:00
|
|
|
using namespace mozilla::a11y;
|
|
|
|
|
2011-05-11 19:55:12 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// ProgressMeterAccessible
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-04-13 14:18:36 -07:00
|
|
|
template class mozilla::a11y::ProgressMeterAccessible<1>;
|
|
|
|
template class mozilla::a11y::ProgressMeterAccessible<100>;
|
2011-05-11 19:55:12 -07:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-05-28 18:18:45 -07:00
|
|
|
// Accessible
|
2011-05-11 19:55:12 -07:00
|
|
|
|
|
|
|
template<int Max>
|
2012-01-11 19:07:35 -08:00
|
|
|
role
|
2011-05-11 19:55:12 -07:00
|
|
|
ProgressMeterAccessible<Max>::NativeRole()
|
|
|
|
{
|
2012-01-11 19:07:35 -08:00
|
|
|
return roles::PROGRESSBAR;
|
2011-05-11 19:55:12 -07:00
|
|
|
}
|
|
|
|
|
2012-04-04 15:07:49 -07:00
|
|
|
template<int Max>
|
2012-08-22 08:56:38 -07:00
|
|
|
uint64_t
|
2012-04-04 15:07:49 -07:00
|
|
|
ProgressMeterAccessible<Max>::NativeState()
|
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
uint64_t state = LeafAccessible::NativeState();
|
2012-04-04 15:07:49 -07:00
|
|
|
|
|
|
|
// An undetermined progressbar (i.e. without a value) has a mixed state.
|
|
|
|
nsAutoString attrValue;
|
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::value, attrValue);
|
|
|
|
|
|
|
|
if (attrValue.IsEmpty())
|
|
|
|
state |= states::MIXED;
|
|
|
|
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2011-09-28 20:13:08 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// ProgressMeterAccessible<Max>: Widgets
|
|
|
|
|
|
|
|
template<int Max>
|
|
|
|
bool
|
|
|
|
ProgressMeterAccessible<Max>::IsWidget() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-05-11 19:55:12 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2014-10-21 17:49:28 -07:00
|
|
|
// ProgressMeterAccessible<Max>: Value
|
2011-05-11 19:55:12 -07:00
|
|
|
|
|
|
|
template<int Max>
|
2012-04-09 02:48:41 -07:00
|
|
|
void
|
|
|
|
ProgressMeterAccessible<Max>::Value(nsString& aValue)
|
2011-05-11 19:55:12 -07:00
|
|
|
{
|
2012-06-04 05:32:29 -07:00
|
|
|
LeafAccessible::Value(aValue);
|
2011-05-11 19:55:12 -07:00
|
|
|
if (!aValue.IsEmpty())
|
2012-04-09 02:48:41 -07:00
|
|
|
return;
|
2011-05-11 19:55:12 -07:00
|
|
|
|
2013-11-19 13:01:15 -08:00
|
|
|
double maxValue = MaxValue();
|
|
|
|
if (IsNaN(maxValue) || maxValue == 0)
|
2012-04-09 02:48:41 -07:00
|
|
|
return;
|
2011-05-11 19:55:12 -07:00
|
|
|
|
2013-11-19 13:01:15 -08:00
|
|
|
double curValue = CurValue();
|
|
|
|
if (IsNaN(curValue))
|
2012-04-14 05:57:00 -07:00
|
|
|
return;
|
2011-05-11 19:55:12 -07:00
|
|
|
|
|
|
|
// Treat the current value bigger than maximum as 100%.
|
|
|
|
double percentValue = (curValue < maxValue) ?
|
|
|
|
(curValue / maxValue) * 100 : 100;
|
|
|
|
|
2012-04-09 02:48:41 -07:00
|
|
|
aValue.AppendFloat(percentValue);
|
2014-05-21 20:48:51 -07:00
|
|
|
aValue.Append('%');
|
2011-05-11 19:55:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
template<int Max>
|
2013-11-19 13:01:15 -08:00
|
|
|
double
|
|
|
|
ProgressMeterAccessible<Max>::MaxValue() const
|
2011-05-11 19:55:12 -07:00
|
|
|
{
|
2013-11-19 13:01:15 -08:00
|
|
|
double value = LeafAccessible::MaxValue();
|
|
|
|
if (!IsNaN(value))
|
|
|
|
return value;
|
2011-05-11 19:55:12 -07:00
|
|
|
|
2013-11-19 13:01:15 -08:00
|
|
|
nsAutoString strValue;
|
|
|
|
if (mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::max, strValue)) {
|
2012-07-27 06:59:29 -07:00
|
|
|
nsresult result = NS_OK;
|
2013-11-19 13:01:15 -08:00
|
|
|
value = strValue.ToDouble(&result);
|
|
|
|
if (NS_SUCCEEDED(result))
|
|
|
|
return value;
|
2011-05-11 19:55:12 -07:00
|
|
|
}
|
|
|
|
|
2013-11-19 13:01:15 -08:00
|
|
|
return Max;
|
2011-05-11 19:55:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
template<int Max>
|
2013-11-19 13:01:15 -08:00
|
|
|
double
|
|
|
|
ProgressMeterAccessible<Max>::MinValue() const
|
2011-05-11 19:55:12 -07:00
|
|
|
{
|
2013-11-19 13:01:15 -08:00
|
|
|
double value = LeafAccessible::MinValue();
|
|
|
|
return IsNaN(value) ? 0 : value;
|
2011-05-11 19:55:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
template<int Max>
|
2013-11-19 13:01:15 -08:00
|
|
|
double
|
|
|
|
ProgressMeterAccessible<Max>::Step() const
|
2011-05-11 19:55:12 -07:00
|
|
|
{
|
2013-11-19 13:01:15 -08:00
|
|
|
double value = LeafAccessible::Step();
|
|
|
|
return IsNaN(value) ? 0 : value;
|
2011-05-11 19:55:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
template<int Max>
|
2013-11-19 13:01:15 -08:00
|
|
|
double
|
|
|
|
ProgressMeterAccessible<Max>::CurValue() const
|
2011-05-11 19:55:12 -07:00
|
|
|
{
|
2013-11-19 13:01:15 -08:00
|
|
|
double value = LeafAccessible::CurValue();
|
|
|
|
if (!IsNaN(value))
|
|
|
|
return value;
|
2011-05-11 19:55:12 -07:00
|
|
|
|
|
|
|
nsAutoString attrValue;
|
2013-11-19 13:01:15 -08:00
|
|
|
if (!mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::value, attrValue))
|
2014-02-27 07:23:16 -08:00
|
|
|
return UnspecifiedNaN<double>();
|
2011-05-11 19:55:12 -07:00
|
|
|
|
2012-07-27 06:59:29 -07:00
|
|
|
nsresult error = NS_OK;
|
2013-11-19 13:01:15 -08:00
|
|
|
value = attrValue.ToDouble(&error);
|
2014-02-27 07:23:16 -08:00
|
|
|
return NS_FAILED(error) ? UnspecifiedNaN<double>() : value;
|
2011-05-11 19:55:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
template<int Max>
|
2013-11-19 13:01:15 -08:00
|
|
|
bool
|
|
|
|
ProgressMeterAccessible<Max>::SetCurValue(double aValue)
|
2011-05-11 19:55:12 -07:00
|
|
|
{
|
2013-11-19 13:01:15 -08:00
|
|
|
return false; // progress meters are readonly.
|
2011-05-11 19:55:12 -07:00
|
|
|
}
|
|
|
|
|
2010-06-11 01:23:18 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-04-12 04:11:40 -07:00
|
|
|
// RadioButtonAccessible
|
2010-06-11 01:23:18 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-04-12 04:11:40 -07:00
|
|
|
RadioButtonAccessible::
|
2012-05-27 02:01:40 -07:00
|
|
|
RadioButtonAccessible(nsIContent* aContent, DocAccessible* aDoc) :
|
2012-06-04 05:32:29 -07:00
|
|
|
LeafAccessible(aContent, aDoc)
|
2010-06-11 01:23:18 -07:00
|
|
|
{
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t
|
2012-04-12 04:11:40 -07:00
|
|
|
RadioButtonAccessible::ActionCount()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-06-05 12:35:43 -07:00
|
|
|
return 1;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2014-09-16 10:30:23 -07:00
|
|
|
void
|
|
|
|
RadioButtonAccessible::ActionNameAt(uint8_t aIndex, nsAString& aName)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-09-16 10:30:23 -07:00
|
|
|
if (aIndex == eAction_Click)
|
|
|
|
aName.AssignLiteral("select");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2014-09-16 10:30:23 -07:00
|
|
|
bool
|
2012-08-22 08:56:38 -07:00
|
|
|
RadioButtonAccessible::DoAction(uint8_t aIndex)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-01-25 07:09:25 -08:00
|
|
|
if (aIndex != eAction_Click)
|
2014-09-16 10:30:23 -07:00
|
|
|
return false;
|
2010-01-25 07:09:25 -08:00
|
|
|
|
|
|
|
DoCommand();
|
2014-09-16 10:30:23 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-01-11 19:07:35 -08:00
|
|
|
role
|
2012-04-12 04:11:40 -07:00
|
|
|
RadioButtonAccessible::NativeRole()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-01-11 19:07:35 -08:00
|
|
|
return roles::RADIOBUTTON;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 20:13:08 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-04-12 04:11:40 -07:00
|
|
|
// RadioButtonAccessible: Widgets
|
2011-09-28 20:13:08 -07:00
|
|
|
|
|
|
|
bool
|
2012-04-12 04:11:40 -07:00
|
|
|
RadioButtonAccessible::IsWidget() const
|
2011-09-28 20:13:08 -07:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|