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