2008-10-16 02:12:05 -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/. */
|
2008-10-16 02:12:05 -07:00
|
|
|
|
|
|
|
#include "nsAccUtils.h"
|
|
|
|
|
2012-04-13 07:17:03 -07:00
|
|
|
#include "Accessible-inl.h"
|
2010-04-26 23:52:03 -07:00
|
|
|
#include "nsAccessibilityService.h"
|
2008-10-16 02:12:05 -07:00
|
|
|
#include "nsARIAMap.h"
|
2012-04-13 07:17:03 -07:00
|
|
|
#include "nsCoreUtils.h"
|
2012-05-27 02:01:40 -07:00
|
|
|
#include "DocAccessible.h"
|
2012-05-31 01:04:41 -07:00
|
|
|
#include "HyperTextAccessible.h"
|
2012-04-13 07:17:03 -07:00
|
|
|
#include "nsIAccessibleTypes.h"
|
|
|
|
#include "Role.h"
|
|
|
|
#include "States.h"
|
2012-05-23 11:05:57 -07:00
|
|
|
#include "TextLeafAccessible.h"
|
2012-08-01 11:31:10 -07:00
|
|
|
#include "nsIMutableArray.h"
|
2008-10-17 03:10:43 -07:00
|
|
|
|
2008-10-16 02:12:05 -07:00
|
|
|
#include "nsIDOMXULContainerElement.h"
|
|
|
|
#include "nsIDOMXULSelectCntrlEl.h"
|
|
|
|
#include "nsIDOMXULSelectCntrlItemEl.h"
|
|
|
|
#include "nsWhitespaceTokenizer.h"
|
2009-09-10 18:07:56 -07:00
|
|
|
#include "nsComponentManagerUtils.h"
|
2008-10-16 02:12:05 -07:00
|
|
|
|
2012-08-08 23:24:31 -07:00
|
|
|
using namespace mozilla;
|
2011-07-27 05:43:01 -07:00
|
|
|
using namespace mozilla::a11y;
|
|
|
|
|
2008-10-16 02:12:05 -07:00
|
|
|
void
|
|
|
|
nsAccUtils::GetAccAttr(nsIPersistentProperties *aAttributes,
|
|
|
|
nsIAtom *aAttrName, nsAString& aAttrValue)
|
|
|
|
{
|
|
|
|
aAttrValue.Truncate();
|
|
|
|
|
2010-03-08 07:45:00 -08:00
|
|
|
aAttributes->GetStringProperty(nsAtomCString(aAttrName), aAttrValue);
|
2008-10-16 02:12:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsAccUtils::SetAccAttr(nsIPersistentProperties *aAttributes,
|
|
|
|
nsIAtom *aAttrName, const nsAString& aAttrValue)
|
|
|
|
{
|
|
|
|
nsAutoString oldValue;
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString attrName;
|
2008-10-16 02:12:05 -07:00
|
|
|
|
2010-03-08 07:45:00 -08:00
|
|
|
aAttributes->SetStringProperty(nsAtomCString(aAttrName), aAttrValue, oldValue);
|
2008-10-16 02:12:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsAccUtils::SetAccGroupAttrs(nsIPersistentProperties *aAttributes,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aLevel, int32_t aSetSize,
|
|
|
|
int32_t aPosInSet)
|
2008-10-16 02:12:05 -07:00
|
|
|
{
|
|
|
|
nsAutoString value;
|
|
|
|
|
|
|
|
if (aLevel) {
|
|
|
|
value.AppendInt(aLevel);
|
2011-06-03 14:35:17 -07:00
|
|
|
SetAccAttr(aAttributes, nsGkAtoms::level, value);
|
2008-10-16 02:12:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aSetSize && aPosInSet) {
|
|
|
|
value.Truncate();
|
|
|
|
value.AppendInt(aPosInSet);
|
2011-06-03 14:35:17 -07:00
|
|
|
SetAccAttr(aAttributes, nsGkAtoms::posinset, value);
|
2008-10-16 02:12:05 -07:00
|
|
|
|
|
|
|
value.Truncate();
|
|
|
|
value.AppendInt(aSetSize);
|
2011-06-03 14:35:17 -07:00
|
|
|
SetAccAttr(aAttributes, nsGkAtoms::setsize, value);
|
2008-10-16 02:12:05 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t
|
2012-05-28 18:18:45 -07:00
|
|
|
nsAccUtils::GetDefaultLevel(Accessible* aAccessible)
|
2010-01-12 11:07:38 -08:00
|
|
|
{
|
2012-01-11 19:07:35 -08:00
|
|
|
roles::Role role = aAccessible->Role();
|
2010-01-12 11:07:38 -08:00
|
|
|
|
2012-01-11 19:07:35 -08:00
|
|
|
if (role == roles::OUTLINEITEM)
|
2010-01-12 11:07:38 -08:00
|
|
|
return 1;
|
|
|
|
|
2012-01-11 19:07:35 -08:00
|
|
|
if (role == roles::ROW) {
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* parent = aAccessible->Parent();
|
2012-01-11 19:07:35 -08:00
|
|
|
// It is a row inside flatten treegrid. Group level is always 1 until it
|
|
|
|
// is overriden by aria-level attribute.
|
|
|
|
if (parent && parent->Role() == roles::TREE_TABLE)
|
2010-01-12 11:07:38 -08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t
|
2012-05-28 18:18:45 -07:00
|
|
|
nsAccUtils::GetARIAOrDefaultLevel(Accessible* aAccessible)
|
2010-01-12 11:07:38 -08:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t level = 0;
|
2010-06-11 21:04:50 -07:00
|
|
|
nsCoreUtils::GetUIntAttr(aAccessible->GetContent(),
|
2011-06-03 14:35:17 -07:00
|
|
|
nsGkAtoms::aria_level, &level);
|
2010-01-12 11:07:38 -08:00
|
|
|
|
|
|
|
if (level != 0)
|
|
|
|
return level;
|
|
|
|
|
2010-06-11 21:04:50 -07:00
|
|
|
return GetDefaultLevel(aAccessible);
|
2010-01-12 11:07:38 -08:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t
|
2010-06-11 01:23:18 -07:00
|
|
|
nsAccUtils::GetLevelForXULContainerItem(nsIContent *aContent)
|
2010-01-06 02:36:50 -08:00
|
|
|
{
|
2010-06-11 01:23:18 -07:00
|
|
|
nsCOMPtr<nsIDOMXULContainerItemElement> item(do_QueryInterface(aContent));
|
2010-01-06 02:36:50 -08:00
|
|
|
if (!item)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMXULContainerElement> container;
|
|
|
|
item->GetParentContainer(getter_AddRefs(container));
|
|
|
|
if (!container)
|
|
|
|
return 0;
|
2008-10-16 02:12:05 -07:00
|
|
|
|
|
|
|
// Get level of the item.
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t level = -1;
|
2008-10-16 02:12:05 -07:00
|
|
|
while (container) {
|
|
|
|
level++;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMXULContainerElement> parentContainer;
|
|
|
|
container->GetParentContainer(getter_AddRefs(parentContainer));
|
|
|
|
parentContainer.swap(container);
|
|
|
|
}
|
2010-01-06 02:36:50 -08:00
|
|
|
|
|
|
|
return level;
|
2008-10-16 02:12:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsAccUtils::SetLiveContainerAttributes(nsIPersistentProperties *aAttributes,
|
|
|
|
nsIContent *aStartContent,
|
|
|
|
nsIContent *aTopContent)
|
|
|
|
{
|
2009-01-12 22:08:46 -08:00
|
|
|
nsAutoString atomic, live, relevant, busy;
|
2008-10-16 02:12:05 -07:00
|
|
|
nsIContent *ancestor = aStartContent;
|
|
|
|
while (ancestor) {
|
2009-02-18 22:56:19 -08:00
|
|
|
|
|
|
|
// container-relevant attribute
|
2008-10-16 02:12:05 -07:00
|
|
|
if (relevant.IsEmpty() &&
|
2011-06-03 14:35:17 -07:00
|
|
|
nsAccUtils::HasDefinedARIAToken(ancestor, nsGkAtoms::aria_relevant) &&
|
|
|
|
ancestor->GetAttr(kNameSpaceID_None, nsGkAtoms::aria_relevant, relevant))
|
|
|
|
SetAccAttr(aAttributes, nsGkAtoms::containerRelevant, relevant);
|
2008-10-16 02:12:05 -07:00
|
|
|
|
2009-06-19 10:44:13 -07:00
|
|
|
// container-live, and container-live-role attributes
|
2009-02-18 22:56:19 -08:00
|
|
|
if (live.IsEmpty()) {
|
2012-04-16 02:24:23 -07:00
|
|
|
nsRoleMapEntry* role = aria::GetRoleMap(ancestor);
|
2009-02-18 22:56:19 -08:00
|
|
|
if (nsAccUtils::HasDefinedARIAToken(ancestor,
|
2011-06-03 14:35:17 -07:00
|
|
|
nsGkAtoms::aria_live)) {
|
|
|
|
ancestor->GetAttr(kNameSpaceID_None, nsGkAtoms::aria_live,
|
2009-02-18 22:56:19 -08:00
|
|
|
live);
|
2009-06-19 10:44:13 -07:00
|
|
|
} else if (role) {
|
|
|
|
GetLiveAttrValue(role->liveAttRule, live);
|
|
|
|
}
|
|
|
|
if (!live.IsEmpty()) {
|
2011-06-03 14:35:17 -07:00
|
|
|
SetAccAttr(aAttributes, nsGkAtoms::containerLive, live);
|
2009-02-18 22:56:19 -08:00
|
|
|
if (role) {
|
2012-06-10 16:44:50 -07:00
|
|
|
nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::containerLiveRole,
|
|
|
|
role->ARIARoleString());
|
2009-02-18 22:56:19 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-10-16 02:12:05 -07:00
|
|
|
|
2009-02-18 22:56:19 -08:00
|
|
|
// container-atomic attribute
|
2008-10-16 02:12:05 -07:00
|
|
|
if (atomic.IsEmpty() &&
|
2011-06-03 14:35:17 -07:00
|
|
|
nsAccUtils::HasDefinedARIAToken(ancestor, nsGkAtoms::aria_atomic) &&
|
|
|
|
ancestor->GetAttr(kNameSpaceID_None, nsGkAtoms::aria_atomic, atomic))
|
|
|
|
SetAccAttr(aAttributes, nsGkAtoms::containerAtomic, atomic);
|
2008-10-16 02:12:05 -07:00
|
|
|
|
2009-02-18 22:56:19 -08:00
|
|
|
// container-busy attribute
|
2008-10-16 02:12:05 -07:00
|
|
|
if (busy.IsEmpty() &&
|
2011-06-03 14:35:17 -07:00
|
|
|
nsAccUtils::HasDefinedARIAToken(ancestor, nsGkAtoms::aria_busy) &&
|
|
|
|
ancestor->GetAttr(kNameSpaceID_None, nsGkAtoms::aria_busy, busy))
|
|
|
|
SetAccAttr(aAttributes, nsGkAtoms::containerBusy, busy);
|
2008-10-16 02:12:05 -07:00
|
|
|
|
|
|
|
if (ancestor == aTopContent)
|
|
|
|
break;
|
|
|
|
|
|
|
|
ancestor = ancestor->GetParent();
|
|
|
|
if (!ancestor)
|
|
|
|
ancestor = aTopContent; // Use <body>/<frameset>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2009-01-12 09:20:34 -08:00
|
|
|
nsAccUtils::HasDefinedARIAToken(nsIContent *aContent, nsIAtom *aAtom)
|
|
|
|
{
|
2009-04-19 23:06:19 -07:00
|
|
|
NS_ASSERTION(aContent, "aContent is null in call to HasDefinedARIAToken!");
|
|
|
|
|
2009-01-12 09:20:34 -08:00
|
|
|
if (!aContent->HasAttr(kNameSpaceID_None, aAtom) ||
|
|
|
|
aContent->AttrValueIs(kNameSpaceID_None, aAtom,
|
2011-06-03 14:35:17 -07:00
|
|
|
nsGkAtoms::_empty, eCaseMatters) ||
|
2009-01-12 09:20:34 -08:00
|
|
|
aContent->AttrValueIs(kNameSpaceID_None, aAtom,
|
2011-06-03 14:35:17 -07:00
|
|
|
nsGkAtoms::_undefined, eCaseMatters)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2009-01-12 09:20:34 -08:00
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2009-01-12 09:20:34 -08:00
|
|
|
}
|
|
|
|
|
2011-08-11 04:45:36 -07:00
|
|
|
nsIAtom*
|
|
|
|
nsAccUtils::GetARIAToken(dom::Element* aElement, nsIAtom* aAttr)
|
|
|
|
{
|
|
|
|
if (!nsAccUtils::HasDefinedARIAToken(aElement, aAttr))
|
2011-06-03 14:35:17 -07:00
|
|
|
return nsGkAtoms::_empty;
|
2011-08-11 04:45:36 -07:00
|
|
|
|
|
|
|
static nsIContent::AttrValuesArray tokens[] =
|
2011-06-03 14:35:17 -07:00
|
|
|
{ &nsGkAtoms::_false, &nsGkAtoms::_true,
|
2012-07-30 07:20:58 -07:00
|
|
|
&nsGkAtoms::mixed, nullptr};
|
2011-08-11 04:45:36 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t idx = aElement->FindAttrValueIn(kNameSpaceID_None,
|
2011-08-11 04:45:36 -07:00
|
|
|
aAttr, tokens, eCaseMatters);
|
|
|
|
if (idx >= 0)
|
|
|
|
return *(tokens[idx]);
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2011-08-11 04:45:36 -07:00
|
|
|
}
|
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible*
|
2012-08-22 08:56:38 -07:00
|
|
|
nsAccUtils::GetAncestorWithRole(Accessible* aDescendant, uint32_t aRole)
|
2008-10-16 02:12:05 -07:00
|
|
|
{
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* document = aDescendant->Document();
|
|
|
|
Accessible* parent = aDescendant;
|
2011-07-23 01:38:33 -07:00
|
|
|
while ((parent = parent->Parent())) {
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t testRole = parent->Role();
|
2010-06-11 01:23:18 -07:00
|
|
|
if (testRole == aRole)
|
|
|
|
return parent;
|
|
|
|
|
|
|
|
if (parent == document)
|
2008-10-16 02:12:05 -07:00
|
|
|
break;
|
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2008-10-16 02:12:05 -07:00
|
|
|
}
|
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible*
|
2012-08-22 08:56:38 -07:00
|
|
|
nsAccUtils::GetSelectableContainer(Accessible* aAccessible, uint64_t aState)
|
2009-12-11 11:38:55 -08:00
|
|
|
{
|
|
|
|
if (!aAccessible)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2009-12-11 11:38:55 -08:00
|
|
|
|
2011-04-09 16:38:06 -07:00
|
|
|
if (!(aState & states::SELECTABLE))
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2009-12-11 11:38:55 -08:00
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* parent = aAccessible;
|
2011-07-23 01:38:33 -07:00
|
|
|
while ((parent = parent->Parent()) && !parent->IsSelect()) {
|
2010-09-01 17:46:59 -07:00
|
|
|
if (Role(parent) == nsIAccessibleRole::ROLE_PANE)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2009-12-11 11:38:55 -08:00
|
|
|
}
|
2010-06-11 01:23:18 -07:00
|
|
|
return parent;
|
2009-12-11 11:38:55 -08:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2012-05-28 18:18:45 -07:00
|
|
|
nsAccUtils::IsARIASelected(Accessible* aAccessible)
|
2009-09-10 18:07:56 -07:00
|
|
|
{
|
2010-06-11 21:04:50 -07:00
|
|
|
return aAccessible->GetContent()->
|
2011-06-03 14:35:17 -07:00
|
|
|
AttrValueIs(kNameSpaceID_None, nsGkAtoms::aria_selected,
|
|
|
|
nsGkAtoms::_true, eCaseMatters);
|
2009-09-10 18:07:56 -07:00
|
|
|
}
|
|
|
|
|
2012-05-31 01:04:41 -07:00
|
|
|
HyperTextAccessible*
|
2010-11-29 08:03:29 -08:00
|
|
|
nsAccUtils::GetTextAccessibleFromSelection(nsISelection* aSelection)
|
2008-10-28 01:43:07 -07:00
|
|
|
{
|
|
|
|
// Get accessible from selection's focus DOM point (the DOM point where
|
|
|
|
// selection is ended).
|
|
|
|
|
2010-05-25 01:12:43 -07:00
|
|
|
nsCOMPtr<nsIDOMNode> focusDOMNode;
|
|
|
|
aSelection->GetFocusNode(getter_AddRefs(focusDOMNode));
|
|
|
|
if (!focusDOMNode)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2008-10-28 01:43:07 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t focusOffset = 0;
|
2008-12-16 02:14:20 -08:00
|
|
|
aSelection->GetFocusOffset(&focusOffset);
|
|
|
|
|
2010-05-25 01:12:43 -07:00
|
|
|
nsCOMPtr<nsINode> focusNode(do_QueryInterface(focusDOMNode));
|
|
|
|
nsCOMPtr<nsINode> resultNode =
|
2008-12-16 02:14:20 -08:00
|
|
|
nsCoreUtils::GetDOMNodeFromDOMPoint(focusNode, focusOffset);
|
2008-10-28 01:43:07 -07:00
|
|
|
|
|
|
|
// Get text accessible containing the result node.
|
2012-05-27 02:01:40 -07:00
|
|
|
DocAccessible* doc =
|
2012-02-07 14:38:54 -08:00
|
|
|
GetAccService()->GetDocAccessible(resultNode->OwnerDoc());
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* accessible = doc ?
|
2012-07-30 07:20:58 -07:00
|
|
|
doc->GetAccessibleOrContainer(resultNode) : nullptr;
|
2010-06-30 19:18:08 -07:00
|
|
|
if (!accessible) {
|
|
|
|
NS_NOTREACHED("No nsIAccessibleText for selection change event!");
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2008-10-28 01:43:07 -07:00
|
|
|
}
|
|
|
|
|
2010-06-30 19:18:08 -07:00
|
|
|
do {
|
2012-05-31 01:04:41 -07:00
|
|
|
HyperTextAccessible* textAcc = accessible->AsHyperText();
|
2010-11-29 08:03:29 -08:00
|
|
|
if (textAcc)
|
2010-06-30 19:18:08 -07:00
|
|
|
return textAcc;
|
2010-11-29 08:03:29 -08:00
|
|
|
|
2011-12-17 22:00:47 -08:00
|
|
|
accessible = accessible->Parent();
|
|
|
|
} while (accessible);
|
2010-06-30 19:18:08 -07:00
|
|
|
|
|
|
|
NS_NOTREACHED("We must reach document accessible implementing nsIAccessibleText!");
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2008-10-28 01:43:07 -07:00
|
|
|
}
|
|
|
|
|
2008-10-16 02:12:05 -07:00
|
|
|
nsresult
|
2012-08-22 08:56:38 -07:00
|
|
|
nsAccUtils::ConvertToScreenCoords(int32_t aX, int32_t aY,
|
|
|
|
uint32_t aCoordinateType,
|
2010-06-11 01:23:18 -07:00
|
|
|
nsAccessNode *aAccessNode,
|
2008-10-16 02:12:05 -07:00
|
|
|
nsIntPoint *aCoords)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aCoords);
|
|
|
|
|
|
|
|
aCoords->MoveTo(aX, aY);
|
|
|
|
|
|
|
|
switch (aCoordinateType) {
|
|
|
|
case nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsIAccessibleCoordinateType::COORDTYPE_WINDOW_RELATIVE:
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG(aAccessNode);
|
|
|
|
*aCoords += GetScreenCoordsForWindow(aAccessNode);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case nsIAccessibleCoordinateType::COORDTYPE_PARENT_RELATIVE:
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG(aAccessNode);
|
|
|
|
*aCoords += GetScreenCoordsForParent(aAccessNode);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-08-22 08:56:38 -07:00
|
|
|
nsAccUtils::ConvertScreenCoordsTo(int32_t *aX, int32_t *aY,
|
|
|
|
uint32_t aCoordinateType,
|
2010-06-11 01:23:18 -07:00
|
|
|
nsAccessNode *aAccessNode)
|
2008-10-16 02:12:05 -07:00
|
|
|
{
|
|
|
|
switch (aCoordinateType) {
|
|
|
|
case nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsIAccessibleCoordinateType::COORDTYPE_WINDOW_RELATIVE:
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG(aAccessNode);
|
|
|
|
nsIntPoint coords = nsAccUtils::GetScreenCoordsForWindow(aAccessNode);
|
|
|
|
*aX -= coords.x;
|
|
|
|
*aY -= coords.y;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case nsIAccessibleCoordinateType::COORDTYPE_PARENT_RELATIVE:
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG(aAccessNode);
|
|
|
|
nsIntPoint coords = nsAccUtils::GetScreenCoordsForParent(aAccessNode);
|
|
|
|
*aX -= coords.x;
|
|
|
|
*aY -= coords.y;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIntPoint
|
2010-06-11 01:23:18 -07:00
|
|
|
nsAccUtils::GetScreenCoordsForWindow(nsAccessNode *aAccessNode)
|
2008-10-16 02:12:05 -07:00
|
|
|
{
|
2010-06-11 01:23:18 -07:00
|
|
|
return nsCoreUtils::GetScreenCoordsForWindow(aAccessNode->GetNode());
|
2008-10-16 02:12:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIntPoint
|
2010-06-11 01:23:18 -07:00
|
|
|
nsAccUtils::GetScreenCoordsForParent(nsAccessNode *aAccessNode)
|
2008-10-16 02:12:05 -07:00
|
|
|
{
|
2012-05-27 02:01:40 -07:00
|
|
|
DocAccessible* document = aAccessNode->Document();
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* parent = document->GetContainerAccessible(aAccessNode->GetNode());
|
2008-10-16 02:12:05 -07:00
|
|
|
if (!parent)
|
|
|
|
return nsIntPoint(0, 0);
|
|
|
|
|
|
|
|
nsIFrame *parentFrame = parent->GetFrame();
|
|
|
|
if (!parentFrame)
|
|
|
|
return nsIntPoint(0, 0);
|
|
|
|
|
2012-10-19 08:10:28 -07:00
|
|
|
nsRect rect = parentFrame->GetScreenRectInAppUnits();
|
|
|
|
return nsPoint(rect.x, rect.y).
|
|
|
|
ToNearestPixels(parentFrame->PresContext()->AppUnitsPerDevPixel());
|
2008-10-16 02:12:05 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t
|
2009-02-15 00:15:31 -08:00
|
|
|
nsAccUtils::GetAttributeCharacteristics(nsIAtom* aAtom)
|
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < nsARIAMap::gWAIUnivAttrMapLength; i++)
|
2009-02-15 00:15:31 -08:00
|
|
|
if (*nsARIAMap::gWAIUnivAttrMap[i].attributeName == aAtom)
|
|
|
|
return nsARIAMap::gWAIUnivAttrMap[i].characteristics;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2012-08-22 08:56:38 -07:00
|
|
|
nsAccUtils::GetLiveAttrValue(uint32_t aRule, nsAString& aValue)
|
2009-02-18 22:56:19 -08:00
|
|
|
{
|
|
|
|
switch (aRule) {
|
|
|
|
case eOffLiveAttr:
|
|
|
|
aValue = NS_LITERAL_STRING("off");
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2009-02-18 22:56:19 -08:00
|
|
|
case ePoliteLiveAttr:
|
|
|
|
aValue = NS_LITERAL_STRING("polite");
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2009-02-18 22:56:19 -08:00
|
|
|
}
|
2009-08-27 22:27:27 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2009-02-18 22:56:19 -08:00
|
|
|
}
|
2008-10-17 03:10:43 -07:00
|
|
|
|
2012-05-07 16:49:41 -07:00
|
|
|
#ifdef DEBUG
|
2008-10-17 03:10:43 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2012-05-28 18:18:45 -07:00
|
|
|
nsAccUtils::IsTextInterfaceSupportCorrect(Accessible* aAccessible)
|
2008-10-17 03:10:43 -07:00
|
|
|
{
|
2011-12-27 14:25:43 -08:00
|
|
|
// Don't test for accessible docs, it makes us create accessibles too
|
|
|
|
// early and fire mutation events before we need to
|
|
|
|
if (aAccessible->IsDoc())
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2008-10-17 03:10:43 -07:00
|
|
|
|
2011-12-27 14:25:43 -08:00
|
|
|
bool foundText = false;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t childCount = aAccessible->ChildCount();
|
|
|
|
for (uint32_t childIdx = 0; childIdx < childCount; childIdx++) {
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* child = aAccessible->GetChildAt(childIdx);
|
2008-10-17 03:10:43 -07:00
|
|
|
if (IsText(child)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
foundText = true;
|
2008-10-17 03:10:43 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (foundText) {
|
|
|
|
// found text child node
|
2010-05-18 07:03:56 -07:00
|
|
|
nsCOMPtr<nsIAccessibleText> text = do_QueryObject(aAccessible);
|
2008-10-17 03:10:43 -07:00
|
|
|
if (!text)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2008-10-17 03:10:43 -07:00
|
|
|
}
|
|
|
|
|
2012-05-07 16:49:41 -07:00
|
|
|
return true;
|
2008-10-17 03:10:43 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t
|
2012-05-28 18:18:45 -07:00
|
|
|
nsAccUtils::TextLength(Accessible* aAccessible)
|
2008-10-17 03:10:43 -07:00
|
|
|
{
|
|
|
|
if (!IsText(aAccessible))
|
|
|
|
return 1;
|
2010-05-25 01:40:54 -07:00
|
|
|
|
2012-05-23 11:05:57 -07:00
|
|
|
TextLeafAccessible* textLeaf = aAccessible->AsTextLeaf();
|
2011-01-31 19:00:45 -08:00
|
|
|
if (textLeaf)
|
|
|
|
return textLeaf->Text().Length();
|
2010-05-25 01:40:54 -07:00
|
|
|
|
2008-10-17 03:10:43 -07:00
|
|
|
// For list bullets (or anything other accessible which would compute its own
|
|
|
|
// text. They don't have their own frame.
|
|
|
|
// XXX In the future, list bullets may have frame and anon content, so
|
|
|
|
// we should be able to remove this at that point
|
|
|
|
nsAutoString text;
|
2011-01-31 19:00:24 -08:00
|
|
|
aAccessible->AppendTextTo(text); // Get all the text
|
2008-10-17 03:10:43 -07:00
|
|
|
return text.Length();
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2012-05-28 18:18:45 -07:00
|
|
|
nsAccUtils::MustPrune(Accessible* aAccessible)
|
2008-10-17 03:10:43 -07:00
|
|
|
{
|
2012-05-21 09:30:53 -07:00
|
|
|
roles::Role role = aAccessible->Role();
|
2008-10-17 03:10:43 -07:00
|
|
|
|
2009-11-09 21:58:52 -08:00
|
|
|
// We don't prune buttons any more however AT don't expect children inside of
|
|
|
|
// button in general, we allow menu buttons to have children to make them
|
|
|
|
// accessible.
|
2012-05-21 09:30:53 -07:00
|
|
|
return role == roles::MENUITEM ||
|
|
|
|
role == roles::COMBOBOX_OPTION ||
|
|
|
|
role == roles::OPTION ||
|
|
|
|
role == roles::ENTRY ||
|
|
|
|
role == roles::FLAT_EQUATION ||
|
|
|
|
role == roles::PASSWORD_TEXT ||
|
|
|
|
role == roles::TOGGLE_BUTTON ||
|
|
|
|
role == roles::GRAPHIC ||
|
|
|
|
role == roles::SLIDER ||
|
|
|
|
role == roles::PROGRESSBAR ||
|
|
|
|
role == roles::SEPARATOR;
|
2008-10-17 03:10:43 -07:00
|
|
|
}
|