2008-10-16 13:12:05 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04: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 13:12:05 +04:00
|
|
|
|
|
|
|
#include "nsAccUtils.h"
|
|
|
|
|
2012-04-13 18:17:03 +04:00
|
|
|
#include "Accessible-inl.h"
|
2013-04-25 07:48:26 +04:00
|
|
|
#include "ARIAMap.h"
|
2010-04-27 10:52:03 +04:00
|
|
|
#include "nsAccessibilityService.h"
|
2012-04-13 18:17:03 +04:00
|
|
|
#include "nsCoreUtils.h"
|
2012-05-27 13:01:40 +04:00
|
|
|
#include "DocAccessible.h"
|
2012-05-31 12:04:41 +04:00
|
|
|
#include "HyperTextAccessible.h"
|
2012-04-13 18:17:03 +04:00
|
|
|
#include "nsIAccessibleTypes.h"
|
|
|
|
#include "Role.h"
|
|
|
|
#include "States.h"
|
2012-05-23 22:05:57 +04:00
|
|
|
#include "TextLeafAccessible.h"
|
2008-10-17 14:10:43 +04:00
|
|
|
|
2008-10-16 13:12:05 +04:00
|
|
|
#include "nsIDOMXULContainerElement.h"
|
2013-09-11 02:18:59 +04:00
|
|
|
#include "nsIPersistentProperties2.h"
|
|
|
|
#include "mozilla/dom/Element.h"
|
2008-10-16 13:12:05 +04:00
|
|
|
|
2012-08-09 10:24:31 +04:00
|
|
|
using namespace mozilla;
|
2011-07-27 16:43:01 +04:00
|
|
|
using namespace mozilla::a11y;
|
|
|
|
|
2008-10-16 13:12:05 +04:00
|
|
|
void
|
|
|
|
nsAccUtils::GetAccAttr(nsIPersistentProperties *aAttributes,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom *aAttrName, nsAString& aAttrValue)
|
2008-10-16 13:12:05 +04:00
|
|
|
{
|
|
|
|
aAttrValue.Truncate();
|
|
|
|
|
2010-03-08 18:45:00 +03:00
|
|
|
aAttributes->GetStringProperty(nsAtomCString(aAttrName), aAttrValue);
|
2008-10-16 13:12:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsAccUtils::SetAccAttr(nsIPersistentProperties *aAttributes,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom *aAttrName, const nsAString& aAttrValue)
|
2008-10-16 13:12:05 +04:00
|
|
|
{
|
|
|
|
nsAutoString oldValue;
|
2010-03-08 18:45:00 +03:00
|
|
|
aAttributes->SetStringProperty(nsAtomCString(aAttrName), aAttrValue, oldValue);
|
2008-10-16 13:12:05 +04:00
|
|
|
}
|
|
|
|
|
2015-03-01 01:25:06 +03:00
|
|
|
void
|
|
|
|
nsAccUtils::SetAccAttr(nsIPersistentProperties *aAttributes,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aAttrName, nsAtom* aAttrValue)
|
2015-03-01 01:25:06 +03:00
|
|
|
{
|
|
|
|
nsAutoString oldValue;
|
|
|
|
aAttributes->SetStringProperty(nsAtomCString(aAttrName),
|
|
|
|
nsAtomString(aAttrValue), oldValue);
|
|
|
|
}
|
|
|
|
|
2008-10-16 13:12:05 +04:00
|
|
|
void
|
|
|
|
nsAccUtils::SetAccGroupAttrs(nsIPersistentProperties *aAttributes,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aLevel, int32_t aSetSize,
|
|
|
|
int32_t aPosInSet)
|
2008-10-16 13:12:05 +04:00
|
|
|
{
|
|
|
|
nsAutoString value;
|
|
|
|
|
|
|
|
if (aLevel) {
|
|
|
|
value.AppendInt(aLevel);
|
2011-06-04 01:35:17 +04:00
|
|
|
SetAccAttr(aAttributes, nsGkAtoms::level, value);
|
2008-10-16 13:12:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aSetSize && aPosInSet) {
|
|
|
|
value.Truncate();
|
|
|
|
value.AppendInt(aPosInSet);
|
2011-06-04 01:35:17 +04:00
|
|
|
SetAccAttr(aAttributes, nsGkAtoms::posinset, value);
|
2008-10-16 13:12:05 +04:00
|
|
|
|
|
|
|
value.Truncate();
|
|
|
|
value.AppendInt(aSetSize);
|
2011-06-04 01:35:17 +04:00
|
|
|
SetAccAttr(aAttributes, nsGkAtoms::setsize, value);
|
2008-10-16 13:12:05 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t
|
2018-05-15 17:14:44 +03:00
|
|
|
nsAccUtils::GetDefaultLevel(const Accessible* aAccessible)
|
2010-01-12 22:07:38 +03:00
|
|
|
{
|
2012-01-12 07:07:35 +04:00
|
|
|
roles::Role role = aAccessible->Role();
|
2010-01-12 22:07:38 +03:00
|
|
|
|
2012-01-12 07:07:35 +04:00
|
|
|
if (role == roles::OUTLINEITEM)
|
2010-01-12 22:07:38 +03:00
|
|
|
return 1;
|
|
|
|
|
2012-01-12 07:07:35 +04:00
|
|
|
if (role == roles::ROW) {
|
2012-05-29 05:18:45 +04:00
|
|
|
Accessible* parent = aAccessible->Parent();
|
2012-01-12 07:07:35 +04:00
|
|
|
// It is a row inside flatten treegrid. Group level is always 1 until it
|
|
|
|
// is overriden by aria-level attribute.
|
2017-07-06 15:00:35 +03:00
|
|
|
if (parent && parent->Role() == roles::TREE_TABLE)
|
2010-01-12 22:07:38 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t
|
2018-05-15 17:14:44 +03:00
|
|
|
nsAccUtils::GetARIAOrDefaultLevel(const Accessible* aAccessible)
|
2010-01-12 22:07:38 +03:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t level = 0;
|
2010-06-12 08:04:50 +04:00
|
|
|
nsCoreUtils::GetUIntAttr(aAccessible->GetContent(),
|
2011-06-04 01:35:17 +04:00
|
|
|
nsGkAtoms::aria_level, &level);
|
2010-01-12 22:07:38 +03:00
|
|
|
|
|
|
|
if (level != 0)
|
|
|
|
return level;
|
|
|
|
|
2010-06-12 08:04:50 +04:00
|
|
|
return GetDefaultLevel(aAccessible);
|
2010-01-12 22:07:38 +03:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t
|
2010-06-11 12:23:18 +04:00
|
|
|
nsAccUtils::GetLevelForXULContainerItem(nsIContent *aContent)
|
2010-01-06 13:36:50 +03:00
|
|
|
{
|
2010-06-11 12:23:18 +04:00
|
|
|
nsCOMPtr<nsIDOMXULContainerItemElement> item(do_QueryInterface(aContent));
|
2010-01-06 13:36:50 +03:00
|
|
|
if (!item)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMXULContainerElement> container;
|
|
|
|
item->GetParentContainer(getter_AddRefs(container));
|
|
|
|
if (!container)
|
|
|
|
return 0;
|
2008-10-16 13:12:05 +04:00
|
|
|
|
|
|
|
// Get level of the item.
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t level = -1;
|
2008-10-16 13:12:05 +04:00
|
|
|
while (container) {
|
|
|
|
level++;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMXULContainerElement> parentContainer;
|
|
|
|
container->GetParentContainer(getter_AddRefs(parentContainer));
|
|
|
|
parentContainer.swap(container);
|
|
|
|
}
|
2010-01-06 13:36:50 +03:00
|
|
|
|
|
|
|
return level;
|
2008-10-16 13:12:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsAccUtils::SetLiveContainerAttributes(nsIPersistentProperties *aAttributes,
|
2016-03-03 15:45:47 +03:00
|
|
|
nsIContent* aStartContent,
|
|
|
|
dom::Element* aTopEl)
|
2008-10-16 13:12:05 +04:00
|
|
|
{
|
2013-06-26 02:11:39 +04:00
|
|
|
nsAutoString live, relevant, busy;
|
2016-03-03 15:45:47 +03:00
|
|
|
nsIContent* ancestor = aStartContent;
|
2008-10-16 13:12:05 +04:00
|
|
|
while (ancestor) {
|
2009-02-19 09:56:19 +03:00
|
|
|
|
|
|
|
// container-relevant attribute
|
2008-10-16 13:12:05 +04:00
|
|
|
if (relevant.IsEmpty() &&
|
2013-03-26 21:25:54 +04:00
|
|
|
HasDefinedARIAToken(ancestor, nsGkAtoms::aria_relevant) &&
|
2017-12-07 21:13:50 +03:00
|
|
|
ancestor->AsElement()->GetAttr(kNameSpaceID_None,
|
|
|
|
nsGkAtoms::aria_relevant, relevant))
|
2011-06-04 01:35:17 +04:00
|
|
|
SetAccAttr(aAttributes, nsGkAtoms::containerRelevant, relevant);
|
2008-10-16 13:12:05 +04:00
|
|
|
|
2009-06-19 21:44:13 +04:00
|
|
|
// container-live, and container-live-role attributes
|
2009-02-19 09:56:19 +03:00
|
|
|
if (live.IsEmpty()) {
|
2016-03-11 05:13:01 +03:00
|
|
|
const nsRoleMapEntry* role = nullptr;
|
2016-03-03 15:45:47 +03:00
|
|
|
if (ancestor->IsElement()) {
|
|
|
|
role = aria::GetRoleMap(ancestor->AsElement());
|
|
|
|
}
|
2013-03-26 21:25:54 +04:00
|
|
|
if (HasDefinedARIAToken(ancestor, nsGkAtoms::aria_live)) {
|
2017-12-07 21:13:50 +03:00
|
|
|
ancestor->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::aria_live, live);
|
2009-06-19 21:44:13 +04:00
|
|
|
} else if (role) {
|
|
|
|
GetLiveAttrValue(role->liveAttRule, live);
|
|
|
|
}
|
|
|
|
if (!live.IsEmpty()) {
|
2011-06-04 01:35:17 +04:00
|
|
|
SetAccAttr(aAttributes, nsGkAtoms::containerLive, live);
|
2009-02-19 09:56:19 +03:00
|
|
|
if (role) {
|
2013-03-26 21:25:54 +04:00
|
|
|
SetAccAttr(aAttributes, nsGkAtoms::containerLiveRole,
|
|
|
|
role->ARIARoleString());
|
2009-02-19 09:56:19 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-10-16 13:12:05 +04:00
|
|
|
|
2009-02-19 09:56:19 +03:00
|
|
|
// container-atomic attribute
|
2017-12-07 21:13:50 +03:00
|
|
|
if (ancestor->IsElement() &&
|
|
|
|
ancestor->AsElement()->AttrValueIs(kNameSpaceID_None,
|
|
|
|
nsGkAtoms::aria_atomic,
|
|
|
|
nsGkAtoms::_true, eCaseMatters)) {
|
2013-06-26 02:11:39 +04:00
|
|
|
SetAccAttr(aAttributes, nsGkAtoms::containerAtomic,
|
|
|
|
NS_LITERAL_STRING("true"));
|
|
|
|
}
|
2008-10-16 13:12:05 +04:00
|
|
|
|
2009-02-19 09:56:19 +03:00
|
|
|
// container-busy attribute
|
2008-10-16 13:12:05 +04:00
|
|
|
if (busy.IsEmpty() &&
|
2013-03-26 21:25:54 +04:00
|
|
|
HasDefinedARIAToken(ancestor, nsGkAtoms::aria_busy) &&
|
2017-12-07 21:13:50 +03:00
|
|
|
ancestor->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::aria_busy, busy))
|
2011-06-04 01:35:17 +04:00
|
|
|
SetAccAttr(aAttributes, nsGkAtoms::containerBusy, busy);
|
2008-10-16 13:12:05 +04:00
|
|
|
|
2016-03-03 15:45:47 +03:00
|
|
|
if (ancestor == aTopEl)
|
2008-10-16 13:12:05 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
ancestor = ancestor->GetParent();
|
|
|
|
if (!ancestor)
|
2016-03-03 15:45:47 +03:00
|
|
|
ancestor = aTopEl; // Use <body>/<frameset>
|
2008-10-16 13:12:05 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAccUtils::HasDefinedARIAToken(nsIContent *aContent, nsAtom *aAtom)
|
2009-01-12 20:20:34 +03:00
|
|
|
{
|
2009-04-20 10:06:19 +04:00
|
|
|
NS_ASSERTION(aContent, "aContent is null in call to HasDefinedARIAToken!");
|
|
|
|
|
2017-12-07 21:13:50 +03:00
|
|
|
if (!aContent->IsElement())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
Element* element = aContent->AsElement();
|
|
|
|
if (!element->HasAttr(kNameSpaceID_None, aAtom) ||
|
|
|
|
element->AttrValueIs(kNameSpaceID_None, aAtom, nsGkAtoms::_empty,
|
|
|
|
eCaseMatters) ||
|
|
|
|
element->AttrValueIs(kNameSpaceID_None, aAtom, nsGkAtoms::_undefined,
|
|
|
|
eCaseMatters)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2009-01-12 20:20:34 +03:00
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2009-01-12 20:20:34 +03:00
|
|
|
}
|
|
|
|
|
2018-04-11 11:22:05 +03:00
|
|
|
nsAtom*
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAccUtils::GetARIAToken(dom::Element* aElement, nsAtom* aAttr)
|
2011-08-11 15:45:36 +04:00
|
|
|
{
|
2013-03-26 21:25:54 +04:00
|
|
|
if (!HasDefinedARIAToken(aElement, aAttr))
|
2011-06-04 01:35:17 +04:00
|
|
|
return nsGkAtoms::_empty;
|
2011-08-11 15:45:36 +04:00
|
|
|
|
2017-12-07 21:13:50 +03:00
|
|
|
static Element::AttrValuesArray tokens[] =
|
2018-04-11 11:22:05 +03:00
|
|
|
{ &nsGkAtoms::_false, &nsGkAtoms::_true,
|
|
|
|
&nsGkAtoms::mixed, nullptr};
|
2011-08-11 15:45:36 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t idx = aElement->FindAttrValueIn(kNameSpaceID_None,
|
2011-08-11 15:45:36 +04:00
|
|
|
aAttr, tokens, eCaseMatters);
|
|
|
|
if (idx >= 0)
|
2018-04-11 11:22:05 +03:00
|
|
|
return *(tokens[idx]);
|
2011-08-11 15:45:36 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2011-08-11 15:45:36 +04:00
|
|
|
}
|
|
|
|
|
2012-05-29 05:18:45 +04:00
|
|
|
Accessible*
|
2012-08-22 19:56:38 +04:00
|
|
|
nsAccUtils::GetSelectableContainer(Accessible* aAccessible, uint64_t aState)
|
2009-12-11 22:38:55 +03:00
|
|
|
{
|
|
|
|
if (!aAccessible)
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2009-12-11 22:38:55 +03:00
|
|
|
|
2011-04-10 03:38:06 +04:00
|
|
|
if (!(aState & states::SELECTABLE))
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2009-12-11 22:38:55 +03:00
|
|
|
|
2012-05-29 05:18:45 +04:00
|
|
|
Accessible* parent = aAccessible;
|
2011-07-23 12:38:33 +04:00
|
|
|
while ((parent = parent->Parent()) && !parent->IsSelect()) {
|
2013-04-01 04:57:07 +04:00
|
|
|
if (parent->Role() == roles::PANE)
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2009-12-11 22:38:55 +03:00
|
|
|
}
|
2010-06-11 12:23:18 +04:00
|
|
|
return parent;
|
2009-12-11 22:38:55 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2012-05-29 05:18:45 +04:00
|
|
|
nsAccUtils::IsARIASelected(Accessible* aAccessible)
|
2009-09-11 05:07:56 +04:00
|
|
|
{
|
2017-12-07 21:13:50 +03:00
|
|
|
if (!aAccessible->GetContent()->IsElement())
|
|
|
|
return false;
|
|
|
|
return aAccessible->GetContent()->AsElement()->
|
2011-06-04 01:35:17 +04:00
|
|
|
AttrValueIs(kNameSpaceID_None, nsGkAtoms::aria_selected,
|
|
|
|
nsGkAtoms::_true, eCaseMatters);
|
2009-09-11 05:07:56 +04:00
|
|
|
}
|
|
|
|
|
2015-06-27 00:41:22 +03:00
|
|
|
Accessible*
|
|
|
|
nsAccUtils::TableFor(Accessible* aRow)
|
|
|
|
{
|
|
|
|
if (aRow) {
|
|
|
|
Accessible* table = aRow->Parent();
|
|
|
|
if (table) {
|
|
|
|
roles::Role tableRole = table->Role();
|
|
|
|
if (tableRole == roles::GROUPING) { // if there's a rowgroup.
|
|
|
|
table = table->Parent();
|
|
|
|
if (table)
|
|
|
|
tableRole = table->Role();
|
|
|
|
}
|
|
|
|
|
2015-07-01 12:02:00 +03:00
|
|
|
return (tableRole == roles::TABLE || tableRole == roles::TREE_TABLE ||
|
|
|
|
tableRole == roles::MATHML_TABLE) ? table : nullptr;
|
2015-06-27 00:41:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2012-05-31 12:04:41 +04:00
|
|
|
HyperTextAccessible*
|
2013-10-26 18:58:53 +04:00
|
|
|
nsAccUtils::GetTextContainer(nsINode* aNode)
|
2008-10-28 11:43:07 +03:00
|
|
|
{
|
|
|
|
// Get text accessible containing the result node.
|
2013-10-26 18:58:53 +04:00
|
|
|
DocAccessible* doc =
|
|
|
|
GetAccService()->GetDocAccessible(aNode->OwnerDoc());
|
|
|
|
Accessible* accessible =
|
|
|
|
doc ? doc->GetAccessibleOrContainer(aNode) : nullptr;
|
|
|
|
if (!accessible)
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2008-10-28 11:43:07 +03:00
|
|
|
|
2010-07-01 06:18:08 +04:00
|
|
|
do {
|
2012-05-31 12:04:41 +04:00
|
|
|
HyperTextAccessible* textAcc = accessible->AsHyperText();
|
2010-11-29 19:03:29 +03:00
|
|
|
if (textAcc)
|
2010-07-01 06:18:08 +04:00
|
|
|
return textAcc;
|
2010-11-29 19:03:29 +03:00
|
|
|
|
2011-12-18 10:00:47 +04:00
|
|
|
accessible = accessible->Parent();
|
|
|
|
} while (accessible);
|
2010-07-01 06:18:08 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2008-10-28 11:43:07 +03:00
|
|
|
}
|
|
|
|
|
2012-12-18 00:11:02 +04:00
|
|
|
nsIntPoint
|
2012-08-22 19:56:38 +04:00
|
|
|
nsAccUtils::ConvertToScreenCoords(int32_t aX, int32_t aY,
|
|
|
|
uint32_t aCoordinateType,
|
2012-12-18 00:11:02 +04:00
|
|
|
Accessible* aAccessible)
|
2008-10-16 13:12:05 +04:00
|
|
|
{
|
2012-12-18 00:11:02 +04:00
|
|
|
nsIntPoint coords(aX, aY);
|
2008-10-16 13:12:05 +04:00
|
|
|
|
|
|
|
switch (aCoordinateType) {
|
|
|
|
case nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsIAccessibleCoordinateType::COORDTYPE_WINDOW_RELATIVE:
|
|
|
|
{
|
2012-12-18 00:11:02 +04:00
|
|
|
coords += nsCoreUtils::GetScreenCoordsForWindow(aAccessible->GetNode());
|
2008-10-16 13:12:05 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case nsIAccessibleCoordinateType::COORDTYPE_PARENT_RELATIVE:
|
|
|
|
{
|
2012-12-18 00:11:02 +04:00
|
|
|
coords += GetScreenCoordsForParent(aAccessible);
|
2008-10-16 13:12:05 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
2012-12-18 00:11:02 +04:00
|
|
|
NS_NOTREACHED("invalid coord type!");
|
2008-10-16 13:12:05 +04:00
|
|
|
}
|
|
|
|
|
2012-12-18 00:11:02 +04:00
|
|
|
return coords;
|
2008-10-16 13:12:05 +04:00
|
|
|
}
|
|
|
|
|
2012-12-18 00:11:02 +04:00
|
|
|
void
|
2012-08-22 19:56:38 +04:00
|
|
|
nsAccUtils::ConvertScreenCoordsTo(int32_t *aX, int32_t *aY,
|
|
|
|
uint32_t aCoordinateType,
|
2012-12-18 00:11:02 +04:00
|
|
|
Accessible* aAccessible)
|
2008-10-16 13:12:05 +04:00
|
|
|
{
|
|
|
|
switch (aCoordinateType) {
|
|
|
|
case nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsIAccessibleCoordinateType::COORDTYPE_WINDOW_RELATIVE:
|
|
|
|
{
|
2012-12-18 00:11:02 +04:00
|
|
|
nsIntPoint coords = nsCoreUtils::GetScreenCoordsForWindow(aAccessible->GetNode());
|
2008-10-16 13:12:05 +04:00
|
|
|
*aX -= coords.x;
|
|
|
|
*aY -= coords.y;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case nsIAccessibleCoordinateType::COORDTYPE_PARENT_RELATIVE:
|
|
|
|
{
|
2012-12-18 00:11:02 +04:00
|
|
|
nsIntPoint coords = GetScreenCoordsForParent(aAccessible);
|
2008-10-16 13:12:05 +04:00
|
|
|
*aX -= coords.x;
|
|
|
|
*aY -= coords.y;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
2012-12-18 00:11:02 +04:00
|
|
|
NS_NOTREACHED("invalid coord type!");
|
2008-10-16 13:12:05 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIntPoint
|
2012-12-18 00:11:02 +04:00
|
|
|
nsAccUtils::GetScreenCoordsForParent(Accessible* aAccessible)
|
2008-10-16 13:12:05 +04:00
|
|
|
{
|
2012-12-18 00:11:02 +04:00
|
|
|
Accessible* parent = aAccessible->Parent();
|
2008-10-16 13:12:05 +04:00
|
|
|
if (!parent)
|
|
|
|
return nsIntPoint(0, 0);
|
|
|
|
|
|
|
|
nsIFrame *parentFrame = parent->GetFrame();
|
|
|
|
if (!parentFrame)
|
|
|
|
return nsIntPoint(0, 0);
|
|
|
|
|
2012-10-19 19:10:28 +04:00
|
|
|
nsRect rect = parentFrame->GetScreenRectInAppUnits();
|
2018-01-12 20:07:29 +03:00
|
|
|
return nsPoint(rect.X(), rect.Y()).
|
2012-10-19 19:10:28 +04:00
|
|
|
ToNearestPixels(parentFrame->PresContext()->AppUnitsPerDevPixel());
|
2008-10-16 13:12:05 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2012-08-22 19:56:38 +04:00
|
|
|
nsAccUtils::GetLiveAttrValue(uint32_t aRule, nsAString& aValue)
|
2009-02-19 09:56:19 +03:00
|
|
|
{
|
|
|
|
switch (aRule) {
|
|
|
|
case eOffLiveAttr:
|
|
|
|
aValue = NS_LITERAL_STRING("off");
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2009-02-19 09:56:19 +03:00
|
|
|
case ePoliteLiveAttr:
|
|
|
|
aValue = NS_LITERAL_STRING("polite");
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2009-02-19 09:56:19 +03:00
|
|
|
}
|
2009-08-28 09:27:27 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2009-02-19 09:56:19 +03:00
|
|
|
}
|
2008-10-17 14:10:43 +04:00
|
|
|
|
2012-05-08 03:49:41 +04:00
|
|
|
#ifdef DEBUG
|
2008-10-17 14:10:43 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2012-05-29 05:18:45 +04:00
|
|
|
nsAccUtils::IsTextInterfaceSupportCorrect(Accessible* aAccessible)
|
2008-10-17 14:10:43 +04:00
|
|
|
{
|
2011-12-28 02:25:43 +04: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 18:59:28 +04:00
|
|
|
return true;
|
2008-10-17 14:10:43 +04:00
|
|
|
|
2011-12-28 02:25:43 +04:00
|
|
|
bool foundText = false;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t childCount = aAccessible->ChildCount();
|
|
|
|
for (uint32_t childIdx = 0; childIdx < childCount; childIdx++) {
|
2012-05-29 05:18:45 +04:00
|
|
|
Accessible* child = aAccessible->GetChildAt(childIdx);
|
2016-04-08 15:35:11 +03:00
|
|
|
if (child->IsText()) {
|
2011-10-17 18:59:28 +04:00
|
|
|
foundText = true;
|
2008-10-17 14:10:43 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-22 04:49:28 +04:00
|
|
|
return !foundText || aAccessible->IsHyperText();
|
2008-10-17 14:10:43 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t
|
2012-05-29 05:18:45 +04:00
|
|
|
nsAccUtils::TextLength(Accessible* aAccessible)
|
2008-10-17 14:10:43 +04:00
|
|
|
{
|
2016-04-08 15:35:11 +03:00
|
|
|
if (!aAccessible->IsText()) {
|
2008-10-17 14:10:43 +04:00
|
|
|
return 1;
|
2016-04-08 15:35:11 +03:00
|
|
|
}
|
2010-05-25 12:40:54 +04:00
|
|
|
|
2012-05-23 22:05:57 +04:00
|
|
|
TextLeafAccessible* textLeaf = aAccessible->AsTextLeaf();
|
2011-02-01 06:00:45 +03:00
|
|
|
if (textLeaf)
|
|
|
|
return textLeaf->Text().Length();
|
2010-05-25 12:40:54 +04:00
|
|
|
|
2008-10-17 14:10:43 +04:00
|
|
|
// For list bullets (or anything other accessible which would compute its own
|
|
|
|
// text. They don't have their own frame.
|
2017-07-06 15:00:35 +03:00
|
|
|
// XXX In the future, list bullets may have frame and anon content, so
|
2008-10-17 14:10:43 +04:00
|
|
|
// we should be able to remove this at that point
|
|
|
|
nsAutoString text;
|
2011-02-01 06:00:24 +03:00
|
|
|
aAccessible->AppendTextTo(text); // Get all the text
|
2008-10-17 14:10:43 +04:00
|
|
|
return text.Length();
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2012-05-29 05:18:45 +04:00
|
|
|
nsAccUtils::MustPrune(Accessible* aAccessible)
|
2015-03-09 15:16:12 +03:00
|
|
|
{
|
2012-05-21 20:30:53 +04:00
|
|
|
roles::Role role = aAccessible->Role();
|
2008-10-17 14:10:43 +04:00
|
|
|
|
2013-05-08 13:26:54 +04:00
|
|
|
return
|
2018-04-23 10:23:00 +03:00
|
|
|
// Always prune the tree for sliders, as it doesn't make sense for a slider
|
|
|
|
// to have descendants and this confuses NVDA.
|
|
|
|
role == roles::SLIDER ||
|
|
|
|
// Don't prune the tree for certain roles if the tree is more complex than
|
|
|
|
// a single text leaf.
|
|
|
|
(
|
|
|
|
(
|
|
|
|
role == roles::MENUITEM ||
|
|
|
|
role == roles::COMBOBOX_OPTION ||
|
|
|
|
role == roles::OPTION ||
|
|
|
|
role == roles::ENTRY ||
|
|
|
|
role == roles::FLAT_EQUATION ||
|
|
|
|
role == roles::PASSWORD_TEXT ||
|
|
|
|
role == roles::PUSHBUTTON ||
|
|
|
|
role == roles::TOGGLE_BUTTON ||
|
|
|
|
role == roles::GRAPHIC ||
|
|
|
|
role == roles::PROGRESSBAR ||
|
|
|
|
role == roles::SEPARATOR
|
|
|
|
) &&
|
|
|
|
aAccessible->ContentChildCount() == 1 &&
|
|
|
|
aAccessible->ContentChildAt(0)->IsTextLeaf()
|
|
|
|
);
|
2008-10-17 14:10:43 +04:00
|
|
|
}
|