Chromium Code Reviews| 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 // Walk up parents until an AXObject can be found. | |
| 506 Node* parentNode = FlatTreeTraversal::parent(inspectedDOMNode); | |
| 507 AXObject* parentAXObject = cache.getOrCreate(parentNode); | |
| 508 while (parentNode && !parentAXObject) { | |
| 509 parentNode = FlatTreeTraversal::parent(inspectedDOMNode); | |
| 510 parentAXObject = cache.getOrCreate(parentNode); | |
| 511 }; | |
| 512 if (parentAXObject) { | |
| 513 if (parentAXObject->accessibilityIsIgnored()) | |
| 514 parentAXObject = parentAXObject->parentObjectUnignored(); | |
|
dgozman
2016/11/08 16:38:41
Could this return nullptr? Let's null-check.
aboxhall
2016/11/08 18:02:18
Done.
(This shouldn't happen in practice, since t
| |
| 515 // Populate parent, ancestors and siblings. | |
| 516 std::unique_ptr<AXNode> parentNodeObject = | |
| 517 buildProtocolAXObject(*parentAXObject, nullptr, true, nodes, cache); | |
| 518 std::unique_ptr<protocol::Array<AXNodeId>> siblingIds = | |
| 519 protocol::Array<AXNodeId>::create(); | |
| 520 findDOMNodeChildren(siblingIds, *parentNode, inspectedDOMNode, nodes, | |
| 521 cache); | |
| 522 parentNodeObject->setChildIds(std::move(siblingIds)); | |
| 523 nodes->addItem(std::move(parentNodeObject)); | |
| 524 | |
| 525 AXObject* grandparentAXObject = parentAXObject->parentObjectUnignored(); | |
| 526 if (grandparentAXObject) | |
| 527 addAncestors(*grandparentAXObject, nullptr, nodes, cache); | |
| 528 } | |
| 529 | |
| 530 // Then populate children. | |
| 531 std::unique_ptr<protocol::Array<AXNodeId>> childIds = | |
| 532 protocol::Array<AXNodeId>::create(); | |
| 533 findDOMNodeChildren(childIds, inspectedDOMNode, inspectedDOMNode, nodes, | |
| 534 cache); | |
| 535 nodeObject.setChildIds(std::move(childIds)); | |
| 536 } | |
| 537 | |
| 538 void InspectorAccessibilityAgent::findDOMNodeChildren( | |
| 539 std::unique_ptr<protocol::Array<AXNodeId>>& childIds, | |
| 540 Node& parentNode, | |
| 541 Node& inspectedDOMNode, | |
| 542 std::unique_ptr<protocol::Array<AXNode>>& nodes, | |
| 543 AXObjectCacheImpl& cache) const { | |
| 544 NodeList* childNodes = parentNode.childNodes(); | |
| 545 for (size_t i = 0; i < childNodes->length(); ++i) { | |
| 546 Node* childNode = childNodes->item(i); | |
| 547 if (childNode == &inspectedDOMNode) { | |
| 548 childIds->addItem(String::number(kIDForInspectedNodeWithNoAXNode)); | |
| 549 continue; | |
| 550 } | |
| 551 | |
| 552 AXObject* childAXObject = cache.getOrCreate(childNode); | |
| 553 if (childAXObject) { | |
| 554 if (childAXObject->accessibilityIsIgnored()) { | |
| 555 // search for un-ignored descendants | |
| 556 findDOMNodeChildren(childIds, *childNode, inspectedDOMNode, nodes, | |
| 557 cache); | |
| 558 } else { | |
| 559 addChild(childIds, *childAXObject, nullptr, nodes, cache); | |
| 560 } | |
| 561 | |
| 562 continue; | |
| 563 } | |
| 564 | |
| 565 if (!childAXObject || | |
| 566 childNode->isShadowIncludingInclusiveAncestorOf(&inspectedDOMNode)) { | |
| 567 // If the inspected node may be a descendant of this node, keep walking | |
| 568 // recursively until we find its actual siblings. | |
| 569 findDOMNodeChildren(childIds, *childNode, inspectedDOMNode, nodes, cache); | |
| 570 continue; | |
| 571 } | |
| 572 | |
| 573 // Otherwise, just add the un-ignored children. | |
| 574 const AXObject::AXObjectVector& indirectChildren = | |
| 575 childAXObject->children(); | |
| 576 for (unsigned i = 0; i < indirectChildren.size(); ++i) | |
| 577 addChild(childIds, *(indirectChildren[i]), nullptr, nodes, cache); | |
| 578 } | |
| 579 } | |
| 580 | |
| 451 std::unique_ptr<AXNode> InspectorAccessibilityAgent::buildProtocolAXObject( | 581 std::unique_ptr<AXNode> InspectorAccessibilityAgent::buildProtocolAXObject( |
| 452 AXObject& axObject) const { | 582 AXObject& axObject, |
| 583 AXObject* inspectedAXObject, | |
| 584 bool fetchRelatives, | |
| 585 std::unique_ptr<protocol::Array<AXNode>>& nodes, | |
| 586 AXObjectCacheImpl& cache) const { | |
| 453 AccessibilityRole role = axObject.roleValue(); | 587 AccessibilityRole role = axObject.roleValue(); |
| 454 std::unique_ptr<AXNode> nodeObject = | 588 std::unique_ptr<AXNode> nodeObject = |
| 455 AXNode::create() | 589 AXNode::create() |
| 456 .setNodeId(String::number(axObject.axObjectID())) | 590 .setNodeId(String::number(axObject.axObjectID())) |
| 457 .setIgnored(false) | 591 .setIgnored(false) |
| 458 .build(); | 592 .build(); |
| 459 nodeObject->setRole(createRoleNameValue(role)); | 593 nodeObject->setRole(createRoleNameValue(role)); |
| 460 | 594 |
| 461 std::unique_ptr<protocol::Array<AXProperty>> properties = | 595 std::unique_ptr<protocol::Array<AXProperty>> properties = |
| 462 protocol::Array<AXProperty>::create(); | 596 protocol::Array<AXProperty>::create(); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 486 } | 620 } |
| 487 } | 621 } |
| 488 name->setSources(std::move(nameSourceProperties)); | 622 name->setSources(std::move(nameSourceProperties)); |
| 489 } | 623 } |
| 490 nodeObject->setProperties(std::move(properties)); | 624 nodeObject->setProperties(std::move(properties)); |
| 491 nodeObject->setName(std::move(name)); | 625 nodeObject->setName(std::move(name)); |
| 492 } else { | 626 } else { |
| 493 nodeObject->setProperties(std::move(properties)); | 627 nodeObject->setProperties(std::move(properties)); |
| 494 } | 628 } |
| 495 | 629 |
| 496 fillCoreProperties(axObject, *(nodeObject.get())); | 630 fillCoreProperties(axObject, inspectedAXObject, fetchRelatives, |
| 631 *(nodeObject.get()), nodes, cache); | |
| 497 return nodeObject; | 632 return nodeObject; |
| 498 } | 633 } |
| 499 | 634 |
| 500 void InspectorAccessibilityAgent::fillCoreProperties(AXObject& axObject, | 635 void InspectorAccessibilityAgent::fillCoreProperties( |
| 501 AXNode& nodeObject) const { | 636 AXObject& axObject, |
| 637 AXObject* inspectedAXObject, | |
| 638 bool fetchRelatives, | |
| 639 AXNode& nodeObject, | |
| 640 std::unique_ptr<protocol::Array<AXNode>>& nodes, | |
| 641 AXObjectCacheImpl& cache) const { | |
| 502 AXNameFrom nameFrom; | 642 AXNameFrom nameFrom; |
| 503 AXObject::AXObjectVector nameObjects; | 643 AXObject::AXObjectVector nameObjects; |
| 504 axObject.name(nameFrom, &nameObjects); | 644 axObject.name(nameFrom, &nameObjects); |
| 505 | 645 |
| 506 AXDescriptionFrom descriptionFrom; | 646 AXDescriptionFrom descriptionFrom; |
| 507 AXObject::AXObjectVector descriptionObjects; | 647 AXObject::AXObjectVector descriptionObjects; |
| 508 String description = | 648 String description = |
| 509 axObject.description(nameFrom, descriptionFrom, &descriptionObjects); | 649 axObject.description(nameFrom, descriptionFrom, &descriptionObjects); |
| 510 if (!description.isEmpty()) { | 650 if (!description.isEmpty()) { |
| 511 nodeObject.setDescription( | 651 nodeObject.setDescription( |
| 512 createValue(description, AXValueTypeEnum::ComputedString)); | 652 createValue(description, AXValueTypeEnum::ComputedString)); |
| 513 } | 653 } |
| 514 // Value. | 654 // Value. |
| 515 if (axObject.supportsRangeValue()) { | 655 if (axObject.supportsRangeValue()) { |
| 516 nodeObject.setValue(createValue(axObject.valueForRange())); | 656 nodeObject.setValue(createValue(axObject.valueForRange())); |
| 517 } else { | 657 } else { |
| 518 String stringValue = axObject.stringValue(); | 658 String stringValue = axObject.stringValue(); |
| 519 if (!stringValue.isEmpty()) | 659 if (!stringValue.isEmpty()) |
| 520 nodeObject.setValue(createValue(stringValue)); | 660 nodeObject.setValue(createValue(stringValue)); |
| 521 } | 661 } |
| 662 | |
| 663 if (fetchRelatives) | |
| 664 populateRelatives(axObject, inspectedAXObject, nodeObject, nodes, cache); | |
| 665 | |
| 666 Node* node = axObject.getNode(); | |
| 667 if (node) | |
| 668 nodeObject.setBackendDOMNodeId(DOMNodeIds::idForNode(node)); | |
| 669 } | |
| 670 | |
| 671 void InspectorAccessibilityAgent::populateRelatives( | |
| 672 AXObject& axObject, | |
| 673 AXObject* inspectedAXObject, | |
| 674 AXNode& nodeObject, | |
| 675 std::unique_ptr<protocol::Array<AXNode>>& nodes, | |
| 676 AXObjectCacheImpl& cache) const { | |
| 677 AXObject* parentObject = axObject.parentObject(); | |
| 678 if (parentObject && parentObject != inspectedAXObject) { | |
| 679 // Use unignored parent unless parent is inspected ignored object. | |
| 680 parentObject = axObject.parentObjectUnignored(); | |
| 681 } | |
| 682 | |
| 683 std::unique_ptr<protocol::Array<AXNodeId>> childIds = | |
| 684 protocol::Array<AXNodeId>::create(); | |
| 685 | |
| 686 if (inspectedAXObject && | |
| 687 &axObject == inspectedAXObject->parentObjectUnignored() && | |
| 688 inspectedAXObject->accessibilityIsIgnored()) { | |
| 689 // This is the parent of an ignored object, so search for its siblings. | |
| 690 addSiblingsOfIgnored(childIds, axObject, inspectedAXObject, nodes, cache); | |
| 691 } else { | |
| 692 addChildren(axObject, inspectedAXObject, childIds, nodes, cache); | |
| 693 } | |
| 694 nodeObject.setChildIds(std::move(childIds)); | |
| 695 } | |
| 696 | |
| 697 void InspectorAccessibilityAgent::addSiblingsOfIgnored( | |
| 698 std::unique_ptr<protocol::Array<AXNodeId>>& childIds, | |
| 699 AXObject& parentAXObject, | |
| 700 AXObject* inspectedAXObject, | |
| 701 std::unique_ptr<protocol::Array<AXNode>>& nodes, | |
| 702 AXObjectCacheImpl& cache) const { | |
| 703 for (AXObject* childAXObject = parentAXObject.rawFirstChild(); childAXObject; | |
| 704 childAXObject = childAXObject->rawNextSibling()) { | |
| 705 if (!childAXObject->accessibilityIsIgnored() || | |
| 706 childAXObject == inspectedAXObject) { | |
| 707 addChild(childIds, *childAXObject, inspectedAXObject, nodes, cache); | |
| 708 continue; | |
| 709 } | |
| 710 | |
| 711 if (isAncestorOf(childAXObject, inspectedAXObject)) { | |
| 712 addSiblingsOfIgnored(childIds, *childAXObject, inspectedAXObject, nodes, | |
| 713 cache); | |
| 714 continue; | |
| 715 } | |
| 716 | |
| 717 const AXObject::AXObjectVector& indirectChildren = | |
| 718 childAXObject->children(); | |
| 719 for (unsigned i = 0; i < indirectChildren.size(); ++i) { | |
| 720 addChild(childIds, *(indirectChildren[i]), inspectedAXObject, nodes, | |
| 721 cache); | |
| 722 } | |
| 723 } | |
| 724 } | |
| 725 | |
| 726 void InspectorAccessibilityAgent::addChild( | |
| 727 std::unique_ptr<protocol::Array<AXNodeId>>& childIds, | |
| 728 AXObject& childAXObject, | |
| 729 AXObject* inspectedAXObject, | |
| 730 std::unique_ptr<protocol::Array<AXNode>>& nodes, | |
| 731 AXObjectCacheImpl& cache) const { | |
| 732 childIds->addItem(String::number(childAXObject.axObjectID())); | |
| 733 if (&childAXObject == inspectedAXObject) | |
| 734 return; | |
| 735 nodes->addItem(buildProtocolAXObject(childAXObject, inspectedAXObject, true, | |
| 736 nodes, cache)); | |
| 737 } | |
| 738 | |
| 739 void InspectorAccessibilityAgent::addChildren( | |
| 740 AXObject& axObject, | |
| 741 AXObject* inspectedAXObject, | |
| 742 std::unique_ptr<protocol::Array<AXNodeId>>& childIds, | |
| 743 std::unique_ptr<protocol::Array<AXNode>>& nodes, | |
| 744 AXObjectCacheImpl& cache) const { | |
| 745 const AXObject::AXObjectVector& children = axObject.children(); | |
| 746 for (unsigned i = 0; i < children.size(); i++) { | |
| 747 AXObject& childAXObject = *children[i].get(); | |
| 748 childIds->addItem(String::number(childAXObject.axObjectID())); | |
| 749 if (&childAXObject != inspectedAXObject && | |
|
dgozman
2016/11/08 16:38:41
Let's break this into multiple if(...)continue.
i
aboxhall
2016/11/08 18:02:18
Done.
| |
| 750 (&axObject == inspectedAXObject || | |
| 751 (inspectedAXObject && | |
| 752 &axObject == inspectedAXObject->parentObjectUnignored()))) { | |
| 753 // Only add children/siblings of inspected node to returned nodes. | |
| 754 std::unique_ptr<AXNode> childNode = buildProtocolAXObject( | |
| 755 childAXObject, inspectedAXObject, true, nodes, cache); | |
| 756 nodes->addItem(std::move(childNode)); | |
| 757 } | |
| 758 } | |
| 522 } | 759 } |
| 523 | 760 |
| 524 DEFINE_TRACE(InspectorAccessibilityAgent) { | 761 DEFINE_TRACE(InspectorAccessibilityAgent) { |
| 525 visitor->trace(m_page); | 762 visitor->trace(m_page); |
| 526 visitor->trace(m_domAgent); | 763 visitor->trace(m_domAgent); |
| 527 InspectorBaseAgent::trace(visitor); | 764 InspectorBaseAgent::trace(visitor); |
| 528 } | 765 } |
| 529 | 766 |
| 530 } // namespace blink | 767 } // namespace blink |
| OLD | NEW |