forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathweb_ax_object_proxy.cc
2142 lines (1882 loc) · 65.6 KB
/
web_ax_object_proxy.cc
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 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/web_test/renderer/web_ax_object_proxy.h"
#include <stddef.h>
#include <algorithm>
#include <map>
#include <utility>
#include "base/strings/stringprintf.h"
#include "gin/handle.h"
#include "third_party/blink/public/platform/scheduler/web_agent_group_scheduler.h"
#include "third_party/blink/public/platform/web_string.h"
#include "third_party/blink/public/web/blink.h"
#include "third_party/blink/public/web/web_document.h"
#include "third_party/blink/public/web/web_local_frame.h"
#include "ui/accessibility/ax_action_data.h"
#include "ui/accessibility/ax_enum_util.h"
#include "ui/accessibility/ax_enums.mojom-shared.h"
#include "ui/accessibility/ax_node_data.h"
#include "ui/gfx/geometry/rect_f.h"
#include "ui/gfx/geometry/transform.h"
namespace content {
namespace {
// Map role value to string, matching Safari/Mac platform implementation to
// avoid rebaselining web tests.
std::string RoleToString(ax::mojom::Role role) {
std::string prefix = "k";
std::ostringstream result;
result << role;
// Check that |result| starts with |prefix|.
DCHECK_EQ(result.str().find(prefix), 0ull);
return "AXRole: AX" + result.str().substr(prefix.size());
}
std::string GetStringValue(const blink::WebAXObject& object) {
std::string value;
if (object.Role() == ax::mojom::Role::kColorWell) {
unsigned int color = object.ColorValue();
unsigned int red = (color >> 16) & 0xFF;
unsigned int green = (color >> 8) & 0xFF;
unsigned int blue = color & 0xFF;
value = base::StringPrintf("rgba(%d, %d, %d, 1)", red, green, blue);
} else {
value = object.GetValueForControl().Utf8();
}
return value.insert(0, "AXValue: ");
}
std::string GetRole(const blink::WebAXObject& object) {
std::string role_string = RoleToString(object.Role());
// Special-case canvas with fallback content because Chromium wants to treat
// this as essentially a separate role that it can map differently depending
// on the platform.
if (object.Role() == ax::mojom::Role::kCanvas &&
object.CanvasHasFallbackContent()) {
role_string += "WithFallbackContent";
}
return role_string;
}
std::string GetLanguage(const blink::WebAXObject& object) {
std::string language = object.Language().Utf8();
return language.insert(0, "AXLanguage: ");
}
std::string GetAttributes(const blink::WebAXObject& object) {
std::string attributes(object.GetName().Utf8());
attributes.append("\n");
attributes.append(GetRole(object));
return attributes;
}
// New bounds calculation algorithm. Retrieves the frame-relative bounds
// of an object by calling getRelativeBounds and then applying the offsets
// and transforms recursively on each container of this object.
gfx::RectF BoundsForObject(const blink::WebAXObject& object) {
blink::WebAXObject container;
gfx::RectF bounds;
gfx::Transform transform;
object.GetRelativeBounds(container, bounds, transform);
gfx::RectF computed_bounds(0, 0, bounds.width(), bounds.height());
while (!container.IsDetached()) {
computed_bounds.Offset(bounds.x(), bounds.y());
computed_bounds.Offset(-container.GetScrollOffset().x(),
-container.GetScrollOffset().y());
computed_bounds = transform.MapRect(computed_bounds);
container.GetRelativeBounds(container, bounds, transform);
}
return computed_bounds;
}
gfx::Rect BoundsForCharacter(const blink::WebAXObject& object,
int character_index) {
DCHECK_EQ(object.Role(), ax::mojom::Role::kStaticText);
int end = 0;
for (unsigned i = 0; i < object.ChildCount(); i++) {
blink::WebAXObject inline_text_box = object.ChildAt(i);
DCHECK_EQ(inline_text_box.Role(), ax::mojom::Role::kInlineTextBox);
int start = end;
blink::WebString name = inline_text_box.GetName();
end += name.length();
if (character_index < start || character_index >= end)
continue;
gfx::RectF inline_text_box_rect = BoundsForObject(inline_text_box);
int local_index = character_index - start;
blink::WebVector<int> character_offsets;
inline_text_box.CharacterOffsets(character_offsets);
if (character_offsets.size() != name.length())
return gfx::Rect();
switch (inline_text_box.GetTextDirection()) {
case ax::mojom::WritingDirection::kLtr: {
if (local_index) {
int left =
inline_text_box_rect.x() + character_offsets[local_index - 1];
int width = character_offsets[local_index] -
character_offsets[local_index - 1];
return gfx::Rect(left, inline_text_box_rect.y(), width,
inline_text_box_rect.height());
}
return gfx::Rect(inline_text_box_rect.x(), inline_text_box_rect.y(),
character_offsets[0], inline_text_box_rect.height());
}
case ax::mojom::WritingDirection::kRtl: {
int right = inline_text_box_rect.x() + inline_text_box_rect.width();
if (local_index) {
int left = right - character_offsets[local_index];
int width = character_offsets[local_index] -
character_offsets[local_index - 1];
return gfx::Rect(left, inline_text_box_rect.y(), width,
inline_text_box_rect.height());
}
int left = right - character_offsets[0];
return gfx::Rect(left, inline_text_box_rect.y(), character_offsets[0],
inline_text_box_rect.height());
}
case ax::mojom::WritingDirection::kTtb: {
if (local_index) {
int top =
inline_text_box_rect.y() + character_offsets[local_index - 1];
int height = character_offsets[local_index] -
character_offsets[local_index - 1];
return gfx::Rect(inline_text_box_rect.x(), top,
inline_text_box_rect.width(), height);
}
return gfx::Rect(inline_text_box_rect.x(), inline_text_box_rect.y(),
inline_text_box_rect.width(), character_offsets[0]);
}
case ax::mojom::WritingDirection::kBtt: {
int bottom = inline_text_box_rect.y() + inline_text_box_rect.height();
if (local_index) {
int top = bottom - character_offsets[local_index];
int height = character_offsets[local_index] -
character_offsets[local_index - 1];
return gfx::Rect(inline_text_box_rect.x(), top,
inline_text_box_rect.width(), height);
}
int top = bottom - character_offsets[0];
return gfx::Rect(inline_text_box_rect.x(), top,
inline_text_box_rect.width(), character_offsets[0]);
}
default:
NOTREACHED();
return gfx::Rect();
}
}
DCHECK(false);
return gfx::Rect();
}
void GetBoundariesForOneWord(const blink::WebAXObject& object,
int character_index,
int& word_start,
int& word_end) {
int end = 0;
for (size_t i = 0; i < object.ChildCount(); i++) {
blink::WebAXObject inline_text_box = object.ChildAt(i);
DCHECK_EQ(inline_text_box.Role(), ax::mojom::Role::kInlineTextBox);
int start = end;
blink::WebString name = inline_text_box.GetName();
end += name.length();
if (end <= character_index)
continue;
int local_index = character_index - start;
blink::WebVector<int> starts;
blink::WebVector<int> ends;
inline_text_box.GetWordBoundaries(starts, ends);
size_t word_count = starts.size();
DCHECK_EQ(ends.size(), word_count);
// If there are no words, use the InlineTextBox boundaries.
if (!word_count) {
word_start = start;
word_end = end;
return;
}
// Look for a character within any word other than the last.
for (size_t j = 0; j < word_count - 1; j++) {
if (local_index < ends[j]) {
word_start = start + starts[j];
word_end = start + ends[j];
return;
}
}
// Return the last word by default.
word_start = start + starts[word_count - 1];
word_end = start + ends[word_count - 1];
return;
}
}
// Collects attributes into a string, delimited by dashes. Used by all methods
// that output lists of attributes: attributesOfLinkedUIElementsCallback,
// AttributesOfChildrenCallback, etc.
class AttributesCollector {
public:
AttributesCollector() {}
AttributesCollector(const AttributesCollector&) = delete;
AttributesCollector& operator=(const AttributesCollector&) = delete;
~AttributesCollector() {}
void CollectAttributes(const blink::WebAXObject& object) {
attributes_.append("\n------------\n");
attributes_.append(GetAttributes(object));
}
std::string attributes() const { return attributes_; }
private:
std::string attributes_;
};
} // namespace
gin::WrapperInfo WebAXObjectProxy::kWrapperInfo = {gin::kEmbedderNativeGin};
WebAXObjectProxy::WebAXObjectProxy(const blink::WebAXObject& object,
WebAXObjectProxy::Factory* factory)
: accessibility_object_(object), factory_(factory) {}
WebAXObjectProxy::~WebAXObjectProxy() = default;
bool WebAXObjectProxy::UpdateLayout() {
if (IsDetached()) {
return false;
}
factory()->GetAXContext()->UpdateAXForAllDocuments();
return true;
}
ui::AXNodeData WebAXObjectProxy::GetAXNodeData() const {
ui::AXNodeData node_data;
if (!IsDetached())
accessibility_object_.Serialize(&node_data, ui::kAXModeComplete);
return node_data;
}
gin::ObjectTemplateBuilder WebAXObjectProxy::GetObjectTemplateBuilder(
v8::Isolate* isolate) {
return gin::Wrappable<WebAXObjectProxy>::GetObjectTemplateBuilder(isolate)
.SetProperty("role", &WebAXObjectProxy::Role)
.SetProperty("stringValue", &WebAXObjectProxy::StringValue)
.SetProperty("language", &WebAXObjectProxy::Language)
.SetProperty("x", &WebAXObjectProxy::X)
.SetProperty("y", &WebAXObjectProxy::Y)
.SetProperty("width", &WebAXObjectProxy::Width)
.SetProperty("height", &WebAXObjectProxy::Height)
.SetProperty("inPageLinkTarget", &WebAXObjectProxy::InPageLinkTarget)
.SetProperty("intValue", &WebAXObjectProxy::IntValue)
.SetProperty("minValue", &WebAXObjectProxy::MinValue)
.SetProperty("maxValue", &WebAXObjectProxy::MaxValue)
.SetProperty("stepValue", &WebAXObjectProxy::StepValue)
.SetProperty("valueDescription", &WebAXObjectProxy::ValueDescription)
.SetProperty("childrenCount", &WebAXObjectProxy::ChildrenCount)
.SetProperty("selectionIsBackward",
&WebAXObjectProxy::SelectionIsBackward)
.SetProperty("selectionAnchorObject",
&WebAXObjectProxy::SelectionAnchorObject)
.SetProperty("selectionAnchorOffset",
&WebAXObjectProxy::SelectionAnchorOffset)
.SetProperty("selectionAnchorAffinity",
&WebAXObjectProxy::SelectionAnchorAffinity)
.SetProperty("selectionFocusObject",
&WebAXObjectProxy::SelectionFocusObject)
.SetProperty("selectionFocusOffset",
&WebAXObjectProxy::SelectionFocusOffset)
.SetProperty("selectionFocusAffinity",
&WebAXObjectProxy::SelectionFocusAffinity)
.SetProperty("isAtomic", &WebAXObjectProxy::IsAtomic)
.SetProperty("isAutofillAvailable",
&WebAXObjectProxy::IsAutofillAvailable)
.SetProperty("isBusy", &WebAXObjectProxy::IsBusy)
.SetProperty("isRequired", &WebAXObjectProxy::IsRequired)
.SetProperty("isEditable", &WebAXObjectProxy::IsEditable)
.SetProperty("isEditableRoot", &WebAXObjectProxy::IsEditableRoot)
.SetProperty("isRichlyEditable", &WebAXObjectProxy::IsRichlyEditable)
.SetProperty("isFocused", &WebAXObjectProxy::IsFocused)
.SetProperty("isFocusable", &WebAXObjectProxy::IsFocusable)
.SetProperty("isModal", &WebAXObjectProxy::IsModal)
.SetProperty("isSelected", &WebAXObjectProxy::IsSelected)
.SetProperty("isSelectable", &WebAXObjectProxy::IsSelectable)
.SetProperty("isMultiLine", &WebAXObjectProxy::IsMultiLine)
.SetProperty("isMultiSelectable", &WebAXObjectProxy::IsMultiSelectable)
.SetProperty("isSelectedOptionActive",
&WebAXObjectProxy::IsSelectedOptionActive)
.SetProperty("isExpanded", &WebAXObjectProxy::IsExpanded)
.SetProperty("checked", &WebAXObjectProxy::Checked)
.SetProperty("isVisible", &WebAXObjectProxy::IsVisible)
.SetProperty("isVisited", &WebAXObjectProxy::IsVisited)
.SetProperty("isOffScreen", &WebAXObjectProxy::IsOffScreen)
.SetProperty("isCollapsed", &WebAXObjectProxy::IsCollapsed)
.SetProperty("hasPopup", &WebAXObjectProxy::HasPopup)
.SetProperty("isValid", &WebAXObjectProxy::IsValid)
.SetProperty("isReadOnly", &WebAXObjectProxy::IsReadOnly)
.SetProperty("isIgnored", &WebAXObjectProxy::IsIgnored)
.SetProperty("restriction", &WebAXObjectProxy::Restriction)
.SetProperty("activeDescendant", &WebAXObjectProxy::ActiveDescendant)
.SetProperty("backgroundColor", &WebAXObjectProxy::BackgroundColor)
.SetProperty("color", &WebAXObjectProxy::Color)
.SetProperty("colorValue", &WebAXObjectProxy::ColorValue)
.SetProperty("fontFamily", &WebAXObjectProxy::FontFamily)
.SetProperty("fontSize", &WebAXObjectProxy::FontSize)
.SetProperty("autocomplete", &WebAXObjectProxy::Autocomplete)
.SetProperty("current", &WebAXObjectProxy::Current)
.SetProperty("invalid", &WebAXObjectProxy::Invalid)
.SetProperty("keyShortcuts", &WebAXObjectProxy::KeyShortcuts)
.SetProperty("ariaColumnCount", &WebAXObjectProxy::AriaColumnCount)
.SetProperty("ariaColumnIndex", &WebAXObjectProxy::AriaColumnIndex)
.SetProperty("ariaColumnSpan", &WebAXObjectProxy::AriaColumnSpan)
.SetProperty("ariaRowCount", &WebAXObjectProxy::AriaRowCount)
.SetProperty("ariaRowIndex", &WebAXObjectProxy::AriaRowIndex)
.SetProperty("ariaRowSpan", &WebAXObjectProxy::AriaRowSpan)
.SetProperty("live", &WebAXObjectProxy::Live)
.SetProperty("orientation", &WebAXObjectProxy::Orientation)
.SetProperty("relevant", &WebAXObjectProxy::Relevant)
.SetProperty("roleDescription", &WebAXObjectProxy::RoleDescription)
.SetProperty("sort", &WebAXObjectProxy::Sort)
.SetProperty("url", &WebAXObjectProxy::Url)
.SetProperty("hierarchicalLevel", &WebAXObjectProxy::HierarchicalLevel)
.SetProperty("posInSet", &WebAXObjectProxy::PosInSet)
.SetProperty("setSize", &WebAXObjectProxy::SetSize)
.SetProperty("clickPointX", &WebAXObjectProxy::ClickPointX)
.SetProperty("clickPointY", &WebAXObjectProxy::ClickPointY)
.SetProperty("rowCount", &WebAXObjectProxy::RowCount)
.SetProperty("rowHeadersCount", &WebAXObjectProxy::RowHeadersCount)
.SetProperty("columnCount", &WebAXObjectProxy::ColumnCount)
.SetProperty("columnHeadersCount", &WebAXObjectProxy::ColumnHeadersCount)
.SetProperty("isClickable", &WebAXObjectProxy::IsClickable)
//
// NEW bounding rect calculation - high-level interface
//
.SetProperty("boundsX", &WebAXObjectProxy::BoundsX)
.SetProperty("boundsY", &WebAXObjectProxy::BoundsY)
.SetProperty("boundsWidth", &WebAXObjectProxy::BoundsWidth)
.SetProperty("boundsHeight", &WebAXObjectProxy::BoundsHeight)
.SetMethod("allAttributes", &WebAXObjectProxy::AllAttributes)
.SetMethod("attributesOfChildren",
&WebAXObjectProxy::AttributesOfChildren)
.SetMethod("ariaActiveDescendantElement",
&WebAXObjectProxy::AriaActiveDescendantElement)
.SetMethod("ariaControlsElementAtIndex",
&WebAXObjectProxy::AriaControlsElementAtIndex)
.SetMethod("ariaDetailsElementAtIndex",
&WebAXObjectProxy::AriaDetailsElementAtIndex)
.SetMethod("ariaErrorMessageElementAtIndex",
&WebAXObjectProxy::AriaErrorMessageElementAtIndex)
.SetMethod("ariaFlowToElementAtIndex",
&WebAXObjectProxy::AriaFlowToElementAtIndex)
.SetMethod("ariaOwnsElementAtIndex",
&WebAXObjectProxy::AriaOwnsElementAtIndex)
.SetMethod("boundsForRange", &WebAXObjectProxy::BoundsForRange)
.SetMethod("childAtIndex", &WebAXObjectProxy::ChildAtIndex)
.SetMethod("elementAtPoint", &WebAXObjectProxy::ElementAtPoint)
.SetMethod("rowHeaderAtIndex", &WebAXObjectProxy::RowHeaderAtIndex)
.SetMethod("columnHeaderAtIndex", &WebAXObjectProxy::ColumnHeaderAtIndex)
.SetMethod("rowIndexRange", &WebAXObjectProxy::RowIndexRange)
.SetMethod("columnIndexRange", &WebAXObjectProxy::ColumnIndexRange)
.SetMethod("cellForColumnAndRow", &WebAXObjectProxy::CellForColumnAndRow)
.SetMethod("setSelectedTextRange",
&WebAXObjectProxy::SetSelectedTextRange)
.SetMethod("setSelection", &WebAXObjectProxy::SetSelection)
.SetMethod("isAttributeSettable", &WebAXObjectProxy::IsAttributeSettable)
.SetMethod("isPressActionSupported",
&WebAXObjectProxy::IsPressActionSupported)
.SetMethod("hasDefaultAction", &WebAXObjectProxy::HasDefaultAction)
.SetMethod("parentElement", &WebAXObjectProxy::ParentElement)
.SetMethod("increment", &WebAXObjectProxy::Increment)
.SetMethod("decrement", &WebAXObjectProxy::Decrement)
.SetMethod("showMenu", &WebAXObjectProxy::ShowMenu)
.SetMethod("press", &WebAXObjectProxy::Press)
.SetMethod("setValue", &WebAXObjectProxy::SetValue)
.SetMethod("isEqual", &WebAXObjectProxy::IsEqual)
.SetMethod("setNotificationListener",
&WebAXObjectProxy::SetNotificationListener)
.SetMethod("unsetNotificationListener",
&WebAXObjectProxy::UnsetNotificationListener)
.SetMethod("takeFocus", &WebAXObjectProxy::TakeFocus)
.SetMethod("scrollToMakeVisible", &WebAXObjectProxy::ScrollToMakeVisible)
.SetMethod("scrollToMakeVisibleWithSubFocus",
&WebAXObjectProxy::ScrollToMakeVisibleWithSubFocus)
.SetMethod("scrollToGlobalPoint", &WebAXObjectProxy::ScrollToGlobalPoint)
.SetMethod("scrollUp", &WebAXObjectProxy::ScrollUp)
.SetMethod("scrollDown", &WebAXObjectProxy::ScrollDown)
.SetMethod("scrollX", &WebAXObjectProxy::ScrollX)
.SetMethod("scrollY", &WebAXObjectProxy::ScrollY)
.SetMethod("toString", &WebAXObjectProxy::ToString)
.SetMethod("wordStart", &WebAXObjectProxy::WordStart)
.SetMethod("wordEnd", &WebAXObjectProxy::WordEnd)
.SetMethod("nextOnLine", &WebAXObjectProxy::NextOnLine)
.SetMethod("previousOnLine", &WebAXObjectProxy::PreviousOnLine)
.SetMethod("misspellingAtIndex", &WebAXObjectProxy::MisspellingAtIndex)
// TODO(hajimehoshi): This is for backward compatibility. Remove them.
.SetMethod("addNotificationListener",
&WebAXObjectProxy::SetNotificationListener)
.SetMethod("removeNotificationListener",
&WebAXObjectProxy::UnsetNotificationListener)
//
// NEW accessible name and description accessors
//
.SetProperty("name", &WebAXObjectProxy::Name)
.SetProperty("nameFrom", &WebAXObjectProxy::NameFrom)
.SetMethod("nameElementCount", &WebAXObjectProxy::NameElementCount)
.SetMethod("nameElementAtIndex", &WebAXObjectProxy::NameElementAtIndex)
.SetProperty("description", &WebAXObjectProxy::Description)
.SetProperty("descriptionFrom", &WebAXObjectProxy::DescriptionFrom)
.SetProperty("placeholder", &WebAXObjectProxy::Placeholder)
.SetProperty("misspellingsCount", &WebAXObjectProxy::MisspellingsCount)
.SetMethod("descriptionElementCount",
&WebAXObjectProxy::DescriptionElementCount)
.SetMethod("descriptionElementAtIndex",
&WebAXObjectProxy::DescriptionElementAtIndex)
//
// NEW bounding rect calculation - low-level interface
//
.SetMethod("offsetContainer", &WebAXObjectProxy::OffsetContainer)
.SetMethod("boundsInContainerX", &WebAXObjectProxy::BoundsInContainerX)
.SetMethod("boundsInContainerY", &WebAXObjectProxy::BoundsInContainerY)
.SetMethod("boundsInContainerWidth",
&WebAXObjectProxy::BoundsInContainerWidth)
.SetMethod("boundsInContainerHeight",
&WebAXObjectProxy::BoundsInContainerHeight)
.SetMethod("hasNonIdentityTransform",
&WebAXObjectProxy::HasNonIdentityTransform);
}
v8::Local<v8::Object> WebAXObjectProxy::GetChildAtIndex(unsigned index) {
if (!UpdateLayout()) {
return v8::Local<v8::Object>();
}
return factory_->GetOrCreate(accessibility_object_.ChildAt(index));
}
bool WebAXObjectProxy::IsRoot() const {
return false;
}
bool WebAXObjectProxy::IsEqualToObject(const blink::WebAXObject& other) {
return accessibility_object_.Equals(other);
}
void WebAXObjectProxy::NotificationReceived(
blink::WebLocalFrame* frame,
const std::string& notification_name,
const std::vector<ui::AXEventIntent>& event_intents) {
if (notification_callback_.IsEmpty())
return;
v8::Local<v8::Context> context = frame->MainWorldScriptContext();
if (context.IsEmpty())
return;
v8::Isolate* isolate = frame->GetAgentGroupScheduler()->Isolate();
v8::Local<v8::Array> intents_array(
v8::Array::New(isolate, event_intents.size()));
for (size_t i = 0; i < event_intents.size(); ++i) {
intents_array
->CreateDataProperty(context, static_cast<uint32_t>(i),
v8::String::NewFromUtf8(
isolate, event_intents[i].ToString().c_str())
.ToLocalChecked())
.Check();
}
v8::Local<v8::Value> argv[] = {
v8::String::NewFromUtf8(isolate, notification_name.c_str())
.ToLocalChecked(),
intents_array};
// TODO(aboxhall): Can we force this to run in a new task, to avoid
// dirtying layout during post-layout hooks?
frame->CallFunctionEvenIfScriptDisabled(
v8::Local<v8::Function>::New(isolate, notification_callback_),
context->Global(), std::size(argv), argv);
}
void WebAXObjectProxy::Reset() {
notification_callback_.Reset();
factory_ = nullptr;
accessibility_object_ = blink::WebAXObject();
}
std::string WebAXObjectProxy::Role() {
if (!UpdateLayout()) {
return "";
}
return GetRole(accessibility_object_);
}
std::string WebAXObjectProxy::StringValue() {
if (!UpdateLayout()) {
return "";
}
return GetStringValue(accessibility_object_);
}
std::string WebAXObjectProxy::Language() {
if (!UpdateLayout()) {
return "";
}
return GetLanguage(accessibility_object_);
}
int WebAXObjectProxy::X() {
if (!UpdateLayout()) {
return -1;
}
return BoundsForObject(accessibility_object_).x();
}
int WebAXObjectProxy::Y() {
if (!UpdateLayout()) {
return -1;
}
return BoundsForObject(accessibility_object_).y();
}
int WebAXObjectProxy::Width() {
if (!UpdateLayout()) {
return -1;
}
return BoundsForObject(accessibility_object_).width();
}
int WebAXObjectProxy::Height() {
if (!UpdateLayout()) {
return -1;
}
return BoundsForObject(accessibility_object_).height();
}
v8::Local<v8::Value> WebAXObjectProxy::InPageLinkTarget(v8::Isolate* isolate) {
if (!UpdateLayout()) {
return v8::Local<v8::Object>();
}
blink::WebAXObject target = accessibility_object_.InPageLinkTarget();
if (target.IsNull())
return v8::Null(isolate);
return factory_->GetOrCreate(target);
}
int WebAXObjectProxy::IntValue() {
if (!UpdateLayout()) {
return -1;
}
if (accessibility_object_.SupportsRangeValue()) {
float value = 0.0;
accessibility_object_.ValueForRange(&value);
return static_cast<int>(value);
} else if (accessibility_object_.Role() == ax::mojom::Role::kHeading) {
return accessibility_object_.HeadingLevel();
} else {
return atoi(accessibility_object_.GetValueForControl().Utf8().data());
}
}
int WebAXObjectProxy::MinValue() {
if (!UpdateLayout()) {
return -1;
}
float min_value = 0.0;
accessibility_object_.MinValueForRange(&min_value);
return min_value;
}
int WebAXObjectProxy::MaxValue() {
if (!UpdateLayout()) {
return -1;
}
float max_value = 0.0;
accessibility_object_.MaxValueForRange(&max_value);
return max_value;
}
int WebAXObjectProxy::StepValue() {
if (!UpdateLayout()) {
return -1;
}
float step_value = 0.0;
accessibility_object_.StepValueForRange(&step_value);
return step_value;
}
std::string WebAXObjectProxy::ValueDescription() {
if (!UpdateLayout()) {
return "";
}
std::string value_description =
GetAXNodeData().GetStringAttribute(ax::mojom::StringAttribute::kValue);
return value_description.insert(0, "AXValueDescription: ");
}
int WebAXObjectProxy::ChildrenCount() {
if (!UpdateLayout()) {
return 0;
}
int count = 1; // Root object always has only one child, the WebView.
if (!IsRoot())
count = accessibility_object_.ChildCount();
return count;
}
bool WebAXObjectProxy::SelectionIsBackward() {
if (!UpdateLayout()) {
return false;
}
bool is_selection_backward = false;
blink::WebAXObject anchor_object;
int anchor_offset = -1;
ax::mojom::TextAffinity anchor_affinity;
blink::WebAXObject focus_object;
int focus_offset = -1;
ax::mojom::TextAffinity focus_affinity;
accessibility_object_.Selection(is_selection_backward, anchor_object,
anchor_offset, anchor_affinity, focus_object,
focus_offset, focus_affinity);
return is_selection_backward;
}
v8::Local<v8::Value> WebAXObjectProxy::SelectionAnchorObject(
v8::Isolate* isolate) {
if (!UpdateLayout()) {
return v8::Local<v8::Object>();
}
bool is_selection_backward = false;
blink::WebAXObject anchor_object;
int anchor_offset = -1;
ax::mojom::TextAffinity anchor_affinity;
blink::WebAXObject focus_object;
int focus_offset = -1;
ax::mojom::TextAffinity focus_affinity;
accessibility_object_.Selection(is_selection_backward, anchor_object,
anchor_offset, anchor_affinity, focus_object,
focus_offset, focus_affinity);
if (anchor_object.IsNull())
return v8::Null(isolate);
return factory_->GetOrCreate(anchor_object);
}
int WebAXObjectProxy::SelectionAnchorOffset() {
if (!UpdateLayout()) {
return -1;
}
bool is_selection_backward = false;
blink::WebAXObject anchor_object;
int anchor_offset = -1;
ax::mojom::TextAffinity anchor_affinity;
blink::WebAXObject focus_object;
int focus_offset = -1;
ax::mojom::TextAffinity focus_affinity;
accessibility_object_.Selection(is_selection_backward, anchor_object,
anchor_offset, anchor_affinity, focus_object,
focus_offset, focus_affinity);
if (anchor_offset < 0)
return -1;
return anchor_offset;
}
std::string WebAXObjectProxy::SelectionAnchorAffinity() {
if (!UpdateLayout()) {
return "";
}
bool is_selection_backward = false;
blink::WebAXObject anchor_object;
int anchor_offset = -1;
ax::mojom::TextAffinity anchor_affinity;
blink::WebAXObject focus_object;
int focus_offset = -1;
ax::mojom::TextAffinity focus_affinity;
accessibility_object_.Selection(is_selection_backward, anchor_object,
anchor_offset, anchor_affinity, focus_object,
focus_offset, focus_affinity);
return anchor_affinity == ax::mojom::TextAffinity::kUpstream ? "upstream"
: "downstream";
}
v8::Local<v8::Value> WebAXObjectProxy::SelectionFocusObject(
v8::Isolate* isolate) {
if (!UpdateLayout()) {
return v8::Local<v8::Object>();
}
bool is_selection_backward = false;
blink::WebAXObject anchor_object;
int anchor_offset = -1;
ax::mojom::TextAffinity anchor_affinity;
blink::WebAXObject focus_object;
int focus_offset = -1;
ax::mojom::TextAffinity focus_affinity;
accessibility_object_.Selection(is_selection_backward, anchor_object,
anchor_offset, anchor_affinity, focus_object,
focus_offset, focus_affinity);
if (focus_object.IsNull())
return v8::Null(isolate);
return factory_->GetOrCreate(focus_object);
}
int WebAXObjectProxy::SelectionFocusOffset() {
if (!UpdateLayout()) {
return -1;
}
bool is_selection_backward = false;
blink::WebAXObject anchor_object;
int anchor_offset = -1;
ax::mojom::TextAffinity anchor_affinity;
blink::WebAXObject focus_object;
int focus_offset = -1;
ax::mojom::TextAffinity focus_affinity;
accessibility_object_.Selection(is_selection_backward, anchor_object,
anchor_offset, anchor_affinity, focus_object,
focus_offset, focus_affinity);
if (focus_offset < 0)
return -1;
return focus_offset;
}
std::string WebAXObjectProxy::SelectionFocusAffinity() {
if (!UpdateLayout()) {
return "";
}
bool is_selection_backward = false;
blink::WebAXObject anchor_object;
int anchor_offset = -1;
ax::mojom::TextAffinity anchor_affinity;
blink::WebAXObject focus_object;
int focus_offset = -1;
ax::mojom::TextAffinity focus_affinity;
accessibility_object_.Selection(is_selection_backward, anchor_object,
anchor_offset, anchor_affinity, focus_object,
focus_offset, focus_affinity);
return focus_affinity == ax::mojom::TextAffinity::kUpstream ? "upstream"
: "downstream";
}
bool WebAXObjectProxy::IsAtomic() {
if (!UpdateLayout()) {
return false;
}
return accessibility_object_.LiveRegionAtomic();
}
bool WebAXObjectProxy::IsAutofillAvailable() {
if (!UpdateLayout()) {
return false;
}
return GetAXNodeData().HasState(ax::mojom::State::kAutofillAvailable);
}
bool WebAXObjectProxy::IsBusy() {
if (!UpdateLayout()) {
return false;
}
return GetAXNodeData().GetBoolAttribute(ax::mojom::BoolAttribute::kBusy);
}
std::string WebAXObjectProxy::Restriction() {
if (!UpdateLayout()) {
return "";
}
blink::WebAXRestriction web_ax_restriction =
static_cast<blink::WebAXRestriction>(GetAXNodeData().GetRestriction());
switch (web_ax_restriction) {
case blink::kWebAXRestrictionReadOnly:
return "readOnly";
case blink::kWebAXRestrictionDisabled:
return "disabled";
case blink::kWebAXRestrictionNone:
break;
}
return "none";
}
bool WebAXObjectProxy::IsRequired() {
if (!UpdateLayout()) {
return false;
}
return GetAXNodeData().HasState(ax::mojom::State::kRequired);
}
bool WebAXObjectProxy::IsEditableRoot() {
if (!UpdateLayout()) {
return false;
}
return GetAXNodeData().GetBoolAttribute(
ax::mojom::BoolAttribute::kNonAtomicTextFieldRoot) &&
GetAXNodeData().HasState(ax::mojom::State::kEditable);
}
bool WebAXObjectProxy::IsEditable() {
if (!UpdateLayout()) {
return false;
}
return GetAXNodeData().HasState(ax::mojom::State::kEditable);
}
bool WebAXObjectProxy::IsRichlyEditable() {
if (!UpdateLayout()) {
return false;
}
return GetAXNodeData().HasState(ax::mojom::State::kRichlyEditable);
}
bool WebAXObjectProxy::IsFocused() {
if (!UpdateLayout()) {
return false;
}
return accessibility_object_.IsFocused();
}
bool WebAXObjectProxy::IsFocusable() {
if (!UpdateLayout()) {
return false;
}
return GetAXNodeData().HasState(ax::mojom::State::kFocusable);
}
bool WebAXObjectProxy::IsModal() {
if (!UpdateLayout()) {
return false;
}
return accessibility_object_.IsModal();
}
bool WebAXObjectProxy::IsSelected() {
if (!UpdateLayout()) {
return false;
}
return GetAXNodeData().GetBoolAttribute(ax::mojom::BoolAttribute::kSelected);
}
bool WebAXObjectProxy::IsSelectable() {
if (!UpdateLayout()) {
return false;
}
ui::AXNodeData node_data = GetAXNodeData();
// It's selectable if it has the attribute, whether it's true or false.
return node_data.HasBoolAttribute(ax::mojom::BoolAttribute::kSelected) &&
node_data.GetRestriction() != ax::mojom::Restriction::kDisabled;
}
bool WebAXObjectProxy::IsMultiLine() {
if (!UpdateLayout()) {
return false;
}
return GetAXNodeData().HasState(ax::mojom::State::kMultiline);
}
bool WebAXObjectProxy::IsMultiSelectable() {
if (!UpdateLayout()) {
return false;
}
return GetAXNodeData().HasState(ax::mojom::State::kMultiselectable);
}
bool WebAXObjectProxy::IsSelectedOptionActive() {
if (!UpdateLayout()) {
return false;
}
return accessibility_object_.IsSelectedOptionActive();
}
bool WebAXObjectProxy::IsExpanded() {
if (!UpdateLayout()) {
return false;
}
return GetAXNodeData().HasState(ax::mojom::State::kExpanded);
}
std::string WebAXObjectProxy::Checked() {
if (!UpdateLayout()) {
return "";
}
switch (accessibility_object_.CheckedState()) {
case ax::mojom::CheckedState::kTrue:
return "true";
case ax::mojom::CheckedState::kMixed:
return "mixed";
case ax::mojom::CheckedState::kFalse:
return "false";
default:
return std::string();
}
}
bool WebAXObjectProxy::IsCollapsed() {
if (!UpdateLayout()) {
return false;
}
return GetAXNodeData().HasState(ax::mojom::State::kCollapsed);
}
bool WebAXObjectProxy::IsVisible() {
if (!UpdateLayout()) {
return false;
}
return !GetAXNodeData().IsInvisible();
}
bool WebAXObjectProxy::IsVisited() {
if (!UpdateLayout()) {
return false;
}
return accessibility_object_.IsVisited();
}
bool WebAXObjectProxy::IsOffScreen() {
if (!UpdateLayout()) {
return false;
}
return accessibility_object_.IsOffScreen();
}
bool WebAXObjectProxy::IsValid() {
if (!UpdateLayout()) {
return false;
}
return !accessibility_object_.IsDetached();
}
bool WebAXObjectProxy::IsReadOnly() {
if (!UpdateLayout()) {
return false;
}
return GetAXNodeData().GetRestriction() == ax::mojom::Restriction::kReadOnly;
}
bool WebAXObjectProxy::IsIgnored() {
if (!UpdateLayout()) {
return false;
}
return accessibility_object_.AccessibilityIsIgnored();
}
v8::Local<v8::Object> WebAXObjectProxy::ActiveDescendant() {
if (!UpdateLayout()) {
return v8::Local<v8::Object>();
}
blink::WebAXObject element = accessibility_object_.AriaActiveDescendant();
return factory_->GetOrCreate(element);
}
unsigned int WebAXObjectProxy::BackgroundColor() {
if (!UpdateLayout()) {
return 0;
}
return GetAXNodeData().GetIntAttribute(
ax::mojom::IntAttribute::kBackgroundColor);
}
unsigned int WebAXObjectProxy::Color() {