/
WebKitAccessibleWrapperAtk.cpp
1536 lines (1302 loc) · 58.9 KB
/
WebKitAccessibleWrapperAtk.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
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 2008 Nuanti Ltd.
* Copyright (C) 2009 Jan Alonzo
* Copyright (C) 2009, 2010, 2011, 2012 Igalia S.L.
* Copyright (C) 2013 Samsung Electronics
*
* Portions from Mozilla a11y, copyright as follows:
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Sun Microsystems, Inc.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "config.h"
#include "WebKitAccessibleWrapperAtk.h"
#if HAVE(ACCESSIBILITY)
#include "AXObjectCache.h"
#include "AccessibilityList.h"
#include "AccessibilityListBoxOption.h"
#include "AccessibilityTable.h"
#include "AccessibilityTableCell.h"
#include "AccessibilityTableRow.h"
#include "Document.h"
#include "Editing.h"
#include "Frame.h"
#include "FrameView.h"
#include "HTMLNames.h"
#include "HTMLTableElement.h"
#include "HostWindow.h"
#include "RenderAncestorIterator.h"
#include "RenderBlock.h"
#include "RenderObject.h"
#include "SVGElement.h"
#include "Settings.h"
#include "TextIterator.h"
#include "VisibleUnits.h"
#include "WebKitAccessibleHyperlink.h"
#include "WebKitAccessibleInterfaceAction.h"
#include "WebKitAccessibleInterfaceComponent.h"
#include "WebKitAccessibleInterfaceDocument.h"
#include "WebKitAccessibleInterfaceEditableText.h"
#include "WebKitAccessibleInterfaceHyperlinkImpl.h"
#include "WebKitAccessibleInterfaceHypertext.h"
#include "WebKitAccessibleInterfaceImage.h"
#include "WebKitAccessibleInterfaceSelection.h"
#include "WebKitAccessibleInterfaceTable.h"
#include "WebKitAccessibleInterfaceTableCell.h"
#include "WebKitAccessibleInterfaceText.h"
#include "WebKitAccessibleInterfaceValue.h"
#include "WebKitAccessibleUtil.h"
#include <glib/gprintf.h>
#include <wtf/text/CString.h>
using namespace WebCore;
struct _WebKitAccessiblePrivate {
// Cached data for AtkObject.
CString accessibleName;
CString accessibleDescription;
// Cached data for AtkAction.
CString actionName;
CString actionKeyBinding;
// Cached data for AtkDocument.
CString documentLocale;
CString documentType;
CString documentEncoding;
CString documentURI;
// Cached data for AtkImage.
CString imageDescription;
};
#define WEBKIT_ACCESSIBLE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), WEBKIT_TYPE_ACCESSIBLE, WebKitAccessiblePrivate))
static AccessibilityObject* fallbackObject()
{
static AccessibilityObject* object = &AccessibilityListBoxOption::create().leakRef();
return object;
}
static AccessibilityObject* core(AtkObject* object)
{
if (!WEBKIT_IS_ACCESSIBLE(object))
return 0;
return webkitAccessibleGetAccessibilityObject(WEBKIT_ACCESSIBLE(object));
}
static const gchar* webkitAccessibleGetName(AtkObject* object)
{
g_return_val_if_fail(WEBKIT_IS_ACCESSIBLE(object), 0);
returnValIfWebKitAccessibleIsInvalid(WEBKIT_ACCESSIBLE(object), 0);
Vector<AccessibilityText> textOrder;
core(object)->accessibilityText(textOrder);
for (const auto& text : textOrder) {
// FIXME: This check is here because AccessibilityNodeObject::titleElementText()
// appends an empty String for the LabelByElementText source when there is a
// titleUIElement(). Removing this check makes some fieldsets lose their name.
if (text.text.isEmpty())
continue;
// WebCore Accessibility should provide us with the text alternative computation
// in the order defined by that spec. So take the first thing that our platform
// does not expose via the AtkObject description.
if (text.textSource != HelpText && text.textSource != SummaryText)
return cacheAndReturnAtkProperty(object, AtkCachedAccessibleName, text.text);
}
return cacheAndReturnAtkProperty(object, AtkCachedAccessibleName, "");
}
static const gchar* webkitAccessibleGetDescription(AtkObject* object)
{
g_return_val_if_fail(WEBKIT_IS_ACCESSIBLE(object), 0);
returnValIfWebKitAccessibleIsInvalid(WEBKIT_ACCESSIBLE(object), 0);
Vector<AccessibilityText> textOrder;
core(object)->accessibilityText(textOrder);
bool nameTextAvailable = false;
for (const auto& text : textOrder) {
// WebCore Accessibility should provide us with the text alternative computation
// in the order defined by that spec. So take the first thing that our platform
// does not expose via the AtkObject name.
if (text.textSource == HelpText || text.textSource == SummaryText)
return cacheAndReturnAtkProperty(object, AtkCachedAccessibleDescription, text.text);
// If there is no other text alternative, the title tag contents will have been
// used for the AtkObject name. We don't want to duplicate it here.
if (text.textSource == TitleTagText && nameTextAvailable)
return cacheAndReturnAtkProperty(object, AtkCachedAccessibleDescription, text.text);
nameTextAvailable = true;
}
return cacheAndReturnAtkProperty(object, AtkCachedAccessibleDescription, "");
}
static void removeAtkRelationByType(AtkRelationSet* relationSet, AtkRelationType relationType)
{
int count = atk_relation_set_get_n_relations(relationSet);
for (int i = 0; i < count; i++) {
AtkRelation* relation = atk_relation_set_get_relation(relationSet, i);
if (atk_relation_get_relation_type(relation) == relationType) {
atk_relation_set_remove(relationSet, relation);
break;
}
}
}
static void setAtkRelationSetFromCoreObject(AccessibilityObject* coreObject, AtkRelationSet* relationSet)
{
// Elements with aria-labelledby should have the labelled-by relation as per the ARIA AAM spec.
// Controls with a label element and fieldsets with a legend element should also use this relation
// as per the HTML AAM spec. The reciprocal label-for relation should also be used.
removeAtkRelationByType(relationSet, ATK_RELATION_LABELLED_BY);
removeAtkRelationByType(relationSet, ATK_RELATION_LABEL_FOR);
if (coreObject->isControl()) {
if (AccessibilityObject* label = coreObject->correspondingLabelForControlElement())
atk_relation_set_add_relation_by_type(relationSet, ATK_RELATION_LABELLED_BY, label->wrapper());
} else if (coreObject->isFieldset()) {
if (AccessibilityObject* label = coreObject->titleUIElement())
atk_relation_set_add_relation_by_type(relationSet, ATK_RELATION_LABELLED_BY, label->wrapper());
} else if (coreObject->roleValue() == LegendRole) {
if (RenderBlock* renderFieldset = ancestorsOfType<RenderBlock>(*coreObject->renderer()).first()) {
if (renderFieldset->isFieldset()) {
AccessibilityObject* fieldset = coreObject->axObjectCache()->getOrCreate(renderFieldset);
atk_relation_set_add_relation_by_type(relationSet, ATK_RELATION_LABEL_FOR, fieldset->wrapper());
}
}
} else if (AccessibilityObject* control = coreObject->correspondingControlForLabelElement()) {
atk_relation_set_add_relation_by_type(relationSet, ATK_RELATION_LABEL_FOR, control->wrapper());
} else {
AccessibilityObject::AccessibilityChildrenVector ariaLabelledByElements;
coreObject->ariaLabelledByElements(ariaLabelledByElements);
for (const auto& accessibilityObject : ariaLabelledByElements)
atk_relation_set_add_relation_by_type(relationSet, ATK_RELATION_LABELLED_BY, accessibilityObject->wrapper());
}
// Elements referenced by aria-labelledby should have the label-for relation as per the ARIA AAM spec.
AccessibilityObject::AccessibilityChildrenVector labels;
coreObject->ariaLabelledByReferencingElements(labels);
for (const auto& accessibilityObject : labels)
atk_relation_set_add_relation_by_type(relationSet, ATK_RELATION_LABEL_FOR, accessibilityObject->wrapper());
// Elements with aria-flowto should have the flows-to relation as per the ARIA AAM spec.
removeAtkRelationByType(relationSet, ATK_RELATION_FLOWS_TO);
AccessibilityObject::AccessibilityChildrenVector ariaFlowToElements;
coreObject->ariaFlowToElements(ariaFlowToElements);
for (const auto& accessibilityObject : ariaFlowToElements)
atk_relation_set_add_relation_by_type(relationSet, ATK_RELATION_FLOWS_TO, accessibilityObject->wrapper());
// Elements referenced by aria-flowto should have the flows-from relation as per the ARIA AAM spec.
removeAtkRelationByType(relationSet, ATK_RELATION_FLOWS_FROM);
AccessibilityObject::AccessibilityChildrenVector flowFrom;
coreObject->ariaFlowToReferencingElements(flowFrom);
for (const auto& accessibilityObject : flowFrom)
atk_relation_set_add_relation_by_type(relationSet, ATK_RELATION_FLOWS_FROM, accessibilityObject->wrapper());
// Elements with aria-describedby should have the described-by relation as per the ARIA AAM spec.
removeAtkRelationByType(relationSet, ATK_RELATION_DESCRIBED_BY);
AccessibilityObject::AccessibilityChildrenVector ariaDescribedByElements;
coreObject->ariaDescribedByElements(ariaDescribedByElements);
for (const auto& accessibilityObject : ariaDescribedByElements)
atk_relation_set_add_relation_by_type(relationSet, ATK_RELATION_DESCRIBED_BY, accessibilityObject->wrapper());
// Elements referenced by aria-describedby should have the description-for relation as per the ARIA AAM spec.
removeAtkRelationByType(relationSet, ATK_RELATION_DESCRIPTION_FOR);
AccessibilityObject::AccessibilityChildrenVector describers;
coreObject->ariaDescribedByReferencingElements(describers);
for (const auto& accessibilityObject : describers)
atk_relation_set_add_relation_by_type(relationSet, ATK_RELATION_DESCRIPTION_FOR, accessibilityObject->wrapper());
// Elements with aria-controls should have the controller-for relation as per the ARIA AAM spec.
removeAtkRelationByType(relationSet, ATK_RELATION_CONTROLLER_FOR);
AccessibilityObject::AccessibilityChildrenVector ariaControls;
coreObject->ariaControlsElements(ariaControls);
for (const auto& accessibilityObject : ariaControls)
atk_relation_set_add_relation_by_type(relationSet, ATK_RELATION_CONTROLLER_FOR, accessibilityObject->wrapper());
// Elements referenced by aria-controls should have the controlled-by relation as per the ARIA AAM spec.
removeAtkRelationByType(relationSet, ATK_RELATION_CONTROLLED_BY);
AccessibilityObject::AccessibilityChildrenVector controllers;
coreObject->ariaControlsReferencingElements(controllers);
for (const auto& accessibilityObject : controllers)
atk_relation_set_add_relation_by_type(relationSet, ATK_RELATION_CONTROLLED_BY, accessibilityObject->wrapper());
// Elements with aria-owns should have the node-parent-of relation as per the ARIA AAM spec.
removeAtkRelationByType(relationSet, ATK_RELATION_NODE_PARENT_OF);
AccessibilityObject::AccessibilityChildrenVector ariaOwns;
coreObject->ariaOwnsElements(ariaOwns);
for (const auto& accessibilityObject : ariaOwns)
atk_relation_set_add_relation_by_type(relationSet, ATK_RELATION_NODE_PARENT_OF, accessibilityObject->wrapper());
// Elements referenced by aria-owns should have the node-child-of relation as per the ARIA AAM spec.
removeAtkRelationByType(relationSet, ATK_RELATION_NODE_CHILD_OF);
AccessibilityObject::AccessibilityChildrenVector owners;
coreObject->ariaOwnsReferencingElements(owners);
for (const auto& accessibilityObject : owners)
atk_relation_set_add_relation_by_type(relationSet, ATK_RELATION_NODE_CHILD_OF, accessibilityObject->wrapper());
#if ATK_CHECK_VERSION(2, 25, 2)
// Elements with aria-details should have the details relation as per the ARIA AAM spec.
removeAtkRelationByType(relationSet, ATK_RELATION_DETAILS);
AccessibilityObject::AccessibilityChildrenVector ariaDetails;
coreObject->ariaDetailsElements(ariaDetails);
for (const auto& accessibilityObject : ariaDetails)
atk_relation_set_add_relation_by_type(relationSet, ATK_RELATION_DETAILS, accessibilityObject->wrapper());
// Elements referenced by aria-details should have the details-for relation as per the ARIA AAM spec.
removeAtkRelationByType(relationSet, ATK_RELATION_DETAILS_FOR);
AccessibilityObject::AccessibilityChildrenVector details;
coreObject->ariaDetailsReferencingElements(details);
for (const auto& accessibilityObject : details)
atk_relation_set_add_relation_by_type(relationSet, ATK_RELATION_DETAILS_FOR, accessibilityObject->wrapper());
// Elements with aria-errormessage should have the error-message relation as per the ARIA AAM spec.
removeAtkRelationByType(relationSet, ATK_RELATION_ERROR_MESSAGE);
AccessibilityObject::AccessibilityChildrenVector ariaErrorMessage;
coreObject->ariaErrorMessageElements(ariaErrorMessage);
for (const auto& accessibilityObject : ariaErrorMessage)
atk_relation_set_add_relation_by_type(relationSet, ATK_RELATION_ERROR_MESSAGE, accessibilityObject->wrapper());
// Elements referenced by aria-errormessage should have the error-for relation as per the ARIA AAM spec.
removeAtkRelationByType(relationSet, ATK_RELATION_ERROR_FOR);
AccessibilityObject::AccessibilityChildrenVector errors;
coreObject->ariaErrorMessageReferencingElements(errors);
for (const auto& accessibilityObject : errors)
atk_relation_set_add_relation_by_type(relationSet, ATK_RELATION_ERROR_FOR, accessibilityObject->wrapper());
#endif
}
static gpointer webkitAccessibleParentClass = nullptr;
static bool isRootObject(AccessibilityObject* coreObject)
{
// The root accessible object in WebCore is always an object with
// the ScrolledArea role with one child with the WebArea role.
if (!coreObject || !coreObject->isScrollView())
return false;
AccessibilityObject* firstChild = coreObject->firstChild();
if (!firstChild || !firstChild->isWebArea())
return false;
return true;
}
static AtkObject* atkParentOfRootObject(AtkObject* object)
{
AccessibilityObject* coreObject = core(object);
AccessibilityObject* coreParent = coreObject->parentObjectUnignored();
// The top level object claims to not have a parent. This makes it
// impossible for assistive technologies to ascend the accessible
// hierarchy all the way to the application. (Bug 30489)
if (!coreParent && isRootObject(coreObject)) {
Document* document = coreObject->document();
if (!document)
return 0;
}
if (!coreParent)
return 0;
return coreParent->wrapper();
}
static AtkObject* webkitAccessibleGetParent(AtkObject* object)
{
g_return_val_if_fail(WEBKIT_IS_ACCESSIBLE(object), 0);
returnValIfWebKitAccessibleIsInvalid(WEBKIT_ACCESSIBLE(object), 0);
// Check first if the parent has been already set.
AtkObject* accessibleParent = ATK_OBJECT_CLASS(webkitAccessibleParentClass)->get_parent(object);
if (accessibleParent)
return accessibleParent;
// Parent not set yet, so try to find it in the hierarchy.
AccessibilityObject* coreObject = core(object);
if (!coreObject)
return 0;
AccessibilityObject* coreParent = coreObject->parentObjectUnignored();
if (!coreParent && isRootObject(coreObject))
return atkParentOfRootObject(object);
if (!coreParent)
return 0;
return coreParent->wrapper();
}
static gint webkitAccessibleGetNChildren(AtkObject* object)
{
g_return_val_if_fail(WEBKIT_IS_ACCESSIBLE(object), 0);
returnValIfWebKitAccessibleIsInvalid(WEBKIT_ACCESSIBLE(object), 0);
AccessibilityObject* coreObject = core(object);
return coreObject->children().size();
}
static AtkObject* webkitAccessibleRefChild(AtkObject* object, gint index)
{
g_return_val_if_fail(WEBKIT_IS_ACCESSIBLE(object), 0);
returnValIfWebKitAccessibleIsInvalid(WEBKIT_ACCESSIBLE(object), 0);
if (index < 0)
return 0;
AccessibilityObject* coreObject = core(object);
AccessibilityObject* coreChild = nullptr;
const AccessibilityObject::AccessibilityChildrenVector& children = coreObject->children();
if (static_cast<size_t>(index) >= children.size())
return 0;
coreChild = children.at(index).get();
if (!coreChild)
return 0;
AtkObject* child = coreChild->wrapper();
atk_object_set_parent(child, object);
g_object_ref(child);
return child;
}
static gint webkitAccessibleGetIndexInParent(AtkObject* object)
{
g_return_val_if_fail(WEBKIT_IS_ACCESSIBLE(object), -1);
returnValIfWebKitAccessibleIsInvalid(WEBKIT_ACCESSIBLE(object), -1);
AccessibilityObject* coreObject = core(object);
AccessibilityObject* parent = coreObject->parentObjectUnignored();
if (!parent && isRootObject(coreObject)) {
AtkObject* atkParent = atkParentOfRootObject(object);
if (!atkParent)
return -1;
unsigned count = atk_object_get_n_accessible_children(atkParent);
for (unsigned i = 0; i < count; ++i) {
AtkObject* child = atk_object_ref_accessible_child(atkParent, i);
bool childIsObject = child == object;
g_object_unref(child);
if (childIsObject)
return i;
}
}
if (!parent)
return -1;
size_t index = parent->children().find(coreObject);
return (index == WTF::notFound) ? -1 : index;
}
static AtkAttributeSet* webkitAccessibleGetAttributes(AtkObject* object)
{
g_return_val_if_fail(WEBKIT_IS_ACCESSIBLE(object), 0);
returnValIfWebKitAccessibleIsInvalid(WEBKIT_ACCESSIBLE(object), 0);
AtkAttributeSet* attributeSet = nullptr;
#if PLATFORM(GTK)
attributeSet = addToAtkAttributeSet(attributeSet, "toolkit", "WebKitGtk");
#endif
AccessibilityObject* coreObject = core(object);
if (!coreObject)
return attributeSet;
// Hack needed for WebKit2 tests because obtaining an element by its ID
// cannot be done from the UIProcess. Assistive technologies have no need
// for this information.
Element* element = coreObject->element() ? coreObject->element() : coreObject->actionElement();
if (element) {
String tagName = element->tagName();
if (!tagName.isEmpty())
attributeSet = addToAtkAttributeSet(attributeSet, "tag", tagName.convertToASCIILowercase().utf8().data());
String id = element->getIdAttribute().string();
if (!id.isEmpty())
attributeSet = addToAtkAttributeSet(attributeSet, "html-id", id.utf8().data());
}
int level = coreObject->isHeading() ? coreObject->headingLevel() : coreObject->hierarchicalLevel();
if (level) {
String value = String::number(level);
attributeSet = addToAtkAttributeSet(attributeSet, "level", value.utf8().data());
}
if (coreObject->roleValue() == MathElementRole) {
if (coreObject->isMathMultiscriptObject(PreSuperscript) || coreObject->isMathMultiscriptObject(PreSubscript))
attributeSet = addToAtkAttributeSet(attributeSet, "multiscript-type", "pre");
else if (coreObject->isMathMultiscriptObject(PostSuperscript) || coreObject->isMathMultiscriptObject(PostSubscript))
attributeSet = addToAtkAttributeSet(attributeSet, "multiscript-type", "post");
}
if (is<AccessibilityTable>(*coreObject) && downcast<AccessibilityTable>(*coreObject).isExposableThroughAccessibility()) {
auto& table = downcast<AccessibilityTable>(*coreObject);
int rowCount = table.ariaRowCount();
if (rowCount)
attributeSet = addToAtkAttributeSet(attributeSet, "rowcount", String::number(rowCount).utf8().data());
int columnCount = table.ariaColumnCount();
if (columnCount)
attributeSet = addToAtkAttributeSet(attributeSet, "colcount", String::number(columnCount).utf8().data());
} else if (is<AccessibilityTableRow>(*coreObject)) {
auto& row = downcast<AccessibilityTableRow>(*coreObject);
int rowIndex = row.ariaRowIndex();
if (rowIndex != -1)
attributeSet = addToAtkAttributeSet(attributeSet, "rowindex", String::number(rowIndex).utf8().data());
} else if (is<AccessibilityTableCell>(*coreObject)) {
auto& cell = downcast<AccessibilityTableCell>(*coreObject);
int rowIndex = cell.ariaRowIndex();
if (rowIndex != -1)
attributeSet = addToAtkAttributeSet(attributeSet, "rowindex", String::number(rowIndex).utf8().data());
int columnIndex = cell.ariaColumnIndex();
if (columnIndex != -1)
attributeSet = addToAtkAttributeSet(attributeSet, "colindex", String::number(columnIndex).utf8().data());
int rowSpan = cell.ariaRowSpan();
if (rowSpan != -1)
attributeSet = addToAtkAttributeSet(attributeSet, "rowspan", String::number(rowSpan).utf8().data());
int columnSpan = cell.ariaColumnSpan();
if (columnSpan != -1)
attributeSet = addToAtkAttributeSet(attributeSet, "colspan", String::number(columnSpan).utf8().data());
}
String placeholder = coreObject->placeholderValue();
if (!placeholder.isEmpty())
attributeSet = addToAtkAttributeSet(attributeSet, "placeholder-text", placeholder.utf8().data());
if (coreObject->supportsARIAAutoComplete())
attributeSet = addToAtkAttributeSet(attributeSet, "autocomplete", coreObject->ariaAutoCompleteValue().utf8().data());
if (coreObject->supportsARIAHasPopup())
attributeSet = addToAtkAttributeSet(attributeSet, "haspopup", coreObject->ariaPopupValue().utf8().data());
if (coreObject->supportsARIACurrent())
attributeSet = addToAtkAttributeSet(attributeSet, "current", coreObject->ariaCurrentValue().utf8().data());
AccessibilitySortDirection sortDirection = coreObject->sortDirection();
if (sortDirection != SortDirectionNone) {
// WAI-ARIA spec says to translate the value as is from the attribute.
const AtomicString& sortAttribute = coreObject->getAttribute(HTMLNames::aria_sortAttr);
attributeSet = addToAtkAttributeSet(attributeSet, "sort", sortAttribute.string().utf8().data());
}
if (coreObject->supportsARIAPosInSet())
attributeSet = addToAtkAttributeSet(attributeSet, "posinset", String::number(coreObject->ariaPosInSet()).utf8().data());
if (coreObject->supportsARIASetSize())
attributeSet = addToAtkAttributeSet(attributeSet, "setsize", String::number(coreObject->ariaSetSize()).utf8().data());
String isReadOnly = coreObject->ariaReadOnlyValue();
if (!isReadOnly.isEmpty())
attributeSet = addToAtkAttributeSet(attributeSet, "readonly", isReadOnly.utf8().data());
String valueDescription = coreObject->valueDescription();
if (!valueDescription.isEmpty())
attributeSet = addToAtkAttributeSet(attributeSet, "valuetext", valueDescription.utf8().data());
// According to the W3C Core Accessibility API Mappings 1.1, section 5.4.1 General Rules:
// "User agents must expose the WAI-ARIA role string if the API supports a mechanism to do so."
// In the case of ATK, the mechanism to do so is an object attribute pair (xml-roles:"string").
// We cannot use the computedRoleString for this purpose because it is not limited to elements
// with ARIA roles, and it might not contain the actual ARIA role value (e.g. DPub ARIA).
String roleString = coreObject->getAttribute(HTMLNames::roleAttr);
if (!roleString.isEmpty())
attributeSet = addToAtkAttributeSet(attributeSet, "xml-roles", roleString.utf8().data());
String computedRoleString = coreObject->computedRoleString();
if (!computedRoleString.isEmpty()) {
attributeSet = addToAtkAttributeSet(attributeSet, "computed-role", computedRoleString.utf8().data());
// The HTML AAM maps several elements to ARIA landmark roles. In order for the type of landmark
// to be obtainable in the same fashion as an ARIA landmark, fall back on the computedRoleString.
if (coreObject->ariaRoleAttribute() == UnknownRole && coreObject->isLandmark())
attributeSet = addToAtkAttributeSet(attributeSet, "xml-roles", computedRoleString.utf8().data());
}
String roleDescription = coreObject->roleDescription();
if (!roleDescription.isEmpty())
attributeSet = addToAtkAttributeSet(attributeSet, "roledescription", roleDescription.utf8().data());
// We need to expose the live region attributes even if the live region is currently disabled/off.
if (auto liveContainer = coreObject->ariaLiveRegionAncestor(false)) {
String liveStatus = liveContainer->ariaLiveRegionStatus();
String relevant = liveContainer->ariaLiveRegionRelevant();
bool isAtomic = liveContainer->ariaLiveRegionAtomic();
String liveRole = roleString.isEmpty() ? computedRoleString : roleString;
// According to the Core AAM, we need to expose the above properties with "container-" prefixed
// object attributes regardless of whether the container is this object, or an ancestor of it.
attributeSet = addToAtkAttributeSet(attributeSet, "container-live", liveStatus.utf8().data());
attributeSet = addToAtkAttributeSet(attributeSet, "container-relevant", relevant.utf8().data());
if (isAtomic)
attributeSet = addToAtkAttributeSet(attributeSet, "container-atomic", "true");
if (!liveRole.isEmpty())
attributeSet = addToAtkAttributeSet(attributeSet, "container-live-role", liveRole.utf8().data());
// According to the Core AAM, if this object is the live region (rather than its descendant),
// we must expose the above properties on the object without a "container-" prefix.
if (liveContainer == coreObject) {
attributeSet = addToAtkAttributeSet(attributeSet, "live", liveStatus.utf8().data());
attributeSet = addToAtkAttributeSet(attributeSet, "relevant", relevant.utf8().data());
if (isAtomic)
attributeSet = addToAtkAttributeSet(attributeSet, "atomic", "true");
} else if (!isAtomic && coreObject->ariaLiveRegionAtomic())
attributeSet = addToAtkAttributeSet(attributeSet, "atomic", "true");
}
// The Core AAM states the author-provided value should be exposed as-is.
String dropEffect = coreObject->getAttribute(HTMLNames::aria_dropeffectAttr);
if (!dropEffect.isEmpty())
attributeSet = addToAtkAttributeSet(attributeSet, "dropeffect", dropEffect.utf8().data());
if (coreObject->isARIAGrabbed())
attributeSet = addToAtkAttributeSet(attributeSet, "grabbed", "true");
else if (coreObject->supportsARIADragging())
attributeSet = addToAtkAttributeSet(attributeSet, "grabbed", "false");
return attributeSet;
}
static AtkRole atkRole(AccessibilityObject* coreObject)
{
AccessibilityRole role = coreObject->roleValue();
switch (role) {
case ApplicationAlertRole:
return ATK_ROLE_ALERT;
case ApplicationAlertDialogRole:
case ApplicationDialogRole:
return ATK_ROLE_DIALOG;
case ApplicationStatusRole:
return ATK_ROLE_STATUSBAR;
case UnknownRole:
return ATK_ROLE_UNKNOWN;
case AudioRole:
#if ATK_CHECK_VERSION(2, 11, 3)
return ATK_ROLE_AUDIO;
#endif
case VideoRole:
#if ATK_CHECK_VERSION(2, 11, 3)
return ATK_ROLE_VIDEO;
#endif
return ATK_ROLE_EMBEDDED;
case ButtonRole:
return ATK_ROLE_PUSH_BUTTON;
case SwitchRole:
case ToggleButtonRole:
return ATK_ROLE_TOGGLE_BUTTON;
case RadioButtonRole:
return ATK_ROLE_RADIO_BUTTON;
case CheckBoxRole:
return ATK_ROLE_CHECK_BOX;
case SliderRole:
return ATK_ROLE_SLIDER;
case TabGroupRole:
case TabListRole:
return ATK_ROLE_PAGE_TAB_LIST;
case TextFieldRole:
case TextAreaRole:
case SearchFieldRole:
return ATK_ROLE_ENTRY;
case StaticTextRole:
#if ATK_CHECK_VERSION(2, 15, 2)
return ATK_ROLE_STATIC;
#else
return ATK_ROLE_TEXT;
#endif
case OutlineRole:
case TreeRole:
return ATK_ROLE_TREE;
case TreeItemRole:
return ATK_ROLE_TREE_ITEM;
case MenuBarRole:
return ATK_ROLE_MENU_BAR;
case MenuListPopupRole:
case MenuRole:
return ATK_ROLE_MENU;
case MenuListOptionRole:
case MenuItemRole:
return ATK_ROLE_MENU_ITEM;
case MenuItemCheckboxRole:
return ATK_ROLE_CHECK_MENU_ITEM;
case MenuItemRadioRole:
return ATK_ROLE_RADIO_MENU_ITEM;
case ColumnRole:
// return ATK_ROLE_TABLE_COLUMN_HEADER; // Is this right?
return ATK_ROLE_UNKNOWN; // Matches Mozilla
case RowRole:
return ATK_ROLE_TABLE_ROW;
case ToolbarRole:
return ATK_ROLE_TOOL_BAR;
case BusyIndicatorRole:
return ATK_ROLE_PROGRESS_BAR; // Is this right?
case ProgressIndicatorRole:
return coreObject->isMeter() ? ATK_ROLE_LEVEL_BAR : ATK_ROLE_PROGRESS_BAR;
case WindowRole:
return ATK_ROLE_WINDOW;
case PopUpButtonRole:
return coreObject->ariaHasPopup() ? ATK_ROLE_PUSH_BUTTON : ATK_ROLE_COMBO_BOX;
case ComboBoxRole:
return ATK_ROLE_COMBO_BOX;
case SplitGroupRole:
return ATK_ROLE_SPLIT_PANE;
case SplitterRole:
return ATK_ROLE_SEPARATOR;
case ColorWellRole:
#if PLATFORM(GTK)
// ATK_ROLE_COLOR_CHOOSER is defined as a dialog (i.e. it's what appears when you push the button).
return ATK_ROLE_PUSH_BUTTON;
#endif
case ListRole:
return ATK_ROLE_LIST;
case ScrollBarRole:
return ATK_ROLE_SCROLL_BAR;
case ScrollAreaRole:
return ATK_ROLE_SCROLL_PANE;
case GridRole:
case TableRole:
return ATK_ROLE_TABLE;
case TreeGridRole:
return ATK_ROLE_TREE_TABLE;
case ApplicationRole:
return ATK_ROLE_APPLICATION;
case ApplicationGroupRole:
case FeedRole:
case FigureRole:
case GroupRole:
case RadioGroupRole:
case SVGRootRole:
case TabPanelRole:
return ATK_ROLE_PANEL;
case RowHeaderRole:
return ATK_ROLE_ROW_HEADER;
case ColumnHeaderRole:
return ATK_ROLE_COLUMN_HEADER;
case CaptionRole:
return ATK_ROLE_CAPTION;
case CellRole:
case GridCellRole:
return coreObject->inheritsPresentationalRole() ? ATK_ROLE_SECTION : ATK_ROLE_TABLE_CELL;
case LinkRole:
case WebCoreLinkRole:
case ImageMapLinkRole:
return ATK_ROLE_LINK;
case ImageMapRole:
return ATK_ROLE_IMAGE_MAP;
case ImageRole:
return ATK_ROLE_IMAGE;
case ListMarkerRole:
return ATK_ROLE_TEXT;
case DocumentArticleRole:
#if ATK_CHECK_VERSION(2, 11, 3)
return ATK_ROLE_ARTICLE;
#endif
case DocumentRole:
return ATK_ROLE_DOCUMENT_FRAME;
case DocumentNoteRole:
return ATK_ROLE_COMMENT;
case HeadingRole:
return ATK_ROLE_HEADING;
case ListBoxRole:
// https://rawgit.com/w3c/aria/master/core-aam/core-aam.html#role-map-listbox
return coreObject->isDescendantOfRole(ComboBoxRole) ? ATK_ROLE_MENU : ATK_ROLE_LIST_BOX;
case ListItemRole:
return coreObject->inheritsPresentationalRole() ? ATK_ROLE_SECTION : ATK_ROLE_LIST_ITEM;
case ListBoxOptionRole:
return coreObject->isDescendantOfRole(ComboBoxRole) ? ATK_ROLE_MENU_ITEM : ATK_ROLE_LIST_ITEM;
case ParagraphRole:
return ATK_ROLE_PARAGRAPH;
case LabelRole:
case LegendRole:
return ATK_ROLE_LABEL;
case BlockquoteRole:
#if ATK_CHECK_VERSION(2, 11, 3)
return ATK_ROLE_BLOCK_QUOTE;
#endif
case FootnoteRole:
#if ATK_CHECK_VERSION(2, 25, 2)
return ATK_ROLE_FOOTNOTE;
#endif
case ApplicationTextGroupRole:
case DivRole:
case PreRole:
case SVGTextRole:
case TextGroupRole:
return ATK_ROLE_SECTION;
case FooterRole:
return ATK_ROLE_FOOTER;
case FormRole:
return ATK_ROLE_FORM;
case CanvasRole:
return ATK_ROLE_CANVAS;
case HorizontalRuleRole:
return ATK_ROLE_SEPARATOR;
case SpinButtonRole:
return ATK_ROLE_SPIN_BUTTON;
case TabRole:
return ATK_ROLE_PAGE_TAB;
case UserInterfaceTooltipRole:
return ATK_ROLE_TOOL_TIP;
case WebAreaRole:
return ATK_ROLE_DOCUMENT_WEB;
case WebApplicationRole:
return ATK_ROLE_EMBEDDED;
#if ATK_CHECK_VERSION(2, 11, 3)
case ApplicationLogRole:
return ATK_ROLE_LOG;
case ApplicationMarqueeRole:
return ATK_ROLE_MARQUEE;
case ApplicationTimerRole:
return ATK_ROLE_TIMER;
case DefinitionRole:
return ATK_ROLE_DEFINITION;
case DocumentMathRole:
return ATK_ROLE_MATH;
case MathElementRole:
if (coreObject->isMathRow())
return ATK_ROLE_PANEL;
if (coreObject->isMathTable())
return ATK_ROLE_TABLE;
if (coreObject->isMathTableRow())
return ATK_ROLE_TABLE_ROW;
if (coreObject->isMathTableCell())
return ATK_ROLE_TABLE_CELL;
if (coreObject->isMathSubscriptSuperscript() || coreObject->isMathMultiscript())
return ATK_ROLE_SECTION;
#if ATK_CHECK_VERSION(2, 15, 4)
if (coreObject->isMathFraction())
return ATK_ROLE_MATH_FRACTION;
if (coreObject->isMathSquareRoot() || coreObject->isMathRoot())
return ATK_ROLE_MATH_ROOT;
if (coreObject->isMathScriptObject(Subscript)
|| coreObject->isMathMultiscriptObject(PreSubscript) || coreObject->isMathMultiscriptObject(PostSubscript))
return ATK_ROLE_SUBSCRIPT;
if (coreObject->isMathScriptObject(Superscript)
|| coreObject->isMathMultiscriptObject(PreSuperscript) || coreObject->isMathMultiscriptObject(PostSuperscript))
return ATK_ROLE_SUPERSCRIPT;
#endif
#if ATK_CHECK_VERSION(2, 15, 2)
if (coreObject->isMathToken())
return ATK_ROLE_STATIC;
#endif
return ATK_ROLE_UNKNOWN;
case LandmarkBannerRole:
case LandmarkComplementaryRole:
case LandmarkContentInfoRole:
case LandmarkDocRegionRole:
case LandmarkMainRole:
case LandmarkNavigationRole:
case LandmarkRegionRole:
case LandmarkSearchRole:
return ATK_ROLE_LANDMARK;
#endif
#if ATK_CHECK_VERSION(2, 11, 4)
case DescriptionListRole:
return ATK_ROLE_DESCRIPTION_LIST;
case TermRole:
case DescriptionListTermRole:
return ATK_ROLE_DESCRIPTION_TERM;
case DescriptionListDetailRole:
return ATK_ROLE_DESCRIPTION_VALUE;
#endif
case InlineRole:
#if ATK_CHECK_VERSION(2, 15, 4)
if (coreObject->isSubscriptStyleGroup())
return ATK_ROLE_SUBSCRIPT;
if (coreObject->isSuperscriptStyleGroup())
return ATK_ROLE_SUPERSCRIPT;
#endif
#if ATK_CHECK_VERSION(2, 15, 2)
return ATK_ROLE_STATIC;
case SVGTextPathRole:
case SVGTSpanRole:
case TimeRole:
return ATK_ROLE_STATIC;
#endif
default:
return ATK_ROLE_UNKNOWN;
}
}
static AtkRole webkitAccessibleGetRole(AtkObject* object)
{
// ATK_ROLE_UNKNOWN should only be applied in cases where there is a valid
// WebCore accessible object for which the platform role mapping is unknown.
g_return_val_if_fail(WEBKIT_IS_ACCESSIBLE(object), ATK_ROLE_INVALID);
returnValIfWebKitAccessibleIsInvalid(WEBKIT_ACCESSIBLE(object), ATK_ROLE_INVALID);
AccessibilityObject* coreObject = core(object);
if (!coreObject)
return ATK_ROLE_INVALID;
// Note: Why doesn't WebCore have a password field for this
if (coreObject->isPasswordField())
return ATK_ROLE_PASSWORD_TEXT;
return atkRole(coreObject);
}
static bool isTextWithCaret(AccessibilityObject* coreObject)
{
if (!coreObject || !coreObject->isAccessibilityRenderObject())
return false;
Document* document = coreObject->document();
if (!document)
return false;
Frame* frame = document->frame();
if (!frame)
return false;
if (!frame->settings().caretBrowsingEnabled())
return false;
// Check text objects and paragraphs only.
AtkObject* axObject = coreObject->wrapper();
AtkRole role = axObject ? atk_object_get_role(axObject) : ATK_ROLE_INVALID;
if (role != ATK_ROLE_TEXT && role != ATK_ROLE_PARAGRAPH)
return false;
// Finally, check whether the caret is set in the current object.
VisibleSelection selection = coreObject->selection();
if (!selection.isCaret())
return false;
return selectionBelongsToObject(coreObject, selection);
}
static void setAtkStateSetFromCoreObject(AccessibilityObject* coreObject, AtkStateSet* stateSet)
{
AccessibilityObject* parent = coreObject->parentObject();
bool isListBoxOption = parent && parent->isListBox();
// Please keep the state list in alphabetical order
if ((isListBoxOption && coreObject->isSelectedOptionActive())
|| coreObject->ariaCurrentState() != ARIACurrentFalse)
atk_state_set_add_state(stateSet, ATK_STATE_ACTIVE);
if (coreObject->isBusy())
atk_state_set_add_state(stateSet, ATK_STATE_BUSY);
#if ATK_CHECK_VERSION(2,11,2)
if (coreObject->supportsChecked() && coreObject->canSetValueAttribute())
atk_state_set_add_state(stateSet, ATK_STATE_CHECKABLE);
#endif
if (coreObject->isChecked())
atk_state_set_add_state(stateSet, ATK_STATE_CHECKED);
if ((coreObject->isTextControl() || coreObject->isNonNativeTextControl()) && coreObject->canSetValueAttribute())
atk_state_set_add_state(stateSet, ATK_STATE_EDITABLE);
// FIXME: Put both ENABLED and SENSITIVE together here for now
if (coreObject->isEnabled()) {
atk_state_set_add_state(stateSet, ATK_STATE_ENABLED);
atk_state_set_add_state(stateSet, ATK_STATE_SENSITIVE);
}
if (coreObject->canSetExpandedAttribute())
atk_state_set_add_state(stateSet, ATK_STATE_EXPANDABLE);
if (coreObject->isExpanded())
atk_state_set_add_state(stateSet, ATK_STATE_EXPANDED);
if (coreObject->canSetFocusAttribute())
atk_state_set_add_state(stateSet, ATK_STATE_FOCUSABLE);
if (coreObject->isFocused() || isTextWithCaret(coreObject))
atk_state_set_add_state(stateSet, ATK_STATE_FOCUSED);
if (coreObject->orientation() == AccessibilityOrientationHorizontal)
atk_state_set_add_state(stateSet, ATK_STATE_HORIZONTAL);
else if (coreObject->orientation() == AccessibilityOrientationVertical)
atk_state_set_add_state(stateSet, ATK_STATE_VERTICAL);
if (coreObject->ariaHasPopup())
atk_state_set_add_state(stateSet, ATK_STATE_HAS_POPUP);
if (coreObject->isIndeterminate())
atk_state_set_add_state(stateSet, ATK_STATE_INDETERMINATE);
if (coreObject->isCheckboxOrRadio() || coreObject->isMenuItem()) {
if (coreObject->checkboxOrRadioValue() == ButtonStateMixed)
atk_state_set_add_state(stateSet, ATK_STATE_INDETERMINATE);
}
if (coreObject->isAriaModalNode())
atk_state_set_add_state(stateSet, ATK_STATE_MODAL);
if (coreObject->invalidStatus() != "false")
atk_state_set_add_state(stateSet, ATK_STATE_INVALID_ENTRY);
if (coreObject->isMultiSelectable())
atk_state_set_add_state(stateSet, ATK_STATE_MULTISELECTABLE);
// TODO: ATK_STATE_OPAQUE
if (coreObject->isPressed())
atk_state_set_add_state(stateSet, ATK_STATE_PRESSED);
#if ATK_CHECK_VERSION(2,15,3)
if (!coreObject->canSetValueAttribute() && (coreObject->supportsARIAReadOnly()))
atk_state_set_add_state(stateSet, ATK_STATE_READ_ONLY);
#endif
if (coreObject->isRequired())
atk_state_set_add_state(stateSet, ATK_STATE_REQUIRED);
// TODO: ATK_STATE_SELECTABLE_TEXT
if (coreObject->canSetSelectedAttribute()) {
atk_state_set_add_state(stateSet, ATK_STATE_SELECTABLE);
// Items in focusable lists have both STATE_SELECT{ABLE,ED}
// and STATE_FOCUS{ABLE,ED}. We'll fake the latter based on
// the former.
if (isListBoxOption)
atk_state_set_add_state(stateSet, ATK_STATE_FOCUSABLE);
}
if (coreObject->isSelected()) {
atk_state_set_add_state(stateSet, ATK_STATE_SELECTED);
// Items in focusable lists have both STATE_SELECT{ABLE,ED}
// and STATE_FOCUS{ABLE,ED}. We'll fake the latter based on the
// former.
if (isListBoxOption)