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" |
11 #include "core/dom/Node.h" | 11 #include "core/dom/Node.h" |
12 #include "core/dom/NodeList.h" | 12 #include "core/dom/NodeList.h" |
| 13 #include "core/dom/shadow/ElementShadow.h" |
13 #include "core/inspector/IdentifiersFactory.h" | 14 #include "core/inspector/IdentifiersFactory.h" |
14 #include "core/inspector/InspectorDOMAgent.h" | 15 #include "core/inspector/InspectorDOMAgent.h" |
15 #include "core/inspector/InspectorStyleSheet.h" | 16 #include "core/inspector/InspectorStyleSheet.h" |
16 #include "core/page/Page.h" | 17 #include "core/page/Page.h" |
17 #include "modules/accessibility/AXObject.h" | 18 #include "modules/accessibility/AXObject.h" |
18 #include "modules/accessibility/AXObjectCacheImpl.h" | 19 #include "modules/accessibility/AXObjectCacheImpl.h" |
19 #include "modules/accessibility/InspectorTypeBuilderHelper.h" | 20 #include "modules/accessibility/InspectorTypeBuilderHelper.h" |
20 #include <memory> | 21 #include <memory> |
21 | 22 |
22 namespace blink { | 23 namespace blink { |
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 std::unique_ptr<protocol::Array<AXNode>>& nodes, | 504 std::unique_ptr<protocol::Array<AXNode>>& nodes, |
504 AXObjectCacheImpl& cache) const { | 505 AXObjectCacheImpl& cache) const { |
505 // Populate children. | 506 // Populate children. |
506 std::unique_ptr<protocol::Array<AXNodeId>> childIds = | 507 std::unique_ptr<protocol::Array<AXNodeId>> childIds = |
507 protocol::Array<AXNodeId>::create(); | 508 protocol::Array<AXNodeId>::create(); |
508 findDOMNodeChildren(childIds, inspectedDOMNode, inspectedDOMNode, nodes, | 509 findDOMNodeChildren(childIds, inspectedDOMNode, inspectedDOMNode, nodes, |
509 cache); | 510 cache); |
510 nodeObject.setChildIds(std::move(childIds)); | 511 nodeObject.setChildIds(std::move(childIds)); |
511 | 512 |
512 // Walk up parents until an AXObject can be found. | 513 // Walk up parents until an AXObject can be found. |
513 Node* parentNode = FlatTreeTraversal::parent(inspectedDOMNode); | 514 Node* parentNode = inspectedDOMNode.isShadowRoot() |
| 515 ? &toShadowRoot(inspectedDOMNode).host() |
| 516 : FlatTreeTraversal::parent(inspectedDOMNode); |
514 AXObject* parentAXObject = cache.getOrCreate(parentNode); | 517 AXObject* parentAXObject = cache.getOrCreate(parentNode); |
515 while (parentNode && !parentAXObject) { | 518 while (parentNode && !parentAXObject) { |
516 parentNode = FlatTreeTraversal::parent(inspectedDOMNode); | 519 parentNode = parentNode->isShadowRoot() |
| 520 ? &toShadowRoot(parentNode)->host() |
| 521 : FlatTreeTraversal::parent(*parentNode); |
517 parentAXObject = cache.getOrCreate(parentNode); | 522 parentAXObject = cache.getOrCreate(parentNode); |
518 }; | 523 }; |
519 | 524 |
520 if (!parentAXObject) | 525 if (!parentAXObject) |
521 return; | 526 return; |
522 | 527 |
523 if (parentAXObject->accessibilityIsIgnored()) | 528 if (parentAXObject->accessibilityIsIgnored()) |
524 parentAXObject = parentAXObject->parentObjectUnignored(); | 529 parentAXObject = parentAXObject->parentObjectUnignored(); |
525 if (!parentAXObject) | 530 if (!parentAXObject) |
526 return; | 531 return; |
(...skipping 11 matching lines...) Expand all Loading... |
538 if (grandparentAXObject) | 543 if (grandparentAXObject) |
539 addAncestors(*grandparentAXObject, nullptr, nodes, cache); | 544 addAncestors(*grandparentAXObject, nullptr, nodes, cache); |
540 } | 545 } |
541 | 546 |
542 void InspectorAccessibilityAgent::findDOMNodeChildren( | 547 void InspectorAccessibilityAgent::findDOMNodeChildren( |
543 std::unique_ptr<protocol::Array<AXNodeId>>& childIds, | 548 std::unique_ptr<protocol::Array<AXNodeId>>& childIds, |
544 Node& parentNode, | 549 Node& parentNode, |
545 Node& inspectedDOMNode, | 550 Node& inspectedDOMNode, |
546 std::unique_ptr<protocol::Array<AXNode>>& nodes, | 551 std::unique_ptr<protocol::Array<AXNode>>& nodes, |
547 AXObjectCacheImpl& cache) const { | 552 AXObjectCacheImpl& cache) const { |
| 553 if (inspectedDOMNode.isShadowRoot() && |
| 554 &parentNode == toShadowRoot(inspectedDOMNode).host()) { |
| 555 childIds->addItem(String::number(kIDForInspectedNodeWithNoAXNode)); |
| 556 return; |
| 557 } |
548 NodeList* childNodes = parentNode.childNodes(); | 558 NodeList* childNodes = parentNode.childNodes(); |
| 559 if (!childNodes->length() && parentNode.isElementNode()) { |
| 560 Element& parentElement = toElement(parentNode); |
| 561 ElementShadow* elementShadow = parentElement.shadow(); |
| 562 if (elementShadow) { |
| 563 ShadowRoot& shadowRoot = elementShadow->youngestShadowRoot(); |
| 564 childNodes = shadowRoot.childNodes(); |
| 565 } |
| 566 } |
549 for (size_t i = 0; i < childNodes->length(); ++i) { | 567 for (size_t i = 0; i < childNodes->length(); ++i) { |
550 Node* childNode = childNodes->item(i); | 568 Node* childNode = childNodes->item(i); |
551 if (childNode == &inspectedDOMNode) { | 569 if (childNode == &inspectedDOMNode) { |
552 childIds->addItem(String::number(kIDForInspectedNodeWithNoAXNode)); | 570 childIds->addItem(String::number(kIDForInspectedNodeWithNoAXNode)); |
553 continue; | 571 continue; |
554 } | 572 } |
555 | 573 |
556 AXObject* childAXObject = cache.getOrCreate(childNode); | 574 AXObject* childAXObject = cache.getOrCreate(childNode); |
557 if (childAXObject) { | 575 if (childAXObject) { |
558 if (childAXObject->accessibilityIsIgnored()) { | 576 if (childAXObject->accessibilityIsIgnored()) { |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
766 } | 784 } |
767 } | 785 } |
768 | 786 |
769 DEFINE_TRACE(InspectorAccessibilityAgent) { | 787 DEFINE_TRACE(InspectorAccessibilityAgent) { |
770 visitor->trace(m_page); | 788 visitor->trace(m_page); |
771 visitor->trace(m_domAgent); | 789 visitor->trace(m_domAgent); |
772 InspectorBaseAgent::trace(visitor); | 790 InspectorBaseAgent::trace(visitor); |
773 } | 791 } |
774 | 792 |
775 } // namespace blink | 793 } // namespace blink |
OLD | NEW |