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

Side by Side Diff: Source/modules/accessibility/AXObject.cpp

Issue 1175533004: Refactor: Clear m_axObjectCache when AXObject detaches (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Added ASSERT Created 5 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 /* 1 /*
2 * Copyright (C) 2008, 2009, 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2008, 2009, 2011 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 }; 363 };
364 364
365 365
366 HTMLDialogElement* getActiveDialogElement(Node* node) 366 HTMLDialogElement* getActiveDialogElement(Node* node)
367 { 367 {
368 return node->document().activeModalDialog(); 368 return node->document().activeModalDialog();
369 } 369 }
370 370
371 } // namespace 371 } // namespace
372 372
373 AXObject::AXObject(AXObjectCacheImpl* axObjectCache) 373 AXObject::AXObject(AXObjectCacheImpl& axObjectCache)
374 : m_id(0) 374 : m_id(0)
375 , m_haveChildren(false) 375 , m_haveChildren(false)
376 , m_role(UnknownRole) 376 , m_role(UnknownRole)
377 , m_lastKnownIsIgnoredValue(DefaultBehavior) 377 , m_lastKnownIsIgnoredValue(DefaultBehavior)
378 , m_detached(false)
379 , m_parent(0) 378 , m_parent(0)
380 , m_lastModificationCount(-1) 379 , m_lastModificationCount(-1)
381 , m_cachedIsIgnored(false) 380 , m_cachedIsIgnored(false)
382 , m_cachedIsInertOrAriaHidden(false) 381 , m_cachedIsInertOrAriaHidden(false)
383 , m_cachedIsDescendantOfLeafNode(false) 382 , m_cachedIsDescendantOfLeafNode(false)
384 , m_cachedIsDescendantOfDisabledNode(false) 383 , m_cachedIsDescendantOfDisabledNode(false)
385 , m_cachedHasInheritedPresentationalRole(false) 384 , m_cachedHasInheritedPresentationalRole(false)
386 , m_cachedIsPresentationalChild(false) 385 , m_cachedIsPresentationalChild(false)
387 , m_cachedLiveRegionRoot(0) 386 , m_cachedLiveRegionRoot(0)
388 , m_axObjectCache(axObjectCache) 387 , m_axObjectCache(&axObjectCache)
389 { 388 {
390 } 389 }
391 390
392 AXObject::~AXObject() 391 AXObject::~AXObject()
393 { 392 {
394 ASSERT(isDetached()); 393 ASSERT(isDetached());
395 } 394 }
396 395
397 void AXObject::detach() 396 void AXObject::detach()
398 { 397 {
399 // Clear any children and call detachFromParent on them so that 398 // Clear any children and call detachFromParent on them so that
400 // no children are left with dangling pointers to their parent. 399 // no children are left with dangling pointers to their parent.
401 clearChildren(); 400 clearChildren();
402 401
403 m_detached = true; 402 m_axObjectCache = nullptr;
404 } 403 }
405 404
406 bool AXObject::isDetached() const 405 bool AXObject::isDetached() const
407 { 406 {
408 return m_detached; 407 return !m_axObjectCache;
409 } 408 }
410 409
411 bool AXObject::isARIATextControl() const 410 bool AXObject::isARIATextControl() const
412 { 411 {
413 return ariaRoleAttribute() == TextFieldRole || ariaRoleAttribute() == Search BoxRole; 412 return ariaRoleAttribute() == TextFieldRole || ariaRoleAttribute() == Search BoxRole;
414 } 413 }
415 414
416 bool AXObject::isButton() const 415 bool AXObject::isButton() const
417 { 416 {
418 AccessibilityRole role = roleValue(); 417 AccessibilityRole role = roleValue();
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 } 487 }
489 488
490 bool AXObject::accessibilityIsIgnored() const 489 bool AXObject::accessibilityIsIgnored() const
491 { 490 {
492 updateCachedAttributeValuesIfNeeded(); 491 updateCachedAttributeValuesIfNeeded();
493 return m_cachedIsIgnored; 492 return m_cachedIsIgnored;
494 } 493 }
495 494
496 void AXObject::updateCachedAttributeValuesIfNeeded() const 495 void AXObject::updateCachedAttributeValuesIfNeeded() const
497 { 496 {
498 AXObjectCacheImpl* cache = axObjectCache(); 497 if (isDetached())
499 if (!cache)
500 return; 498 return;
501 499
502 if (cache->modificationCount() == m_lastModificationCount) 500 AXObjectCacheImpl& cache = axObjectCache();
501
502 if (cache.modificationCount() == m_lastModificationCount)
503 return; 503 return;
504 504
505 m_lastModificationCount = cache->modificationCount(); 505 m_lastModificationCount = cache.modificationCount();
506 m_cachedIsInertOrAriaHidden = computeIsInertOrAriaHidden(); 506 m_cachedIsInertOrAriaHidden = computeIsInertOrAriaHidden();
507 m_cachedIsDescendantOfLeafNode = (leafNodeAncestor() != 0); 507 m_cachedIsDescendantOfLeafNode = (leafNodeAncestor() != 0);
508 m_cachedIsDescendantOfDisabledNode = (disabledAncestor() != 0); 508 m_cachedIsDescendantOfDisabledNode = (disabledAncestor() != 0);
509 m_cachedHasInheritedPresentationalRole = (inheritsPresentationalRoleFrom() ! = 0); 509 m_cachedHasInheritedPresentationalRole = (inheritsPresentationalRoleFrom() ! = 0);
510 m_cachedIsPresentationalChild = (ancestorForWhichThisIsAPresentationalChild( ) != 0); 510 m_cachedIsPresentationalChild = (ancestorForWhichThisIsAPresentationalChild( ) != 0);
511 m_cachedIsIgnored = computeAccessibilityIsIgnored(); 511 m_cachedIsIgnored = computeAccessibilityIsIgnored();
512 m_cachedLiveRegionRoot = isLiveRegion() ? 512 m_cachedLiveRegionRoot = isLiveRegion() ?
513 this : 513 this :
514 (parentObjectIfExists() ? parentObjectIfExists()->liveRegionRoot() : 0); 514 (parentObjectIfExists() ? parentObjectIfExists()->liveRegionRoot() : 0);
515 } 515 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 return m_cachedIsInertOrAriaHidden; 552 return m_cachedIsInertOrAriaHidden;
553 } 553 }
554 554
555 bool AXObject::computeIsInertOrAriaHidden(IgnoredReasons* ignoredReasons) const 555 bool AXObject::computeIsInertOrAriaHidden(IgnoredReasons* ignoredReasons) const
556 { 556 {
557 if (node()) { 557 if (node()) {
558 if (node()->isInert()) { 558 if (node()->isInert()) {
559 if (ignoredReasons) { 559 if (ignoredReasons) {
560 HTMLDialogElement* dialog = getActiveDialogElement(node()); 560 HTMLDialogElement* dialog = getActiveDialogElement(node());
561 if (dialog) { 561 if (dialog) {
562 AXObject* dialogObject = axObjectCache()->getOrCreate(dialog ); 562 AXObject* dialogObject = axObjectCache().getOrCreate(dialog) ;
563 if (dialogObject) 563 if (dialogObject)
564 ignoredReasons->append(IgnoredReason(AXActiveModalDialog , dialogObject)); 564 ignoredReasons->append(IgnoredReason(AXActiveModalDialog , dialogObject));
565 else 565 else
566 ignoredReasons->append(IgnoredReason(AXInert)); 566 ignoredReasons->append(IgnoredReason(AXInert));
567 } else { 567 } else {
568 // TODO(aboxhall): handle inert attribute if it eventuates 568 // TODO(aboxhall): handle inert attribute if it eventuates
569 ignoredReasons->append(IgnoredReason(AXInert)); 569 ignoredReasons->append(IgnoredReason(AXInert));
570 } 570 }
571 } 571 }
572 return true; 572 return true;
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
891 return result; 891 return result;
892 } 892 }
893 893
894 AXObject* AXObject::elementAccessibilityHitTest(const IntPoint& point) const 894 AXObject* AXObject::elementAccessibilityHitTest(const IntPoint& point) const
895 { 895 {
896 // Send the hit test back into the sub-frame if necessary. 896 // Send the hit test back into the sub-frame if necessary.
897 if (isAttachment()) { 897 if (isAttachment()) {
898 Widget* widget = widgetForAttachmentView(); 898 Widget* widget = widgetForAttachmentView();
899 // Normalize the point for the widget's bounds. 899 // Normalize the point for the widget's bounds.
900 if (widget && widget->isFrameView()) 900 if (widget && widget->isFrameView())
901 return axObjectCache()->getOrCreate(widget)->accessibilityHitTest(In tPoint(point - widget->frameRect().location())); 901 return axObjectCache().getOrCreate(widget)->accessibilityHitTest(Int Point(point - widget->frameRect().location()));
902 } 902 }
903 903
904 // Check if there are any mock elements that need to be handled. 904 // Check if there are any mock elements that need to be handled.
905 for (const auto& child : m_children) { 905 for (const auto& child : m_children) {
906 if (child->isMockObject() && child->elementRect().contains(point)) 906 if (child->isMockObject() && child->elementRect().contains(point))
907 return child->elementAccessibilityHitTest(point); 907 return child->elementAccessibilityHitTest(point);
908 } 908 }
909 909
910 return const_cast<AXObject*>(this); 910 return const_cast<AXObject*>(this);
911 } 911 }
912 912
913 const AXObject::AccessibilityChildrenVector& AXObject::children() 913 const AXObject::AccessibilityChildrenVector& AXObject::children()
914 { 914 {
915 updateChildrenIfNecessary(); 915 updateChildrenIfNecessary();
916 916
917 return m_children; 917 return m_children;
918 } 918 }
919 919
920 AXObject* AXObject::parentObject() const 920 AXObject* AXObject::parentObject() const
921 { 921 {
922 if (m_detached) 922 if (isDetached())
923 return 0; 923 return 0;
924 924
925 if (m_parent) 925 if (m_parent)
926 return m_parent; 926 return m_parent;
927 927
928 if (axObjectCache()->isAriaOwned(this)) 928 if (axObjectCache().isAriaOwned(this))
929 return axObjectCache()->getAriaOwnedParent(this); 929 return axObjectCache().getAriaOwnedParent(this);
930 930
931 return computeParent(); 931 return computeParent();
932 } 932 }
933 933
934 AXObject* AXObject::parentObjectIfExists() const 934 AXObject* AXObject::parentObjectIfExists() const
935 { 935 {
936 if (m_detached) 936 if (isDetached())
937 return 0; 937 return 0;
938 938
939 if (m_parent) 939 if (m_parent)
940 return m_parent; 940 return m_parent;
941 941
942 return computeParentIfExists(); 942 return computeParentIfExists();
943 } 943 }
944 944
945 AXObject* AXObject::parentObjectUnignored() const 945 AXObject* AXObject::parentObjectUnignored() const
946 { 946 {
(...skipping 23 matching lines...) Expand all
970 AXObject* AXObject::focusedUIElement() const 970 AXObject* AXObject::focusedUIElement() const
971 { 971 {
972 Document* doc = document(); 972 Document* doc = document();
973 if (!doc) 973 if (!doc)
974 return 0; 974 return 0;
975 975
976 Page* page = doc->page(); 976 Page* page = doc->page();
977 if (!page) 977 if (!page)
978 return 0; 978 return 0;
979 979
980 return axObjectCache()->focusedUIElementForPage(page); 980 return axObjectCache().focusedUIElementForPage(page);
981 } 981 }
982 982
983 Document* AXObject::document() const 983 Document* AXObject::document() const
984 { 984 {
985 FrameView* frameView = documentFrameView(); 985 FrameView* frameView = documentFrameView();
986 if (!frameView) 986 if (!frameView)
987 return 0; 987 return 0;
988 988
989 return frameView->frame().document(); 989 return frameView->frame().document();
990 } 990 }
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
1309 offsetX = 0; 1309 offsetX = 0;
1310 offsetY = 0; 1310 offsetY = 0;
1311 } 1311 }
1312 } 1312 }
1313 } 1313 }
1314 1314
1315 void AXObject::notifyIfIgnoredValueChanged() 1315 void AXObject::notifyIfIgnoredValueChanged()
1316 { 1316 {
1317 bool isIgnored = accessibilityIsIgnored(); 1317 bool isIgnored = accessibilityIsIgnored();
1318 if (lastKnownIsIgnoredValue() != isIgnored) { 1318 if (lastKnownIsIgnoredValue() != isIgnored) {
1319 axObjectCache()->childrenChanged(parentObject()); 1319 axObjectCache().childrenChanged(parentObject());
1320 setLastKnownIsIgnoredValue(isIgnored); 1320 setLastKnownIsIgnoredValue(isIgnored);
1321 } 1321 }
1322 } 1322 }
1323 1323
1324 void AXObject::selectionChanged() 1324 void AXObject::selectionChanged()
1325 { 1325 {
1326 if (AXObject* parent = parentObjectIfExists()) 1326 if (AXObject* parent = parentObjectIfExists())
1327 parent->selectionChanged(); 1327 parent->selectionChanged();
1328 } 1328 }
1329 1329
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
1474 } 1474 }
1475 1475
1476 const AtomicString& AXObject::internalRoleName(AccessibilityRole role) 1476 const AtomicString& AXObject::internalRoleName(AccessibilityRole role)
1477 { 1477 {
1478 static const Vector<AtomicString>* internalRoleNameVector = createInternalRo leNameVector(); 1478 static const Vector<AtomicString>* internalRoleNameVector = createInternalRo leNameVector();
1479 1479
1480 return internalRoleNameVector->at(role); 1480 return internalRoleNameVector->at(role);
1481 } 1481 }
1482 1482
1483 } // namespace blink 1483 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/accessibility/AXObject.h ('k') | Source/modules/accessibility/AXObjectCacheImpl.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698