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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* 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/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 .
*/
#include <osx/salinst.h>
#include <osx/saldata.hxx>
#include <osx/a11ywrapper.h>
#include <osx/a11ylistener.hxx>
#include <osx/a11yfactory.h>
#include <osx/a11yfocustracker.hxx>
#include <quartz/salgdi.h>
#include <quartz/utils.h>
#include "a11yfocuslistener.hxx"
#include "a11yactionwrapper.h"
#include "a11ycomponentwrapper.h"
#include "a11yselectionwrapper.h"
#include "a11ytablewrapper.h"
#include "a11ytextwrapper.h"
#include "a11yvaluewrapper.h"
#include "a11yrolehelper.h"
#include <com/sun/star/accessibility/AccessibleRole.hpp>
#include <com/sun/star/accessibility/AccessibleStateType.hpp>
#include <com/sun/star/accessibility/XAccessibleEventBroadcaster.hpp>
#include <com/sun/star/awt/Size.hpp>
#include <com/sun/star/accessibility/XAccessibleRelationSet.hpp>
#include <com/sun/star/accessibility/AccessibleRelationType.hpp>
#include <com/sun/star/lang/DisposedException.hpp>
#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
#include <sal/log.hxx>
#include <osl/diagnose.h>
using namespace ::com::sun::star::accessibility;
using namespace ::com::sun::star::awt;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::uno;
@interface SalFrameWindow : NSWindow
{
}
-(Reference<XAccessibleContext>)accessibleContext;
@end
static bool isPopupMenuOpen = false;
static std::ostream &operator<<(std::ostream &s, NSObject *obj) {
return s << [[obj description] UTF8String];
}
@implementation AquaA11yWrapper
#pragma mark -
#pragma mark Init and dealloc
-(id)init {
return [ super init ];
}
-(id)initWithAccessibleContext: (Reference < XAccessibleContext >) rxAccessibleContext {
self = [ super init ];
if ( self ) {
[ self setDefaults: rxAccessibleContext ];
}
return self;
}
-(void)setDisposed {
// Related: tdf#148453 Acquire solar mutex during native accessibility calls
SolarMutexGuard aGuard;
mIsDisposed = YES;
// Release all strong C++ references
maReferenceWrapper = ReferenceWrapper();
// Related tdf@158914 avoid resurrecting object's C++ references
// Posting an NSAccessibilityUIElementDestroyedNotification
// notification causes [ AquaA11yWrapper isAccessibilityElement ]
// to be called on the object so mark the object as disposed
// before posting the destroyed notification.
NSAccessibilityPostNotification( self, NSAccessibilityUIElementDestroyedNotification );
}
-(void) setDefaults: (Reference < XAccessibleContext >) rxAccessibleContext {
mActsAsRadioGroup = NO;
maReferenceWrapper.rAccessibleContext = rxAccessibleContext;
mIsTableCell = NO;
mIsDisposed = NO;
// Querying all supported interfaces
try {
// XAccessibleContext2
maReferenceWrapper.rAccessibleContext2.set( rxAccessibleContext, UNO_QUERY );
// XAccessibleComponent
maReferenceWrapper.rAccessibleComponent.set( rxAccessibleContext, UNO_QUERY );
// XAccessibleExtendedComponent
maReferenceWrapper.rAccessibleExtendedComponent.set( rxAccessibleContext, UNO_QUERY );
// XAccessibleSelection
maReferenceWrapper.rAccessibleSelection.set( rxAccessibleContext, UNO_QUERY );
// XAccessibleTable
maReferenceWrapper.rAccessibleTable.set( rxAccessibleContext, UNO_QUERY );
// XAccessibleText
maReferenceWrapper.rAccessibleText.set( rxAccessibleContext, UNO_QUERY );
// XAccessibleEditableText
maReferenceWrapper.rAccessibleEditableText.set( rxAccessibleContext, UNO_QUERY );
// XAccessibleValue
maReferenceWrapper.rAccessibleValue.set( rxAccessibleContext, UNO_QUERY );
// XAccessibleAction
maReferenceWrapper.rAccessibleAction.set( rxAccessibleContext, UNO_QUERY );
// XAccessibleTextAttributes
maReferenceWrapper.rAccessibleTextAttributes.set( rxAccessibleContext, UNO_QUERY );
// XAccessibleMultiLineText
maReferenceWrapper.rAccessibleMultiLineText.set( rxAccessibleContext, UNO_QUERY );
// XAccessibleTextMarkup
maReferenceWrapper.rAccessibleTextMarkup.set( rxAccessibleContext, UNO_QUERY );
// XAccessibleEventBroadcaster
#if 0
/* #i102033# NSAccessibility does not seemt to know an equivalent for transient children.
That means we need to cache this, else e.g. tree list boxes are not accessible (moreover
it crashes by notifying dead objects - which would seemt o be another bug)
FIXME:
Unfortunately this can increase memory consumption drastically until the non transient parent
is destroyed and finally all the transients are released.
*/
if ( ! ( rxAccessibleContext -> getAccessibleStateSet() & AccessibleStateType::TRANSIENT ) )
#endif
{
Reference< XAccessibleEventBroadcaster > xBroadcaster(rxAccessibleContext, UNO_QUERY);
if( xBroadcaster.is() ) {
/*
* We intentionally do not hold a reference to the event listener in the wrapper object,
* but let the listener control the life cycle of the wrapper instead ..
*/
xBroadcaster->addAccessibleEventListener( new AquaA11yEventListener( self, rxAccessibleContext -> getAccessibleRole() ) );
}
}
// TABLE_CELL
if ( rxAccessibleContext -> getAccessibleRole() == AccessibleRole::TABLE_CELL ) {
mIsTableCell = YES;
}
} catch ( const Exception ) {
}
}
#pragma mark -
#pragma mark Utility Section
// generates selectors for attribute name AXAttributeNameHere
// (getter without parameter) attributeNameHereAttribute
// (getter with parameter) attributeNameHereAttributeForParameter:
// (setter) setAttributeNameHereAttributeForElement:to:
-(SEL)selectorForAttribute:(NSString *)attribute asGetter:(BOOL)asGetter withGetterParameter:(BOOL)withGetterParameter {
SEL selector = static_cast<SEL>(nil);
NSAutoreleasePool * pool = [ [ NSAutoreleasePool alloc ] init ];
@try {
// step 1: create method name from attribute name
NSMutableString * methodName = [ NSMutableString string ];
if ( ! asGetter ) {
[ methodName appendString: @"set" ];
}
NSRange const aRange = { 2, 1 };
NSString * firstChar = [ attribute substringWithRange: aRange ]; // drop leading "AX" and get first char
if ( asGetter ) {
[ methodName appendString: [ firstChar lowercaseString ] ];
} else {
[ methodName appendString: firstChar ];
}
[ methodName appendString: [ attribute substringFromIndex: 3 ] ]; // append rest of attribute name
// append rest of method name
[ methodName appendString: @"Attribute" ];
if ( ! asGetter ) {
[ methodName appendString: @"ForElement:to:" ];
} else if ( asGetter && withGetterParameter ) {
[ methodName appendString: @"ForParameter:" ];
}
// step 2: create selector
selector = NSSelectorFromString ( methodName );
} @catch ( id ) {
selector = static_cast<SEL>(nil);
}
[ pool release ];
return selector;
}
-(Reference < XAccessible >)getFirstRadioButtonInGroup {
Reference < XAccessibleRelationSet > rxAccessibleRelationSet = [ self accessibleContext ] -> getAccessibleRelationSet();
if( rxAccessibleRelationSet.is() )
{
AccessibleRelation relationMemberOf = rxAccessibleRelationSet -> getRelationByType ( AccessibleRelationType_MEMBER_OF );
if ( relationMemberOf.RelationType == AccessibleRelationType_MEMBER_OF && relationMemberOf.TargetSet.hasElements() )
return relationMemberOf.TargetSet[0];
}
return Reference < XAccessible > ();
}
-(BOOL)isFirstRadioButtonInGroup {
Reference < XAccessible > rFirstMateAccessible = [ self getFirstRadioButtonInGroup ];
if ( rFirstMateAccessible.is() && rFirstMateAccessible -> getAccessibleContext().get() == [ self accessibleContext ] ) {
return YES;
}
return NO;
}
#pragma mark -
#pragma mark Attribute Value Getters
// ( called via Reflection by accessibilityAttributeValue )
/*
Radiobutton grouping is done differently in NSAccessibility and the UNO-API. In UNO related radio buttons share an entry in their
RelationSet. In NSAccessibility the relationship is expressed through the hierarchy. An AXRadioGroup contains two or more AXRadioButton
objects. Since this group is not available in the UNO hierarchy, an extra wrapper is used for it. This wrapper shares almost all
attributes with the first radio button of the group, except for the role, subrole, role description, parent and children attributes.
So in this five methods there is a special treatment for radio buttons and groups.
*/
-(id)roleAttribute {
if ( mActsAsRadioGroup ) {
return NSAccessibilityRadioGroupRole;
}
else {
return [ AquaA11yRoleHelper getNativeRoleFrom: [ self accessibleContext ] ];
}
}
-(id)subroleAttribute {
if ( mActsAsRadioGroup ) {
return @"";
} else {
NSString * subRole = [ AquaA11yRoleHelper getNativeSubroleFrom: [ self accessibleContext ] -> getAccessibleRole() ];
if ( ! [ subRole isEqualToString: @"" ] ) {
return subRole;
} else {
SAL_WNODEPRECATED_DECLARATIONS_PUSH
//TODO: 10.10 accessibilityAttributeValue:
return [ super accessibilityAttributeValue: NSAccessibilitySubroleAttribute ];
SAL_WNODEPRECATED_DECLARATIONS_POP
}
}
}
-(id)titleAttribute {
// Related tdf#158914: explicitly call autorelease selector
// CreateNSString() is not a getter. It expects the caller to
// release the returned string.
return [ CreateNSString ( [ self accessibleContext ] -> getAccessibleName() ) autorelease ];
}
-(id)descriptionAttribute {
if ( [ self accessibleContext ] -> getAccessibleRole() == AccessibleRole::COMBO_BOX ) {
return [ self titleAttribute ];
} else if ( [ self accessibleExtendedComponent ] ) {
return [ AquaA11yComponentWrapper descriptionAttributeForElement: self ];
} else {
// Related tdf#158914: explicitly call autorelease selector
// CreateNSString() is not a getter. It expects the caller to
// release the returned string.
return [ CreateNSString ( [ self accessibleContext ] -> getAccessibleDescription() ) autorelease ];
}
}
-(id)enabledAttribute {
sal_Int64 nStateSet = [ self accessibleContext ] -> getAccessibleStateSet();
if ( nStateSet ) {
return [ NSNumber numberWithBool: ( (nStateSet & AccessibleStateType::ENABLED) != 0 ) ];
} else {
return nil;
}
}
-(id)focusedAttribute {
if ( [ self accessibleContext ] -> getAccessibleRole() == AccessibleRole::COMBO_BOX ) {
id isFocused = nil;
Reference < XAccessible > rxParent = [ self accessibleContext ] -> getAccessibleParent();
if ( rxParent.is() ) {
Reference < XAccessibleContext > rxContext = rxParent -> getAccessibleContext();
if ( rxContext.is() ) {
sal_Int64 nStateSet = rxContext -> getAccessibleStateSet();
if ( nStateSet ) {
isFocused = [ NSNumber numberWithBool: ( ( nStateSet & AccessibleStateType::FOCUSED ) != 0 ) ];
}
}
}
return isFocused;
} else if ( [ self accessibleContext ] -> getAccessibleStateSet() ) {
sal_Int64 nStateSet = [ self accessibleContext ] -> getAccessibleStateSet();
return [ NSNumber numberWithBool: ( ( nStateSet & AccessibleStateType::FOCUSED ) != 0 ) ];
} else {
return nil;
}
}
-(id)parentAttribute {
if ( [ self accessibleContext ] -> getAccessibleRole() == AccessibleRole::RADIO_BUTTON && ! mActsAsRadioGroup ) {
Reference < XAccessible > rxAccessible = [ self getFirstRadioButtonInGroup ];
if ( rxAccessible.is() && rxAccessible -> getAccessibleContext().is() ) {
Reference < XAccessibleContext > rxAccessibleContext = rxAccessible -> getAccessibleContext();
id parent_wrapper = [ AquaA11yFactory wrapperForAccessibleContext: rxAccessibleContext createIfNotExists: YES asRadioGroup: YES ];
[ parent_wrapper autorelease ];
return NSAccessibilityUnignoredAncestor( parent_wrapper );
}
return nil;
}
try {
Reference< XAccessible > xParent( [ self accessibleContext ] -> getAccessibleParent() );
if ( xParent.is() ) {
Reference< XAccessibleContext > xContext( xParent -> getAccessibleContext() );
if ( xContext.is() ) {
id parent_wrapper = [ AquaA11yFactory wrapperForAccessibleContext: xContext ];
[ parent_wrapper autorelease ];
return NSAccessibilityUnignoredAncestor( parent_wrapper );
}
}
} catch (const Exception&) {
}
OSL_ASSERT( false );
return nil;
}
-(id)childrenAttribute {
if ( mActsAsRadioGroup ) {
NSMutableArray * children = [ [ NSMutableArray alloc ] init ];
Reference < XAccessibleRelationSet > rxAccessibleRelationSet = [ self accessibleContext ] -> getAccessibleRelationSet();
AccessibleRelation const relationMemberOf = rxAccessibleRelationSet -> getRelationByType ( AccessibleRelationType_MEMBER_OF );
if ( relationMemberOf.RelationType == AccessibleRelationType_MEMBER_OF && relationMemberOf.TargetSet.hasElements() ) {
for (Reference <XAccessible> const & rMateAccessible : relationMemberOf.TargetSet ) {
if ( rMateAccessible.is() ) {
Reference< XAccessibleContext > rMateAccessibleContext( rMateAccessible -> getAccessibleContext() );
if ( rMateAccessibleContext.is() ) {
id wrapper = [ AquaA11yFactory wrapperForAccessibleContext: rMateAccessibleContext ];
[ children addObject: wrapper ];
[ wrapper release ];
}
}
}
}
return [children autorelease];
} else if ( [ self accessibleTable ] )
{
AquaA11yTableWrapper* pTable = [self isKindOfClass: [AquaA11yTableWrapper class]] ? static_cast<AquaA11yTableWrapper*>(self) : nil;
return [ AquaA11yTableWrapper childrenAttributeForElement: pTable ];
} else {
NSMutableArray * children = [ [ NSMutableArray alloc ] init ];
try {
Reference< XAccessibleContext > xContext( [ self accessibleContext ] );
try {
sal_Int64 cnt = xContext -> getAccessibleChildCount();
for ( sal_Int64 i = 0; i < cnt; i++ ) {
Reference< XAccessible > xChild( xContext -> getAccessibleChild( i ) );
if( xChild.is() ) {
Reference< XAccessibleContext > xChildContext( xChild -> getAccessibleContext() );
// the menubar is already accessible (including Apple- and Application-Menu) through NSApplication => omit it here
if ( xChildContext.is() && AccessibleRole::MENU_BAR != xChildContext -> getAccessibleRole() ) {
id wrapper = [ AquaA11yFactory wrapperForAccessibleContext: xChildContext ];
[ children addObject: wrapper ];
[ wrapper release ];
}
}
}
}
catch (const IndexOutOfBoundsException&)
{
SAL_WARN("vcl", "Accessible object has invalid index in parent");
}
// if not already acting as RadioGroup now is the time to replace RadioButtons with RadioGroups and remove RadioButtons
if ( ! mActsAsRadioGroup ) {
NSEnumerator * enumerator = [ children objectEnumerator ];
AquaA11yWrapper * element;
while ( ( element = static_cast<AquaA11yWrapper *>([ enumerator nextObject ]) ) ) {
if ( [ element accessibleContext ] -> getAccessibleRole() == AccessibleRole::RADIO_BUTTON ) {
if ( [ element isFirstRadioButtonInGroup ] ) {
id wrapper = [ AquaA11yFactory wrapperForAccessibleContext: [ element accessibleContext ] createIfNotExists: YES asRadioGroup: YES ];
[ children replaceObjectAtIndex: [ children indexOfObjectIdenticalTo: element ] withObject: wrapper ];
}
[ children removeObject: element ];
}
}
}
return NSAccessibilityUnignoredChildren( [ children autorelease ] );
} catch (const Exception &) {
// TODO: Log
}
[ children autorelease ];
return [NSArray array];
}
}
-(id)windowAttribute {
// go upstairs until reaching the broken connection
AquaA11yWrapper * aWrapper = self;
int loops = 0;
while ( [ aWrapper accessibleContext ] -> getAccessibleParent().is() ) {
AquaA11yWrapper *aTentativeParentWrapper = [ AquaA11yFactory wrapperForAccessibleContext: [ aWrapper accessibleContext ] -> getAccessibleParent() -> getAccessibleContext() ];
// Quick-and-dirty fix for infinite loop after fixing crash in
// fdo#47275
if ( aTentativeParentWrapper == aWrapper )
break;
// Even dirtier fix for infinite loop in fdo#55156
if ( loops++ == 100 )
break;
aWrapper = aTentativeParentWrapper;
[ aWrapper autorelease ];
}
// get associated NSWindow
NSWindow* theWindow = [ aWrapper windowForParent ];
return theWindow;
}
-(id)topLevelUIElementAttribute {
return [ self windowAttribute ];
}
-(id)sizeAttribute {
if ( [ self accessibleComponent ] ) {
return [ AquaA11yComponentWrapper sizeAttributeForElement: self ];
} else {
return nil;
}
}
-(id)positionAttribute {
if ( [ self accessibleComponent ] ) {
return [ AquaA11yComponentWrapper positionAttributeForElement: self ];
} else {
return nil;
}
}
-(id)helpAttribute {
// Related tdf#158914: explicitly call autorelease selector
// CreateNSString() is not a getter. It expects the caller to
// release the returned string.
return [ CreateNSString ( [ self accessibleContext ] -> getAccessibleDescription() ) autorelease ];
}
-(id)identifierAttribute {
if ([ self accessibleContext2]) {
return [ CreateNSString ( [ self accessibleContext2 ] -> getAccessibleId() ) autorelease ];
} else {
return nil;
}
}
-(id)roleDescriptionAttribute {
if ( mActsAsRadioGroup ) {
return [ AquaA11yRoleHelper getRoleDescriptionFrom: NSAccessibilityRadioGroupRole with: @"" ];
} else if( [ self accessibleContext ] -> getAccessibleRole() == AccessibleRole::RADIO_BUTTON ) {
// FIXME: VO should read this because of hierarchy, this is just a workaround
// get parent and its children
AquaA11yWrapper * parent = [ self parentAttribute ];
NSArray * children = [ parent childrenAttribute ];
// find index of self
int index = 1;
NSEnumerator * enumerator = [ children objectEnumerator ];
AquaA11yWrapper * child = nil;
while ( ( child = [ enumerator nextObject ] ) ) {
if ( self == child ) {
break;
}
index++;
}
// build string
NSNumber * nIndex = [ NSNumber numberWithInt: index ];
NSNumber * nGroupsize = [ NSNumber numberWithInt: [ children count ] ];
NSMutableString * value = [ NSMutableString string ];
[ value appendString: @"radio button " ];
[ value appendString: [ nIndex stringValue ] ];
[ value appendString: @" of " ];
[ value appendString: [ nGroupsize stringValue ] ];
return value;
} else {
return [ AquaA11yRoleHelper getRoleDescriptionFrom:
[ AquaA11yRoleHelper getNativeRoleFrom: [ self accessibleContext ] ]
with: [ AquaA11yRoleHelper getNativeSubroleFrom: [ self accessibleContext ] -> getAccessibleRole() ] ];
}
}
-(id)valueAttribute {
if ( [ [ self roleAttribute ] isEqualToString: NSAccessibilityMenuItemRole ] ) {
return nil;
} else if ( [ self accessibleText ] ) {
return [ AquaA11yTextWrapper valueAttributeForElement: self ];
} else if ( [ self accessibleValue ] ) {
return [ AquaA11yValueWrapper valueAttributeForElement: self ];
} else {
return nil;
}
}
-(id)minValueAttribute {
if ( [ self accessibleValue ] ) {
return [ AquaA11yValueWrapper minValueAttributeForElement: self ];
} else {
return nil;
}
}
-(id)maxValueAttribute {
if ( [ self accessibleValue ] ) {
return [ AquaA11yValueWrapper maxValueAttributeForElement: self ];
} else {
return nil;
}
}
-(id)contentsAttribute {
return [ self childrenAttribute ];
}
-(id)selectedChildrenAttribute {
return [ AquaA11ySelectionWrapper selectedChildrenAttributeForElement: self ];
}
-(id)numberOfCharactersAttribute {
if ( [ self accessibleText ] ) {
return [ AquaA11yTextWrapper numberOfCharactersAttributeForElement: self ];
} else {
return nil;
}
}
-(id)selectedTextAttribute {
if ( [ self accessibleText ] ) {
return [ AquaA11yTextWrapper selectedTextAttributeForElement: self ];
} else {
return nil;
}
}
-(id)selectedTextRangeAttribute {
if ( [ self accessibleText ] ) {
return [ AquaA11yTextWrapper selectedTextRangeAttributeForElement: self ];
} else {
return nil;
}
}
-(id)visibleCharacterRangeAttribute {
if ( [ self accessibleText ] ) {
return [ AquaA11yTextWrapper visibleCharacterRangeAttributeForElement: self ];
} else {
return nil;
}
}
-(id)tabsAttribute {
// Related tdf#67943: return children if this is a tab bar
// This will cause VoiceOver to announce that the currently selected tab
// is "X of Y" tabs in the tab bar.
if ( [ self accessibleContext ] -> getAccessibleRole() == AccessibleRole::PAGE_TAB_LIST ) {
return [ self childrenAttribute ];
} else {
return nil;
}
}
-(id)sharedTextUIElementsAttribute {
if ( [ self accessibleText ] ) {
return [ AquaA11yTextWrapper sharedTextUIElementsAttributeForElement: self ];
} else {
return nil;
}
}
-(id)sharedCharacterRangeAttribute {
if ( [ self accessibleText ] ) {
return [ AquaA11yTextWrapper sharedCharacterRangeAttributeForElement: self ];
} else {
return nil;
}
}
-(id)expandedAttribute {
sal_Int64 nStateSet = [ self accessibleContext ] -> getAccessibleStateSet();
return [ NSNumber numberWithBool: ( ( nStateSet & AccessibleStateType::EXPANDED ) != 0 ) ];
}
-(id)selectedAttribute {
sal_Int64 nStateSet = [ self accessibleContext ] -> getAccessibleStateSet();
return [ NSNumber numberWithBool: ( ( nStateSet & AccessibleStateType::SELECTED ) != 0 ) ];
}
-(id)stringForRangeAttributeForParameter:(id)range {
if ( [ self accessibleText ] ) {
return [ AquaA11yTextWrapper stringForRangeAttributeForElement: self forParameter: range ];
} else {
return nil;
}
}
-(id)attributedStringForRangeAttributeForParameter:(id)range {
if ( [ self accessibleText ] ) {
return [ AquaA11yTextWrapper attributedStringForRangeAttributeForElement: self forParameter: range ];
} else {
return nil;
}
}
-(id)rangeForIndexAttributeForParameter:(id)index {
if ( [ self accessibleText ] ) {
return [ AquaA11yTextWrapper rangeForIndexAttributeForElement: self forParameter: index ];
} else {
return nil;
}
}
-(id)rangeForPositionAttributeForParameter:(id)point {
if ( [ self accessibleText ] ) {
return [ AquaA11yTextWrapper rangeForPositionAttributeForElement: self forParameter: point ];
} else {
return nil;
}
}
-(id)boundsForRangeAttributeForParameter:(id)range {
if ( [ self accessibleText ] ) {
return [ AquaA11yTextWrapper boundsForRangeAttributeForElement: self forParameter: range ];
} else {
return nil;
}
}
-(id)styleRangeForIndexAttributeForParameter:(id)index {
if ( [ self accessibleText ] ) {
return [ AquaA11yTextWrapper styleRangeForIndexAttributeForElement: self forParameter: index ];
} else {
return nil;
}
}
-(id)rTFForRangeAttributeForParameter:(id)range {
if ( [ self accessibleText ] ) {
return [ AquaA11yTextWrapper rTFForRangeAttributeForElement: self forParameter: range ];
} else {
return nil;
}
}
-(id)orientationAttribute {
NSString * orientation = nil;
sal_Int64 stateSet = [ self accessibleContext ] -> getAccessibleStateSet();
if ( stateSet & AccessibleStateType::HORIZONTAL ) {
orientation = NSAccessibilityHorizontalOrientationValue;
} else if ( stateSet & AccessibleStateType::VERTICAL ) {
orientation = NSAccessibilityVerticalOrientationValue;
}
return orientation;
}
-(id)titleUIElementAttribute {
if ( [ self accessibleContext ] -> getAccessibleRelationSet().is() ) {
NSString * title = [ self titleAttribute ];
id titleElement = nil;
if ( [ title length ] == 0 ) {
AccessibleRelation relationLabeledBy = [ self accessibleContext ] -> getAccessibleRelationSet() -> getRelationByType ( AccessibleRelationType_LABELED_BY );
if ( relationLabeledBy.RelationType == AccessibleRelationType_LABELED_BY && relationLabeledBy.TargetSet.hasElements() ) {
Reference <XAccessible> rxAccessible = relationLabeledBy.TargetSet[0];
titleElement = [ AquaA11yFactory wrapperForAccessibleContext: rxAccessible -> getAccessibleContext() ];
}
}
return titleElement;
} else {
return nil;
}
}
-(id)servesAsTitleForUIElementsAttribute {
if ( [ self accessibleContext ] -> getAccessibleRelationSet().is() ) {
id titleForElement = nil;
AccessibleRelation relationLabelFor = [ self accessibleContext ] -> getAccessibleRelationSet() -> getRelationByType ( AccessibleRelationType_LABEL_FOR );
if ( relationLabelFor.RelationType == AccessibleRelationType_LABEL_FOR && relationLabelFor.TargetSet.hasElements() ) {
Reference <XAccessible> rxAccessible = relationLabelFor.TargetSet[0];
titleForElement = [ AquaA11yFactory wrapperForAccessibleContext: rxAccessible -> getAccessibleContext() ];
}
return titleForElement;
} else {
return nil;
}
}
-(id)lineForIndexAttributeForParameter:(id)index {
if ( [ self accessibleMultiLineText ] ) {
return [ AquaA11yTextWrapper lineForIndexAttributeForElement: self forParameter: index ];
} else {
return nil;
}
}
-(id)rangeForLineAttributeForParameter:(id)line {
if ( [ self accessibleMultiLineText ] ) {
return [ AquaA11yTextWrapper rangeForLineAttributeForElement: self forParameter: line ];
} else {
return nil;
}
}
#pragma mark -
#pragma mark Accessibility Protocol
-(id)accessibilityAttributeValue:(NSString *)attribute {
// Related: tdf#148453 Acquire solar mutex during native accessibility calls
SolarMutexGuard aGuard;
if ( mIsDisposed )
return nil;
SAL_INFO("vcl.a11y", "[" << self << " accessibilityAttributeValue:" << attribute << "]");
// #i90575# guard NSAccessibility protocol against unwanted access
if ( isPopupMenuOpen ) {
return nil;
}
id value = nil;
// if we are no longer in the wrapper repository, we have been disposed
AquaA11yWrapper * theWrapper = [ AquaA11yFactory wrapperForAccessibleContext: [ self accessibleContext ] createIfNotExists: NO ];
if ( theWrapper || mIsTableCell ) {
try {
SEL methodSelector = [ self selectorForAttribute: attribute asGetter: YES withGetterParameter: NO ];
if ( [ self respondsToSelector: methodSelector ] ) {
value = [ self performSelector: methodSelector ];
}
} catch ( const DisposedException & ) {
mIsTableCell = NO; // just to be sure
[ AquaA11yFactory removeFromWrapperRepositoryFor: [ self accessibleContext ] ];
return nil;
} catch ( const Exception & ) {
// empty
}
}
if ( theWrapper ) {
[ theWrapper release ]; // the above called method calls retain on the returned Wrapper
}
return value;
}
-(BOOL)accessibilityIsIgnored {
// Related: tdf#148453 Acquire solar mutex during native accessibility calls
SolarMutexGuard aGuard;
if ( mIsDisposed )
return YES;
SAL_INFO("vcl.a11y", "[" << self << " accessibilityIsIgnored]");
// #i90575# guard NSAccessibility protocol against unwanted access
if ( isPopupMenuOpen ) {
return NO;
}
bool ignored = false;
try {
sal_Int16 nRole = [ self accessibleContext ] -> getAccessibleRole();
switch ( nRole ) {
//case AccessibleRole::PANEL:
case AccessibleRole::FRAME:
case AccessibleRole::ROOT_PANE:
case AccessibleRole::SEPARATOR:
case AccessibleRole::FILLER:
case AccessibleRole::DIALOG:
ignored = true;
break;
default:
ignored = ! ( [ self accessibleContext ] -> getAccessibleStateSet() & AccessibleStateType::VISIBLE );
break;
}
} catch ( DisposedException& ) {
ignored = true;
} catch ( RuntimeException& ) {
ignored = true;
}
return ignored; // TODO: to be completed
}
-(NSArray *)accessibilityAttributeNames {
// Related: tdf#148453 Acquire solar mutex during native accessibility calls
SolarMutexGuard aGuard;
if ( mIsDisposed )
return nil;
SAL_INFO("vcl.a11y", "[" << self << " accessibilityAttributeNames]");
// #i90575# guard NSAccessibility protocol against unwanted access
if ( isPopupMenuOpen ) {
return nil;
}
NSString * nativeSubrole = nil;
NSString * title = nil;
NSMutableArray * attributeNames = nil;
sal_Int64 nAccessibleChildren = 0;
try {
// Default Attributes
attributeNames = [ NSMutableArray arrayWithObjects:
NSAccessibilityRoleAttribute,
NSAccessibilityDescriptionAttribute,
NSAccessibilityParentAttribute,
NSAccessibilityWindowAttribute,
NSAccessibilityHelpAttribute,
NSAccessibilityTopLevelUIElementAttribute,
NSAccessibilityRoleDescriptionAttribute,
nil ];
nativeSubrole = static_cast<NSString *>([ AquaA11yRoleHelper getNativeSubroleFrom: [ self accessibleContext ] -> getAccessibleRole() ]);
title = static_cast<NSString *>([ self titleAttribute ]);
Reference < XAccessibleRelationSet > rxRelationSet = [ self accessibleContext ] -> getAccessibleRelationSet();
// Special Attributes depending on attribute values
if ( nativeSubrole && ! [ nativeSubrole isEqualToString: @"" ] ) {
[ attributeNames addObject: NSAccessibilitySubroleAttribute ];
}
try
{
nAccessibleChildren = [ self accessibleContext ] -> getAccessibleChildCount();
if ( nAccessibleChildren > 0 ) {
[ attributeNames addObject: NSAccessibilityChildrenAttribute ];
}
}
catch( DisposedException& ) {}
catch( RuntimeException& ) {}
if ( title && ! [ title isEqualToString: @"" ] ) {
[ attributeNames addObject: NSAccessibilityTitleAttribute ];
}
if ( [ title length ] == 0 && rxRelationSet.is() && rxRelationSet -> containsRelation ( AccessibleRelationType_LABELED_BY ) ) {
[ attributeNames addObject: NSAccessibilityTitleUIElementAttribute ];
}
if ( rxRelationSet.is() && rxRelationSet -> containsRelation ( AccessibleRelationType_LABEL_FOR ) ) {
[ attributeNames addObject: NSAccessibilityServesAsTitleForUIElementsAttribute ];
}
// Special Attributes depending on interface
if( [self accessibleContext ] -> getAccessibleRole() == AccessibleRole::TABLE )
[AquaA11yTableWrapper addAttributeNamesTo: attributeNames object: self];
if ( [ self accessibleText ] ) {
[ AquaA11yTextWrapper addAttributeNamesTo: attributeNames ];
}
if ( [ self accessibleComponent ] ) {
[ AquaA11yComponentWrapper addAttributeNamesTo: attributeNames ];
}
if ( [ self accessibleSelection ] ) {
[ AquaA11ySelectionWrapper addAttributeNamesTo: attributeNames ];
}
if ( [ self accessibleValue ] ) {
[ AquaA11yValueWrapper addAttributeNamesTo: attributeNames ];
}
// Related: tdf#153374 Don't release autoreleased attributeNames
return attributeNames;
} catch ( DisposedException & ) { // Object is no longer available
// Related: tdf#153374 Don't release autoreleased attributeNames
// Also, return an autoreleased empty array instead of a retained array.
[ AquaA11yFactory removeFromWrapperRepositoryFor: [ self accessibleContext ] ];
return [ NSArray array ];
}
}
-(BOOL)accessibilityIsAttributeSettable:(NSString *)attribute {
// Related: tdf#148453 Acquire solar mutex during native accessibility calls
SolarMutexGuard aGuard;
if ( mIsDisposed )
return NO;
SAL_INFO("vcl.a11y", "[" << self << " accessibilityAttributeIsSettable:" << attribute << "]");
bool isSettable = false;
if ( [ self accessibleText ] ) {
isSettable = [ AquaA11yTextWrapper isAttributeSettable: attribute forElement: self ];
}
if ( ! isSettable && [ self accessibleComponent ] ) {
isSettable = [ AquaA11yComponentWrapper isAttributeSettable: attribute forElement: self ];
}
if ( ! isSettable && [ self accessibleSelection ] ) {
isSettable = [ AquaA11ySelectionWrapper isAttributeSettable: attribute forElement: self ];
}
if ( ! isSettable && [ self accessibleValue ] ) {
isSettable = [ AquaA11yValueWrapper isAttributeSettable: attribute forElement: self ];
}
return isSettable; // TODO: to be completed
}
-(NSArray *)accessibilityParameterizedAttributeNames {
// Related: tdf#148453 Acquire solar mutex during native accessibility calls
SolarMutexGuard aGuard;
if ( mIsDisposed )
return [ NSArray array ];
SAL_INFO("vcl.a11y", "[" << self << " accessibilityParameterizedAttributeNames]");
NSMutableArray * attributeNames = [ NSMutableArray array ];
// Special Attributes depending on interface
if ( [ self accessibleText ] ) {
[ AquaA11yTextWrapper addParameterizedAttributeNamesTo: attributeNames ];
}
return attributeNames; // TODO: to be completed
}
-(id)accessibilityAttributeValue:(NSString *)attribute forParameter:(id)parameter {
// Related: tdf#148453 Acquire solar mutex during native accessibility calls
SolarMutexGuard aGuard;
if ( mIsDisposed )
return nil;
SAL_INFO("vcl.a11y", "[" << self << " accessibilityAttributeValue:" << attribute << " forParameter:" << (static_cast<NSObject*>(parameter)) << "]");
SEL methodSelector = [ self selectorForAttribute: attribute asGetter: YES withGetterParameter: YES ];
if ( [ self respondsToSelector: methodSelector ] ) {
try {
return [ self performSelector: methodSelector withObject: parameter ];
} catch ( const DisposedException & ) {
mIsTableCell = NO; // just to be sure
[ AquaA11yFactory removeFromWrapperRepositoryFor: [ self accessibleContext ] ];
return nil;
} catch ( const Exception & ) {
// empty
}
}
return nil; // TODO: to be completed
}
-(BOOL)accessibilitySetOverrideValue:(id)value forAttribute:(NSString *)attribute
{
SAL_INFO("vcl.a11y", "[" << self << " accessibilitySetOverrideValue:" << (static_cast<NSObject*>(value)) << " forAttribute:" << attribute << "]");
return NO; // TODO
}
-(void)accessibilitySetValue:(id)value forAttribute:(NSString *)attribute {
// Related: tdf#148453 Acquire solar mutex during native accessibility calls
SolarMutexGuard aGuard;
if ( mIsDisposed )
return;
SAL_INFO("vcl.a11y", "[" << self << " accessibilitySetValue:" << (static_cast<NSObject*>(value)) << " forAttribute:" << attribute << "]");
SEL methodSelector = [ self selectorForAttribute: attribute asGetter: NO withGetterParameter: NO ];
if ( [ AquaA11yComponentWrapper respondsToSelector: methodSelector ] ) {
[ AquaA11yComponentWrapper performSelector: methodSelector withObject: self withObject: value ];
}
if ( [ AquaA11yTextWrapper respondsToSelector: methodSelector ] ) {
[ AquaA11yTextWrapper performSelector: methodSelector withObject: self withObject: value ];
}
if ( [ AquaA11ySelectionWrapper respondsToSelector: methodSelector ] ) {
[ AquaA11ySelectionWrapper performSelector: methodSelector withObject: self withObject: value ];
}
if ( [ AquaA11yValueWrapper respondsToSelector: methodSelector ] ) {
[ AquaA11yValueWrapper performSelector: methodSelector withObject: self withObject: value ];
}
}
-(id)accessibilityFocusedUIElement {
// Related: tdf#148453 Acquire solar mutex during native accessibility calls
SolarMutexGuard aGuard;
if ( mIsDisposed )
return nil;
SAL_INFO("vcl.a11y", "[" << self << " accessibilityFocusedUIElement]");
// #i90575# guard NSAccessibility protocol against unwanted access
if ( isPopupMenuOpen ) {
return nil;
}
// as this seems to be the first API call on a newly created SalFrameView object,
// make sure self gets registered in the repository ..
[ self accessibleContext ];
AquaA11yWrapper * focusedUIElement = AquaA11yFocusListener::get()->getFocusedUIElement();
// AquaA11yWrapper * ancestor = focusedUIElement;
// Make sure the focused object is a descendant of self
// do {
// if( self == ancestor )
return focusedUIElement;
// ancestor = [ ancestor accessibilityAttributeValue: NSAccessibilityParentAttribute ];
// } while( nil != ancestor );
return self;
}
-(NSString *)accessibilityActionDescription:(NSString *)action {
SAL_INFO("vcl.a11y", "[" << self << " accessibilityActionDescription:" << action << "]");
return NSAccessibilityActionDescription(action);
}
-(AquaA11yWrapper *)actionResponder {
AquaA11yWrapper * wrapper = nil;
// get some information
NSString * role = static_cast<NSString *>([ self accessibilityAttributeValue: NSAccessibilityRoleAttribute ]);
id enabledAttr = [ self enabledAttribute ];
bool enabled = [ enabledAttr boolValue ];
NSView * parent = static_cast<NSView *>([ self accessibilityAttributeValue: NSAccessibilityParentAttribute ]);
AquaA11yWrapper * parentAsWrapper = nil;
if ( [ parent isKindOfClass: [ AquaA11yWrapper class ] ] ) {
parentAsWrapper = static_cast<AquaA11yWrapper *>(parent);
}
SAL_WNODEPRECATED_DECLARATIONS_PUSH
//TODO: 10.10 accessibilityAttributeValue:
NSString * parentRole = static_cast<NSString *>([ parent accessibilityAttributeValue: NSAccessibilityRoleAttribute ]);
SAL_WNODEPRECATED_DECLARATIONS_POP
// if we are a textarea inside a combobox, then the combobox is the action responder
if ( enabled
&& [ role isEqualToString: NSAccessibilityTextAreaRole ]
&& [ parentRole isEqualToString: NSAccessibilityComboBoxRole ]
&& parentAsWrapper ) {
wrapper = parentAsWrapper;
} else if ( enabled && [ self accessibleAction ] ) {
wrapper = self ;
}
return wrapper;
}
-(void)accessibilityPerformAction:(NSString *)action {
[ self performAction: action ];
}
-(BOOL)performAction:(NSString *)action {
// Related: tdf#148453 Acquire solar mutex during native accessibility calls
SolarMutexGuard aGuard;
if ( mIsDisposed )
return NO;
SAL_INFO("vcl.a11y", "[" << self << " accessibilityPerformAction:" << action << "]");
AquaA11yWrapper * actionResponder = [ self actionResponder ];
if ( actionResponder ) {
[ AquaA11yActionWrapper doAction: action ofElement: actionResponder ];
return YES;
}
return NO;
}
-(NSArray *)accessibilityActionNames {
// Related: tdf#148453 Acquire solar mutex during native accessibility calls
SolarMutexGuard aGuard;
if ( mIsDisposed )
return nil;
SAL_INFO("vcl.a11y", "[" << self << " accessibilityActionNames]");
NSArray * actionNames = nil;
AquaA11yWrapper * actionResponder = [ self actionResponder ];
if ( actionResponder ) {
actionNames = [ AquaA11yActionWrapper actionNamesForElement: actionResponder ];
} else {
actionNames = [ NSArray array ];
}
return actionNames;
}
#pragma mark -
#pragma mark Hit Test
-(BOOL)isViewElement:(NSObject *)viewElement hitByPoint:(NSPoint)point {
bool hit = false;
NSAutoreleasePool * pool = [ [ NSAutoreleasePool alloc ] init ];
SAL_WNODEPRECATED_DECLARATIONS_PUSH
//TODO: 10.10 accessibilityAttributeValue:
NSValue * position = [ viewElement accessibilityAttributeValue: NSAccessibilityPositionAttribute ];
NSValue * size = [ viewElement accessibilityAttributeValue: NSAccessibilitySizeAttribute ];
SAL_WNODEPRECATED_DECLARATIONS_POP
if ( position && size ) {
float minX = [ position pointValue ].x;
float minY = [ position pointValue ].y;
float maxX = minX + [ size sizeValue ].width;
float maxY = minY + [ size sizeValue ].height;
if ( minX < point.x && maxX > point.x && minY < point.y && maxY > point.y ) {
hit = true;
}
}
[ pool release ];
return hit;
}
static Reference < XAccessibleContext > hitTestRunner ( css::awt::Point point,
Reference < XAccessibleContext > const & rxAccessibleContext ) {
Reference < XAccessibleContext > hitChild;
Reference < XAccessibleContext > emptyReference;
try {
Reference < XAccessibleComponent > rxAccessibleComponent ( rxAccessibleContext, UNO_QUERY );
if ( rxAccessibleComponent.is() ) {
css::awt::Point location = rxAccessibleComponent -> getLocationOnScreen();
css::awt::Point hitPoint ( point.X - location.X , point.Y - location.Y);
Reference < XAccessible > rxAccessible = rxAccessibleComponent -> getAccessibleAtPoint ( hitPoint );
if ( rxAccessible.is() && rxAccessible -> getAccessibleContext().is() &&
rxAccessible -> getAccessibleContext() -> getAccessibleChildCount() == 0 ) {
hitChild = rxAccessible -> getAccessibleContext();
}
}
// iterate the hierarchy looking doing recursive hit testing.
// apparently necessary as a special treatment for e.g. comboboxes
if ( !hitChild.is() ) {
bool bSafeToIterate = true;
sal_Int64 nCount = rxAccessibleContext -> getAccessibleChildCount();
if (nCount < 0 || nCount > SAL_MAX_UINT16 /* slow enough for anyone */)
bSafeToIterate = false;
else { // manages descendants is an horror from the a11y standards guys.
sal_Int64 nStateSet = rxAccessibleContext -> getAccessibleStateSet();
if ( nStateSet & AccessibleStateType::MANAGES_DESCENDANTS )
bSafeToIterate = false;
}
if( bSafeToIterate ) {
try {
for ( sal_Int64 i = 0; i < rxAccessibleContext -> getAccessibleChildCount(); i++ ) {
Reference < XAccessible > rxAccessibleChild = rxAccessibleContext -> getAccessibleChild ( i );
if ( rxAccessibleChild.is() && rxAccessibleChild -> getAccessibleContext().is() && rxAccessibleChild -> getAccessibleContext() -> getAccessibleRole() != AccessibleRole::LIST ) {
Reference < XAccessibleContext > myHitChild = hitTestRunner ( point, rxAccessibleChild -> getAccessibleContext() );
if ( myHitChild.is() ) {
hitChild = myHitChild;
break;
}
}
}
}
catch (const IndexOutOfBoundsException&)
{
SAL_WARN("vcl", "Accessible object has invalid index in parent");
}
}
}
} catch ( RuntimeException ) {
return emptyReference;
}
return hitChild;
}
-(id)accessibilityHitTest:(NSPoint)point {
// Related: tdf#148453 Acquire solar mutex during native accessibility calls
SolarMutexGuard aGuard;
if ( mIsDisposed )
return nil;
SAL_INFO("vcl.a11y", "[" << self << " accessibilityHitTest:" << point << "]");
Reference < XAccessibleContext > hitChild;
NSRect screenRect = [ [ NSScreen mainScreen ] frame ];
css::awt::Point hitPoint ( static_cast<sal_Int32>(point.x) , static_cast<sal_Int32>(screenRect.size.height - point.y) );
// check child windows first
NSWindow * window = static_cast<NSWindow *>([ self accessibilityAttributeValue: NSAccessibilityWindowAttribute ]);
NSArray * childWindows = [ window childWindows ];
if ( [ childWindows count ] > 0 ) {
NSWindow * element = nil;
NSEnumerator * enumerator = [ childWindows objectEnumerator ];
while ( ( element = [ enumerator nextObject ] ) && !hitChild.is() ) {
if ( [ element isKindOfClass: [ SalFrameWindow class ] ] && [ self isViewElement: element hitByPoint: point ] ) {
// we have a child window that is hit
Reference < XAccessibleRelationSet > relationSet = [ static_cast<SalFrameWindow *>(element) accessibleContext ] -> getAccessibleRelationSet();
if ( relationSet.is() && relationSet -> containsRelation ( AccessibleRelationType_SUB_WINDOW_OF )) {
// we have a valid relation to the parent element
AccessibleRelation const relation = relationSet -> getRelationByType ( AccessibleRelationType_SUB_WINDOW_OF );
for (Reference<XAccessible> const & rxAccessible : relation.TargetSet) {
if ( rxAccessible.is() && rxAccessible -> getAccessibleContext().is() ) {
// hit test for children of parent
hitChild = hitTestRunner ( hitPoint, rxAccessible -> getAccessibleContext() );
if (hitChild.is())
break;
}
}
}
}
}
}
// nothing hit yet, so check ourself
if ( ! hitChild.is() ) {
if ( !maReferenceWrapper.rAccessibleContext ) {
[ self setDefaults: [ self accessibleContext ] ];
}
hitChild = hitTestRunner ( hitPoint, maReferenceWrapper.rAccessibleContext );
}
if ( hitChild.is() ) {
// Related tdf#158914: do not retain wrapper
// [ AquaA11yFactory wrapperForAccessibleContext: ] already retains
// the returned object so retaining it until the next call to this
// selector can lead to a memory leak when dragging selected cells
// in Calc to a new location. So autorelease the object so that
// transient objects stay alive but not past the next clearing of
// the autorelease pool.
return [ [ AquaA11yFactory wrapperForAccessibleContext: hitChild ] autorelease ];
}
return nil;
}
#pragma mark -
#pragma mark Access Methods
-(XAccessibleAction *)accessibleAction {
return maReferenceWrapper.rAccessibleAction.get();
}
-(XAccessibleContext *)accessibleContext {
return maReferenceWrapper.rAccessibleContext.get();
}
-(XAccessibleContext2 *)accessibleContext2 {
return maReferenceWrapper.rAccessibleContext2.get();
}
-(XAccessibleComponent *)accessibleComponent {
return maReferenceWrapper.rAccessibleComponent.get();
}
-(XAccessibleExtendedComponent *)accessibleExtendedComponent {
return maReferenceWrapper.rAccessibleExtendedComponent.get();
}
-(XAccessibleSelection *)accessibleSelection {
return maReferenceWrapper.rAccessibleSelection.get();
}
-(XAccessibleTable *)accessibleTable {
return maReferenceWrapper.rAccessibleTable.get();
}
-(XAccessibleText *)accessibleText {
return maReferenceWrapper.rAccessibleText.get();
}
-(XAccessibleEditableText *)accessibleEditableText {
return maReferenceWrapper.rAccessibleEditableText.get();
}
-(XAccessibleValue *)accessibleValue {
return maReferenceWrapper.rAccessibleValue.get();
}
-(XAccessibleTextAttributes *)accessibleTextAttributes {
return maReferenceWrapper.rAccessibleTextAttributes.get();
}
-(XAccessibleMultiLineText *)accessibleMultiLineText {
return maReferenceWrapper.rAccessibleMultiLineText.get();
}
-(XAccessibleTextMarkup *)accessibleTextMarkup {
return maReferenceWrapper.rAccessibleTextMarkup.get();
}
-(NSWindow*)windowForParent {
return nil;
}
-(void)setActsAsRadioGroup:(BOOL)actsAsRadioGroup {
mActsAsRadioGroup = actsAsRadioGroup;
}
-(BOOL)actsAsRadioGroup {
return mActsAsRadioGroup;
}
+(void)setPopupMenuOpen:(BOOL)popupMenuOpen {
isPopupMenuOpen = popupMenuOpen;
}
// NSAccessibility selectors
- (BOOL)isAccessibilityElement
{
return ! [ self accessibilityIsIgnored ];
}
- (BOOL)isAccessibilityFocused
{
NSNumber *pNumber = [ self accessibilityAttributeValue: NSAccessibilityFocusedAttribute ];
if ( pNumber )
return [ pNumber boolValue ];
else
return NO;
}
- (id)accessibilityTopLevelUIElement
{
return [ self accessibilityAttributeValue: NSAccessibilityTopLevelUIElementAttribute ];
}
- (id)accessibilityValue
{
return [ self accessibilityAttributeValue: NSAccessibilityValueAttribute ];
}
- (NSArray *)accessibilityVisibleChildren
{
return [ self accessibilityChildren ];
}
- (NSAccessibilitySubrole)accessibilitySubrole
{
return [ self accessibilityAttributeValue: NSAccessibilitySubroleAttribute ];
}
- (NSString *)accessibilityTitle
{
return [ self accessibilityAttributeValue: NSAccessibilityTitleAttribute ];
}
- (id)accessibilityTitleUIElement
{
return [ self accessibilityAttributeValue: NSAccessibilityTitleUIElementAttribute ];
}
- (NSAccessibilityOrientation)accessibilityOrientation
{
NSNumber *pNumber = [ self accessibilityAttributeValue: NSAccessibilityOrientationAttribute ];
if ( pNumber )
return NSAccessibilityOrientation([ pNumber integerValue ]);
else
return NSAccessibilityOrientationUnknown;
}
- (id)accessibilityParent
{
return [ self accessibilityAttributeValue: NSAccessibilityParentAttribute ];
}
- (NSAccessibilityRole)accessibilityRole
{
return [ self accessibilityAttributeValue: NSAccessibilityRoleAttribute ];
}
- (NSString *)accessibilityRoleDescription
{
return [ self accessibilityAttributeValue: NSAccessibilityRoleDescriptionAttribute ];
}
- (BOOL)isAccessibilitySelected
{
NSNumber *pNumber = [ self accessibilityAttributeValue: NSAccessibilitySelectedAttribute ];
if ( pNumber )
return [ pNumber boolValue ];
else
return NO;
}
- (NSArray *)accessibilitySelectedChildren
{
return [ self accessibilityAttributeValue: NSAccessibilitySelectedChildrenAttribute ];
}
- (NSArray *)accessibilityServesAsTitleForUIElements
{
return [ self accessibilityAttributeValue: NSAccessibilityServesAsTitleForUIElementsAttribute ];
}
- (id)accessibilityMinValue
{
return [ self accessibilityAttributeValue: NSAccessibilityMinValueAttribute ];
}
- (id)accessibilityMaxValue
{
return [ self accessibilityAttributeValue: NSAccessibilityMaxValueAttribute ];
}
- (id)accessibilityWindow
{
return [ self accessibilityAttributeValue: NSAccessibilityWindowAttribute ];
}
- (NSString *)accessibilityHelp
{
return [ self accessibilityAttributeValue: NSAccessibilityHelpAttribute ];
}
- (NSString *) accessibilityIdentifier
{
return [ self accessibilityAttributeValue: NSAccessibilityIdentifierAttribute ];
}
- (BOOL)isAccessibilityExpanded
{
NSNumber *pNumber = [ self accessibilityAttributeValue: NSAccessibilityExpandedAttribute ];
if ( pNumber )
return [ pNumber boolValue ];
else
return NO;
}
- (BOOL)isAccessibilityEnabled
{
NSNumber *pNumber = [ self accessibilityAttributeValue: NSAccessibilityEnabledAttribute ];
if ( pNumber )
return [ pNumber boolValue ];
else
return NO;
}
- (NSArray *)accessibilityChildren
{
return [ self accessibilityAttributeValue: NSAccessibilityChildrenAttribute ];
}
- (NSArray <id<NSAccessibilityElement>> *)accessibilityChildrenInNavigationOrder
{
return [ self accessibilityChildren ];
}
- (NSArray *)accessibilityContents
{
return [ self accessibilityAttributeValue: NSAccessibilityContentsAttribute ];
}
- (NSString *)accessibilityLabel
{
return [ self accessibilityAttributeValue: NSAccessibilityDescriptionAttribute ];
}
- (id)accessibilityApplicationFocusedUIElement
{
return [ self accessibilityFocusedUIElement ];
}
- (BOOL)isAccessibilityDisclosed
{
NSNumber *pNumber = [ self accessibilityAttributeValue: NSAccessibilityDisclosingAttribute ];
if ( pNumber )
return [ pNumber boolValue ];
else
return NO;
}
- (id)accessibilityHorizontalScrollBar
{
return [ self accessibilityAttributeValue: NSAccessibilityHorizontalScrollBarAttribute ];
}
- (id)accessibilityVerticalScrollBar
{
return [ self accessibilityAttributeValue: NSAccessibilityVerticalScrollBarAttribute ];
}
- (NSArray *)accessibilityTabs
{
return [ self accessibilityAttributeValue: NSAccessibilityTabsAttribute ];
}
- (NSArray *)accessibilityColumns
{
return [ self accessibilityAttributeValue: NSAccessibilityColumnsAttribute ];
}
- (NSArray *)accessibilityRows
{
return [ self accessibilityAttributeValue: NSAccessibilityRowsAttribute ];
}
- (NSRange)accessibilitySharedCharacterRange
{
NSValue *pValue = [ self accessibilityAttributeValue: NSAccessibilitySharedCharacterRangeAttribute ];
if ( pValue )
return [ pValue rangeValue ];
else
return NSMakeRange( NSNotFound, 0 );
}
- (NSArray *)accessibilitySharedTextUIElements
{
return [ self accessibilityAttributeValue: NSAccessibilitySharedTextUIElementsAttribute ];
}
- (NSRange)accessibilityVisibleCharacterRange
{
NSValue *pValue = [ self accessibilityAttributeValue: NSAccessibilityVisibleCharacterRangeAttribute ];
if ( pValue )
return [ pValue rangeValue ];
else
return NSMakeRange( NSNotFound, 0 );
}
- (NSInteger)accessibilityNumberOfCharacters
{
NSNumber *pNumber = [ self accessibilityAttributeValue: NSAccessibilityNumberOfCharactersAttribute ];
if ( pNumber )
return [ pNumber integerValue ];
else
return 0;
}
- (NSString *)accessibilitySelectedText
{
return [ self accessibilityAttributeValue: NSAccessibilitySelectedTextAttribute ];
}
- (NSRange)accessibilitySelectedTextRange
{
NSValue *pValue = [ self accessibilityAttributeValue: NSAccessibilitySelectedTextRangeAttribute ];
if ( pValue )
return [ pValue rangeValue ];
else
return NSMakeRange( NSNotFound, 0 );
}
- (NSAttributedString *)accessibilityAttributedStringForRange:(NSRange)aRange
{
return [ self accessibilityAttributeValue: NSAccessibilityAttributedStringForRangeParameterizedAttribute forParameter: [ NSValue valueWithRange: aRange ] ];
}
- (NSRange)accessibilityRangeForLine:(NSInteger)nLine
{
NSValue *pValue = [ self accessibilityAttributeValue: NSAccessibilityRangeForLineParameterizedAttribute forParameter: [NSNumber numberWithInteger: nLine ] ];
if ( pValue )
return [ pValue rangeValue ];
else
return NSMakeRange( NSNotFound, 0 );
}
- (NSString *)accessibilityStringForRange:(NSRange)aRange
{
return [ self accessibilityAttributeValue: NSAccessibilityStringForRangeParameterizedAttribute forParameter: [ NSValue valueWithRange: aRange ] ];
}
- (NSRange)accessibilityRangeForPosition:(NSPoint)aPoint
{
NSValue *pValue = [ self accessibilityAttributeValue: NSAccessibilityRangeForPositionParameterizedAttribute forParameter: [ NSValue valueWithPoint: aPoint ] ];
if ( pValue )
return [ pValue rangeValue ];
else
return NSMakeRange( NSNotFound, 0 );
}
- (NSRange)accessibilityRangeForIndex:(NSInteger)nIndex
{
NSValue *pValue = [ self accessibilityAttributeValue: NSAccessibilityRangeForIndexParameterizedAttribute forParameter: [ NSNumber numberWithInteger: nIndex ] ];
if ( pValue )
return [ pValue rangeValue ];
else
return NSMakeRange( NSNotFound, 0 );
}
- (NSRect)accessibilityFrameForRange:(NSRange)aRange
{
NSValue *pValue = [ self accessibilityAttributeValue: NSAccessibilityBoundsForRangeParameterizedAttribute forParameter: [ NSValue valueWithRange: aRange ] ];
if ( pValue )
return [ pValue rectValue ];
else
return NSZeroRect;
}
- (NSData *)accessibilityRTFForRange:(NSRange)aRange
{
return [ self accessibilityAttributeValue: NSAccessibilityRTFForRangeParameterizedAttribute forParameter: [ NSValue valueWithRange: aRange ] ];
}
- (NSRange)accessibilityStyleRangeForIndex:(NSInteger)nIndex
{
NSValue *pValue = [ self accessibilityAttributeValue: NSAccessibilityStyleRangeForIndexParameterizedAttribute forParameter: [ NSNumber numberWithInteger: nIndex ] ];
if ( pValue )
return [ pValue rangeValue ];
else
return NSMakeRange( NSNotFound, 0 );
}
- (NSInteger)accessibilityLineForIndex:(NSInteger)nIndex
{
NSNumber *pNumber = [ self accessibilityAttributeValue: NSAccessibilityLineForIndexParameterizedAttribute forParameter: [ NSNumber numberWithInteger: nIndex ] ];
if ( pNumber )
return [ pNumber integerValue ];
else
return 0;
}
- (BOOL)accessibilityPerformDecrement
{
return [ self performAction: NSAccessibilityDecrementAction ];
}
- (BOOL)accessibilityPerformPick
{
return [ self performAction: NSAccessibilityPickAction ];
}
- (BOOL)accessibilityPerformShowMenu
{
return [ self performAction: NSAccessibilityShowMenuAction ];
}
- (BOOL)accessibilityPerformPress
{
return [ self performAction: NSAccessibilityPressAction ];
}
- (BOOL)accessibilityPerformIncrement
{
return [ self performAction: NSAccessibilityIncrementAction ];
}
// NSAccessibilityElement selectors
- (NSRect)accessibilityFrame
{
// Related: tdf#148453 Acquire solar mutex during native accessibility calls
SolarMutexGuard aGuard;
if ( mIsDisposed )
return NSZeroRect;
try {
XAccessibleComponent *pAccessibleComponent = [ self accessibleComponent ];
if ( pAccessibleComponent ) {
com::sun::star::awt::Point location = pAccessibleComponent->getLocationOnScreen();
com::sun::star::awt::Size size = pAccessibleComponent->getSize();
NSRect screenRect = sal::aqua::getTotalScreenBounds();
NSRect frame = NSMakeRect( float(location.X), float( screenRect.size.height - size.Height - location.Y ), float(size.Width), float(size.Height) );
return frame;
}
} catch ( DisposedException& ) {
} catch ( RuntimeException& ) {
}
return NSZeroRect;
}
- (BOOL)accessibilityNotifiesWhenDestroyed
{
return YES;
}
- (BOOL)isAccessibilitySelectorAllowed:(SEL)aSelector
{
if ( ! aSelector )
return NO;
// don't explicitly report (non-)expanded state when not expandable
if (aSelector == @selector(isAccessibilityExpanded))
{
// Acquire solar mutex during native accessibility calls
SolarMutexGuard aGuard;
if ( mIsDisposed )
return NO;
const sal_Int64 nStateSet = [ self accessibleContext ] -> getAccessibleStateSet();
if (!( nStateSet & AccessibleStateType::EXPANDABLE))
return false;
}
if ( [ self respondsToSelector: aSelector ] ) {
// Ignore actions if action is not supported
NSAccessibilityActionName pActionName = [ AquaA11yActionWrapper actionNameForSelector: aSelector ];
if ( pActionName ) {
NSArray *pActionNames = [ self accessibilityActionNames ];
if ( ! pActionNames || ! [ pActionNames containsObject: pActionName ] )
return NO;
} else {
// Ignore "setAccessibility" selectors if attribute is not settable
static NSString *pSetPrefix = @"setAccessibility";
NSString *pSelName = NSStringFromSelector( aSelector );
if ( pSelName && [ pSelName hasPrefix: pSetPrefix ] && [ pSelName hasSuffix: @":" ] ) {
NSAccessibilityAttributeName pAttrName = [ pSelName substringToIndex: [ pSelName length ] - 1 ];
if ( pAttrName && [ pAttrName length ] > [ pSetPrefix length ] ) {
pAttrName = [ pAttrName substringFromIndex: [ pSetPrefix length ] ];
if ( pAttrName && [ pAttrName length ] ) {
pAttrName = [ @"AX" stringByAppendingString: pAttrName ];
if ( pAttrName && [ pAttrName length ] && ! [ self accessibilityIsAttributeSettable: pAttrName ] )
return NO;
}
}
}
}
}
return [ super isAccessibilitySelectorAllowed: aSelector ];
}
@end
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|