| OLD | NEW |
| 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 "modules/accessibility/InspectorAccessibilityAgent.h" | 5 #include "modules/accessibility/InspectorAccessibilityAgent.h" |
| 6 | 6 |
| 7 #include "core/HTMLNames.h" | 7 #include "core/HTMLNames.h" |
| 8 #include "core/dom/AXObjectCache.h" | 8 #include "core/dom/AXObjectCache.h" |
| 9 #include "core/dom/DOMNodeIds.h" | 9 #include "core/dom/DOMNodeIds.h" |
| 10 #include "core/dom/Element.h" | 10 #include "core/dom/Element.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 using protocol::Accessibility::AXRelatedNode; | 31 using protocol::Accessibility::AXRelatedNode; |
| 32 using protocol::Accessibility::AXRelationshipAttributes; | 32 using protocol::Accessibility::AXRelationshipAttributes; |
| 33 using protocol::Accessibility::AXValue; | 33 using protocol::Accessibility::AXValue; |
| 34 using protocol::Accessibility::AXWidgetAttributes; | 34 using protocol::Accessibility::AXWidgetAttributes; |
| 35 using protocol::Accessibility::AXWidgetStates; | 35 using protocol::Accessibility::AXWidgetStates; |
| 36 | 36 |
| 37 using namespace HTMLNames; | 37 using namespace HTMLNames; |
| 38 | 38 |
| 39 namespace { | 39 namespace { |
| 40 | 40 |
| 41 static const AXID kIDForInspectedNodeWithNoAXNode = 0; |
| 42 |
| 41 void fillLiveRegionProperties(AXObject& axObject, | 43 void fillLiveRegionProperties(AXObject& axObject, |
| 42 protocol::Array<AXProperty>& properties) { | 44 protocol::Array<AXProperty>& properties) { |
| 43 if (!axObject.liveRegionRoot()) | 45 if (!axObject.liveRegionRoot()) |
| 44 return; | 46 return; |
| 45 | 47 |
| 46 properties.addItem( | 48 properties.addItem( |
| 47 createProperty(AXLiveRegionAttributesEnum::Live, | 49 createProperty(AXLiveRegionAttributesEnum::Live, |
| 48 createValue(axObject.containerLiveRegionStatus(), | 50 createValue(axObject.containerLiveRegionStatus(), |
| 49 AXValueTypeEnum::Token))); | 51 AXValueTypeEnum::Token))); |
| 50 properties.addItem( | 52 properties.addItem( |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 std::unique_ptr<AXValue> roleNameValue; | 368 std::unique_ptr<AXValue> roleNameValue; |
| 367 if (!roleName.isNull()) { | 369 if (!roleName.isNull()) { |
| 368 roleNameValue = createValue(roleName, AXValueTypeEnum::Role); | 370 roleNameValue = createValue(roleName, AXValueTypeEnum::Role); |
| 369 } else { | 371 } else { |
| 370 roleNameValue = createValue(AXObject::internalRoleName(role), | 372 roleNameValue = createValue(AXObject::internalRoleName(role), |
| 371 AXValueTypeEnum::InternalRole); | 373 AXValueTypeEnum::InternalRole); |
| 372 } | 374 } |
| 373 return roleNameValue; | 375 return roleNameValue; |
| 374 } | 376 } |
| 375 | 377 |
| 378 bool isAncestorOf(AXObject* possibleAncestor, AXObject* descendant) { |
| 379 if (!possibleAncestor || !descendant) |
| 380 return false; |
| 381 |
| 382 AXObject* ancestor = descendant; |
| 383 while (ancestor) { |
| 384 if (ancestor == possibleAncestor) |
| 385 return true; |
| 386 ancestor = ancestor->parentObject(); |
| 387 } |
| 388 return false; |
| 389 } |
| 390 |
| 376 } // namespace | 391 } // namespace |
| 377 | 392 |
| 378 InspectorAccessibilityAgent::InspectorAccessibilityAgent( | 393 InspectorAccessibilityAgent::InspectorAccessibilityAgent( |
| 379 Page* page, | 394 Page* page, |
| 380 InspectorDOMAgent* domAgent) | 395 InspectorDOMAgent* domAgent) |
| 381 : m_page(page), m_domAgent(domAgent) {} | 396 : m_page(page), m_domAgent(domAgent) {} |
| 382 | 397 |
| 383 void InspectorAccessibilityAgent::getAXNodeChain( | 398 void InspectorAccessibilityAgent::getPartialAXTree( |
| 384 ErrorString* errorString, | 399 ErrorString* errorString, |
| 385 int domNodeId, | 400 int domNodeId, |
| 386 bool fetchAncestors, | 401 const Maybe<bool>& fetchRelatives, |
| 387 std::unique_ptr<protocol::Array<protocol::Accessibility::AXNode>>* nodes) { | 402 std::unique_ptr<protocol::Array<AXNode>>* nodes) { |
| 388 if (!m_domAgent->enabled()) { | 403 if (!m_domAgent->enabled()) { |
| 389 *errorString = "DOM agent must be enabled"; | 404 *errorString = "DOM agent must be enabled"; |
| 390 return; | 405 return; |
| 391 } | 406 } |
| 392 Node* domNode = m_domAgent->assertNode(errorString, domNodeId); | 407 Node* domNode = m_domAgent->assertNode(errorString, domNodeId); |
| 393 if (!domNode) | 408 if (!domNode) |
| 394 return; | 409 return; |
| 395 | 410 |
| 396 Document& document = domNode->document(); | 411 Document& document = domNode->document(); |
| 397 document.updateStyleAndLayoutIgnorePendingStylesheets(); | 412 document.updateStyleAndLayoutIgnorePendingStylesheets(); |
| 398 DocumentLifecycle::DisallowTransitionScope disallowTransition( | 413 DocumentLifecycle::DisallowTransitionScope disallowTransition( |
| 399 document.lifecycle()); | 414 document.lifecycle()); |
| 400 LocalFrame* localFrame = document.frame(); | 415 LocalFrame* localFrame = document.frame(); |
| 401 if (!localFrame) { | 416 if (!localFrame) { |
| 402 *errorString = "Frame is detached."; | 417 *errorString = "Frame is detached."; |
| 403 return; | 418 return; |
| 404 } | 419 } |
| 405 std::unique_ptr<ScopedAXObjectCache> scopedCache = | 420 std::unique_ptr<ScopedAXObjectCache> scopedCache = |
| 406 ScopedAXObjectCache::create(document); | 421 ScopedAXObjectCache::create(document); |
| 407 AXObjectCacheImpl* cache = toAXObjectCacheImpl(scopedCache->get()); | 422 AXObjectCacheImpl* cache = toAXObjectCacheImpl(scopedCache->get()); |
| 408 | 423 |
| 409 AXObject* inspectedAXObject = cache->getOrCreate(domNode); | 424 AXObject* inspectedAXObject = cache->getOrCreate(domNode); |
| 410 *nodes = protocol::Array<protocol::Accessibility::AXNode>::create(); | 425 *nodes = protocol::Array<protocol::Accessibility::AXNode>::create(); |
| 411 if (!inspectedAXObject || inspectedAXObject->accessibilityIsIgnored()) { | 426 if (!inspectedAXObject || inspectedAXObject->accessibilityIsIgnored()) { |
| 412 (*nodes)->addItem(buildObjectForIgnoredNode(domNode, inspectedAXObject)); | 427 (*nodes)->addItem(buildObjectForIgnoredNode(domNode, inspectedAXObject, |
| 428 fetchRelatives.fromMaybe(true), |
| 429 *nodes, *cache)); |
| 413 } else { | 430 } else { |
| 414 (*nodes)->addItem(buildProtocolAXObject(*inspectedAXObject)); | 431 (*nodes)->addItem( |
| 432 buildProtocolAXObject(*inspectedAXObject, inspectedAXObject, |
| 433 fetchRelatives.fromMaybe(true), *nodes, *cache)); |
| 415 } | 434 } |
| 416 | 435 |
| 417 if (fetchAncestors && inspectedAXObject) { | 436 if (!inspectedAXObject || !inspectedAXObject->isAXLayoutObject()) |
| 418 AXObject* parent = inspectedAXObject->parentObjectUnignored(); | 437 return; |
| 419 while (parent) { | 438 |
| 420 (*nodes)->addItem(buildProtocolAXObject(*parent)); | 439 AXObject* parent = inspectedAXObject->parentObjectUnignored(); |
| 421 parent = parent->parentObjectUnignored(); | 440 if (!parent) |
| 422 } | 441 return; |
| 442 |
| 443 if (fetchRelatives.fromMaybe(true)) |
| 444 addAncestors(*parent, inspectedAXObject, *nodes, *cache); |
| 445 } |
| 446 |
| 447 void InspectorAccessibilityAgent::addAncestors( |
| 448 AXObject& firstAncestor, |
| 449 AXObject* inspectedAXObject, |
| 450 std::unique_ptr<protocol::Array<AXNode>>& nodes, |
| 451 AXObjectCacheImpl& cache) const { |
| 452 AXObject* ancestor = &firstAncestor; |
| 453 while (ancestor) { |
| 454 nodes->addItem(buildProtocolAXObject(*ancestor, inspectedAXObject, true, |
| 455 nodes, cache)); |
| 456 ancestor = ancestor->parentObjectUnignored(); |
| 423 } | 457 } |
| 424 } | 458 } |
| 425 | 459 |
| 426 std::unique_ptr<AXNode> InspectorAccessibilityAgent::buildObjectForIgnoredNode( | 460 std::unique_ptr<AXNode> InspectorAccessibilityAgent::buildObjectForIgnoredNode( |
| 427 Node* domNode, | 461 Node* domNode, |
| 428 AXObject* axObject) const { | 462 AXObject* axObject, |
| 463 bool fetchRelatives, |
| 464 std::unique_ptr<protocol::Array<AXNode>>& nodes, |
| 465 AXObjectCacheImpl& cache) const { |
| 429 AXObject::IgnoredReasons ignoredReasons; | 466 AXObject::IgnoredReasons ignoredReasons; |
| 430 | 467 AXID axID = kIDForInspectedNodeWithNoAXNode; |
| 431 AXID axID = 0; | 468 if (axObject && axObject->isAXLayoutObject()) |
| 432 if (axObject) | |
| 433 axID = axObject->axObjectID(); | 469 axID = axObject->axObjectID(); |
| 434 std::unique_ptr<AXNode> ignoredNodeObject = | 470 std::unique_ptr<AXNode> ignoredNodeObject = |
| 435 AXNode::create().setNodeId(String::number(axID)).setIgnored(true).build(); | 471 AXNode::create().setNodeId(String::number(axID)).setIgnored(true).build(); |
| 436 if (axObject) { | 472 AccessibilityRole role = AccessibilityRole::IgnoredRole; |
| 473 ignoredNodeObject->setRole(createRoleNameValue(role)); |
| 474 |
| 475 if (axObject && axObject->isAXLayoutObject()) { |
| 437 axObject->computeAccessibilityIsIgnored(&ignoredReasons); | 476 axObject->computeAccessibilityIsIgnored(&ignoredReasons); |
| 438 axID = axObject->axObjectID(); | 477 |
| 439 AccessibilityRole role = axObject->roleValue(); | 478 if (fetchRelatives) { |
| 440 ignoredNodeObject->setRole(createRoleNameValue(role)); | 479 populateRelatives(*axObject, axObject, *(ignoredNodeObject.get()), nodes, |
| 480 cache); |
| 481 } |
| 441 } else if (domNode && !domNode->layoutObject()) { | 482 } else if (domNode && !domNode->layoutObject()) { |
| 483 if (fetchRelatives) { |
| 484 populateDOMNodeRelatives(*domNode, *(ignoredNodeObject.get()), nodes, |
| 485 cache); |
| 486 } |
| 442 ignoredReasons.append(IgnoredReason(AXNotRendered)); | 487 ignoredReasons.append(IgnoredReason(AXNotRendered)); |
| 443 } | 488 } |
| 444 | 489 |
| 490 if (domNode) |
| 491 ignoredNodeObject->setBackendDomNodeId(DOMNodeIds::idForNode(domNode)); |
| 492 |
| 445 std::unique_ptr<protocol::Array<AXProperty>> ignoredReasonProperties = | 493 std::unique_ptr<protocol::Array<AXProperty>> ignoredReasonProperties = |
| 446 protocol::Array<AXProperty>::create(); | 494 protocol::Array<AXProperty>::create(); |
| 447 for (size_t i = 0; i < ignoredReasons.size(); i++) | 495 for (size_t i = 0; i < ignoredReasons.size(); i++) |
| 448 ignoredReasonProperties->addItem(createProperty(ignoredReasons[i])); | 496 ignoredReasonProperties->addItem(createProperty(ignoredReasons[i])); |
| 449 ignoredNodeObject->setIgnoredReasons(std::move(ignoredReasonProperties)); | 497 ignoredNodeObject->setIgnoredReasons(std::move(ignoredReasonProperties)); |
| 450 | 498 |
| 451 return ignoredNodeObject; | 499 return ignoredNodeObject; |
| 452 } | 500 } |
| 453 | 501 |
| 502 void InspectorAccessibilityAgent::populateDOMNodeRelatives( |
| 503 Node& inspectedDOMNode, |
| 504 AXNode& nodeObject, |
| 505 std::unique_ptr<protocol::Array<AXNode>>& nodes, |
| 506 AXObjectCacheImpl& cache) const { |
| 507 // Walk up parents until an AXObject can be found. |
| 508 Node* parentNode = FlatTreeTraversal::parent(inspectedDOMNode); |
| 509 AXObject* parentAXObject = cache.getOrCreate(parentNode); |
| 510 while (parentNode && !parentAXObject) { |
| 511 parentNode = FlatTreeTraversal::parent(inspectedDOMNode); |
| 512 parentAXObject = cache.getOrCreate(parentNode); |
| 513 }; |
| 514 if (parentAXObject) { |
| 515 if (parentAXObject->accessibilityIsIgnored()) |
| 516 parentAXObject = parentAXObject->parentObjectUnignored(); |
| 517 // Populate parent, ancestors and siblings. |
| 518 std::unique_ptr<AXNode> parentNodeObject = |
| 519 buildProtocolAXObject(*parentAXObject, nullptr, true, nodes, cache); |
| 520 std::unique_ptr<protocol::Array<AXNodeId>> siblingIds = |
| 521 protocol::Array<AXNodeId>::create(); |
| 522 findDOMNodeChildren(siblingIds, *parentNode, inspectedDOMNode, nodes, |
| 523 cache); |
| 524 parentNodeObject->setChildIds(std::move(siblingIds)); |
| 525 nodes->addItem(std::move(parentNodeObject)); |
| 526 |
| 527 AXObject* grandparentAXObject = parentAXObject->parentObjectUnignored(); |
| 528 if (grandparentAXObject) |
| 529 addAncestors(*grandparentAXObject, nullptr, nodes, cache); |
| 530 } |
| 531 |
| 532 // Then populate children. |
| 533 std::unique_ptr<protocol::Array<AXNodeId>> childIds = |
| 534 protocol::Array<AXNodeId>::create(); |
| 535 findDOMNodeChildren(childIds, inspectedDOMNode, inspectedDOMNode, nodes, |
| 536 cache); |
| 537 nodeObject.setChildIds(std::move(childIds)); |
| 538 } |
| 539 |
| 540 void InspectorAccessibilityAgent::findDOMNodeChildren( |
| 541 std::unique_ptr<protocol::Array<AXNodeId>>& childIds, |
| 542 Node& parentNode, |
| 543 Node& inspectedDOMNode, |
| 544 std::unique_ptr<protocol::Array<AXNode>>& nodes, |
| 545 AXObjectCacheImpl& cache) const { |
| 546 NodeList* childNodes = parentNode.childNodes(); |
| 547 for (size_t i = 0; i < childNodes->length(); ++i) { |
| 548 Node* childNode = childNodes->item(i); |
| 549 if (childNode == &inspectedDOMNode) { |
| 550 childIds->addItem(String::number(kIDForInspectedNodeWithNoAXNode)); |
| 551 continue; |
| 552 } |
| 553 |
| 554 AXObject* childAXObject = cache.getOrCreate(childNode); |
| 555 if (childAXObject) { |
| 556 if (childAXObject->accessibilityIsIgnored()) { |
| 557 // search for un-ignored descendants |
| 558 findDOMNodeChildren(childIds, *childNode, inspectedDOMNode, nodes, |
| 559 cache); |
| 560 } else { |
| 561 addChild(childIds, *childAXObject, nullptr, nodes, cache); |
| 562 } |
| 563 |
| 564 continue; |
| 565 } |
| 566 |
| 567 if (!childAXObject || |
| 568 childNode->isShadowIncludingInclusiveAncestorOf(&inspectedDOMNode)) { |
| 569 // If the inspected node may be a descendant of this node, keep walking |
| 570 // recursively until we find its actual siblings. |
| 571 findDOMNodeChildren(childIds, *childNode, inspectedDOMNode, nodes, cache); |
| 572 continue; |
| 573 } |
| 574 |
| 575 // Otherwise, just add the un-ignored children. |
| 576 const AXObject::AXObjectVector& indirectChildren = |
| 577 childAXObject->children(); |
| 578 for (unsigned i = 0; i < indirectChildren.size(); ++i) |
| 579 addChild(childIds, *(indirectChildren[i]), nullptr, nodes, cache); |
| 580 } |
| 581 } |
| 582 |
| 454 std::unique_ptr<AXNode> InspectorAccessibilityAgent::buildProtocolAXObject( | 583 std::unique_ptr<AXNode> InspectorAccessibilityAgent::buildProtocolAXObject( |
| 455 AXObject& axObject) const { | 584 AXObject& axObject, |
| 585 AXObject* inspectedAXObject, |
| 586 bool fetchRelatives, |
| 587 std::unique_ptr<protocol::Array<AXNode>>& nodes, |
| 588 AXObjectCacheImpl& cache) const { |
| 456 AccessibilityRole role = axObject.roleValue(); | 589 AccessibilityRole role = axObject.roleValue(); |
| 457 std::unique_ptr<AXNode> nodeObject = | 590 std::unique_ptr<AXNode> nodeObject = |
| 458 AXNode::create() | 591 AXNode::create() |
| 459 .setNodeId(String::number(axObject.axObjectID())) | 592 .setNodeId(String::number(axObject.axObjectID())) |
| 460 .setIgnored(false) | 593 .setIgnored(false) |
| 461 .build(); | 594 .build(); |
| 462 nodeObject->setRole(createRoleNameValue(role)); | 595 nodeObject->setRole(createRoleNameValue(role)); |
| 463 | 596 |
| 464 std::unique_ptr<protocol::Array<AXProperty>> properties = | 597 std::unique_ptr<protocol::Array<AXProperty>> properties = |
| 465 protocol::Array<AXProperty>::create(); | 598 protocol::Array<AXProperty>::create(); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 489 } | 622 } |
| 490 } | 623 } |
| 491 name->setSources(std::move(nameSourceProperties)); | 624 name->setSources(std::move(nameSourceProperties)); |
| 492 } | 625 } |
| 493 nodeObject->setProperties(std::move(properties)); | 626 nodeObject->setProperties(std::move(properties)); |
| 494 nodeObject->setName(std::move(name)); | 627 nodeObject->setName(std::move(name)); |
| 495 } else { | 628 } else { |
| 496 nodeObject->setProperties(std::move(properties)); | 629 nodeObject->setProperties(std::move(properties)); |
| 497 } | 630 } |
| 498 | 631 |
| 499 fillCoreProperties(axObject, *(nodeObject.get())); | 632 fillCoreProperties(axObject, inspectedAXObject, fetchRelatives, |
| 633 *(nodeObject.get()), nodes, cache); |
| 500 return nodeObject; | 634 return nodeObject; |
| 501 } | 635 } |
| 502 | 636 |
| 503 void InspectorAccessibilityAgent::fillCoreProperties(AXObject& axObject, | 637 void InspectorAccessibilityAgent::fillCoreProperties( |
| 504 AXNode& nodeObject) const { | 638 AXObject& axObject, |
| 639 AXObject* inspectedAXObject, |
| 640 bool fetchRelatives, |
| 641 AXNode& nodeObject, |
| 642 std::unique_ptr<protocol::Array<AXNode>>& nodes, |
| 643 AXObjectCacheImpl& cache) const { |
| 505 AXNameFrom nameFrom; | 644 AXNameFrom nameFrom; |
| 506 AXObject::AXObjectVector nameObjects; | 645 AXObject::AXObjectVector nameObjects; |
| 507 axObject.name(nameFrom, &nameObjects); | 646 axObject.name(nameFrom, &nameObjects); |
| 508 | 647 |
| 509 AXDescriptionFrom descriptionFrom; | 648 AXDescriptionFrom descriptionFrom; |
| 510 AXObject::AXObjectVector descriptionObjects; | 649 AXObject::AXObjectVector descriptionObjects; |
| 511 String description = | 650 String description = |
| 512 axObject.description(nameFrom, descriptionFrom, &descriptionObjects); | 651 axObject.description(nameFrom, descriptionFrom, &descriptionObjects); |
| 513 if (!description.isEmpty()) { | 652 if (!description.isEmpty()) { |
| 514 nodeObject.setDescription( | 653 nodeObject.setDescription( |
| 515 createValue(description, AXValueTypeEnum::ComputedString)); | 654 createValue(description, AXValueTypeEnum::ComputedString)); |
| 516 } | 655 } |
| 517 // Value. | 656 // Value. |
| 518 if (axObject.supportsRangeValue()) { | 657 if (axObject.supportsRangeValue()) { |
| 519 nodeObject.setValue(createValue(axObject.valueForRange())); | 658 nodeObject.setValue(createValue(axObject.valueForRange())); |
| 520 } else { | 659 } else { |
| 521 String stringValue = axObject.stringValue(); | 660 String stringValue = axObject.stringValue(); |
| 522 if (!stringValue.isEmpty()) | 661 if (!stringValue.isEmpty()) |
| 523 nodeObject.setValue(createValue(stringValue)); | 662 nodeObject.setValue(createValue(stringValue)); |
| 524 } | 663 } |
| 664 |
| 665 if (fetchRelatives) |
| 666 populateRelatives(axObject, inspectedAXObject, nodeObject, nodes, cache); |
| 667 |
| 668 Node* node = axObject.getNode(); |
| 669 if (node) |
| 670 nodeObject.setBackendDomNodeId(DOMNodeIds::idForNode(node)); |
| 671 } |
| 672 |
| 673 void InspectorAccessibilityAgent::populateRelatives( |
| 674 AXObject& axObject, |
| 675 AXObject* inspectedAXObject, |
| 676 AXNode& nodeObject, |
| 677 std::unique_ptr<protocol::Array<AXNode>>& nodes, |
| 678 AXObjectCacheImpl& cache) const { |
| 679 AXObject* parentObject = axObject.parentObject(); |
| 680 if (parentObject && parentObject != inspectedAXObject) { |
| 681 // Use unignored parent unless parent is inspected ignored object. |
| 682 parentObject = axObject.parentObjectUnignored(); |
| 683 } |
| 684 |
| 685 std::unique_ptr<protocol::Array<AXNodeId>> childIds = |
| 686 protocol::Array<AXNodeId>::create(); |
| 687 |
| 688 if (inspectedAXObject && |
| 689 &axObject == inspectedAXObject->parentObjectUnignored() && |
| 690 inspectedAXObject->accessibilityIsIgnored()) { |
| 691 // This is the parent of an ignored object, so search for its siblings. |
| 692 addSiblingsOfIgnored(childIds, axObject, inspectedAXObject, nodes, cache); |
| 693 } else { |
| 694 addChildren(axObject, inspectedAXObject, childIds, nodes, cache); |
| 695 } |
| 696 nodeObject.setChildIds(std::move(childIds)); |
| 697 } |
| 698 |
| 699 void InspectorAccessibilityAgent::addSiblingsOfIgnored( |
| 700 std::unique_ptr<protocol::Array<AXNodeId>>& childIds, |
| 701 AXObject& parentAXObject, |
| 702 AXObject* inspectedAXObject, |
| 703 std::unique_ptr<protocol::Array<AXNode>>& nodes, |
| 704 AXObjectCacheImpl& cache) const { |
| 705 for (AXObject* childAXObject = parentAXObject.rawFirstChild(); childAXObject; |
| 706 childAXObject = childAXObject->rawNextSibling()) { |
| 707 if (!childAXObject->accessibilityIsIgnored() || |
| 708 childAXObject == inspectedAXObject) { |
| 709 addChild(childIds, *childAXObject, inspectedAXObject, nodes, cache); |
| 710 continue; |
| 711 } |
| 712 |
| 713 if (isAncestorOf(childAXObject, inspectedAXObject)) { |
| 714 addSiblingsOfIgnored(childIds, *childAXObject, inspectedAXObject, nodes, |
| 715 cache); |
| 716 continue; |
| 717 } |
| 718 |
| 719 const AXObject::AXObjectVector& indirectChildren = |
| 720 childAXObject->children(); |
| 721 for (unsigned i = 0; i < indirectChildren.size(); ++i) { |
| 722 addChild(childIds, *(indirectChildren[i]), inspectedAXObject, nodes, |
| 723 cache); |
| 724 } |
| 725 } |
| 726 } |
| 727 |
| 728 void InspectorAccessibilityAgent::addChild( |
| 729 std::unique_ptr<protocol::Array<AXNodeId>>& childIds, |
| 730 AXObject& childAXObject, |
| 731 AXObject* inspectedAXObject, |
| 732 std::unique_ptr<protocol::Array<AXNode>>& nodes, |
| 733 AXObjectCacheImpl& cache) const { |
| 734 childIds->addItem(String::number(childAXObject.axObjectID())); |
| 735 if (&childAXObject == inspectedAXObject) |
| 736 return; |
| 737 nodes->addItem(buildProtocolAXObject(childAXObject, inspectedAXObject, true, |
| 738 nodes, cache)); |
| 739 } |
| 740 |
| 741 void InspectorAccessibilityAgent::addChildren( |
| 742 AXObject& axObject, |
| 743 AXObject* inspectedAXObject, |
| 744 std::unique_ptr<protocol::Array<AXNodeId>>& childIds, |
| 745 std::unique_ptr<protocol::Array<AXNode>>& nodes, |
| 746 AXObjectCacheImpl& cache) const { |
| 747 const AXObject::AXObjectVector& children = axObject.children(); |
| 748 for (unsigned i = 0; i < children.size(); i++) { |
| 749 AXObject& childAXObject = *children[i].get(); |
| 750 childIds->addItem(String::number(childAXObject.axObjectID())); |
| 751 if (&childAXObject != inspectedAXObject && |
| 752 (&axObject == inspectedAXObject || |
| 753 (inspectedAXObject && |
| 754 &axObject == inspectedAXObject->parentObjectUnignored()))) { |
| 755 // Only add children/siblings of inspected node to returned nodes. |
| 756 std::unique_ptr<AXNode> childNode = buildProtocolAXObject( |
| 757 childAXObject, inspectedAXObject, true, nodes, cache); |
| 758 nodes->addItem(std::move(childNode)); |
| 759 } |
| 760 } |
| 525 } | 761 } |
| 526 | 762 |
| 527 DEFINE_TRACE(InspectorAccessibilityAgent) { | 763 DEFINE_TRACE(InspectorAccessibilityAgent) { |
| 528 visitor->trace(m_page); | 764 visitor->trace(m_page); |
| 529 visitor->trace(m_domAgent); | 765 visitor->trace(m_domAgent); |
| 530 InspectorBaseAgent::trace(visitor); | 766 InspectorBaseAgent::trace(visitor); |
| 531 } | 767 } |
| 532 | 768 |
| 533 } // namespace blink | 769 } // namespace blink |
| OLD | NEW |