| 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 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 std::unique_ptr<ScopedAXObjectCache> scopedCache = | 463 std::unique_ptr<ScopedAXObjectCache> scopedCache = |
| 464 ScopedAXObjectCache::create(document); | 464 ScopedAXObjectCache::create(document); |
| 465 AXObjectCacheImpl* cache = toAXObjectCacheImpl(scopedCache->get()); | 465 AXObjectCacheImpl* cache = toAXObjectCacheImpl(scopedCache->get()); |
| 466 | 466 |
| 467 AXObject* inspectedAXObject = cache->getOrCreate(domNode); | 467 AXObject* inspectedAXObject = cache->getOrCreate(domNode); |
| 468 *nodes = protocol::Array<protocol::Accessibility::AXNode>::create(); | 468 *nodes = protocol::Array<protocol::Accessibility::AXNode>::create(); |
| 469 if (!inspectedAXObject || inspectedAXObject->accessibilityIsIgnored()) { | 469 if (!inspectedAXObject || inspectedAXObject->accessibilityIsIgnored()) { |
| 470 (*nodes)->addItem(buildObjectForIgnoredNode(domNode, inspectedAXObject, | 470 (*nodes)->addItem(buildObjectForIgnoredNode(domNode, inspectedAXObject, |
| 471 fetchRelatives.fromMaybe(true), | 471 fetchRelatives.fromMaybe(true), |
| 472 *nodes, *cache)); | 472 *nodes, *cache)); |
| 473 return Response::OK(); |
| 473 } else { | 474 } else { |
| 474 (*nodes)->addItem( | 475 (*nodes)->addItem( |
| 475 buildProtocolAXObject(*inspectedAXObject, inspectedAXObject, | 476 buildProtocolAXObject(*inspectedAXObject, inspectedAXObject, |
| 476 fetchRelatives.fromMaybe(true), *nodes, *cache)); | 477 fetchRelatives.fromMaybe(true), *nodes, *cache)); |
| 477 } | 478 } |
| 478 | 479 |
| 479 if (!inspectedAXObject || !inspectedAXObject->isAXLayoutObject()) | 480 if (!inspectedAXObject) |
| 480 return Response::OK(); | 481 return Response::OK(); |
| 481 | 482 |
| 482 AXObject* parent = inspectedAXObject->parentObjectUnignored(); | 483 AXObject* parent = inspectedAXObject->parentObjectUnignored(); |
| 483 if (!parent) | 484 if (!parent) |
| 484 return Response::OK(); | 485 return Response::OK(); |
| 485 | 486 |
| 486 if (fetchRelatives.fromMaybe(true)) | 487 if (fetchRelatives.fromMaybe(true)) |
| 487 addAncestors(*parent, inspectedAXObject, *nodes, *cache); | 488 addAncestors(*parent, inspectedAXObject, *nodes, *cache); |
| 488 | 489 |
| 489 return Response::OK(); | 490 return Response::OK(); |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 690 std::unique_ptr<protocol::Array<AXNodeId>> childIds = | 691 std::unique_ptr<protocol::Array<AXNodeId>> childIds = |
| 691 protocol::Array<AXNodeId>::create(); | 692 protocol::Array<AXNodeId>::create(); |
| 692 | 693 |
| 693 if (&axObject != inspectedAXObject || | 694 if (&axObject != inspectedAXObject || |
| 694 (inspectedAXObject && !inspectedAXObject->accessibilityIsIgnored())) { | 695 (inspectedAXObject && !inspectedAXObject->accessibilityIsIgnored())) { |
| 695 addChildren(axObject, inspectedAXObject, childIds, nodes, cache); | 696 addChildren(axObject, inspectedAXObject, childIds, nodes, cache); |
| 696 } | 697 } |
| 697 nodeObject.setChildIds(std::move(childIds)); | 698 nodeObject.setChildIds(std::move(childIds)); |
| 698 } | 699 } |
| 699 | 700 |
| 700 void InspectorAccessibilityAgent::addChild( | |
| 701 std::unique_ptr<protocol::Array<AXNodeId>>& childIds, | |
| 702 AXObject& childAXObject, | |
| 703 AXObject* inspectedAXObject, | |
| 704 std::unique_ptr<protocol::Array<AXNode>>& nodes, | |
| 705 AXObjectCacheImpl& cache) const { | |
| 706 childIds->addItem(String::number(childAXObject.axObjectID())); | |
| 707 if (&childAXObject == inspectedAXObject) | |
| 708 return; | |
| 709 nodes->addItem(buildProtocolAXObject(childAXObject, inspectedAXObject, true, | |
| 710 nodes, cache)); | |
| 711 } | |
| 712 | |
| 713 void InspectorAccessibilityAgent::addChildren( | 701 void InspectorAccessibilityAgent::addChildren( |
| 714 AXObject& axObject, | 702 AXObject& axObject, |
| 715 AXObject* inspectedAXObject, | 703 AXObject* inspectedAXObject, |
| 716 std::unique_ptr<protocol::Array<AXNodeId>>& childIds, | 704 std::unique_ptr<protocol::Array<AXNodeId>>& childIds, |
| 717 std::unique_ptr<protocol::Array<AXNode>>& nodes, | 705 std::unique_ptr<protocol::Array<AXNode>>& nodes, |
| 718 AXObjectCacheImpl& cache) const { | 706 AXObjectCacheImpl& cache) const { |
| 719 if (inspectedAXObject && inspectedAXObject->accessibilityIsIgnored() && | 707 if (inspectedAXObject && inspectedAXObject->accessibilityIsIgnored() && |
| 720 &axObject == inspectedAXObject->parentObjectUnignored()) { | 708 &axObject == inspectedAXObject->parentObjectUnignored()) { |
| 721 childIds->addItem(String::number(inspectedAXObject->axObjectID())); | 709 childIds->addItem(String::number(inspectedAXObject->axObjectID())); |
| 722 return; | 710 return; |
| 723 } | 711 } |
| 724 | 712 |
| 725 const AXObject::AXObjectVector& children = axObject.children(); | 713 const AXObject::AXObjectVector& children = axObject.children(); |
| 726 for (unsigned i = 0; i < children.size(); i++) { | 714 for (unsigned i = 0; i < children.size(); i++) { |
| 727 AXObject& childAXObject = *children[i].get(); | 715 AXObject& childAXObject = *children[i].get(); |
| 728 childIds->addItem(String::number(childAXObject.axObjectID())); | 716 childIds->addItem(String::number(childAXObject.axObjectID())); |
| 729 if (&childAXObject == inspectedAXObject) | 717 if (&childAXObject == inspectedAXObject) |
| 730 continue; | 718 continue; |
| 731 if (&axObject != inspectedAXObject) { | 719 if (&axObject != inspectedAXObject && |
| 732 if (!inspectedAXObject) | 720 (axObject.getNode() || |
| 733 continue; | 721 axObject.parentObjectUnignored() != inspectedAXObject)) { |
| 734 if (&axObject != inspectedAXObject->parentObjectUnignored()) | 722 continue; |
| 735 continue; | |
| 736 } | 723 } |
| 737 | 724 |
| 738 // Only add children/siblings of inspected node to returned nodes. | 725 // Only add children of inspected node (or un-inspectable children of |
| 726 // inspected node) to returned nodes. |
| 739 std::unique_ptr<AXNode> childNode = buildProtocolAXObject( | 727 std::unique_ptr<AXNode> childNode = buildProtocolAXObject( |
| 740 childAXObject, inspectedAXObject, true, nodes, cache); | 728 childAXObject, inspectedAXObject, true, nodes, cache); |
| 741 nodes->addItem(std::move(childNode)); | 729 nodes->addItem(std::move(childNode)); |
| 742 } | 730 } |
| 743 } | 731 } |
| 744 | 732 |
| 745 DEFINE_TRACE(InspectorAccessibilityAgent) { | 733 DEFINE_TRACE(InspectorAccessibilityAgent) { |
| 746 visitor->trace(m_page); | 734 visitor->trace(m_page); |
| 747 visitor->trace(m_domAgent); | 735 visitor->trace(m_domAgent); |
| 748 InspectorBaseAgent::trace(visitor); | 736 InspectorBaseAgent::trace(visitor); |
| 749 } | 737 } |
| 750 | 738 |
| 751 } // namespace blink | 739 } // namespace blink |
| OLD | NEW |