mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:18:48 +00:00
2eb290e0d3
- Bug 1197954 - Extract GLXFBConfig selection code for X11 windows. r=lsalzman (2816a11bdd)
- Bug 1261439 - replace nsAccUtils::IsEmbeddedObject on a bit flag check, r=marcoz (16319b9295)
- bug 1262563 - add IsFromUserInput to show / hide event messages r=davidb (dc96903cfa)
- bug 1262563 - fire show / hide events for proxied accessibles r=davidb (9b1deb77c9)
- bug 1255009 - make AccShowEvent store the insertion index of the new child r=davidb (5b3d984446)
- bug 1261144 - remove filters::GetEmbeddedObj() because it is unused r=lsocks (837bb1777c)
- bug 1261144 - devirtualize AppendObject() because the base class impl is never called r=lsocks (a8fe470965)
- bug 1261144 - move Count() from AccCollector to EmbeddedObjCollector r=lsocks (11d9734561)
- bug 1261144 - move GetAccessibleAt to EmbeddedObjCollector r=lsocks (6ac2731ec1)
- bug 1261144 - devirtualize GetIndexAt() because the base class version is never called r=lsocks (54cc48712e)
- bug 1261144 - move EnsureNGetObject to EmbeddedObjCollector r=lsocks (225b123fb0)
- bug 1261144 - move EnsureNGetIndex() to EmbeddedObjCollector r=lsocks (81986c9a95)
- bug 1261144 - move the data members of AccCollector to EmbeddedObjCollector r=lsocks (5ba20f1c30)
- bug 1261144 - remove the AccCollector class r=lsocks (6f52909c58)
- bug 1261144 - use filters::GetEmbeddedObject() directly in EmbeddedObjCollector r=lsocks (cb86410837)
- bug 1261144 - devirtualize the dtor of EmbeddedObjCollector r=lsocks (b3d23cf341)
- Bug 1261144 - stop including Filters.h in EmbeddedObjCollector.h r=lsocks (2940a4dc3d)
- bug 1261144 - call Accessible::IsText() directly from EmbeddedObjCollector r=lsocks (b93a86aa2a)
- bug 1262233 - stop using a sync message to implement ProxyAccessible::EmbeddedChildCount() r=lsocks (e2d3b6d608)
- bug 1262233 - stop implementing ProxyAccessible::IndexOfEmbeddedChild() with a sync message r=lsocks (dcedecd9d4)
- bug 1262233 - add ProxyAccessible::IsEmbeddedObject() r=lsocks (084915a784)
- bug 1262233 - stop implementing ProxyAccessible::EmbeddedChildAt() with a sync message r=lsocks (2924d04c4a)
- bug 1241453 - fire nsIAccessibleStateChangeEvents for proxied accessibles r=davidb (e423829903)
- bug 1241453 - fire nsIAccessibleEvents for proxied accessibles r=davidb (6a02c2f8a3)
- bug 1241453 - fire nsIAccessibleCaretMoveEvents for proxies r=davidb (4fb1f5be4f)
- bug 1241453 - fire nsIAccessibleTextChangeEvents for proxies r=davidb (c53a5b5122)
- Bug 1264526 - process ARIA owns relocations for in-the-document accessibles only, r=yzen (e19887eee4)
- Bug 1261174 - more events logging, r=yzen (14b83c693d)
- Bug 1257350 - Use intptr_t to avoid C4312 on VS2015; r=tbsaunde (1fc3ee9b6d)
- bug 1250882 - make xpcAccessible::GetAttributes() work with proxied accessibles r=davidb (fa676531c2)
- bug 1210741 - make AccessibleWrap::get_accLocation work with proxied accessibles r=davidb (6600987ec8)
- bug 1219528 - make NAVDIR_{FIRST,LAST}CHILD and NAVDIR_{NEXT,PREVIOUS} cases of AccessibleWrap::accNavigate deal with proxies r=davidb (c011ebcd2b)
- bug 1219528 - make AccessibleWrap::accNavigate cases using relations work with proxies r=davidb (de20c76bcc)
- bug 1215657 - make AccessibleWrap::accHitTest() work with proxies r=davidb (25da22a733)
- bug 1215657 - make AccessibleWrap::accDoDefaultAction work with proxies r=davidb (029d34d135)
- bug 1208779 - null check aAccessible in GetChildIDFor() for 32 bit as well as 64 bit windows r=davidb (08319d45e7)
- bug 1207862 - refactor GetXPAccessibleFor() so proxies and non proxies are handle in the same place for each type of id r=davidb (3ff1646e02)
- bug 1207862 - make AccessibleWrap::GetXPAccessibleFor() return the AccessibleWrap for proxies r=davidb (1184a0efeb)
- bug 1218564 - remove check for password roles in AccessibleWrap::get_accValue r=surkov (477e0bb92b)
- bug 1219528 - don't bail out of AccessibleWrap::accNavigate if the accessible wraps a proxy r=davidb (9540866b5b)
- Bug 1257303 - Cast to intptr_t to avoid C4312 on VS2015; r=tbsaunde (93af27e0db)
- Bug 1210549 - Fix AccessibleWrap::GetXPAccessibleFor for proxied accessibles r=tbsaunde (b4ed017706)
448 lines
12 KiB
C++
448 lines
12 KiB
C++
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
/* 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/. */
|
|
|
|
#include "nsAccUtils.h"
|
|
|
|
#include "Accessible-inl.h"
|
|
#include "ARIAMap.h"
|
|
#include "nsAccessibilityService.h"
|
|
#include "nsCoreUtils.h"
|
|
#include "DocAccessible.h"
|
|
#include "HyperTextAccessible.h"
|
|
#include "nsIAccessibleTypes.h"
|
|
#include "Role.h"
|
|
#include "States.h"
|
|
#include "TextLeafAccessible.h"
|
|
|
|
#include "nsIDOMXULContainerElement.h"
|
|
#include "nsIPersistentProperties2.h"
|
|
#include "mozilla/dom/Element.h"
|
|
|
|
using namespace mozilla;
|
|
using namespace mozilla::a11y;
|
|
|
|
void
|
|
nsAccUtils::GetAccAttr(nsIPersistentProperties *aAttributes,
|
|
nsIAtom *aAttrName, nsAString& aAttrValue)
|
|
{
|
|
aAttrValue.Truncate();
|
|
|
|
aAttributes->GetStringProperty(nsAtomCString(aAttrName), aAttrValue);
|
|
}
|
|
|
|
void
|
|
nsAccUtils::SetAccAttr(nsIPersistentProperties *aAttributes,
|
|
nsIAtom *aAttrName, const nsAString& aAttrValue)
|
|
{
|
|
nsAutoString oldValue;
|
|
aAttributes->SetStringProperty(nsAtomCString(aAttrName), aAttrValue, oldValue);
|
|
}
|
|
|
|
void
|
|
nsAccUtils::SetAccAttr(nsIPersistentProperties *aAttributes,
|
|
nsIAtom* aAttrName, nsIAtom* aAttrValue)
|
|
{
|
|
nsAutoString oldValue;
|
|
aAttributes->SetStringProperty(nsAtomCString(aAttrName),
|
|
nsAtomString(aAttrValue), oldValue);
|
|
}
|
|
|
|
void
|
|
nsAccUtils::SetAccGroupAttrs(nsIPersistentProperties *aAttributes,
|
|
int32_t aLevel, int32_t aSetSize,
|
|
int32_t aPosInSet)
|
|
{
|
|
nsAutoString value;
|
|
|
|
if (aLevel) {
|
|
value.AppendInt(aLevel);
|
|
SetAccAttr(aAttributes, nsGkAtoms::level, value);
|
|
}
|
|
|
|
if (aSetSize && aPosInSet) {
|
|
value.Truncate();
|
|
value.AppendInt(aPosInSet);
|
|
SetAccAttr(aAttributes, nsGkAtoms::posinset, value);
|
|
|
|
value.Truncate();
|
|
value.AppendInt(aSetSize);
|
|
SetAccAttr(aAttributes, nsGkAtoms::setsize, value);
|
|
}
|
|
}
|
|
|
|
int32_t
|
|
nsAccUtils::GetDefaultLevel(Accessible* aAccessible)
|
|
{
|
|
roles::Role role = aAccessible->Role();
|
|
|
|
if (role == roles::OUTLINEITEM)
|
|
return 1;
|
|
|
|
if (role == roles::ROW) {
|
|
Accessible* parent = aAccessible->Parent();
|
|
// 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)
|
|
return 1;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
int32_t
|
|
nsAccUtils::GetARIAOrDefaultLevel(Accessible* aAccessible)
|
|
{
|
|
int32_t level = 0;
|
|
nsCoreUtils::GetUIntAttr(aAccessible->GetContent(),
|
|
nsGkAtoms::aria_level, &level);
|
|
|
|
if (level != 0)
|
|
return level;
|
|
|
|
return GetDefaultLevel(aAccessible);
|
|
}
|
|
|
|
int32_t
|
|
nsAccUtils::GetLevelForXULContainerItem(nsIContent *aContent)
|
|
{
|
|
nsCOMPtr<nsIDOMXULContainerItemElement> item(do_QueryInterface(aContent));
|
|
if (!item)
|
|
return 0;
|
|
|
|
nsCOMPtr<nsIDOMXULContainerElement> container;
|
|
item->GetParentContainer(getter_AddRefs(container));
|
|
if (!container)
|
|
return 0;
|
|
|
|
// Get level of the item.
|
|
int32_t level = -1;
|
|
while (container) {
|
|
level++;
|
|
|
|
nsCOMPtr<nsIDOMXULContainerElement> parentContainer;
|
|
container->GetParentContainer(getter_AddRefs(parentContainer));
|
|
parentContainer.swap(container);
|
|
}
|
|
|
|
return level;
|
|
}
|
|
|
|
void
|
|
nsAccUtils::SetLiveContainerAttributes(nsIPersistentProperties *aAttributes,
|
|
nsIContent* aStartContent,
|
|
dom::Element* aTopEl)
|
|
{
|
|
nsAutoString live, relevant, busy;
|
|
nsIContent* ancestor = aStartContent;
|
|
while (ancestor) {
|
|
|
|
// container-relevant attribute
|
|
if (relevant.IsEmpty() &&
|
|
HasDefinedARIAToken(ancestor, nsGkAtoms::aria_relevant) &&
|
|
ancestor->GetAttr(kNameSpaceID_None, nsGkAtoms::aria_relevant, relevant))
|
|
SetAccAttr(aAttributes, nsGkAtoms::containerRelevant, relevant);
|
|
|
|
// container-live, and container-live-role attributes
|
|
if (live.IsEmpty()) {
|
|
const nsRoleMapEntry* role = nullptr;
|
|
if (ancestor->IsElement()) {
|
|
role = aria::GetRoleMap(ancestor->AsElement());
|
|
}
|
|
if (HasDefinedARIAToken(ancestor, nsGkAtoms::aria_live)) {
|
|
ancestor->GetAttr(kNameSpaceID_None, nsGkAtoms::aria_live, live);
|
|
} else if (role) {
|
|
GetLiveAttrValue(role->liveAttRule, live);
|
|
}
|
|
if (!live.IsEmpty()) {
|
|
SetAccAttr(aAttributes, nsGkAtoms::containerLive, live);
|
|
if (role) {
|
|
SetAccAttr(aAttributes, nsGkAtoms::containerLiveRole,
|
|
role->ARIARoleString());
|
|
}
|
|
}
|
|
}
|
|
|
|
// container-atomic attribute
|
|
if (ancestor->AttrValueIs(kNameSpaceID_None, nsGkAtoms::aria_atomic,
|
|
nsGkAtoms::_true, eCaseMatters)) {
|
|
SetAccAttr(aAttributes, nsGkAtoms::containerAtomic,
|
|
NS_LITERAL_STRING("true"));
|
|
}
|
|
|
|
// container-busy attribute
|
|
if (busy.IsEmpty() &&
|
|
HasDefinedARIAToken(ancestor, nsGkAtoms::aria_busy) &&
|
|
ancestor->GetAttr(kNameSpaceID_None, nsGkAtoms::aria_busy, busy))
|
|
SetAccAttr(aAttributes, nsGkAtoms::containerBusy, busy);
|
|
|
|
if (ancestor == aTopEl)
|
|
break;
|
|
|
|
ancestor = ancestor->GetParent();
|
|
if (!ancestor)
|
|
ancestor = aTopEl; // Use <body>/<frameset>
|
|
}
|
|
}
|
|
|
|
bool
|
|
nsAccUtils::HasDefinedARIAToken(nsIContent *aContent, nsIAtom *aAtom)
|
|
{
|
|
NS_ASSERTION(aContent, "aContent is null in call to HasDefinedARIAToken!");
|
|
|
|
if (!aContent->HasAttr(kNameSpaceID_None, aAtom) ||
|
|
aContent->AttrValueIs(kNameSpaceID_None, aAtom,
|
|
nsGkAtoms::_empty, eCaseMatters) ||
|
|
aContent->AttrValueIs(kNameSpaceID_None, aAtom,
|
|
nsGkAtoms::_undefined, eCaseMatters)) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
nsIAtom*
|
|
nsAccUtils::GetARIAToken(dom::Element* aElement, nsIAtom* aAttr)
|
|
{
|
|
if (!HasDefinedARIAToken(aElement, aAttr))
|
|
return nsGkAtoms::_empty;
|
|
|
|
static nsIContent::AttrValuesArray tokens[] =
|
|
{ &nsGkAtoms::_false, &nsGkAtoms::_true,
|
|
&nsGkAtoms::mixed, nullptr};
|
|
|
|
int32_t idx = aElement->FindAttrValueIn(kNameSpaceID_None,
|
|
aAttr, tokens, eCaseMatters);
|
|
if (idx >= 0)
|
|
return *(tokens[idx]);
|
|
|
|
return nullptr;
|
|
}
|
|
|
|
Accessible*
|
|
nsAccUtils::GetSelectableContainer(Accessible* aAccessible, uint64_t aState)
|
|
{
|
|
if (!aAccessible)
|
|
return nullptr;
|
|
|
|
if (!(aState & states::SELECTABLE))
|
|
return nullptr;
|
|
|
|
Accessible* parent = aAccessible;
|
|
while ((parent = parent->Parent()) && !parent->IsSelect()) {
|
|
if (parent->Role() == roles::PANE)
|
|
return nullptr;
|
|
}
|
|
return parent;
|
|
}
|
|
|
|
bool
|
|
nsAccUtils::IsARIASelected(Accessible* aAccessible)
|
|
{
|
|
return aAccessible->GetContent()->
|
|
AttrValueIs(kNameSpaceID_None, nsGkAtoms::aria_selected,
|
|
nsGkAtoms::_true, eCaseMatters);
|
|
}
|
|
|
|
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();
|
|
}
|
|
|
|
return (tableRole == roles::TABLE || tableRole == roles::TREE_TABLE ||
|
|
tableRole == roles::MATHML_TABLE) ? table : nullptr;
|
|
}
|
|
}
|
|
|
|
return nullptr;
|
|
}
|
|
|
|
HyperTextAccessible*
|
|
nsAccUtils::GetTextContainer(nsINode* aNode)
|
|
{
|
|
// Get text accessible containing the result node.
|
|
DocAccessible* doc =
|
|
GetAccService()->GetDocAccessible(aNode->OwnerDoc());
|
|
Accessible* accessible =
|
|
doc ? doc->GetAccessibleOrContainer(aNode) : nullptr;
|
|
if (!accessible)
|
|
return nullptr;
|
|
|
|
do {
|
|
HyperTextAccessible* textAcc = accessible->AsHyperText();
|
|
if (textAcc)
|
|
return textAcc;
|
|
|
|
accessible = accessible->Parent();
|
|
} while (accessible);
|
|
|
|
return nullptr;
|
|
}
|
|
|
|
nsIntPoint
|
|
nsAccUtils::ConvertToScreenCoords(int32_t aX, int32_t aY,
|
|
uint32_t aCoordinateType,
|
|
Accessible* aAccessible)
|
|
{
|
|
nsIntPoint coords(aX, aY);
|
|
|
|
switch (aCoordinateType) {
|
|
case nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE:
|
|
break;
|
|
|
|
case nsIAccessibleCoordinateType::COORDTYPE_WINDOW_RELATIVE:
|
|
{
|
|
coords += nsCoreUtils::GetScreenCoordsForWindow(aAccessible->GetNode());
|
|
break;
|
|
}
|
|
|
|
case nsIAccessibleCoordinateType::COORDTYPE_PARENT_RELATIVE:
|
|
{
|
|
coords += GetScreenCoordsForParent(aAccessible);
|
|
break;
|
|
}
|
|
|
|
default:
|
|
NS_NOTREACHED("invalid coord type!");
|
|
}
|
|
|
|
return coords;
|
|
}
|
|
|
|
void
|
|
nsAccUtils::ConvertScreenCoordsTo(int32_t *aX, int32_t *aY,
|
|
uint32_t aCoordinateType,
|
|
Accessible* aAccessible)
|
|
{
|
|
switch (aCoordinateType) {
|
|
case nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE:
|
|
break;
|
|
|
|
case nsIAccessibleCoordinateType::COORDTYPE_WINDOW_RELATIVE:
|
|
{
|
|
nsIntPoint coords = nsCoreUtils::GetScreenCoordsForWindow(aAccessible->GetNode());
|
|
*aX -= coords.x;
|
|
*aY -= coords.y;
|
|
break;
|
|
}
|
|
|
|
case nsIAccessibleCoordinateType::COORDTYPE_PARENT_RELATIVE:
|
|
{
|
|
nsIntPoint coords = GetScreenCoordsForParent(aAccessible);
|
|
*aX -= coords.x;
|
|
*aY -= coords.y;
|
|
break;
|
|
}
|
|
|
|
default:
|
|
NS_NOTREACHED("invalid coord type!");
|
|
}
|
|
}
|
|
|
|
nsIntPoint
|
|
nsAccUtils::GetScreenCoordsForParent(Accessible* aAccessible)
|
|
{
|
|
Accessible* parent = aAccessible->Parent();
|
|
if (!parent)
|
|
return nsIntPoint(0, 0);
|
|
|
|
nsIFrame *parentFrame = parent->GetFrame();
|
|
if (!parentFrame)
|
|
return nsIntPoint(0, 0);
|
|
|
|
nsRect rect = parentFrame->GetScreenRectInAppUnits();
|
|
return nsPoint(rect.x, rect.y).
|
|
ToNearestPixels(parentFrame->PresContext()->AppUnitsPerDevPixel());
|
|
}
|
|
|
|
bool
|
|
nsAccUtils::GetLiveAttrValue(uint32_t aRule, nsAString& aValue)
|
|
{
|
|
switch (aRule) {
|
|
case eOffLiveAttr:
|
|
aValue = NS_LITERAL_STRING("off");
|
|
return true;
|
|
case ePoliteLiveAttr:
|
|
aValue = NS_LITERAL_STRING("polite");
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
|
|
bool
|
|
nsAccUtils::IsTextInterfaceSupportCorrect(Accessible* aAccessible)
|
|
{
|
|
// Don't test for accessible docs, it makes us create accessibles too
|
|
// early and fire mutation events before we need to
|
|
if (aAccessible->IsDoc())
|
|
return true;
|
|
|
|
bool foundText = false;
|
|
uint32_t childCount = aAccessible->ChildCount();
|
|
for (uint32_t childIdx = 0; childIdx < childCount; childIdx++) {
|
|
Accessible* child = aAccessible->GetChildAt(childIdx);
|
|
if (child->IsText()) {
|
|
foundText = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
return !foundText || aAccessible->IsHyperText();
|
|
}
|
|
#endif
|
|
|
|
uint32_t
|
|
nsAccUtils::TextLength(Accessible* aAccessible)
|
|
{
|
|
if (!aAccessible->IsText()) {
|
|
return 1;
|
|
}
|
|
|
|
TextLeafAccessible* textLeaf = aAccessible->AsTextLeaf();
|
|
if (textLeaf)
|
|
return textLeaf->Text().Length();
|
|
|
|
// 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;
|
|
aAccessible->AppendTextTo(text); // Get all the text
|
|
return text.Length();
|
|
}
|
|
|
|
bool
|
|
nsAccUtils::MustPrune(Accessible* aAccessible)
|
|
{
|
|
roles::Role role = aAccessible->Role();
|
|
|
|
// Don't prune the tree for certain roles if the tree is more complex than
|
|
// a single text leaf.
|
|
return
|
|
(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::SLIDER ||
|
|
role == roles::PROGRESSBAR ||
|
|
role == roles::SEPARATOR) &&
|
|
aAccessible->ContentChildCount() == 1 &&
|
|
aAccessible->ContentChildAt(0)->IsTextLeaf();
|
|
}
|