forked from mozilla/gecko-dev
-
Notifications
You must be signed in to change notification settings - Fork 2
/
nsAccUtils.cpp
715 lines (599 loc) · 21.1 KB
/
nsAccUtils.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2007
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Alexander Surkov <surkov.alexander@gmail.com> (original author)
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsCoreUtils.h"
#include "nsAccUtils.h"
#include "States.h"
#include "nsIAccessibleTypes.h"
#include "nsAccessibilityService.h"
#include "nsAccessibilityAtoms.h"
#include "nsARIAMap.h"
#include "nsDocAccessible.h"
#include "nsHyperTextAccessible.h"
#include "nsHTMLTableAccessible.h"
#include "nsTextAccessible.h"
#include "nsXULTreeGridAccessible.h"
#include "nsIDOMXULContainerElement.h"
#include "nsIDOMXULSelectCntrlEl.h"
#include "nsIDOMXULSelectCntrlItemEl.h"
#include "nsWhitespaceTokenizer.h"
#include "nsComponentManagerUtils.h"
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;
nsCAutoString attrName;
aAttributes->SetStringProperty(nsAtomCString(aAttrName), aAttrValue, oldValue);
}
void
nsAccUtils::SetAccGroupAttrs(nsIPersistentProperties *aAttributes,
PRInt32 aLevel, PRInt32 aSetSize,
PRInt32 aPosInSet)
{
nsAutoString value;
if (aLevel) {
value.AppendInt(aLevel);
SetAccAttr(aAttributes, nsAccessibilityAtoms::level, value);
}
if (aSetSize && aPosInSet) {
value.Truncate();
value.AppendInt(aPosInSet);
SetAccAttr(aAttributes, nsAccessibilityAtoms::posinset, value);
value.Truncate();
value.AppendInt(aSetSize);
SetAccAttr(aAttributes, nsAccessibilityAtoms::setsize, value);
}
}
PRInt32
nsAccUtils::GetDefaultLevel(nsAccessible *aAccessible)
{
PRUint32 role = aAccessible->Role();
if (role == nsIAccessibleRole::ROLE_OUTLINEITEM)
return 1;
if (role == nsIAccessibleRole::ROLE_ROW) {
nsAccessible *parent = aAccessible->GetParent();
if (parent && parent->Role() == nsIAccessibleRole::ROLE_TREE_TABLE) {
// It is a row inside flatten treegrid. Group level is always 1 until it
// is overriden by aria-level attribute.
return 1;
}
}
return 0;
}
PRInt32
nsAccUtils::GetARIAOrDefaultLevel(nsAccessible *aAccessible)
{
PRInt32 level = 0;
nsCoreUtils::GetUIntAttr(aAccessible->GetContent(),
nsAccessibilityAtoms::aria_level, &level);
if (level != 0)
return level;
return GetDefaultLevel(aAccessible);
}
void
nsAccUtils::GetPositionAndSizeForXULSelectControlItem(nsIContent *aContent,
PRInt32 *aPosInSet,
PRInt32 *aSetSize)
{
nsCOMPtr<nsIDOMXULSelectControlItemElement> item(do_QueryInterface(aContent));
if (!item)
return;
nsCOMPtr<nsIDOMXULSelectControlElement> control;
item->GetControl(getter_AddRefs(control));
if (!control)
return;
PRUint32 itemsCount = 0;
control->GetItemCount(&itemsCount);
PRInt32 indexOf = 0;
control->GetIndexOfItem(item, &indexOf);
*aSetSize = itemsCount;
*aPosInSet = indexOf;
for (PRUint32 index = 0; index < itemsCount; index++) {
nsCOMPtr<nsIDOMXULSelectControlItemElement> currItem;
control->GetItemAtIndex(index, getter_AddRefs(currItem));
nsCOMPtr<nsINode> currNode(do_QueryInterface(currItem));
nsAccessible* itemAcc = currNode ?
GetAccService()->GetAccessible(currNode) : nsnull;
if (!itemAcc || itemAcc->State() & states::INVISIBLE) {
(*aSetSize)--;
if (index < static_cast<PRUint32>(indexOf))
(*aPosInSet)--;
}
}
(*aPosInSet)++; // group position is 1-index based.
}
void
nsAccUtils::GetPositionAndSizeForXULContainerItem(nsIContent *aContent,
PRInt32 *aPosInSet,
PRInt32 *aSetSize)
{
nsCOMPtr<nsIDOMXULContainerItemElement> item(do_QueryInterface(aContent));
if (!item)
return;
nsCOMPtr<nsIDOMXULContainerElement> container;
item->GetParentContainer(getter_AddRefs(container));
if (!container)
return;
// Get item count.
PRUint32 itemsCount = 0;
container->GetItemCount(&itemsCount);
// Get item index.
PRInt32 indexOf = 0;
container->GetIndexOfItem(item, &indexOf);
// Calculate set size and position in the set.
*aSetSize = 0, *aPosInSet = 0;
for (PRInt32 index = indexOf; index >= 0; index--) {
nsCOMPtr<nsIDOMXULElement> item;
container->GetItemAtIndex(index, getter_AddRefs(item));
nsCOMPtr<nsINode> itemNode(do_QueryInterface(item));
nsAccessible* itemAcc = itemNode ?
GetAccService()->GetAccessible(itemNode) : nsnull;
if (itemAcc) {
PRUint32 itemRole = Role(itemAcc);
if (itemRole == nsIAccessibleRole::ROLE_SEPARATOR)
break; // We reached the beginning of our group.
if (!(itemAcc->State() & states::INVISIBLE)) {
(*aSetSize)++;
(*aPosInSet)++;
}
}
}
for (PRInt32 index = indexOf + 1; index < static_cast<PRInt32>(itemsCount);
index++) {
nsCOMPtr<nsIDOMXULElement> item;
container->GetItemAtIndex(index, getter_AddRefs(item));
nsCOMPtr<nsINode> itemNode(do_QueryInterface(item));
nsAccessible* itemAcc =
itemNode ? GetAccService()->GetAccessible(itemNode) : nsnull;
if (itemAcc) {
PRUint32 itemRole = Role(itemAcc);
if (itemRole == nsIAccessibleRole::ROLE_SEPARATOR)
break; // We reached the end of our group.
if (!(itemAcc->State() & states::INVISIBLE))
(*aSetSize)++;
}
}
}
PRInt32
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.
PRInt32 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,
nsIContent *aTopContent)
{
nsAutoString atomic, live, relevant, busy;
nsIContent *ancestor = aStartContent;
while (ancestor) {
// container-relevant attribute
if (relevant.IsEmpty() &&
nsAccUtils::HasDefinedARIAToken(ancestor, nsAccessibilityAtoms::aria_relevant) &&
ancestor->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_relevant, relevant))
SetAccAttr(aAttributes, nsAccessibilityAtoms::containerRelevant, relevant);
// container-live, and container-live-role attributes
if (live.IsEmpty()) {
nsRoleMapEntry *role = GetRoleMapEntry(ancestor);
if (nsAccUtils::HasDefinedARIAToken(ancestor,
nsAccessibilityAtoms::aria_live)) {
ancestor->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_live,
live);
} else if (role) {
GetLiveAttrValue(role->liveAttRule, live);
}
if (!live.IsEmpty()) {
SetAccAttr(aAttributes, nsAccessibilityAtoms::containerLive, live);
if (role) {
nsAccUtils::SetAccAttr(aAttributes,
nsAccessibilityAtoms::containerLiveRole,
NS_ConvertASCIItoUTF16(role->roleString));
}
}
}
// container-atomic attribute
if (atomic.IsEmpty() &&
nsAccUtils::HasDefinedARIAToken(ancestor, nsAccessibilityAtoms::aria_atomic) &&
ancestor->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_atomic, atomic))
SetAccAttr(aAttributes, nsAccessibilityAtoms::containerAtomic, atomic);
// container-busy attribute
if (busy.IsEmpty() &&
nsAccUtils::HasDefinedARIAToken(ancestor, nsAccessibilityAtoms::aria_busy) &&
ancestor->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_busy, busy))
SetAccAttr(aAttributes, nsAccessibilityAtoms::containerBusy, busy);
if (ancestor == aTopContent)
break;
ancestor = ancestor->GetParent();
if (!ancestor)
ancestor = aTopContent; // Use <body>/<frameset>
}
}
PRBool
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,
nsAccessibilityAtoms::_empty, eCaseMatters) ||
aContent->AttrValueIs(kNameSpaceID_None, aAtom,
nsAccessibilityAtoms::_undefined, eCaseMatters)) {
return PR_FALSE;
}
return PR_TRUE;
}
nsAccessible *
nsAccUtils::GetAncestorWithRole(nsAccessible *aDescendant, PRUint32 aRole)
{
nsAccessible *document = aDescendant->GetDocAccessible();
nsAccessible *parent = aDescendant;
while ((parent = parent->GetParent())) {
PRUint32 testRole = parent->Role();
if (testRole == aRole)
return parent;
if (parent == document)
break;
}
return nsnull;
}
nsAccessible*
nsAccUtils::GetSelectableContainer(nsAccessible* aAccessible, PRUint64 aState)
{
if (!aAccessible)
return nsnull;
if (!(aState & states::SELECTABLE))
return nsnull;
nsAccessible* parent = aAccessible;
while ((parent = parent->GetParent()) && !parent->IsSelect()) {
if (Role(parent) == nsIAccessibleRole::ROLE_PANE)
return nsnull;
}
return parent;
}
nsAccessible*
nsAccUtils::GetMultiSelectableContainer(nsINode* aNode)
{
nsAccessible* accessible = GetAccService()->GetAccessible(aNode);
if (accessible) {
nsAccessible* container = GetSelectableContainer(accessible,
accessible->State());
if (container && container->State() & states::MULTISELECTABLE)
return container;
}
return nsnull;
}
PRBool
nsAccUtils::IsARIASelected(nsAccessible *aAccessible)
{
return aAccessible->GetContent()->
AttrValueIs(kNameSpaceID_None, nsAccessibilityAtoms::aria_selected,
nsAccessibilityAtoms::_true, eCaseMatters);
}
nsHyperTextAccessible*
nsAccUtils::GetTextAccessibleFromSelection(nsISelection* aSelection)
{
// Get accessible from selection's focus DOM point (the DOM point where
// selection is ended).
nsCOMPtr<nsIDOMNode> focusDOMNode;
aSelection->GetFocusNode(getter_AddRefs(focusDOMNode));
if (!focusDOMNode)
return nsnull;
PRInt32 focusOffset = 0;
aSelection->GetFocusOffset(&focusOffset);
nsCOMPtr<nsINode> focusNode(do_QueryInterface(focusDOMNode));
nsCOMPtr<nsINode> resultNode =
nsCoreUtils::GetDOMNodeFromDOMPoint(focusNode, focusOffset);
nsCOMPtr<nsIWeakReference> weakShell(nsCoreUtils::GetWeakShellFor(resultNode));
// Get text accessible containing the result node.
nsAccessible* accessible =
GetAccService()->GetAccessibleOrContainer(resultNode, weakShell);
if (!accessible) {
NS_NOTREACHED("No nsIAccessibleText for selection change event!");
return nsnull;
}
do {
nsHyperTextAccessible* textAcc = accessible->AsHyperText();
if (textAcc)
return textAcc;
} while (accessible = accessible->GetParent());
NS_NOTREACHED("We must reach document accessible implementing nsIAccessibleText!");
return nsnull;
}
nsresult
nsAccUtils::ConvertToScreenCoords(PRInt32 aX, PRInt32 aY,
PRUint32 aCoordinateType,
nsAccessNode *aAccessNode,
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
nsAccUtils::ConvertScreenCoordsTo(PRInt32 *aX, PRInt32 *aY,
PRUint32 aCoordinateType,
nsAccessNode *aAccessNode)
{
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
nsAccUtils::GetScreenCoordsForWindow(nsAccessNode *aAccessNode)
{
return nsCoreUtils::GetScreenCoordsForWindow(aAccessNode->GetNode());
}
nsIntPoint
nsAccUtils::GetScreenCoordsForParent(nsAccessNode *aAccessNode)
{
nsAccessible *parent =
GetAccService()->GetContainerAccessible(aAccessNode->GetNode(),
aAccessNode->GetWeakShell());
if (!parent)
return nsIntPoint(0, 0);
nsIFrame *parentFrame = parent->GetFrame();
if (!parentFrame)
return nsIntPoint(0, 0);
nsIntRect parentRect = parentFrame->GetScreenRectExternal();
return nsIntPoint(parentRect.x, parentRect.y);
}
nsRoleMapEntry*
nsAccUtils::GetRoleMapEntry(nsINode *aNode)
{
nsIContent *content = nsCoreUtils::GetRoleContent(aNode);
nsAutoString roleString;
if (!content ||
!content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::role, roleString) ||
roleString.IsEmpty()) {
// We treat role="" as if the role attribute is absent (per aria spec:8.1.1)
return nsnull;
}
nsWhitespaceTokenizer tokenizer(roleString);
while (tokenizer.hasMoreTokens()) {
// Do a binary search through table for the next role in role list
NS_LossyConvertUTF16toASCII role(tokenizer.nextToken());
PRUint32 low = 0;
PRUint32 high = nsARIAMap::gWAIRoleMapLength;
while (low < high) {
PRUint32 index = (low + high) / 2;
PRInt32 compare = PL_strcmp(role.get(), nsARIAMap::gWAIRoleMap[index].roleString);
if (compare == 0) {
// The role attribute maps to an entry in the role table
return &nsARIAMap::gWAIRoleMap[index];
}
if (compare < 0) {
high = index;
}
else {
low = index + 1;
}
}
}
// Always use some entry if there is a non-empty role string
// To ensure an accessible object is created
return &nsARIAMap::gLandmarkRoleMap;
}
PRUint8
nsAccUtils::GetAttributeCharacteristics(nsIAtom* aAtom)
{
for (PRUint32 i = 0; i < nsARIAMap::gWAIUnivAttrMapLength; i++)
if (*nsARIAMap::gWAIUnivAttrMap[i].attributeName == aAtom)
return nsARIAMap::gWAIUnivAttrMap[i].characteristics;
return 0;
}
PRBool
nsAccUtils::GetLiveAttrValue(PRUint32 aRule, nsAString& aValue)
{
switch (aRule) {
case eOffLiveAttr:
aValue = NS_LITERAL_STRING("off");
return PR_TRUE;
case ePoliteLiveAttr:
aValue = NS_LITERAL_STRING("polite");
return PR_TRUE;
}
return PR_FALSE;
}
#ifdef DEBUG_A11Y
PRBool
nsAccUtils::IsTextInterfaceSupportCorrect(nsAccessible *aAccessible)
{
PRBool foundText = PR_FALSE;
nsCOMPtr<nsIAccessibleDocument> accDoc = do_QueryObject(aAccessible);
if (accDoc) {
// Don't test for accessible docs, it makes us create accessibles too
// early and fire mutation events before we need to
return PR_TRUE;
}
PRInt32 childCount = aAccessible->GetChildCount();
for (PRint32 childIdx = 0; childIdx < childCount; childIdx++) {
nsAccessible *child = GetChildAt(childIdx);
if (IsText(child)) {
foundText = PR_TRUE;
break;
}
}
if (foundText) {
// found text child node
nsCOMPtr<nsIAccessibleText> text = do_QueryObject(aAccessible);
if (!text)
return PR_FALSE;
}
return PR_TRUE;
}
#endif
PRUint32
nsAccUtils::TextLength(nsAccessible *aAccessible)
{
if (!IsText(aAccessible))
return 1;
nsTextAccessible* 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();
}
PRBool
nsAccUtils::MustPrune(nsIAccessible *aAccessible)
{
PRUint32 role = nsAccUtils::Role(aAccessible);
// 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.
return role == nsIAccessibleRole::ROLE_MENUITEM ||
role == nsIAccessibleRole::ROLE_COMBOBOX_OPTION ||
role == nsIAccessibleRole::ROLE_OPTION ||
role == nsIAccessibleRole::ROLE_ENTRY ||
role == nsIAccessibleRole::ROLE_FLAT_EQUATION ||
role == nsIAccessibleRole::ROLE_PASSWORD_TEXT ||
role == nsIAccessibleRole::ROLE_TOGGLE_BUTTON ||
role == nsIAccessibleRole::ROLE_GRAPHIC ||
role == nsIAccessibleRole::ROLE_SLIDER ||
role == nsIAccessibleRole::ROLE_PROGRESSBAR ||
role == nsIAccessibleRole::ROLE_SEPARATOR;
}
nsresult
nsAccUtils::GetHeaderCellsFor(nsIAccessibleTable *aTable,
nsIAccessibleTableCell *aCell,
PRInt32 aRowOrColHeaderCells, nsIArray **aCells)
{
nsresult rv = NS_OK;
nsCOMPtr<nsIMutableArray> cells = do_CreateInstance(NS_ARRAY_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
PRInt32 rowIdx = -1;
rv = aCell->GetRowIndex(&rowIdx);
NS_ENSURE_SUCCESS(rv, rv);
PRInt32 colIdx = -1;
rv = aCell->GetColumnIndex(&colIdx);
NS_ENSURE_SUCCESS(rv, rv);
PRBool moveToLeft = aRowOrColHeaderCells == eRowHeaderCells;
// Move to the left or top to find row header cells or column header cells.
PRInt32 index = (moveToLeft ? colIdx : rowIdx) - 1;
for (; index >= 0; index--) {
PRInt32 curRowIdx = moveToLeft ? rowIdx : index;
PRInt32 curColIdx = moveToLeft ? index : colIdx;
nsCOMPtr<nsIAccessible> cell;
rv = aTable->GetCellAt(curRowIdx, curColIdx, getter_AddRefs(cell));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIAccessibleTableCell> tableCellAcc =
do_QueryInterface(cell);
// GetCellAt should always return an nsIAccessibleTableCell (XXX Bug 587529)
NS_ENSURE_STATE(tableCellAcc);
PRInt32 origIdx = 1;
if (moveToLeft)
rv = tableCellAcc->GetColumnIndex(&origIdx);
else
rv = tableCellAcc->GetRowIndex(&origIdx);
NS_ENSURE_SUCCESS(rv, rv);
if (origIdx == index) {
// Append original header cells only.
PRUint32 role = Role(cell);
PRBool isHeader = moveToLeft ?
role == nsIAccessibleRole::ROLE_ROWHEADER :
role == nsIAccessibleRole::ROLE_COLUMNHEADER;
if (isHeader)
cells->AppendElement(cell, PR_FALSE);
}
}
NS_ADDREF(*aCells = cells);
return NS_OK;
}