1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/renderer/accessibility/blink_ax_tree_source.h"
9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/string_util.h"
11 #include "base/strings/utf_string_conversions.h"
12 #include "content/renderer/accessibility/blink_ax_enum_conversion.h"
13 #include "content/renderer/browser_plugin/browser_plugin.h"
14 #include "content/renderer/render_frame_impl.h"
15 #include "content/renderer/render_frame_proxy.h"
16 #include "content/renderer/render_view_impl.h"
17 #include "third_party/WebKit/public/platform/WebRect.h"
18 #include "third_party/WebKit/public/platform/WebSize.h"
19 #include "third_party/WebKit/public/platform/WebString.h"
20 #include "third_party/WebKit/public/platform/WebVector.h"
21 #include "third_party/WebKit/public/web/WebAXEnums.h"
22 #include "third_party/WebKit/public/web/WebAXObject.h"
23 #include "third_party/WebKit/public/web/WebDocument.h"
24 #include "third_party/WebKit/public/web/WebDocumentType.h"
25 #include "third_party/WebKit/public/web/WebElement.h"
26 #include "third_party/WebKit/public/web/WebFormControlElement.h"
27 #include "third_party/WebKit/public/web/WebFrame.h"
28 #include "third_party/WebKit/public/web/WebLocalFrame.h"
29 #include "third_party/WebKit/public/web/WebNode.h"
30 #include "third_party/WebKit/public/web/WebPlugin.h"
31 #include "third_party/WebKit/public/web/WebPluginContainer.h"
32 #include "third_party/WebKit/public/web/WebView.h"
34 using base::ASCIIToUTF16
;
35 using base::UTF16ToUTF8
;
36 using blink::WebAXObject
;
37 using blink::WebDocument
;
38 using blink::WebDocumentType
;
39 using blink::WebElement
;
40 using blink::WebLocalFrame
;
42 using blink::WebPlugin
;
43 using blink::WebPluginContainer
;
44 using blink::WebVector
;
51 // Returns true if |ancestor| is the first unignored parent of |child|,
52 // which means that when walking up the parent chain from |child|,
53 // |ancestor| is the *first* ancestor that isn't marked as
54 // accessibilityIsIgnored().
55 bool IsParentUnignoredOf(WebAXObject ancestor
,
57 WebAXObject parent
= child
.parentObject();
58 while (!parent
.isDetached() && parent
.accessibilityIsIgnored())
59 parent
= parent
.parentObject();
60 return parent
.equals(ancestor
);
63 std::string
GetEquivalentAriaRoleString(const ui::AXRole role
) {
65 case ui::AX_ROLE_ARTICLE
:
67 case ui::AX_ROLE_BANNER
:
69 case ui::AX_ROLE_BUTTON
:
71 case ui::AX_ROLE_COMPLEMENTARY
:
72 return "complementary";
73 case ui::AX_ROLE_FIGURE
:
75 case ui::AX_ROLE_FOOTER
:
77 case ui::AX_ROLE_HEADING
:
79 case ui::AX_ROLE_IMAGE
:
81 case ui::AX_ROLE_MAIN
:
83 case ui::AX_ROLE_NAVIGATION
:
85 case ui::AX_ROLE_RADIO_BUTTON
:
87 case ui::AX_ROLE_REGION
:
89 case ui::AX_ROLE_SLIDER
:
98 void AddIntListAttributeFromWebObjects(ui::AXIntListAttribute attr
,
99 WebVector
<WebAXObject
> objects
,
100 ui::AXNodeData
* dst
) {
101 std::vector
<int32
> ids
;
102 for(size_t i
= 0; i
< objects
.size(); i
++)
103 ids
.push_back(objects
[i
].axID());
105 dst
->AddIntListAttribute(attr
, ids
);
108 } // Anonymous namespace
110 BlinkAXTreeSource::BlinkAXTreeSource(RenderFrameImpl
* render_frame
)
111 : render_frame_(render_frame
),
112 node_to_frame_routing_id_map_(NULL
),
113 node_to_browser_plugin_instance_id_map_(NULL
),
114 accessibility_focus_id_(-1) {
117 BlinkAXTreeSource::~BlinkAXTreeSource() {
120 void BlinkAXTreeSource::SetRoot(blink::WebAXObject root
) {
124 bool BlinkAXTreeSource::IsInTree(blink::WebAXObject node
) const {
125 const blink::WebAXObject
& root
= GetRoot();
126 while (IsValid(node
)) {
127 if (node
.equals(root
))
129 node
= GetParent(node
);
134 void BlinkAXTreeSource::CollectChildFrameIdMapping(
135 std::map
<int32
, int>* node_to_frame_routing_id_map
,
136 std::map
<int32
, int>* node_to_browser_plugin_instance_id_map
) {
137 node_to_frame_routing_id_map_
= node_to_frame_routing_id_map
;
138 node_to_browser_plugin_instance_id_map_
=
139 node_to_browser_plugin_instance_id_map
;
142 blink::WebAXObject
BlinkAXTreeSource::GetRoot() const {
145 return GetMainDocument().accessibilityObject();
148 blink::WebAXObject
BlinkAXTreeSource::GetFromId(int32 id
) const {
149 return GetMainDocument().accessibilityObjectFromID(id
);
152 int32
BlinkAXTreeSource::GetId(blink::WebAXObject node
) const {
156 void BlinkAXTreeSource::GetChildren(
157 blink::WebAXObject parent
,
158 std::vector
<blink::WebAXObject
>* out_children
) const {
159 if (parent
.role() == blink::WebAXRoleStaticText
) {
160 blink::WebAXObject ancestor
= parent
;
161 while (!ancestor
.isDetached()) {
162 if (ancestor
.axID() == accessibility_focus_id_
) {
163 parent
.loadInlineTextBoxes();
166 ancestor
= ancestor
.parentObject();
170 bool is_iframe
= false;
171 WebNode node
= parent
.node();
172 if (!node
.isNull() && node
.isElementNode()) {
173 WebElement element
= node
.to
<WebElement
>();
174 is_iframe
= (element
.tagName() == ASCIIToUTF16("IFRAME"));
177 for (unsigned i
= 0; i
< parent
.childCount(); i
++) {
178 blink::WebAXObject child
= parent
.childAt(i
);
180 // The child may be invalid due to issues in blink accessibility code.
181 if (child
.isDetached())
184 // Skip children whose parent isn't |parent|.
185 // As an exception, include children of an iframe element.
186 if (!is_iframe
&& !IsParentUnignoredOf(parent
, child
))
189 out_children
->push_back(child
);
193 blink::WebAXObject
BlinkAXTreeSource::GetParent(
194 blink::WebAXObject node
) const {
195 // Blink returns ignored objects when walking up the parent chain,
196 // we have to skip those here. Also, stop when we get to the root
198 blink::WebAXObject root
= GetRoot();
200 if (node
.equals(root
))
201 return blink::WebAXObject();
202 node
= node
.parentObject();
203 } while (!node
.isDetached() && node
.accessibilityIsIgnored());
208 bool BlinkAXTreeSource::IsValid(blink::WebAXObject node
) const {
209 return !node
.isDetached(); // This also checks if it's null.
212 bool BlinkAXTreeSource::IsEqual(blink::WebAXObject node1
,
213 blink::WebAXObject node2
) const {
214 return node1
.equals(node2
);
217 blink::WebAXObject
BlinkAXTreeSource::GetNull() const {
218 return blink::WebAXObject();
221 void BlinkAXTreeSource::SerializeNode(blink::WebAXObject src
,
222 ui::AXNodeData
* dst
) const {
223 dst
->role
= AXRoleFromBlink(src
.role());
224 dst
->state
= AXStateFromBlink(src
);
225 dst
->location
= src
.boundingBoxRect();
226 dst
->id
= src
.axID();
227 std::string name
= UTF16ToUTF8(src
.deprecatedTitle());
230 if (src
.valueDescription().length()) {
231 dst
->AddStringAttribute(ui::AX_ATTR_VALUE
,
232 UTF16ToUTF8(src
.valueDescription()));
234 dst
->AddStringAttribute(ui::AX_ATTR_VALUE
, UTF16ToUTF8(src
.stringValue()));
237 if (dst
->role
== ui::AX_ROLE_COLOR_WELL
) {
239 src
.colorValue(r
, g
, b
);
240 dst
->AddIntAttribute(ui::AX_ATTR_COLOR_VALUE_RED
, r
);
241 dst
->AddIntAttribute(ui::AX_ATTR_COLOR_VALUE_GREEN
, g
);
242 dst
->AddIntAttribute(ui::AX_ATTR_COLOR_VALUE_BLUE
, b
);
245 if (src
.invalidState()) {
246 dst
->AddIntAttribute(ui::AX_ATTR_INVALID_STATE
,
247 AXInvalidStateFromBlink(src
.invalidState()));
249 if (src
.invalidState() == blink::WebAXInvalidStateOther
) {
250 dst
->AddStringAttribute(ui::AX_ATTR_ARIA_INVALID_VALUE
,
251 UTF16ToUTF8(src
.ariaInvalidValue()));
254 if (dst
->role
== ui::AX_ROLE_INLINE_TEXT_BOX
) {
255 dst
->AddIntAttribute(ui::AX_ATTR_TEXT_DIRECTION
,
256 AXTextDirectionFromBlink(src
.textDirection()));
258 WebVector
<int> src_character_offsets
;
259 src
.characterOffsets(src_character_offsets
);
260 std::vector
<int32
> character_offsets
;
261 character_offsets
.reserve(src_character_offsets
.size());
262 for (size_t i
= 0; i
< src_character_offsets
.size(); ++i
)
263 character_offsets
.push_back(src_character_offsets
[i
]);
264 dst
->AddIntListAttribute(ui::AX_ATTR_CHARACTER_OFFSETS
, character_offsets
);
266 WebVector
<int> src_word_starts
;
267 WebVector
<int> src_word_ends
;
268 src
.wordBoundaries(src_word_starts
, src_word_ends
);
269 std::vector
<int32
> word_starts
;
270 std::vector
<int32
> word_ends
;
271 word_starts
.reserve(src_word_starts
.size());
272 word_ends
.reserve(src_word_starts
.size());
273 for (size_t i
= 0; i
< src_word_starts
.size(); ++i
) {
274 word_starts
.push_back(src_word_starts
[i
]);
275 word_ends
.push_back(src_word_ends
[i
]);
277 dst
->AddIntListAttribute(ui::AX_ATTR_WORD_STARTS
, word_starts
);
278 dst
->AddIntListAttribute(ui::AX_ATTR_WORD_ENDS
, word_ends
);
281 if (src
.accessKey().length()) {
282 dst
->AddStringAttribute(ui::AX_ATTR_ACCESS_KEY
,
283 UTF16ToUTF8(src
.accessKey()));
286 if (src
.actionVerb().length())
287 dst
->AddStringAttribute(ui::AX_ATTR_ACTION
, UTF16ToUTF8(src
.actionVerb()));
288 if (src
.ariaAutoComplete().length())
289 dst
->AddStringAttribute(ui::AX_ATTR_AUTO_COMPLETE
,
290 UTF16ToUTF8(src
.ariaAutoComplete()));
291 if (src
.isAriaReadOnly())
292 dst
->AddBoolAttribute(ui::AX_ATTR_ARIA_READONLY
, true);
293 if (src
.isButtonStateMixed())
294 dst
->AddBoolAttribute(ui::AX_ATTR_BUTTON_MIXED
, true);
295 if (src
.canSetValueAttribute())
296 dst
->AddBoolAttribute(ui::AX_ATTR_CAN_SET_VALUE
, true);
297 if (src
.deprecatedAccessibilityDescription().length()) {
298 dst
->AddStringAttribute(
299 ui::AX_ATTR_DESCRIPTION
,
300 UTF16ToUTF8(src
.deprecatedAccessibilityDescription()));
302 if (src
.hasComputedStyle()) {
303 dst
->AddStringAttribute(ui::AX_ATTR_DISPLAY
,
304 UTF16ToUTF8(src
.computedStyleDisplay()));
306 if (src
.deprecatedHelpText().length())
307 dst
->AddStringAttribute(ui::AX_ATTR_HELP
,
308 UTF16ToUTF8(src
.deprecatedHelpText()));
309 if (src
.deprecatedPlaceholder().length()) {
310 dst
->AddStringAttribute(ui::AX_ATTR_PLACEHOLDER
,
311 UTF16ToUTF8(src
.deprecatedPlaceholder()));
313 if (src
.keyboardShortcut().length()) {
314 dst
->AddStringAttribute(ui::AX_ATTR_SHORTCUT
,
315 UTF16ToUTF8(src
.keyboardShortcut()));
317 if (!src
.deprecatedTitleUIElement().isDetached()) {
318 dst
->AddIntAttribute(ui::AX_ATTR_TITLE_UI_ELEMENT
,
319 src
.deprecatedTitleUIElement().axID());
321 if (!src
.ariaActiveDescendant().isDetached()) {
322 dst
->AddIntAttribute(ui::AX_ATTR_ACTIVEDESCENDANT_ID
,
323 src
.ariaActiveDescendant().axID());
326 if (!src
.url().isEmpty())
327 dst
->AddStringAttribute(ui::AX_ATTR_URL
, src
.url().spec());
329 if (dst
->role
== ui::AX_ROLE_HEADING
)
330 dst
->AddIntAttribute(ui::AX_ATTR_HIERARCHICAL_LEVEL
, src
.headingLevel());
331 else if ((dst
->role
== ui::AX_ROLE_TREE_ITEM
||
332 dst
->role
== ui::AX_ROLE_ROW
) &&
333 src
.hierarchicalLevel() > 0) {
334 dst
->AddIntAttribute(ui::AX_ATTR_HIERARCHICAL_LEVEL
,
335 src
.hierarchicalLevel());
338 // Treat the active list box item as focused.
339 if (dst
->role
== ui::AX_ROLE_LIST_BOX_OPTION
&&
340 src
.isSelectedOptionActive()) {
341 dst
->state
|= (1 << ui::AX_STATE_FOCUSED
);
344 if (src
.canvasHasFallbackContent())
345 dst
->AddBoolAttribute(ui::AX_ATTR_CANVAS_HAS_FALLBACK
, true);
347 WebNode node
= src
.node();
348 bool is_iframe
= false;
350 if (!node
.isNull() && node
.isElementNode()) {
351 WebElement element
= node
.to
<WebElement
>();
352 is_iframe
= (element
.tagName() == ASCIIToUTF16("IFRAME"));
354 // TODO(ctguil): The tagName in WebKit is lower cased but
355 // HTMLElement::nodeName calls localNameUpper. Consider adding
356 // a WebElement method that returns the original lower cased tagName.
357 dst
->AddStringAttribute(
358 ui::AX_ATTR_HTML_TAG
,
359 base::StringToLowerASCII(UTF16ToUTF8(element
.tagName())));
360 for (unsigned i
= 0; i
< element
.attributeCount(); ++i
) {
361 std::string name
= base::StringToLowerASCII(UTF16ToUTF8(
362 element
.attributeLocalName(i
)));
363 std::string value
= UTF16ToUTF8(element
.attributeValue(i
));
364 dst
->html_attributes
.push_back(std::make_pair(name
, value
));
367 if (!src
.isReadOnly() || dst
->role
== ui::AX_ROLE_TEXT_FIELD
) {
368 dst
->AddIntAttribute(ui::AX_ATTR_TEXT_SEL_START
, src
.selectionStart());
369 dst
->AddIntAttribute(ui::AX_ATTR_TEXT_SEL_END
, src
.selectionEnd());
371 WebVector
<int> src_line_breaks
;
372 src
.lineBreaks(src_line_breaks
);
373 if (src_line_breaks
.size() > 0) {
374 std::vector
<int32
> line_breaks
;
375 line_breaks
.reserve(src_line_breaks
.size());
376 for (size_t i
= 0; i
< src_line_breaks
.size(); ++i
)
377 line_breaks
.push_back(src_line_breaks
[i
]);
378 dst
->AddIntListAttribute(ui::AX_ATTR_LINE_BREAKS
, line_breaks
);
381 if (dst
->role
== ui::AX_ROLE_TEXT_FIELD
&&
382 src
.textInputType().length()) {
383 dst
->AddStringAttribute(ui::AX_ATTR_TEXT_INPUT_TYPE
,
384 UTF16ToUTF8(src
.textInputType()));
388 blink::WebAXOptionalBool optionalBool
= src
.isAriaGrabbed();
389 if (optionalBool
== blink::WebAXOptionalBoolFalse
)
390 dst
->AddBoolAttribute(ui::AX_ATTR_GRABBED
, false);
391 else if (optionalBool
== blink::WebAXOptionalBoolTrue
)
392 dst
->AddBoolAttribute(ui::AX_ATTR_GRABBED
, true);
395 if (element
.hasAttribute("role")) {
396 dst
->AddStringAttribute(ui::AX_ATTR_ROLE
,
397 UTF16ToUTF8(element
.getAttribute("role")));
399 std::string role
= GetEquivalentAriaRoleString(dst
->role
);
401 dst
->AddStringAttribute(ui::AX_ATTR_ROLE
, role
);
404 // Browser plugin (used in a <webview>).
405 if (node_to_browser_plugin_instance_id_map_
) {
406 BrowserPlugin
* browser_plugin
= BrowserPlugin::GetFromNode(element
);
407 if (browser_plugin
) {
408 (*node_to_browser_plugin_instance_id_map_
)[dst
->id
] =
409 browser_plugin
->browser_plugin_instance_id();
410 dst
->AddBoolAttribute(ui::AX_ATTR_IS_AX_TREE_HOST
, true);
415 if (src
.isInLiveRegion()) {
416 dst
->AddBoolAttribute(ui::AX_ATTR_LIVE_ATOMIC
, src
.liveRegionAtomic());
417 dst
->AddBoolAttribute(ui::AX_ATTR_LIVE_BUSY
, src
.liveRegionBusy());
418 if (src
.liveRegionBusy())
419 dst
->state
|= (1 << ui::AX_STATE_BUSY
);
420 if (!src
.liveRegionStatus().isEmpty()) {
421 dst
->AddStringAttribute(ui::AX_ATTR_LIVE_STATUS
,
422 UTF16ToUTF8(src
.liveRegionStatus()));
424 dst
->AddStringAttribute(ui::AX_ATTR_LIVE_RELEVANT
,
425 UTF16ToUTF8(src
.liveRegionRelevant()));
426 dst
->AddBoolAttribute(ui::AX_ATTR_CONTAINER_LIVE_ATOMIC
,
427 src
.containerLiveRegionAtomic());
428 dst
->AddBoolAttribute(ui::AX_ATTR_CONTAINER_LIVE_BUSY
,
429 src
.containerLiveRegionBusy());
430 dst
->AddStringAttribute(ui::AX_ATTR_CONTAINER_LIVE_STATUS
,
431 UTF16ToUTF8(src
.containerLiveRegionStatus()));
432 dst
->AddStringAttribute(ui::AX_ATTR_CONTAINER_LIVE_RELEVANT
,
433 UTF16ToUTF8(src
.containerLiveRegionRelevant()));
436 if (dst
->role
== ui::AX_ROLE_PROGRESS_INDICATOR
||
437 dst
->role
== ui::AX_ROLE_METER
||
438 dst
->role
== ui::AX_ROLE_SCROLL_BAR
||
439 dst
->role
== ui::AX_ROLE_SLIDER
||
440 dst
->role
== ui::AX_ROLE_SPIN_BUTTON
) {
441 dst
->AddFloatAttribute(ui::AX_ATTR_VALUE_FOR_RANGE
, src
.valueForRange());
442 dst
->AddFloatAttribute(ui::AX_ATTR_MAX_VALUE_FOR_RANGE
,
443 src
.maxValueForRange());
444 dst
->AddFloatAttribute(ui::AX_ATTR_MIN_VALUE_FOR_RANGE
,
445 src
.minValueForRange());
448 if (dst
->role
== ui::AX_ROLE_WEB_AREA
) {
449 dst
->AddStringAttribute(ui::AX_ATTR_HTML_TAG
, "#document");
450 const WebDocument
& document
= src
.document();
452 name
= UTF16ToUTF8(document
.title());
453 dst
->AddStringAttribute(ui::AX_ATTR_DOC_TITLE
,
454 UTF16ToUTF8(document
.title()));
455 dst
->AddStringAttribute(ui::AX_ATTR_DOC_URL
, document
.url().spec());
456 dst
->AddStringAttribute(
457 ui::AX_ATTR_DOC_MIMETYPE
,
458 document
.isXHTMLDocument() ? "text/xhtml" : "text/html");
459 dst
->AddBoolAttribute(ui::AX_ATTR_DOC_LOADED
, src
.isLoaded());
460 dst
->AddFloatAttribute(ui::AX_ATTR_DOC_LOADING_PROGRESS
,
461 src
.estimatedLoadingProgress());
463 const WebDocumentType
& doctype
= document
.doctype();
464 if (!doctype
.isNull()) {
465 dst
->AddStringAttribute(ui::AX_ATTR_DOC_DOCTYPE
,
466 UTF16ToUTF8(doctype
.name()));
469 const gfx::Size
& scroll_offset
= document
.scrollOffset();
470 dst
->AddIntAttribute(ui::AX_ATTR_SCROLL_X
, scroll_offset
.width());
471 dst
->AddIntAttribute(ui::AX_ATTR_SCROLL_Y
, scroll_offset
.height());
473 const gfx::Size
& min_offset
= document
.minimumScrollOffset();
474 dst
->AddIntAttribute(ui::AX_ATTR_SCROLL_X_MIN
, min_offset
.width());
475 dst
->AddIntAttribute(ui::AX_ATTR_SCROLL_Y_MIN
, min_offset
.height());
477 const gfx::Size
& max_offset
= document
.maximumScrollOffset();
478 dst
->AddIntAttribute(ui::AX_ATTR_SCROLL_X_MAX
, max_offset
.width());
479 dst
->AddIntAttribute(ui::AX_ATTR_SCROLL_Y_MAX
, max_offset
.height());
481 if (node_to_frame_routing_id_map_
&& !src
.equals(GetRoot())) {
482 WebLocalFrame
* frame
= document
.frame();
483 RenderFrameImpl
* render_frame
= RenderFrameImpl::FromWebFrame(frame
);
485 (*node_to_frame_routing_id_map_
)[dst
->id
] =
486 render_frame
->GetRoutingID();
487 dst
->AddBoolAttribute(ui::AX_ATTR_IS_AX_TREE_HOST
, true);
489 RenderFrameProxy
* render_frame_proxy
=
490 RenderFrameProxy::FromWebFrame(frame
);
491 if (render_frame_proxy
) {
492 (*node_to_frame_routing_id_map_
)[dst
->id
] =
493 render_frame_proxy
->routing_id();
494 dst
->AddBoolAttribute(ui::AX_ATTR_IS_AX_TREE_HOST
, true);
500 if (dst
->role
== ui::AX_ROLE_TABLE
) {
501 int column_count
= src
.columnCount();
502 int row_count
= src
.rowCount();
503 if (column_count
> 0 && row_count
> 0) {
504 std::set
<int32
> unique_cell_id_set
;
505 std::vector
<int32
> cell_ids
;
506 std::vector
<int32
> unique_cell_ids
;
507 dst
->AddIntAttribute(ui::AX_ATTR_TABLE_COLUMN_COUNT
, column_count
);
508 dst
->AddIntAttribute(ui::AX_ATTR_TABLE_ROW_COUNT
, row_count
);
509 WebAXObject header
= src
.headerContainerObject();
510 if (!header
.isDetached())
511 dst
->AddIntAttribute(ui::AX_ATTR_TABLE_HEADER_ID
, header
.axID());
512 for (int i
= 0; i
< column_count
* row_count
; ++i
) {
513 WebAXObject cell
= src
.cellForColumnAndRow(
514 i
% column_count
, i
/ column_count
);
516 if (!cell
.isDetached()) {
517 cell_id
= cell
.axID();
518 if (unique_cell_id_set
.find(cell_id
) == unique_cell_id_set
.end()) {
519 unique_cell_id_set
.insert(cell_id
);
520 unique_cell_ids
.push_back(cell_id
);
523 cell_ids
.push_back(cell_id
);
525 dst
->AddIntListAttribute(ui::AX_ATTR_CELL_IDS
, cell_ids
);
526 dst
->AddIntListAttribute(ui::AX_ATTR_UNIQUE_CELL_IDS
, unique_cell_ids
);
530 if (dst
->role
== ui::AX_ROLE_ROW
) {
531 dst
->AddIntAttribute(ui::AX_ATTR_TABLE_ROW_INDEX
, src
.rowIndex());
532 WebAXObject header
= src
.rowHeader();
533 if (!header
.isDetached())
534 dst
->AddIntAttribute(ui::AX_ATTR_TABLE_ROW_HEADER_ID
, header
.axID());
537 if (dst
->role
== ui::AX_ROLE_COLUMN
) {
538 dst
->AddIntAttribute(ui::AX_ATTR_TABLE_COLUMN_INDEX
, src
.columnIndex());
539 WebAXObject header
= src
.columnHeader();
540 if (!header
.isDetached())
541 dst
->AddIntAttribute(ui::AX_ATTR_TABLE_COLUMN_HEADER_ID
, header
.axID());
544 if (dst
->role
== ui::AX_ROLE_CELL
||
545 dst
->role
== ui::AX_ROLE_ROW_HEADER
||
546 dst
->role
== ui::AX_ROLE_COLUMN_HEADER
) {
547 dst
->AddIntAttribute(ui::AX_ATTR_TABLE_CELL_COLUMN_INDEX
,
548 src
.cellColumnIndex());
549 dst
->AddIntAttribute(ui::AX_ATTR_TABLE_CELL_COLUMN_SPAN
,
550 src
.cellColumnSpan());
551 dst
->AddIntAttribute(ui::AX_ATTR_TABLE_CELL_ROW_INDEX
, src
.cellRowIndex());
552 dst
->AddIntAttribute(ui::AX_ATTR_TABLE_CELL_ROW_SPAN
, src
.cellRowSpan());
555 if ((dst
->role
== ui::AX_ROLE_ROW_HEADER
||
556 dst
->role
== ui::AX_ROLE_COLUMN_HEADER
) && src
.sortDirection()) {
557 dst
->AddIntAttribute(ui::AX_ATTR_SORT_DIRECTION
,
558 AXSortDirectionFromBlink(src
.sortDirection()));
561 dst
->AddStringAttribute(ui::AX_ATTR_NAME
, name
);
563 // Add the ids of *indirect* children - those who are children of this node,
564 // but whose parent is *not* this node. One example is a table
565 // cell, which is a child of both a row and a column. Because the cell's
566 // parent is the row, the row adds it as a child, and the column adds it
567 // as an indirect child.
568 int child_count
= src
.childCount();
569 for (int i
= 0; i
< child_count
; ++i
) {
570 WebAXObject child
= src
.childAt(i
);
571 std::vector
<int32
> indirect_child_ids
;
572 if (!is_iframe
&& !child
.isDetached() && !IsParentUnignoredOf(src
, child
))
573 indirect_child_ids
.push_back(child
.axID());
574 if (indirect_child_ids
.size() > 0) {
575 dst
->AddIntListAttribute(
576 ui::AX_ATTR_INDIRECT_CHILD_IDS
, indirect_child_ids
);
580 WebVector
<WebAXObject
> controls
;
581 if (src
.ariaControls(controls
))
582 AddIntListAttributeFromWebObjects(ui::AX_ATTR_CONTROLS_IDS
, controls
, dst
);
584 WebVector
<WebAXObject
> describedby
;
585 if (src
.deprecatedAriaDescribedby(describedby
)) {
586 AddIntListAttributeFromWebObjects(
587 ui::AX_ATTR_DESCRIBEDBY_IDS
, describedby
, dst
);
590 if (src
.ariaDropEffect().length()) {
591 dst
->AddStringAttribute(ui::AX_ATTR_DROPEFFECT
,
592 UTF16ToUTF8(src
.ariaDropEffect()));
595 WebVector
<WebAXObject
> flowTo
;
596 if (src
.ariaFlowTo(flowTo
))
597 AddIntListAttributeFromWebObjects(ui::AX_ATTR_FLOWTO_IDS
, flowTo
, dst
);
599 WebVector
<WebAXObject
> labelledby
;
600 if (src
.deprecatedAriaLabelledby(labelledby
)) {
601 AddIntListAttributeFromWebObjects(
602 ui::AX_ATTR_LABELLEDBY_IDS
, labelledby
, dst
);
605 WebVector
<WebAXObject
> owns
;
606 if (src
.ariaOwns(owns
))
607 AddIntListAttributeFromWebObjects(ui::AX_ATTR_OWNS_IDS
, owns
, dst
);
610 blink::WebDocument
BlinkAXTreeSource::GetMainDocument() const {
611 if (render_frame_
&& render_frame_
->GetWebFrame())
612 return render_frame_
->GetWebFrame()->document();
613 return WebDocument();
616 } // namespace content