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