Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(378)

Side by Side Diff: content/renderer/accessibility/blink_ax_tree_source.cc

Issue 1435113003: Make use of new AX name calc in Chromium. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update inspector-protocol test expectations Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/renderer/accessibility/blink_ax_tree_source.h" 5 #include "content/renderer/accessibility/blink_ax_tree_source.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 void AddIntListAttributeFromWebObjects(ui::AXIntListAttribute attr, 101 void AddIntListAttributeFromWebObjects(ui::AXIntListAttribute attr,
102 WebVector<WebAXObject> objects, 102 WebVector<WebAXObject> objects,
103 AXContentNodeData* dst) { 103 AXContentNodeData* dst) {
104 std::vector<int32> ids; 104 std::vector<int32> ids;
105 for(size_t i = 0; i < objects.size(); i++) 105 for(size_t i = 0; i < objects.size(); i++)
106 ids.push_back(objects[i].axID()); 106 ids.push_back(objects[i].axID());
107 if (ids.size() > 0) 107 if (ids.size() > 0)
108 dst->AddIntListAttribute(attr, ids); 108 dst->AddIntListAttribute(attr, ids);
109 } 109 }
110 110
111 } // Anonymous namespace 111 } // namespace
112 112
113 BlinkAXTreeSource::BlinkAXTreeSource(RenderFrameImpl* render_frame) 113 BlinkAXTreeSource::BlinkAXTreeSource(RenderFrameImpl* render_frame)
114 : render_frame_(render_frame), 114 : render_frame_(render_frame),
115 accessibility_focus_id_(-1) { 115 accessibility_focus_id_(-1) {
116 } 116 }
117 117
118 BlinkAXTreeSource::~BlinkAXTreeSource() { 118 BlinkAXTreeSource::~BlinkAXTreeSource() {
119 } 119 }
120 120
121 void BlinkAXTreeSource::SetRoot(blink::WebAXObject root) { 121 void BlinkAXTreeSource::SetRoot(blink::WebAXObject root) {
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 blink::WebAXObject BlinkAXTreeSource::GetNull() const { 256 blink::WebAXObject BlinkAXTreeSource::GetNull() const {
257 return blink::WebAXObject(); 257 return blink::WebAXObject();
258 } 258 }
259 259
260 void BlinkAXTreeSource::SerializeNode(blink::WebAXObject src, 260 void BlinkAXTreeSource::SerializeNode(blink::WebAXObject src,
261 AXContentNodeData* dst) const { 261 AXContentNodeData* dst) const {
262 dst->role = AXRoleFromBlink(src.role()); 262 dst->role = AXRoleFromBlink(src.role());
263 dst->state = AXStateFromBlink(src); 263 dst->state = AXStateFromBlink(src);
264 dst->location = src.boundingBoxRect(); 264 dst->location = src.boundingBoxRect();
265 dst->id = src.axID(); 265 dst->id = src.axID();
266 std::string name = src.deprecatedTitle().utf8(); 266
267 blink::WebAXNameFrom nameFrom;
268 blink::WebVector<blink::WebAXObject> nameObjects;
269 blink::WebString web_name = src.name(nameFrom, nameObjects);
270 if (!web_name.isEmpty()) {
271 dst->AddStringAttribute(ui::AX_ATTR_NAME, web_name.utf8());
272 dst->AddIntAttribute(ui::AX_ATTR_NAME_FROM, AXNameFromFromBlink(nameFrom));
273 AddIntListAttributeFromWebObjects(
274 ui::AX_ATTR_LABELLEDBY_IDS, nameObjects, dst);
275 }
276
277 blink::WebAXDescriptionFrom descriptionFrom;
278 blink::WebVector<blink::WebAXObject> descriptionObjects;
279 blink::WebString web_description = src.description(
280 nameFrom, descriptionFrom, descriptionObjects);
281 if (!web_description.isEmpty()) {
282 dst->AddStringAttribute(ui::AX_ATTR_DESCRIPTION, web_description.utf8());
283 dst->AddIntAttribute(ui::AX_ATTR_DESCRIPTION_FROM,
284 AXDescriptionFromFromBlink(descriptionFrom));
285 AddIntListAttributeFromWebObjects(
286 ui::AX_ATTR_DESCRIBEDBY_IDS, descriptionObjects, dst);
287 }
288
289 blink::WebString web_placeholder = src.placeholder(nameFrom, descriptionFrom);
290 if (!web_placeholder.isEmpty())
291 dst->AddStringAttribute(ui::AX_ATTR_PLACEHOLDER, web_placeholder.utf8());
267 292
268 std::string value; 293 std::string value;
269 if (src.valueDescription().length()) { 294 if (src.valueDescription().length()) {
270 dst->AddStringAttribute(ui::AX_ATTR_VALUE, src.valueDescription().utf8()); 295 dst->AddStringAttribute(ui::AX_ATTR_VALUE, src.valueDescription().utf8());
271 } else { 296 } else {
272 dst->AddStringAttribute(ui::AX_ATTR_VALUE, src.stringValue().utf8()); 297 dst->AddStringAttribute(ui::AX_ATTR_VALUE, src.stringValue().utf8());
273 } 298 }
274 299
275 if (dst->role == ui::AX_ROLE_COLOR_WELL) 300 if (dst->role == ui::AX_ROLE_COLOR_WELL)
276 dst->AddIntAttribute(ui::AX_ATTR_COLOR_VALUE, src.colorValue()); 301 dst->AddIntAttribute(ui::AX_ATTR_COLOR_VALUE, src.colorValue());
277 302
278 303
279 // Text attributes. 304 // Text attributes.
280 if (src.backgroundColor()) 305 if (src.backgroundColor())
281 dst->AddIntAttribute(ui::AX_ATTR_BACKGROUND_COLOR, src.backgroundColor()); 306 dst->AddIntAttribute(ui::AX_ATTR_BACKGROUND_COLOR, src.backgroundColor());
282 307
283 if (src.color()) 308 if (src.color())
284 dst->AddIntAttribute(ui::AX_ATTR_COLOR, src.color()); 309 dst->AddIntAttribute(ui::AX_ATTR_COLOR, src.color());
285 310
286 // Font size is in pixels. 311 // Font size is in pixels.
287 if (src.fontSize()) 312 if (src.fontSize())
288 dst->AddFloatAttribute(ui::AX_ATTR_FONT_SIZE, src.fontSize()); 313 dst->AddFloatAttribute(ui::AX_ATTR_FONT_SIZE, src.fontSize());
289 314
290 if (src.invalidState()) { 315 if (src.invalidState()) {
291 dst->AddIntAttribute(ui::AX_ATTR_INVALID_STATE, 316 dst->AddIntAttribute(ui::AX_ATTR_INVALID_STATE,
292 AXInvalidStateFromBlink(src.invalidState())); 317 AXInvalidStateFromBlink(src.invalidState()));
293 } 318 }
294 if (src.invalidState() == blink::WebAXInvalidStateOther) { 319 if (src.invalidState() == blink::WebAXInvalidStateOther) {
295 dst->AddStringAttribute( 320 dst->AddStringAttribute(
296 ui::AX_ATTR_ARIA_INVALID_VALUE, 321 ui::AX_ATTR_ARIA_INVALID_VALUE, src.ariaInvalidValue().utf8());
297 src.ariaInvalidValue().utf8());
298 } 322 }
299 323
300 if (src.textDirection()) { 324 if (src.textDirection()) {
301 dst->AddIntAttribute(ui::AX_ATTR_TEXT_DIRECTION, 325 dst->AddIntAttribute(ui::AX_ATTR_TEXT_DIRECTION,
302 AXTextDirectionFromBlink(src.textDirection())); 326 AXTextDirectionFromBlink(src.textDirection()));
303 } 327 }
304 328
305 if (src.textStyle()) { 329 if (src.textStyle()) {
306 dst->AddIntAttribute(ui::AX_ATTR_TEXT_STYLE, 330 dst->AddIntAttribute(ui::AX_ATTR_TEXT_STYLE,
307 AXTextStyleFromBlink(src.textStyle())); 331 AXTextStyleFromBlink(src.textStyle()));
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 if (src.ariaAutoComplete().length()) 366 if (src.ariaAutoComplete().length())
343 dst->AddStringAttribute( 367 dst->AddStringAttribute(
344 ui::AX_ATTR_AUTO_COMPLETE, 368 ui::AX_ATTR_AUTO_COMPLETE,
345 src.ariaAutoComplete().utf8()); 369 src.ariaAutoComplete().utf8());
346 if (src.isAriaReadOnly()) 370 if (src.isAriaReadOnly())
347 dst->AddBoolAttribute(ui::AX_ATTR_ARIA_READONLY, true); 371 dst->AddBoolAttribute(ui::AX_ATTR_ARIA_READONLY, true);
348 if (src.isButtonStateMixed()) 372 if (src.isButtonStateMixed())
349 dst->AddBoolAttribute(ui::AX_ATTR_BUTTON_MIXED, true); 373 dst->AddBoolAttribute(ui::AX_ATTR_BUTTON_MIXED, true);
350 if (src.canSetValueAttribute()) 374 if (src.canSetValueAttribute())
351 dst->AddBoolAttribute(ui::AX_ATTR_CAN_SET_VALUE, true); 375 dst->AddBoolAttribute(ui::AX_ATTR_CAN_SET_VALUE, true);
352 if (src.deprecatedAccessibilityDescription().length()) {
353 dst->AddStringAttribute(
354 ui::AX_ATTR_DESCRIPTION,
355 src.deprecatedAccessibilityDescription().utf8());
356 }
357 if (src.hasComputedStyle()) { 376 if (src.hasComputedStyle()) {
358 dst->AddStringAttribute( 377 dst->AddStringAttribute(
359 ui::AX_ATTR_DISPLAY, 378 ui::AX_ATTR_DISPLAY, src.computedStyleDisplay().utf8());
360 src.computedStyleDisplay().utf8());
361 }
362 if (src.deprecatedHelpText().length())
363 dst->AddStringAttribute(ui::AX_ATTR_HELP, src.deprecatedHelpText().utf8());
364 if (src.deprecatedPlaceholder().length()) {
365 dst->AddStringAttribute(
366 ui::AX_ATTR_PLACEHOLDER,
367 src.deprecatedPlaceholder().utf8());
368 } 379 }
369 if (src.keyboardShortcut().length()) { 380 if (src.keyboardShortcut().length()) {
370 dst->AddStringAttribute( 381 dst->AddStringAttribute(
371 ui::AX_ATTR_SHORTCUT, 382 ui::AX_ATTR_SHORTCUT,
372 src.keyboardShortcut().utf8()); 383 src.keyboardShortcut().utf8());
373 } 384 }
374 if (!src.deprecatedTitleUIElement().isDetached()) {
375 dst->AddIntAttribute(ui::AX_ATTR_TITLE_UI_ELEMENT,
376 src.deprecatedTitleUIElement().axID());
377 }
378 if (!src.ariaActiveDescendant().isDetached()) { 385 if (!src.ariaActiveDescendant().isDetached()) {
379 dst->AddIntAttribute(ui::AX_ATTR_ACTIVEDESCENDANT_ID, 386 dst->AddIntAttribute(ui::AX_ATTR_ACTIVEDESCENDANT_ID,
380 src.ariaActiveDescendant().axID()); 387 src.ariaActiveDescendant().axID());
381 } 388 }
382 389
383 if (!src.url().isEmpty()) 390 if (!src.url().isEmpty())
384 dst->AddStringAttribute(ui::AX_ATTR_URL, src.url().spec()); 391 dst->AddStringAttribute(ui::AX_ATTR_URL, src.url().spec());
385 392
386 if (dst->role == ui::AX_ROLE_HEADING) 393 if (dst->role == ui::AX_ROLE_HEADING)
387 dst->AddIntAttribute(ui::AX_ATTR_HIERARCHICAL_LEVEL, src.headingLevel()); 394 dst->AddIntAttribute(ui::AX_ATTR_HIERARCHICAL_LEVEL, src.headingLevel());
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 dst->role == ui::AX_ROLE_SCROLL_BAR || 515 dst->role == ui::AX_ROLE_SCROLL_BAR ||
509 dst->role == ui::AX_ROLE_SLIDER || 516 dst->role == ui::AX_ROLE_SLIDER ||
510 dst->role == ui::AX_ROLE_SPIN_BUTTON) { 517 dst->role == ui::AX_ROLE_SPIN_BUTTON) {
511 dst->AddFloatAttribute(ui::AX_ATTR_VALUE_FOR_RANGE, src.valueForRange()); 518 dst->AddFloatAttribute(ui::AX_ATTR_VALUE_FOR_RANGE, src.valueForRange());
512 dst->AddFloatAttribute(ui::AX_ATTR_MAX_VALUE_FOR_RANGE, 519 dst->AddFloatAttribute(ui::AX_ATTR_MAX_VALUE_FOR_RANGE,
513 src.maxValueForRange()); 520 src.maxValueForRange());
514 dst->AddFloatAttribute(ui::AX_ATTR_MIN_VALUE_FOR_RANGE, 521 dst->AddFloatAttribute(ui::AX_ATTR_MIN_VALUE_FOR_RANGE,
515 src.minValueForRange()); 522 src.minValueForRange());
516 } 523 }
517 524
518 if (dst->role == ui::AX_ROLE_WEB_AREA) { 525 if (dst->role == ui::AX_ROLE_WEB_AREA)
519 dst->AddStringAttribute(ui::AX_ATTR_HTML_TAG, "#document"); 526 dst->AddStringAttribute(ui::AX_ATTR_HTML_TAG, "#document");
520 const WebDocument& document = src.document();
521 if (name.empty())
522 name = document.title().utf8();
523 }
524 527
525 if (dst->role == ui::AX_ROLE_TABLE) { 528 if (dst->role == ui::AX_ROLE_TABLE) {
526 int column_count = src.columnCount(); 529 int column_count = src.columnCount();
527 int row_count = src.rowCount(); 530 int row_count = src.rowCount();
528 if (column_count > 0 && row_count > 0) { 531 if (column_count > 0 && row_count > 0) {
529 std::set<int32> unique_cell_id_set; 532 std::set<int32> unique_cell_id_set;
530 std::vector<int32> cell_ids; 533 std::vector<int32> cell_ids;
531 std::vector<int32> unique_cell_ids; 534 std::vector<int32> unique_cell_ids;
532 dst->AddIntAttribute(ui::AX_ATTR_TABLE_COLUMN_COUNT, column_count); 535 dst->AddIntAttribute(ui::AX_ATTR_TABLE_COLUMN_COUNT, column_count);
533 dst->AddIntAttribute(ui::AX_ATTR_TABLE_ROW_COUNT, row_count); 536 dst->AddIntAttribute(ui::AX_ATTR_TABLE_ROW_COUNT, row_count);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 dst->AddIntAttribute(ui::AX_ATTR_TABLE_CELL_ROW_INDEX, src.cellRowIndex()); 579 dst->AddIntAttribute(ui::AX_ATTR_TABLE_CELL_ROW_INDEX, src.cellRowIndex());
577 dst->AddIntAttribute(ui::AX_ATTR_TABLE_CELL_ROW_SPAN, src.cellRowSpan()); 580 dst->AddIntAttribute(ui::AX_ATTR_TABLE_CELL_ROW_SPAN, src.cellRowSpan());
578 } 581 }
579 582
580 if ((dst->role == ui::AX_ROLE_ROW_HEADER || 583 if ((dst->role == ui::AX_ROLE_ROW_HEADER ||
581 dst->role == ui::AX_ROLE_COLUMN_HEADER) && src.sortDirection()) { 584 dst->role == ui::AX_ROLE_COLUMN_HEADER) && src.sortDirection()) {
582 dst->AddIntAttribute(ui::AX_ATTR_SORT_DIRECTION, 585 dst->AddIntAttribute(ui::AX_ATTR_SORT_DIRECTION,
583 AXSortDirectionFromBlink(src.sortDirection())); 586 AXSortDirectionFromBlink(src.sortDirection()));
584 } 587 }
585 588
586 dst->AddStringAttribute(ui::AX_ATTR_NAME, name);
587
588 // Add the ids of *indirect* children - those who are children of this node, 589 // Add the ids of *indirect* children - those who are children of this node,
589 // but whose parent is *not* this node. One example is a table 590 // but whose parent is *not* this node. One example is a table
590 // cell, which is a child of both a row and a column. Because the cell's 591 // cell, which is a child of both a row and a column. Because the cell's
591 // parent is the row, the row adds it as a child, and the column adds it 592 // parent is the row, the row adds it as a child, and the column adds it
592 // as an indirect child. 593 // as an indirect child.
593 int child_count = src.childCount(); 594 int child_count = src.childCount();
594 for (int i = 0; i < child_count; ++i) { 595 for (int i = 0; i < child_count; ++i) {
595 WebAXObject child = src.childAt(i); 596 WebAXObject child = src.childAt(i);
596 std::vector<int32> indirect_child_ids; 597 std::vector<int32> indirect_child_ids;
597 if (!is_iframe && !child.isDetached() && !IsParentUnignoredOf(src, child)) 598 if (!is_iframe && !child.isDetached() && !IsParentUnignoredOf(src, child))
598 indirect_child_ids.push_back(child.axID()); 599 indirect_child_ids.push_back(child.axID());
599 if (indirect_child_ids.size() > 0) { 600 if (indirect_child_ids.size() > 0) {
600 dst->AddIntListAttribute( 601 dst->AddIntListAttribute(
601 ui::AX_ATTR_INDIRECT_CHILD_IDS, indirect_child_ids); 602 ui::AX_ATTR_INDIRECT_CHILD_IDS, indirect_child_ids);
602 } 603 }
603 } 604 }
604 605
605 WebVector<WebAXObject> controls; 606 WebVector<WebAXObject> controls;
606 if (src.ariaControls(controls)) 607 if (src.ariaControls(controls))
607 AddIntListAttributeFromWebObjects(ui::AX_ATTR_CONTROLS_IDS, controls, dst); 608 AddIntListAttributeFromWebObjects(ui::AX_ATTR_CONTROLS_IDS, controls, dst);
608 609
609 WebVector<WebAXObject> describedby;
610 if (src.deprecatedAriaDescribedby(describedby)) {
611 AddIntListAttributeFromWebObjects(
612 ui::AX_ATTR_DESCRIBEDBY_IDS, describedby, dst);
613 }
614
615 WebVector<WebAXObject> flowTo; 610 WebVector<WebAXObject> flowTo;
616 if (src.ariaFlowTo(flowTo)) 611 if (src.ariaFlowTo(flowTo))
617 AddIntListAttributeFromWebObjects(ui::AX_ATTR_FLOWTO_IDS, flowTo, dst); 612 AddIntListAttributeFromWebObjects(ui::AX_ATTR_FLOWTO_IDS, flowTo, dst);
618 613
619 WebVector<WebAXObject> labelledby;
620 if (src.deprecatedAriaLabelledby(labelledby)) {
621 AddIntListAttributeFromWebObjects(
622 ui::AX_ATTR_LABELLEDBY_IDS, labelledby, dst);
623 }
624
625 WebVector<WebAXObject> owns;
626 if (src.ariaOwns(owns))
627 AddIntListAttributeFromWebObjects(ui::AX_ATTR_OWNS_IDS, owns, dst);
628
629
630 if (src.isScrollableContainer()) { 614 if (src.isScrollableContainer()) {
631 const gfx::Point& scrollOffset = src.scrollOffset(); 615 const gfx::Point& scrollOffset = src.scrollOffset();
632 dst->AddIntAttribute(ui::AX_ATTR_SCROLL_X, scrollOffset.x()); 616 dst->AddIntAttribute(ui::AX_ATTR_SCROLL_X, scrollOffset.x());
633 dst->AddIntAttribute(ui::AX_ATTR_SCROLL_Y, scrollOffset.y()); 617 dst->AddIntAttribute(ui::AX_ATTR_SCROLL_Y, scrollOffset.y());
634 618
635 const gfx::Point& minScrollOffset = src.minimumScrollOffset(); 619 const gfx::Point& minScrollOffset = src.minimumScrollOffset();
636 dst->AddIntAttribute(ui::AX_ATTR_SCROLL_X_MIN, minScrollOffset.x()); 620 dst->AddIntAttribute(ui::AX_ATTR_SCROLL_X_MIN, minScrollOffset.x());
637 dst->AddIntAttribute(ui::AX_ATTR_SCROLL_Y_MIN, minScrollOffset.y()); 621 dst->AddIntAttribute(ui::AX_ATTR_SCROLL_Y_MIN, minScrollOffset.y());
638 622
639 const gfx::Point& maxScrollOffset = src.maximumScrollOffset(); 623 const gfx::Point& maxScrollOffset = src.maximumScrollOffset();
640 dst->AddIntAttribute(ui::AX_ATTR_SCROLL_X_MAX, maxScrollOffset.x()); 624 dst->AddIntAttribute(ui::AX_ATTR_SCROLL_X_MAX, maxScrollOffset.x());
641 dst->AddIntAttribute(ui::AX_ATTR_SCROLL_Y_MAX, maxScrollOffset.y()); 625 dst->AddIntAttribute(ui::AX_ATTR_SCROLL_Y_MAX, maxScrollOffset.y());
642 } 626 }
643 } 627 }
644 628
645 blink::WebDocument BlinkAXTreeSource::GetMainDocument() const { 629 blink::WebDocument BlinkAXTreeSource::GetMainDocument() const {
646 if (render_frame_ && render_frame_->GetWebFrame()) 630 if (render_frame_ && render_frame_->GetWebFrame())
647 return render_frame_->GetWebFrame()->document(); 631 return render_frame_->GetWebFrame()->document();
648 return WebDocument(); 632 return WebDocument();
649 } 633 }
650 634
651 } // namespace content 635 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698