2012-04-05 20:23:30 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
|
|
|
/* 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/. */
|
|
|
|
|
2013-04-25 07:48:26 +04:00
|
|
|
#include "ARIAMap.h"
|
2013-07-26 14:26:44 +04:00
|
|
|
#include "nsAccUtils.h"
|
2012-04-05 20:23:30 +04:00
|
|
|
#include "States.h"
|
|
|
|
|
|
|
|
#include "mozilla/dom/Element.h"
|
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::a11y;
|
|
|
|
using namespace mozilla::a11y::aria;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used to store state map rule data for ARIA attribute of enum type.
|
|
|
|
*/
|
|
|
|
struct EnumTypeData
|
|
|
|
{
|
|
|
|
// ARIA attribute name.
|
2017-10-27 02:31:13 +03:00
|
|
|
nsStaticAtom* const mAttrName;
|
2012-04-05 20:23:30 +04:00
|
|
|
|
|
|
|
// States if the attribute value is matched to the enum value. Used as
|
2014-08-11 16:13:44 +04:00
|
|
|
// nsIContent::AttrValuesArray, last item must be nullptr.
|
2017-10-27 02:31:13 +03:00
|
|
|
nsStaticAtom* const* const mValues[4];
|
2014-08-11 16:13:44 +04:00
|
|
|
|
|
|
|
// States applied if corresponding enum values are matched.
|
|
|
|
const uint64_t mStates[3];
|
|
|
|
|
|
|
|
// States to clear in case of match.
|
|
|
|
const uint64_t mClearState;
|
2012-04-05 20:23:30 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
enum ETokenType
|
|
|
|
{
|
|
|
|
eBoolType = 0,
|
|
|
|
eMixedType = 1, // can take 'mixed' value
|
|
|
|
eDefinedIfAbsent = 2 // permanent and false state are applied if absent
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used to store state map rule data for ARIA attribute of token type (including
|
|
|
|
* mixed value).
|
|
|
|
*/
|
|
|
|
struct TokenTypeData
|
|
|
|
{
|
2017-10-03 01:05:19 +03:00
|
|
|
TokenTypeData(nsAtom* aAttrName, uint32_t aType,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint64_t aPermanentState,
|
|
|
|
uint64_t aTrueState,
|
|
|
|
uint64_t aFalseState = 0) :
|
2012-04-05 20:23:30 +04:00
|
|
|
mAttrName(aAttrName), mType(aType), mPermanentState(aPermanentState),
|
|
|
|
mTrueState(aTrueState), mFalseState(aFalseState)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
// ARIA attribute name.
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* const mAttrName;
|
2012-04-05 20:23:30 +04:00
|
|
|
|
|
|
|
// Type.
|
2012-08-22 19:56:38 +04:00
|
|
|
const uint32_t mType;
|
2012-04-05 20:23:30 +04:00
|
|
|
|
|
|
|
// State applied if the attribute is defined or mType doesn't have
|
|
|
|
// eDefinedIfAbsent flag set.
|
2012-08-22 19:56:38 +04:00
|
|
|
const uint64_t mPermanentState;
|
2012-04-05 20:23:30 +04:00
|
|
|
|
|
|
|
// States applied if the attribute value is true/false.
|
2012-08-22 19:56:38 +04:00
|
|
|
const uint64_t mTrueState;
|
|
|
|
const uint64_t mFalseState;
|
2012-04-05 20:23:30 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Map enum type attribute value to accessible state.
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
static void MapEnumType(dom::Element* aElement, uint64_t* aState,
|
2012-04-05 20:23:30 +04:00
|
|
|
const EnumTypeData& aData);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Map token type attribute value to states.
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
static void MapTokenType(dom::Element* aContent, uint64_t* aState,
|
2012-04-05 20:23:30 +04:00
|
|
|
const TokenTypeData& aData);
|
|
|
|
|
|
|
|
bool
|
2012-08-22 19:56:38 +04:00
|
|
|
aria::MapToState(EStateRule aRule, dom::Element* aElement, uint64_t* aState)
|
2012-04-05 20:23:30 +04:00
|
|
|
{
|
|
|
|
switch (aRule) {
|
|
|
|
case eARIAAutoComplete:
|
|
|
|
{
|
2014-08-11 16:13:44 +04:00
|
|
|
static const EnumTypeData data = {
|
2012-04-05 20:23:30 +04:00
|
|
|
nsGkAtoms::aria_autocomplete,
|
2014-08-11 16:13:44 +04:00
|
|
|
{ &nsGkAtoms::inlinevalue,
|
|
|
|
&nsGkAtoms::list,
|
|
|
|
&nsGkAtoms::both, nullptr },
|
|
|
|
{ states::SUPPORTS_AUTOCOMPLETION,
|
|
|
|
states::HASPOPUP | states::SUPPORTS_AUTOCOMPLETION,
|
|
|
|
states::HASPOPUP | states::SUPPORTS_AUTOCOMPLETION }, 0
|
|
|
|
};
|
2012-04-05 20:23:30 +04:00
|
|
|
|
|
|
|
MapEnumType(aElement, aState, data);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
case eARIABusy:
|
|
|
|
{
|
2014-08-11 16:13:44 +04:00
|
|
|
static const EnumTypeData data = {
|
2012-04-05 20:23:30 +04:00
|
|
|
nsGkAtoms::aria_busy,
|
2014-08-11 16:13:44 +04:00
|
|
|
{ &nsGkAtoms::_true,
|
|
|
|
&nsGkAtoms::error, nullptr },
|
|
|
|
{ states::BUSY,
|
|
|
|
states::INVALID }, 0
|
|
|
|
};
|
2012-04-05 20:23:30 +04:00
|
|
|
|
|
|
|
MapEnumType(aElement, aState, data);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
case eARIACheckableBool:
|
|
|
|
{
|
|
|
|
static const TokenTypeData data(
|
|
|
|
nsGkAtoms::aria_checked, eBoolType | eDefinedIfAbsent,
|
|
|
|
states::CHECKABLE, states::CHECKED);
|
|
|
|
|
|
|
|
MapTokenType(aElement, aState, data);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
case eARIACheckableMixed:
|
|
|
|
{
|
|
|
|
static const TokenTypeData data(
|
|
|
|
nsGkAtoms::aria_checked, eMixedType | eDefinedIfAbsent,
|
|
|
|
states::CHECKABLE, states::CHECKED);
|
|
|
|
|
|
|
|
MapTokenType(aElement, aState, data);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
case eARIACheckedMixed:
|
|
|
|
{
|
|
|
|
static const TokenTypeData data(
|
|
|
|
nsGkAtoms::aria_checked, eMixedType,
|
|
|
|
states::CHECKABLE, states::CHECKED);
|
|
|
|
|
|
|
|
MapTokenType(aElement, aState, data);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-07-03 18:02:00 +03:00
|
|
|
case eARIACurrent:
|
|
|
|
{
|
|
|
|
static const TokenTypeData data(
|
|
|
|
nsGkAtoms::aria_current, eBoolType,
|
|
|
|
0, states::CURRENT);
|
|
|
|
|
|
|
|
MapTokenType(aElement, aState, data);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-04-05 20:23:30 +04:00
|
|
|
case eARIADisabled:
|
|
|
|
{
|
|
|
|
static const TokenTypeData data(
|
|
|
|
nsGkAtoms::aria_disabled, eBoolType,
|
|
|
|
0, states::UNAVAILABLE);
|
|
|
|
|
|
|
|
MapTokenType(aElement, aState, data);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
case eARIAExpanded:
|
|
|
|
{
|
|
|
|
static const TokenTypeData data(
|
|
|
|
nsGkAtoms::aria_expanded, eBoolType,
|
|
|
|
0, states::EXPANDED, states::COLLAPSED);
|
|
|
|
|
|
|
|
MapTokenType(aElement, aState, data);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
case eARIAHasPopup:
|
|
|
|
{
|
|
|
|
static const TokenTypeData data(
|
|
|
|
nsGkAtoms::aria_haspopup, eBoolType,
|
|
|
|
0, states::HASPOPUP);
|
|
|
|
|
|
|
|
MapTokenType(aElement, aState, data);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
case eARIAInvalid:
|
|
|
|
{
|
|
|
|
static const TokenTypeData data(
|
|
|
|
nsGkAtoms::aria_invalid, eBoolType,
|
|
|
|
0, states::INVALID);
|
|
|
|
|
|
|
|
MapTokenType(aElement, aState, data);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-11-28 18:01:43 +03:00
|
|
|
case eARIAModal:
|
|
|
|
{
|
|
|
|
static const TokenTypeData data(
|
|
|
|
nsGkAtoms::aria_modal, eBoolType,
|
|
|
|
0, states::MODAL);
|
|
|
|
|
|
|
|
MapTokenType(aElement, aState, data);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-04-05 20:23:30 +04:00
|
|
|
case eARIAMultiline:
|
|
|
|
{
|
|
|
|
static const TokenTypeData data(
|
|
|
|
nsGkAtoms::aria_multiline, eBoolType | eDefinedIfAbsent,
|
|
|
|
0, states::MULTI_LINE, states::SINGLE_LINE);
|
|
|
|
|
|
|
|
MapTokenType(aElement, aState, data);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
case eARIAMultiSelectable:
|
|
|
|
{
|
|
|
|
static const TokenTypeData data(
|
|
|
|
nsGkAtoms::aria_multiselectable, eBoolType,
|
|
|
|
0, states::MULTISELECTABLE | states::EXTSELECTABLE);
|
|
|
|
|
|
|
|
MapTokenType(aElement, aState, data);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
case eARIAOrientation:
|
|
|
|
{
|
2014-08-11 16:13:44 +04:00
|
|
|
static const EnumTypeData data = {
|
|
|
|
nsGkAtoms::aria_orientation,
|
|
|
|
{ &nsGkAtoms::horizontal,
|
|
|
|
&nsGkAtoms::vertical, nullptr },
|
|
|
|
{ states::HORIZONTAL,
|
|
|
|
states::VERTICAL },
|
|
|
|
states::HORIZONTAL | states::VERTICAL
|
|
|
|
};
|
2012-04-05 20:23:30 +04:00
|
|
|
|
2014-08-11 16:13:44 +04:00
|
|
|
MapEnumType(aElement, aState, data);
|
2012-04-05 20:23:30 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
case eARIAPressed:
|
|
|
|
{
|
|
|
|
static const TokenTypeData data(
|
|
|
|
nsGkAtoms::aria_pressed, eMixedType,
|
2014-04-04 12:01:19 +04:00
|
|
|
0, states::PRESSED);
|
2012-04-05 20:23:30 +04:00
|
|
|
|
|
|
|
MapTokenType(aElement, aState, data);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
case eARIAReadonly:
|
|
|
|
{
|
|
|
|
static const TokenTypeData data(
|
|
|
|
nsGkAtoms::aria_readonly, eBoolType,
|
|
|
|
0, states::READONLY);
|
|
|
|
|
|
|
|
MapTokenType(aElement, aState, data);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
case eARIAReadonlyOrEditable:
|
|
|
|
{
|
|
|
|
static const TokenTypeData data(
|
|
|
|
nsGkAtoms::aria_readonly, eBoolType | eDefinedIfAbsent,
|
|
|
|
0, states::READONLY, states::EDITABLE);
|
|
|
|
|
|
|
|
MapTokenType(aElement, aState, data);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-02-14 14:57:35 +04:00
|
|
|
case eARIAReadonlyOrEditableIfDefined:
|
|
|
|
{
|
|
|
|
static const TokenTypeData data(
|
|
|
|
nsGkAtoms::aria_readonly, eBoolType,
|
|
|
|
0, states::READONLY, states::EDITABLE);
|
|
|
|
|
|
|
|
MapTokenType(aElement, aState, data);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-04-05 20:23:30 +04:00
|
|
|
case eARIARequired:
|
|
|
|
{
|
|
|
|
static const TokenTypeData data(
|
|
|
|
nsGkAtoms::aria_required, eBoolType,
|
|
|
|
0, states::REQUIRED);
|
|
|
|
|
|
|
|
MapTokenType(aElement, aState, data);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
case eARIASelectable:
|
|
|
|
{
|
|
|
|
static const TokenTypeData data(
|
|
|
|
nsGkAtoms::aria_selected, eBoolType | eDefinedIfAbsent,
|
|
|
|
states::SELECTABLE, states::SELECTED);
|
2013-07-19 19:20:51 +04:00
|
|
|
|
|
|
|
MapTokenType(aElement, aState, data);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
case eARIASelectableIfDefined:
|
|
|
|
{
|
|
|
|
static const TokenTypeData data(
|
|
|
|
nsGkAtoms::aria_selected, eBoolType,
|
|
|
|
states::SELECTABLE, states::SELECTED);
|
2012-04-05 20:23:30 +04:00
|
|
|
|
|
|
|
MapTokenType(aElement, aState, data);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
case eReadonlyUntilEditable:
|
|
|
|
{
|
|
|
|
if (!(*aState & states::EDITABLE))
|
|
|
|
*aState |= states::READONLY;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-04-13 02:44:16 +04:00
|
|
|
case eIndeterminateIfNoValue:
|
|
|
|
{
|
|
|
|
if (!aElement->HasAttr(kNameSpaceID_None, nsGkAtoms::aria_valuenow) &&
|
|
|
|
!aElement->HasAttr(kNameSpaceID_None, nsGkAtoms::aria_valuetext))
|
|
|
|
*aState |= states::MIXED;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-07-26 14:26:44 +04:00
|
|
|
case eFocusableUntilDisabled:
|
|
|
|
{
|
|
|
|
if (!nsAccUtils::HasDefinedARIAToken(aElement, nsGkAtoms::aria_disabled) ||
|
|
|
|
aElement->AttrValueIs(kNameSpaceID_None, nsGkAtoms::aria_disabled,
|
|
|
|
nsGkAtoms::_false, eCaseMatters))
|
|
|
|
*aState |= states::FOCUSABLE;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-04-05 20:23:30 +04:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-08-22 19:56:38 +04:00
|
|
|
MapEnumType(dom::Element* aElement, uint64_t* aState, const EnumTypeData& aData)
|
2012-04-05 20:23:30 +04:00
|
|
|
{
|
|
|
|
switch (aElement->FindAttrValueIn(kNameSpaceID_None, aData.mAttrName,
|
2014-08-11 16:13:44 +04:00
|
|
|
aData.mValues, eCaseMatters)) {
|
2012-04-05 20:23:30 +04:00
|
|
|
case 0:
|
2014-08-11 16:13:44 +04:00
|
|
|
*aState = (*aState & ~aData.mClearState) | aData.mStates[0];
|
2012-04-05 20:23:30 +04:00
|
|
|
return;
|
|
|
|
case 1:
|
2014-08-11 16:13:44 +04:00
|
|
|
*aState = (*aState & ~aData.mClearState) | aData.mStates[1];
|
2012-04-05 20:23:30 +04:00
|
|
|
return;
|
|
|
|
case 2:
|
2014-08-11 16:13:44 +04:00
|
|
|
*aState = (*aState & ~aData.mClearState) | aData.mStates[2];
|
2012-04-05 20:23:30 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-08-22 19:56:38 +04:00
|
|
|
MapTokenType(dom::Element* aElement, uint64_t* aState,
|
2012-04-05 20:23:30 +04:00
|
|
|
const TokenTypeData& aData)
|
|
|
|
{
|
2013-08-01 19:11:56 +04:00
|
|
|
if (nsAccUtils::HasDefinedARIAToken(aElement, aData.mAttrName)) {
|
2017-07-03 20:12:00 +03:00
|
|
|
if (aElement->AttrValueIs(kNameSpaceID_None, aData.mAttrName,
|
2012-04-05 20:23:30 +04:00
|
|
|
nsGkAtoms::mixed, eCaseMatters)) {
|
2017-07-03 20:12:00 +03:00
|
|
|
if (aData.mType & eMixedType)
|
|
|
|
*aState |= aData.mPermanentState | states::MIXED;
|
|
|
|
else // unsupported use of 'mixed' is an authoring error
|
|
|
|
*aState |= aData.mPermanentState | aData.mFalseState;
|
2012-04-05 20:23:30 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aElement->AttrValueIs(kNameSpaceID_None, aData.mAttrName,
|
|
|
|
nsGkAtoms::_false, eCaseMatters)) {
|
|
|
|
*aState |= aData.mPermanentState | aData.mFalseState;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-08-01 19:11:56 +04:00
|
|
|
*aState |= aData.mPermanentState | aData.mTrueState;
|
2012-04-05 20:23:30 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aData.mType & eDefinedIfAbsent)
|
|
|
|
*aState |= aData.mPermanentState | aData.mFalseState;
|
|
|
|
}
|