2007-08-03 22:27:27 -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-08-03 22:27:27 -07:00
|
|
|
|
2012-06-10 16:44:50 -07:00
|
|
|
#include "XULSliderAccessible.h"
|
2007-08-03 22:27:27 -07:00
|
|
|
|
2011-09-27 18:46:11 -07:00
|
|
|
#include "nsAccessibilityService.h"
|
2012-01-11 19:07:35 -08:00
|
|
|
#include "Role.h"
|
2011-04-09 16:38:06 -07:00
|
|
|
#include "States.h"
|
2010-04-26 23:52:03 -07:00
|
|
|
|
|
|
|
#include "nsIFrame.h"
|
2013-09-10 15:18:59 -07:00
|
|
|
#include "mozilla/dom/Element.h"
|
2013-11-19 13:01:15 -08:00
|
|
|
#include "mozilla/FloatingPoint.h"
|
2007-08-03 22:27:27 -07:00
|
|
|
|
2011-07-27 05:43:01 -07:00
|
|
|
using namespace mozilla::a11y;
|
|
|
|
|
2010-06-11 01:23:18 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-06-10 16:44:50 -07:00
|
|
|
// XULSliderAccessible
|
2010-06-11 01:23:18 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2007-08-03 22:27:27 -07:00
|
|
|
|
2012-06-10 16:44:50 -07:00
|
|
|
XULSliderAccessible::
|
|
|
|
XULSliderAccessible(nsIContent* aContent, DocAccessible* aDoc) :
|
2012-05-28 18:18:45 -07:00
|
|
|
AccessibleWrap(aContent, aDoc)
|
2007-08-03 22:27:27 -07:00
|
|
|
{
|
2012-12-10 19:31:42 -08:00
|
|
|
mStateFlags |= eHasNumericValue;
|
2007-08-03 22:27:27 -07:00
|
|
|
}
|
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
// Accessible
|
2007-08-03 22:27:27 -07:00
|
|
|
|
2012-01-11 19:07:35 -08:00
|
|
|
role
|
2012-06-10 16:44:50 -07:00
|
|
|
XULSliderAccessible::NativeRole()
|
2007-08-03 22:27:27 -07:00
|
|
|
{
|
2012-01-11 19:07:35 -08:00
|
|
|
return roles::SLIDER;
|
2007-08-03 22:27:27 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint64_t
|
2012-06-10 16:44:50 -07:00
|
|
|
XULSliderAccessible::NativeInteractiveState() const
|
2012-06-03 22:41:06 -07:00
|
|
|
{
|
|
|
|
if (NativelyUnavailable())
|
|
|
|
return states::UNAVAILABLE;
|
2009-05-22 09:09:51 -07:00
|
|
|
|
2012-05-27 21:52:53 -07:00
|
|
|
nsIContent* sliderElm = GetSliderElement();
|
2012-06-03 22:41:06 -07:00
|
|
|
if (sliderElm) {
|
|
|
|
nsIFrame* frame = sliderElm->GetPrimaryFrame();
|
|
|
|
if (frame && frame->IsFocusable())
|
|
|
|
return states::FOCUSABLE;
|
|
|
|
}
|
2009-05-22 09:09:51 -07:00
|
|
|
|
2012-06-03 22:41:06 -07:00
|
|
|
return 0;
|
|
|
|
}
|
2009-05-22 09:09:51 -07:00
|
|
|
|
2012-06-03 22:41:06 -07:00
|
|
|
bool
|
2012-06-10 16:44:50 -07:00
|
|
|
XULSliderAccessible::NativelyUnavailable() const
|
2012-06-03 22:41:06 -07:00
|
|
|
{
|
|
|
|
return mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::disabled,
|
|
|
|
nsGkAtoms::_true, eCaseMatters);
|
2009-05-22 09:09:51 -07:00
|
|
|
}
|
|
|
|
|
2012-04-09 02:48:41 -07:00
|
|
|
void
|
2012-06-10 16:44:50 -07:00
|
|
|
XULSliderAccessible::Value(nsString& aValue)
|
2007-08-03 22:27:27 -07:00
|
|
|
{
|
2012-04-09 02:48:41 -07:00
|
|
|
GetSliderAttr(nsGkAtoms::curpos, aValue);
|
2007-08-03 22:27:27 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t
|
2012-06-10 16:44:50 -07:00
|
|
|
XULSliderAccessible::ActionCount()
|
2009-05-22 09:09:51 -07:00
|
|
|
{
|
2011-06-05 12:35:43 -07:00
|
|
|
return 1;
|
2009-05-22 09:09:51 -07:00
|
|
|
}
|
|
|
|
|
2014-09-16 10:30:23 -07:00
|
|
|
void
|
|
|
|
XULSliderAccessible::ActionNameAt(uint8_t aIndex, nsAString& aName)
|
2009-05-22 09:09:51 -07:00
|
|
|
{
|
|
|
|
aName.Truncate();
|
2014-09-16 10:30:23 -07:00
|
|
|
if (aIndex == 0)
|
|
|
|
aName.AssignLiteral("activate");
|
2009-05-22 09:09:51 -07:00
|
|
|
}
|
|
|
|
|
2014-09-16 10:30:23 -07:00
|
|
|
bool
|
2012-08-22 08:56:38 -07:00
|
|
|
XULSliderAccessible::DoAction(uint8_t aIndex)
|
2009-05-22 09:09:51 -07:00
|
|
|
{
|
2014-09-16 10:30:23 -07:00
|
|
|
if (aIndex != 0)
|
|
|
|
return false;
|
2009-05-22 09:09:51 -07:00
|
|
|
|
2012-05-27 21:52:53 -07:00
|
|
|
nsIContent* sliderElm = GetSliderElement();
|
|
|
|
if (sliderElm)
|
|
|
|
DoCommand(sliderElm);
|
2009-05-22 09:09:51 -07:00
|
|
|
|
2014-09-16 10:30:23 -07:00
|
|
|
return true;
|
2009-05-22 09:09:51 -07:00
|
|
|
}
|
|
|
|
|
2013-11-19 13:01:15 -08:00
|
|
|
double
|
|
|
|
XULSliderAccessible::MaxValue() const
|
2007-08-03 22:27:27 -07:00
|
|
|
{
|
2013-11-19 13:01:15 -08:00
|
|
|
double value = AccessibleWrap::MaxValue();
|
|
|
|
return IsNaN(value) ? GetSliderAttr(nsGkAtoms::maxpos) : value;
|
2007-08-03 22:27:27 -07:00
|
|
|
}
|
|
|
|
|
2013-11-19 13:01:15 -08:00
|
|
|
double
|
|
|
|
XULSliderAccessible::MinValue() const
|
2007-08-03 22:27:27 -07:00
|
|
|
{
|
2013-11-19 13:01:15 -08:00
|
|
|
double value = AccessibleWrap::MinValue();
|
|
|
|
return IsNaN(value) ? GetSliderAttr(nsGkAtoms::minpos) : value;
|
2007-08-03 22:27:27 -07:00
|
|
|
}
|
|
|
|
|
2013-11-19 13:01:15 -08:00
|
|
|
double
|
|
|
|
XULSliderAccessible::Step() const
|
2007-08-03 22:27:27 -07:00
|
|
|
{
|
2013-11-19 13:01:15 -08:00
|
|
|
double value = AccessibleWrap::Step();
|
|
|
|
return IsNaN(value) ? GetSliderAttr(nsGkAtoms::increment) : value;
|
2007-08-03 22:27:27 -07:00
|
|
|
}
|
|
|
|
|
2013-11-19 13:01:15 -08:00
|
|
|
double
|
|
|
|
XULSliderAccessible::CurValue() const
|
2007-08-03 22:27:27 -07:00
|
|
|
{
|
2013-11-19 13:01:15 -08:00
|
|
|
double value = AccessibleWrap::CurValue();
|
|
|
|
return IsNaN(value) ? GetSliderAttr(nsGkAtoms::curpos) : value;
|
2007-08-03 22:27:27 -07:00
|
|
|
}
|
|
|
|
|
2013-11-19 13:01:15 -08:00
|
|
|
bool
|
|
|
|
XULSliderAccessible::SetCurValue(double aValue)
|
2007-08-03 22:27:27 -07:00
|
|
|
{
|
2013-11-19 13:01:15 -08:00
|
|
|
if (AccessibleWrap::SetCurValue(aValue))
|
|
|
|
return true;
|
2007-08-03 22:27:27 -07:00
|
|
|
|
2011-06-03 14:35:17 -07:00
|
|
|
return SetSliderAttr(nsGkAtoms::curpos, aValue);
|
2007-08-03 22:27:27 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2012-06-10 16:44:50 -07:00
|
|
|
XULSliderAccessible::CanHaveAnonChildren()
|
2009-05-22 09:09:51 -07:00
|
|
|
{
|
|
|
|
// Do not allow anonymous xul:slider be accessible.
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2009-05-22 09:09:51 -07:00
|
|
|
}
|
|
|
|
|
2007-08-03 22:27:27 -07:00
|
|
|
// Utils
|
|
|
|
|
2012-05-27 21:52:53 -07:00
|
|
|
nsIContent*
|
2012-06-10 16:44:50 -07:00
|
|
|
XULSliderAccessible::GetSliderElement() const
|
2009-05-11 08:20:03 -07:00
|
|
|
{
|
|
|
|
if (!mSliderNode) {
|
|
|
|
// XXX: we depend on anonymous content.
|
2012-05-27 21:52:53 -07:00
|
|
|
mSliderNode = mContent->OwnerDoc()->
|
|
|
|
GetAnonymousElementByAttribute(mContent, nsGkAtoms::anonid,
|
|
|
|
NS_LITERAL_STRING("slider"));
|
2009-05-11 08:20:03 -07:00
|
|
|
}
|
|
|
|
|
2012-05-27 21:52:53 -07:00
|
|
|
return mSliderNode;
|
2009-05-11 08:20:03 -07:00
|
|
|
}
|
|
|
|
|
2007-08-03 22:27:27 -07:00
|
|
|
nsresult
|
2013-11-19 13:01:15 -08:00
|
|
|
XULSliderAccessible::GetSliderAttr(nsIAtom* aName, nsAString& aValue) const
|
2007-08-03 22:27:27 -07:00
|
|
|
{
|
|
|
|
aValue.Truncate();
|
|
|
|
|
2009-05-05 20:16:36 -07:00
|
|
|
if (IsDefunct())
|
2007-08-03 22:27:27 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2012-05-27 21:52:53 -07:00
|
|
|
nsIContent* sliderElm = GetSliderElement();
|
|
|
|
if (sliderElm)
|
|
|
|
sliderElm->GetAttr(kNameSpaceID_None, aName, aValue);
|
2009-05-11 08:20:03 -07:00
|
|
|
|
2007-08-03 22:27:27 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-06-10 16:44:50 -07:00
|
|
|
XULSliderAccessible::SetSliderAttr(nsIAtom* aName, const nsAString& aValue)
|
2007-08-03 22:27:27 -07:00
|
|
|
{
|
2009-05-05 20:16:36 -07:00
|
|
|
if (IsDefunct())
|
2007-08-03 22:27:27 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2012-05-27 21:52:53 -07:00
|
|
|
nsIContent* sliderElm = GetSliderElement();
|
|
|
|
if (sliderElm)
|
|
|
|
sliderElm->SetAttr(kNameSpaceID_None, aName, aValue, true);
|
2009-05-11 08:20:03 -07:00
|
|
|
|
2007-08-03 22:27:27 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-11-19 13:01:15 -08:00
|
|
|
double
|
|
|
|
XULSliderAccessible::GetSliderAttr(nsIAtom* aName) const
|
2007-08-03 22:27:27 -07:00
|
|
|
{
|
2009-05-05 20:16:36 -07:00
|
|
|
nsAutoString attrValue;
|
|
|
|
nsresult rv = GetSliderAttr(aName, attrValue);
|
2013-11-19 13:01:15 -08:00
|
|
|
if (NS_FAILED(rv))
|
2014-02-27 07:23:16 -08:00
|
|
|
return UnspecifiedNaN<double>();
|
2009-05-05 20:16:36 -07:00
|
|
|
|
2012-07-27 06:59:29 -07:00
|
|
|
nsresult error = NS_OK;
|
2011-03-25 04:14:19 -07:00
|
|
|
double value = attrValue.ToDouble(&error);
|
2014-02-27 07:23:16 -08:00
|
|
|
return NS_FAILED(error) ? UnspecifiedNaN<double>() : value;
|
2007-08-03 22:27:27 -07:00
|
|
|
}
|
|
|
|
|
2013-11-19 13:01:15 -08:00
|
|
|
bool
|
2012-06-10 16:44:50 -07:00
|
|
|
XULSliderAccessible::SetSliderAttr(nsIAtom* aName, double aValue)
|
2007-08-03 22:27:27 -07:00
|
|
|
{
|
|
|
|
nsAutoString value;
|
|
|
|
value.AppendFloat(aValue);
|
|
|
|
|
2013-11-19 13:01:15 -08:00
|
|
|
return NS_SUCCEEDED(SetSliderAttr(aName, value));
|
2007-08-03 22:27:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-11 01:23:18 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-06-10 16:44:50 -07:00
|
|
|
// XULThumbAccessible
|
2010-06-11 01:23:18 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2007-08-03 22:27:27 -07:00
|
|
|
|
2012-06-10 16:44:50 -07:00
|
|
|
XULThumbAccessible::
|
|
|
|
XULThumbAccessible(nsIContent* aContent, DocAccessible* aDoc) :
|
2012-05-28 18:18:45 -07:00
|
|
|
AccessibleWrap(aContent, aDoc)
|
2010-06-11 01:23:18 -07:00
|
|
|
{
|
|
|
|
}
|
2007-08-03 22:27:27 -07:00
|
|
|
|
2010-09-04 19:14:01 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-06-10 16:44:50 -07:00
|
|
|
// XULThumbAccessible: Accessible
|
2009-05-11 08:20:03 -07:00
|
|
|
|
2012-01-11 19:07:35 -08:00
|
|
|
role
|
2012-06-10 16:44:50 -07:00
|
|
|
XULThumbAccessible::NativeRole()
|
2007-08-03 22:27:27 -07:00
|
|
|
{
|
2012-01-11 19:07:35 -08:00
|
|
|
return roles::INDICATOR;
|
2007-08-03 22:27:27 -07:00
|
|
|
}
|
|
|
|
|