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 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 return roleNameValue; | 373 return roleNameValue; |
374 } | 374 } |
375 | 375 |
376 } // namespace | 376 } // namespace |
377 | 377 |
378 InspectorAccessibilityAgent::InspectorAccessibilityAgent( | 378 InspectorAccessibilityAgent::InspectorAccessibilityAgent( |
379 Page* page, | 379 Page* page, |
380 InspectorDOMAgent* domAgent) | 380 InspectorDOMAgent* domAgent) |
381 : m_page(page), m_domAgent(domAgent) {} | 381 : m_page(page), m_domAgent(domAgent) {} |
382 | 382 |
383 void InspectorAccessibilityAgent::getAXNodeChain( | 383 Response InspectorAccessibilityAgent::getAXNodeChain( |
384 ErrorString* errorString, | |
385 int domNodeId, | 384 int domNodeId, |
386 bool fetchAncestors, | 385 bool fetchAncestors, |
387 std::unique_ptr<protocol::Array<protocol::Accessibility::AXNode>>* nodes) { | 386 std::unique_ptr<protocol::Array<protocol::Accessibility::AXNode>>* nodes) { |
388 if (!m_domAgent->enabled()) { | 387 if (!m_domAgent->enabled()) |
389 *errorString = "DOM agent must be enabled"; | 388 return Response::Error("DOM agent must be enabled"); |
390 return; | |
391 } | |
392 Node* domNode = nullptr; | 389 Node* domNode = nullptr; |
393 Response response = m_domAgent->assertNode(domNodeId, domNode); | 390 Response response = m_domAgent->assertNode(domNodeId, domNode); |
394 if (!response.isSuccess()) { | 391 if (!response.isSuccess()) |
395 *errorString = response.errorMessage(); | 392 return response; |
396 return; | |
397 } | |
398 | 393 |
399 Document& document = domNode->document(); | 394 Document& document = domNode->document(); |
400 document.updateStyleAndLayoutIgnorePendingStylesheets(); | 395 document.updateStyleAndLayoutIgnorePendingStylesheets(); |
401 DocumentLifecycle::DisallowTransitionScope disallowTransition( | 396 DocumentLifecycle::DisallowTransitionScope disallowTransition( |
402 document.lifecycle()); | 397 document.lifecycle()); |
403 LocalFrame* localFrame = document.frame(); | 398 LocalFrame* localFrame = document.frame(); |
404 if (!localFrame) { | 399 if (!localFrame) |
405 *errorString = "Frame is detached."; | 400 return Response::Error("Frame is detached."); |
406 return; | |
407 } | |
408 std::unique_ptr<ScopedAXObjectCache> scopedCache = | 401 std::unique_ptr<ScopedAXObjectCache> scopedCache = |
409 ScopedAXObjectCache::create(document); | 402 ScopedAXObjectCache::create(document); |
410 AXObjectCacheImpl* cache = toAXObjectCacheImpl(scopedCache->get()); | 403 AXObjectCacheImpl* cache = toAXObjectCacheImpl(scopedCache->get()); |
411 | 404 |
412 AXObject* inspectedAXObject = cache->getOrCreate(domNode); | 405 AXObject* inspectedAXObject = cache->getOrCreate(domNode); |
413 *nodes = protocol::Array<protocol::Accessibility::AXNode>::create(); | 406 *nodes = protocol::Array<protocol::Accessibility::AXNode>::create(); |
414 if (!inspectedAXObject || inspectedAXObject->accessibilityIsIgnored()) { | 407 if (!inspectedAXObject || inspectedAXObject->accessibilityIsIgnored()) { |
415 (*nodes)->addItem(buildObjectForIgnoredNode(domNode, inspectedAXObject)); | 408 (*nodes)->addItem(buildObjectForIgnoredNode(domNode, inspectedAXObject)); |
416 } else { | 409 } else { |
417 (*nodes)->addItem(buildProtocolAXObject(*inspectedAXObject)); | 410 (*nodes)->addItem(buildProtocolAXObject(*inspectedAXObject)); |
418 } | 411 } |
419 | 412 |
420 if (fetchAncestors && inspectedAXObject) { | 413 if (fetchAncestors && inspectedAXObject) { |
421 AXObject* parent = inspectedAXObject->parentObjectUnignored(); | 414 AXObject* parent = inspectedAXObject->parentObjectUnignored(); |
422 while (parent) { | 415 while (parent) { |
423 (*nodes)->addItem(buildProtocolAXObject(*parent)); | 416 (*nodes)->addItem(buildProtocolAXObject(*parent)); |
424 parent = parent->parentObjectUnignored(); | 417 parent = parent->parentObjectUnignored(); |
425 } | 418 } |
426 } | 419 } |
| 420 return Response::OK(); |
427 } | 421 } |
428 | 422 |
429 std::unique_ptr<AXNode> InspectorAccessibilityAgent::buildObjectForIgnoredNode( | 423 std::unique_ptr<AXNode> InspectorAccessibilityAgent::buildObjectForIgnoredNode( |
430 Node* domNode, | 424 Node* domNode, |
431 AXObject* axObject) const { | 425 AXObject* axObject) const { |
432 AXObject::IgnoredReasons ignoredReasons; | 426 AXObject::IgnoredReasons ignoredReasons; |
433 | 427 |
434 AXID axID = 0; | 428 AXID axID = 0; |
435 if (axObject) | 429 if (axObject) |
436 axID = axObject->axObjectID(); | 430 axID = axObject->axObjectID(); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 } | 521 } |
528 } | 522 } |
529 | 523 |
530 DEFINE_TRACE(InspectorAccessibilityAgent) { | 524 DEFINE_TRACE(InspectorAccessibilityAgent) { |
531 visitor->trace(m_page); | 525 visitor->trace(m_page); |
532 visitor->trace(m_domAgent); | 526 visitor->trace(m_domAgent); |
533 InspectorBaseAgent::trace(visitor); | 527 InspectorBaseAgent::trace(visitor); |
534 } | 528 } |
535 | 529 |
536 } // namespace blink | 530 } // namespace blink |
OLD | NEW |