Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(113)

Side by Side Diff: third_party/WebKit/Source/modules/accessibility/InspectorAccessibilityAgent.cpp

Issue 2004313003: DevTools: migrate from OwnPtr to std::unique_ptr for inspector protocol classes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebaselined Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 else 239 else
240 properties->addItem(createProperty(AXWidgetStatesEnum::Pressed, createValue("true", AXValueTypeEnum::Tristate))); 240 properties->addItem(createProperty(AXWidgetStatesEnum::Pressed, createValue("true", AXValueTypeEnum::Tristate)));
241 } 241 }
242 } 242 }
243 243
244 if (roleAllowsSelected(role)) { 244 if (roleAllowsSelected(role)) {
245 properties->addItem(createProperty(AXWidgetStatesEnum::Selected, createB ooleanValue(axObject->isSelected()))); 245 properties->addItem(createProperty(AXWidgetStatesEnum::Selected, createB ooleanValue(axObject->isSelected())));
246 } 246 }
247 } 247 }
248 248
249 PassOwnPtr<AXProperty> createRelatedNodeListProperty(const String& key, AXRelate dObjectVector& nodes) 249 std::unique_ptr<AXProperty> createRelatedNodeListProperty(const String& key, AXR elatedObjectVector& nodes)
250 { 250 {
251 OwnPtr<AXValue> nodeListValue = createRelatedNodeListValue(nodes, AXValueTyp eEnum::NodeList); 251 std::unique_ptr<AXValue> nodeListValue = createRelatedNodeListValue(nodes, A XValueTypeEnum::NodeList);
252 return createProperty(key, std::move(nodeListValue)); 252 return createProperty(key, std::move(nodeListValue));
253 } 253 }
254 254
255 PassOwnPtr<AXProperty> createRelatedNodeListProperty(const String& key, AXObject ::AXObjectVector& nodes, const QualifiedName& attr, AXObject* axObject) 255 std::unique_ptr<AXProperty> createRelatedNodeListProperty(const String& key, AXO bject::AXObjectVector& nodes, const QualifiedName& attr, AXObject* axObject)
256 { 256 {
257 OwnPtr<AXValue> nodeListValue = createRelatedNodeListValue(nodes); 257 std::unique_ptr<AXValue> nodeListValue = createRelatedNodeListValue(nodes);
258 const AtomicString& attrValue = axObject->getAttribute(attr); 258 const AtomicString& attrValue = axObject->getAttribute(attr);
259 nodeListValue->setValue(protocol::StringValue::create(attrValue)); 259 nodeListValue->setValue(protocol::StringValue::create(attrValue));
260 return createProperty(key, std::move(nodeListValue)); 260 return createProperty(key, std::move(nodeListValue));
261 } 261 }
262 262
263 void fillRelationships(AXObject* axObject, protocol::Array<AXProperty>* properti es) 263 void fillRelationships(AXObject* axObject, protocol::Array<AXProperty>* properti es)
264 { 264 {
265 if (AXObject* activeDescendant = axObject->activeDescendant()) { 265 if (AXObject* activeDescendant = axObject->activeDescendant()) {
266 properties->addItem(createProperty(AXRelationshipAttributesEnum::Actived escendant, createRelatedNodeListValue(activeDescendant))); 266 properties->addItem(createProperty(AXRelationshipAttributesEnum::Actived escendant, createRelatedNodeListValue(activeDescendant)));
267 } 267 }
(...skipping 13 matching lines...) Expand all
281 if (!results.isEmpty()) 281 if (!results.isEmpty())
282 properties->addItem(createRelatedNodeListProperty(AXRelationshipAttribut esEnum::Describedby, results, aria_describedbyAttr, axObject)); 282 properties->addItem(createRelatedNodeListProperty(AXRelationshipAttribut esEnum::Describedby, results, aria_describedbyAttr, axObject));
283 results.clear(); 283 results.clear();
284 284
285 axObject->ariaOwnsElements(results); 285 axObject->ariaOwnsElements(results);
286 if (!results.isEmpty()) 286 if (!results.isEmpty())
287 properties->addItem(createRelatedNodeListProperty(AXRelationshipAttribut esEnum::Owns, results, aria_ownsAttr, axObject)); 287 properties->addItem(createRelatedNodeListProperty(AXRelationshipAttribut esEnum::Owns, results, aria_ownsAttr, axObject));
288 results.clear(); 288 results.clear();
289 } 289 }
290 290
291 PassOwnPtr<AXValue> createRoleNameValue(AccessibilityRole role) 291 std::unique_ptr<AXValue> createRoleNameValue(AccessibilityRole role)
292 { 292 {
293 AtomicString roleName = AXObject::roleName(role); 293 AtomicString roleName = AXObject::roleName(role);
294 OwnPtr<AXValue> roleNameValue; 294 std::unique_ptr<AXValue> roleNameValue;
295 if (!roleName.isNull()) { 295 if (!roleName.isNull()) {
296 roleNameValue = createValue(roleName, AXValueTypeEnum::Role); 296 roleNameValue = createValue(roleName, AXValueTypeEnum::Role);
297 } else { 297 } else {
298 roleNameValue = createValue(AXObject::internalRoleName(role), AXValueTyp eEnum::InternalRole); 298 roleNameValue = createValue(AXObject::internalRoleName(role), AXValueTyp eEnum::InternalRole);
299 } 299 }
300 return roleNameValue; 300 return roleNameValue;
301 } 301 }
302 302
303 PassOwnPtr<AXNode> buildObjectForIgnoredNode(Node* node, AXObject* axObject, AXO bjectCacheImpl* cacheImpl) 303 std::unique_ptr<AXNode> buildObjectForIgnoredNode(Node* node, AXObject* axObject , AXObjectCacheImpl* cacheImpl)
304 { 304 {
305 AXObject::IgnoredReasons ignoredReasons; 305 AXObject::IgnoredReasons ignoredReasons;
306 306
307 AXID axID = 0; 307 AXID axID = 0;
308 OwnPtr<AXNode> ignoredNodeObject = AXNode::create().setNodeId(String::number (axID)).setIgnored(true).build(); 308 std::unique_ptr<AXNode> ignoredNodeObject = AXNode::create().setNodeId(Strin g::number(axID)).setIgnored(true).build();
309 if (axObject) { 309 if (axObject) {
310 axObject->computeAccessibilityIsIgnored(&ignoredReasons); 310 axObject->computeAccessibilityIsIgnored(&ignoredReasons);
311 axID = axObject->axObjectID(); 311 axID = axObject->axObjectID();
312 AccessibilityRole role = axObject->roleValue(); 312 AccessibilityRole role = axObject->roleValue();
313 ignoredNodeObject->setRole(createRoleNameValue(role)); 313 ignoredNodeObject->setRole(createRoleNameValue(role));
314 } else if (!node->layoutObject()) { 314 } else if (!node->layoutObject()) {
315 ignoredReasons.append(IgnoredReason(AXNotRendered)); 315 ignoredReasons.append(IgnoredReason(AXNotRendered));
316 } 316 }
317 317
318 OwnPtr<protocol::Array<AXProperty>> ignoredReasonProperties = protocol::Arra y<AXProperty>::create(); 318 std::unique_ptr<protocol::Array<AXProperty>> ignoredReasonProperties = proto col::Array<AXProperty>::create();
319 for (size_t i = 0; i < ignoredReasons.size(); i++) 319 for (size_t i = 0; i < ignoredReasons.size(); i++)
320 ignoredReasonProperties->addItem(createProperty(ignoredReasons[i])); 320 ignoredReasonProperties->addItem(createProperty(ignoredReasons[i]));
321 ignoredNodeObject->setIgnoredReasons(std::move(ignoredReasonProperties)); 321 ignoredNodeObject->setIgnoredReasons(std::move(ignoredReasonProperties));
322 322
323 return ignoredNodeObject; 323 return ignoredNodeObject;
324 } 324 }
325 325
326 PassOwnPtr<AXNode> buildObjectForNode(Node* node, AXObject* axObject, AXObjectCa cheImpl* cacheImpl, PassOwnPtr<protocol::Array<AXProperty>> properties) 326 std::unique_ptr<AXNode> buildObjectForNode(Node* node, AXObject* axObject, AXObj ectCacheImpl* cacheImpl, std::unique_ptr<protocol::Array<AXProperty>> properties )
327 { 327 {
328 AccessibilityRole role = axObject->roleValue(); 328 AccessibilityRole role = axObject->roleValue();
329 OwnPtr<AXNode> nodeObject = AXNode::create().setNodeId(String::number(axObje ct->axObjectID())).setIgnored(false).build(); 329 std::unique_ptr<AXNode> nodeObject = AXNode::create().setNodeId(String::numb er(axObject->axObjectID())).setIgnored(false).build();
330 nodeObject->setRole(createRoleNameValue(role)); 330 nodeObject->setRole(createRoleNameValue(role));
331 331
332 AXObject::NameSources nameSources; 332 AXObject::NameSources nameSources;
333 String computedName = axObject->name(&nameSources); 333 String computedName = axObject->name(&nameSources);
334 if (!nameSources.isEmpty()) { 334 if (!nameSources.isEmpty()) {
335 OwnPtr<AXValue> name = createValue(computedName, AXValueTypeEnum::Comput edString); 335 std::unique_ptr<AXValue> name = createValue(computedName, AXValueTypeEnu m::ComputedString);
336 if (!nameSources.isEmpty()) { 336 if (!nameSources.isEmpty()) {
337 OwnPtr<protocol::Array<AXValueSource>> nameSourceProperties = protoc ol::Array<AXValueSource>::create(); 337 std::unique_ptr<protocol::Array<AXValueSource>> nameSourceProperties = protocol::Array<AXValueSource>::create();
338 for (size_t i = 0; i < nameSources.size(); ++i) { 338 for (size_t i = 0; i < nameSources.size(); ++i) {
339 NameSource& nameSource = nameSources[i]; 339 NameSource& nameSource = nameSources[i];
340 nameSourceProperties->addItem(createValueSource(nameSource)); 340 nameSourceProperties->addItem(createValueSource(nameSource));
341 if (nameSource.text.isNull() || nameSource.superseded) 341 if (nameSource.text.isNull() || nameSource.superseded)
342 continue; 342 continue;
343 if (!nameSource.relatedObjects.isEmpty()) { 343 if (!nameSource.relatedObjects.isEmpty()) {
344 properties->addItem(createRelatedNodeListProperty(AXRelation shipAttributesEnum::Labelledby, nameSource.relatedObjects)); 344 properties->addItem(createRelatedNodeListProperty(AXRelation shipAttributesEnum::Labelledby, nameSource.relatedObjects));
345 } 345 }
346 } 346 }
347 name->setSources(std::move(nameSourceProperties)); 347 name->setSources(std::move(nameSourceProperties));
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 383
384 Document& document = node->document(); 384 Document& document = node->document();
385 OwnPtr<ScopedAXObjectCache> cache = ScopedAXObjectCache::create(document); 385 OwnPtr<ScopedAXObjectCache> cache = ScopedAXObjectCache::create(document);
386 AXObjectCacheImpl* cacheImpl = toAXObjectCacheImpl(cache->get()); 386 AXObjectCacheImpl* cacheImpl = toAXObjectCacheImpl(cache->get());
387 AXObject* axObject = cacheImpl->getOrCreate(node); 387 AXObject* axObject = cacheImpl->getOrCreate(node);
388 if (!axObject || axObject->accessibilityIsIgnored()) { 388 if (!axObject || axObject->accessibilityIsIgnored()) {
389 *accessibilityNode = buildObjectForIgnoredNode(node, axObject, cacheImpl ); 389 *accessibilityNode = buildObjectForIgnoredNode(node, axObject, cacheImpl );
390 return; 390 return;
391 } 391 }
392 392
393 OwnPtr<protocol::Array<AXProperty>> properties = protocol::Array<AXProperty> ::create(); 393 std::unique_ptr<protocol::Array<AXProperty>> properties = protocol::Array<AX Property>::create();
394 fillLiveRegionProperties(axObject, properties.get()); 394 fillLiveRegionProperties(axObject, properties.get());
395 fillGlobalStates(axObject, properties.get()); 395 fillGlobalStates(axObject, properties.get());
396 fillWidgetProperties(axObject, properties.get()); 396 fillWidgetProperties(axObject, properties.get());
397 fillWidgetStates(axObject, properties.get()); 397 fillWidgetStates(axObject, properties.get());
398 fillRelationships(axObject, properties.get()); 398 fillRelationships(axObject, properties.get());
399 399
400 *accessibilityNode = buildObjectForNode(node, axObject, cacheImpl, std::move (properties)); 400 *accessibilityNode = buildObjectForNode(node, axObject, cacheImpl, std::move (properties));
401 } 401 }
402 402
403 DEFINE_TRACE(InspectorAccessibilityAgent) 403 DEFINE_TRACE(InspectorAccessibilityAgent)
404 { 404 {
405 visitor->trace(m_page); 405 visitor->trace(m_page);
406 visitor->trace(m_domAgent); 406 visitor->trace(m_domAgent);
407 InspectorBaseAgent::trace(visitor); 407 InspectorBaseAgent::trace(visitor);
408 } 408 }
409 409
410 } // namespace blink 410 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698