| 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/inspector/IdentifiersFactory.h" | |
| 12 #include "core/inspector/InspectorDOMAgent.h" | 11 #include "core/inspector/InspectorDOMAgent.h" |
| 13 #include "core/inspector/InspectorStyleSheet.h" | 12 #include "core/inspector/InspectorStyleSheet.h" |
| 14 #include "core/page/Page.h" | 13 #include "core/page/Page.h" |
| 15 #include "modules/accessibility/AXObject.h" | 14 #include "modules/accessibility/AXObject.h" |
| 16 #include "modules/accessibility/AXObjectCacheImpl.h" | 15 #include "modules/accessibility/AXObjectCacheImpl.h" |
| 17 #include "modules/accessibility/InspectorTypeBuilderHelper.h" | 16 #include "modules/accessibility/InspectorTypeBuilderHelper.h" |
| 18 #include <memory> | 17 #include <memory> |
| 19 | 18 |
| 20 namespace blink { | 19 namespace blink { |
| 21 | 20 |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 AtomicString roleName = AXObject::roleName(role); | 293 AtomicString roleName = AXObject::roleName(role); |
| 295 std::unique_ptr<AXValue> roleNameValue; | 294 std::unique_ptr<AXValue> roleNameValue; |
| 296 if (!roleName.isNull()) { | 295 if (!roleName.isNull()) { |
| 297 roleNameValue = createValue(roleName, AXValueTypeEnum::Role); | 296 roleNameValue = createValue(roleName, AXValueTypeEnum::Role); |
| 298 } else { | 297 } else { |
| 299 roleNameValue = createValue(AXObject::internalRoleName(role), AXValueTyp
eEnum::InternalRole); | 298 roleNameValue = createValue(AXObject::internalRoleName(role), AXValueTyp
eEnum::InternalRole); |
| 300 } | 299 } |
| 301 return roleNameValue; | 300 return roleNameValue; |
| 302 } | 301 } |
| 303 | 302 |
| 304 std::unique_ptr<AXNode> buildObjectForIgnoredNode(Node* node, const AXObject* ax
Object) | 303 std::unique_ptr<AXNode> buildObjectForIgnoredNode(Node* node, AXObject* axObject
, AXObjectCacheImpl* cacheImpl) |
| 305 { | 304 { |
| 306 AXObject::IgnoredReasons ignoredReasons; | 305 AXObject::IgnoredReasons ignoredReasons; |
| 307 | 306 |
| 308 AXID axID = 0; | 307 AXID axID = 0; |
| 309 std::unique_ptr<AXNode> ignoredNodeObject = AXNode::create().setNodeId(Strin
g::number(axID)).setIgnored(true).build(); | 308 std::unique_ptr<AXNode> ignoredNodeObject = AXNode::create().setNodeId(Strin
g::number(axID)).setIgnored(true).build(); |
| 310 if (axObject) { | 309 if (axObject) { |
| 311 axObject->computeAccessibilityIsIgnored(&ignoredReasons); | 310 axObject->computeAccessibilityIsIgnored(&ignoredReasons); |
| 312 axID = axObject->axObjectID(); | 311 axID = axObject->axObjectID(); |
| 313 AccessibilityRole role = axObject->roleValue(); | 312 AccessibilityRole role = axObject->roleValue(); |
| 314 ignoredNodeObject->setRole(createRoleNameValue(role)); | 313 ignoredNodeObject->setRole(createRoleNameValue(role)); |
| 315 } else if (node && !node->layoutObject()) { | 314 } else if (!node->layoutObject()) { |
| 316 ignoredReasons.append(IgnoredReason(AXNotRendered)); | 315 ignoredReasons.append(IgnoredReason(AXNotRendered)); |
| 317 } | 316 } |
| 318 | 317 |
| 319 std::unique_ptr<protocol::Array<AXProperty>> ignoredReasonProperties = proto
col::Array<AXProperty>::create(); | 318 std::unique_ptr<protocol::Array<AXProperty>> ignoredReasonProperties = proto
col::Array<AXProperty>::create(); |
| 320 for (size_t i = 0; i < ignoredReasons.size(); i++) | 319 for (size_t i = 0; i < ignoredReasons.size(); i++) |
| 321 ignoredReasonProperties->addItem(createProperty(ignoredReasons[i])); | 320 ignoredReasonProperties->addItem(createProperty(ignoredReasons[i])); |
| 322 ignoredNodeObject->setIgnoredReasons(std::move(ignoredReasonProperties)); | 321 ignoredNodeObject->setIgnoredReasons(std::move(ignoredReasonProperties)); |
| 323 | 322 |
| 324 return ignoredNodeObject; | 323 return ignoredNodeObject; |
| 325 } | 324 } |
| 326 | 325 |
| 327 std::unique_ptr<AXNode> buildProtocolAXObject(AXObject* axObject) | 326 std::unique_ptr<AXNode> buildObjectForNode(Node* node, AXObject* axObject, AXObj
ectCacheImpl* cacheImpl, std::unique_ptr<protocol::Array<AXProperty>> properties
) |
| 328 { | 327 { |
| 329 AccessibilityRole role = axObject->roleValue(); | 328 AccessibilityRole role = axObject->roleValue(); |
| 330 std::unique_ptr<AXNode> nodeObject = AXNode::create().setNodeId(String::numb
er(axObject->axObjectID())).setIgnored(false).build(); | 329 std::unique_ptr<AXNode> nodeObject = AXNode::create().setNodeId(String::numb
er(axObject->axObjectID())).setIgnored(false).build(); |
| 331 nodeObject->setRole(createRoleNameValue(role)); | 330 nodeObject->setRole(createRoleNameValue(role)); |
| 332 | 331 |
| 333 std::unique_ptr<protocol::Array<AXProperty>> properties = protocol::Array<AX
Property>::create(); | |
| 334 fillLiveRegionProperties(axObject, properties.get()); | |
| 335 fillGlobalStates(axObject, properties.get()); | |
| 336 fillWidgetProperties(axObject, properties.get()); | |
| 337 fillWidgetStates(axObject, properties.get()); | |
| 338 fillRelationships(axObject, properties.get()); | |
| 339 | |
| 340 AXObject::NameSources nameSources; | 332 AXObject::NameSources nameSources; |
| 341 String computedName = axObject->name(&nameSources); | 333 String computedName = axObject->name(&nameSources); |
| 342 if (!nameSources.isEmpty()) { | 334 if (!nameSources.isEmpty()) { |
| 343 std::unique_ptr<AXValue> name = createValue(computedName, AXValueTypeEnu
m::ComputedString); | 335 std::unique_ptr<AXValue> name = createValue(computedName, AXValueTypeEnu
m::ComputedString); |
| 344 if (!nameSources.isEmpty()) { | 336 if (!nameSources.isEmpty()) { |
| 345 std::unique_ptr<protocol::Array<AXValueSource>> nameSourceProperties
= protocol::Array<AXValueSource>::create(); | 337 std::unique_ptr<protocol::Array<AXValueSource>> nameSourceProperties
= protocol::Array<AXValueSource>::create(); |
| 346 for (size_t i = 0; i < nameSources.size(); ++i) { | 338 for (size_t i = 0; i < nameSources.size(); ++i) { |
| 347 NameSource& nameSource = nameSources[i]; | 339 NameSource& nameSource = nameSources[i]; |
| 348 nameSourceProperties->addItem(createValueSource(nameSource)); | 340 nameSourceProperties->addItem(createValueSource(nameSource)); |
| 349 if (nameSource.text.isNull() || nameSource.superseded) | 341 if (nameSource.text.isNull() || nameSource.superseded) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 365 } | 357 } |
| 366 | 358 |
| 367 } // namespace | 359 } // namespace |
| 368 | 360 |
| 369 InspectorAccessibilityAgent::InspectorAccessibilityAgent(Page* page, InspectorDO
MAgent* domAgent) | 361 InspectorAccessibilityAgent::InspectorAccessibilityAgent(Page* page, InspectorDO
MAgent* domAgent) |
| 370 : m_page(page) | 362 : m_page(page) |
| 371 , m_domAgent(domAgent) | 363 , m_domAgent(domAgent) |
| 372 { | 364 { |
| 373 } | 365 } |
| 374 | 366 |
| 375 void InspectorAccessibilityAgent::getAXNodeChain(ErrorString* errorString, int d
omNodeId, bool fetchAncestors, std::unique_ptr<protocol::Array<protocol::Accessi
bility::AXNode>>* nodes) | 367 void InspectorAccessibilityAgent::getAXNode(ErrorString* errorString, int nodeId
, Maybe<AXNode>* accessibilityNode) |
| 376 { | 368 { |
| 369 Frame* mainFrame = m_page->mainFrame(); |
| 370 if (!mainFrame->isLocalFrame()) { |
| 371 *errorString = "Can't inspect out of process frames yet"; |
| 372 return; |
| 373 } |
| 374 |
| 377 if (!m_domAgent->enabled()) { | 375 if (!m_domAgent->enabled()) { |
| 378 *errorString = "DOM agent must be enabled"; | 376 *errorString = "DOM agent must be enabled"; |
| 379 return; | 377 return; |
| 380 } | 378 } |
| 381 Node* node = m_domAgent->assertNode(errorString, domNodeId); | 379 Node* node = m_domAgent->assertNode(errorString, nodeId); |
| 382 if (!node) | 380 if (!node) |
| 383 return; | 381 return; |
| 384 | 382 |
| 385 Document& document = node->document(); | 383 Document& document = node->document(); |
| 386 document.updateStyleAndLayoutIgnorePendingStylesheets(); | 384 document.updateStyleAndLayoutIgnorePendingStylesheets(); |
| 387 DocumentLifecycle::DisallowTransitionScope disallowTransition(document.lifec
ycle()); | 385 DocumentLifecycle::DisallowTransitionScope disallowTransition(document.lifec
ycle()); |
| 388 LocalFrame* localFrame = document.frame(); | 386 std::unique_ptr<ScopedAXObjectCache> cache = ScopedAXObjectCache::create(doc
ument); |
| 389 if (!localFrame) { | 387 AXObjectCacheImpl* cacheImpl = toAXObjectCacheImpl(cache->get()); |
| 390 *errorString = "Frame is detached."; | 388 AXObject* axObject = cacheImpl->getOrCreate(node); |
| 389 if (!axObject || axObject->accessibilityIsIgnored()) { |
| 390 *accessibilityNode = buildObjectForIgnoredNode(node, axObject, cacheImpl
); |
| 391 return; | 391 return; |
| 392 } | 392 } |
| 393 std::unique_ptr<ScopedAXObjectCache> scopedCache = ScopedAXObjectCache::crea
te(document); | |
| 394 AXObjectCacheImpl* cache = toAXObjectCacheImpl(scopedCache->get()); | |
| 395 AXObject* axObject = cache->getOrCreate(node); | |
| 396 *nodes = protocol::Array<protocol::Accessibility::AXNode>::create(); | |
| 397 if (!axObject || axObject->accessibilityIsIgnored()) { | |
| 398 (*nodes)->addItem(buildObjectForIgnoredNode(node, axObject)); | |
| 399 } else { | |
| 400 (*nodes)->addItem(buildProtocolAXObject(axObject)); | |
| 401 } | |
| 402 | 393 |
| 403 if (fetchAncestors && axObject) { | 394 std::unique_ptr<protocol::Array<AXProperty>> properties = protocol::Array<AX
Property>::create(); |
| 404 AXObject* parent = axObject->parentObjectUnignored(); | 395 fillLiveRegionProperties(axObject, properties.get()); |
| 405 while (parent) { | 396 fillGlobalStates(axObject, properties.get()); |
| 406 (*nodes)->addItem(buildProtocolAXObject(parent)); | 397 fillWidgetProperties(axObject, properties.get()); |
| 407 parent = parent->parentObjectUnignored(); | 398 fillWidgetStates(axObject, properties.get()); |
| 408 } | 399 fillRelationships(axObject, properties.get()); |
| 409 } | 400 |
| 401 *accessibilityNode = buildObjectForNode(node, axObject, cacheImpl, std::move
(properties)); |
| 410 } | 402 } |
| 411 | 403 |
| 412 DEFINE_TRACE(InspectorAccessibilityAgent) | 404 DEFINE_TRACE(InspectorAccessibilityAgent) |
| 413 { | 405 { |
| 414 visitor->trace(m_page); | 406 visitor->trace(m_page); |
| 415 visitor->trace(m_domAgent); | 407 visitor->trace(m_domAgent); |
| 416 InspectorBaseAgent::trace(visitor); | 408 InspectorBaseAgent::trace(visitor); |
| 417 } | 409 } |
| 418 | 410 |
| 419 } // namespace blink | 411 } // namespace blink |
| OLD | NEW |