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