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

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

Issue 2709033003: Migrate WTF::HashMap::get() to ::at() (Closed)
Patch Set: rebase Created 3 years, 10 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) 2014, Google Inc. All rights reserved. 2 * Copyright (C) 2014, Google 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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 if (obj->accessibilityIsIgnored()) 182 if (obj->accessibilityIsIgnored())
183 obj = obj->parentObjectUnignored(); 183 obj = obj->parentObjectUnignored();
184 184
185 return obj; 185 return obj;
186 } 186 }
187 187
188 AXObject* AXObjectCacheImpl::get(LayoutObject* layoutObject) { 188 AXObject* AXObjectCacheImpl::get(LayoutObject* layoutObject) {
189 if (!layoutObject) 189 if (!layoutObject)
190 return 0; 190 return 0;
191 191
192 AXID axID = m_layoutObjectMapping.get(layoutObject); 192 AXID axID = m_layoutObjectMapping.at(layoutObject);
193 ASSERT(!HashTraits<AXID>::isDeletedValue(axID)); 193 ASSERT(!HashTraits<AXID>::isDeletedValue(axID));
194 if (!axID) 194 if (!axID)
195 return 0; 195 return 0;
196 196
197 return m_objects.get(axID); 197 return m_objects.at(axID);
198 } 198 }
199 199
200 // Returns true if |node| is an <option> element and its parent <select> 200 // Returns true if |node| is an <option> element and its parent <select>
201 // is a menu list (not a list box). 201 // is a menu list (not a list box).
202 static bool isMenuListOption(Node* node) { 202 static bool isMenuListOption(Node* node) {
203 if (!isHTMLOptionElement(node)) 203 if (!isHTMLOptionElement(node))
204 return false; 204 return false;
205 HTMLSelectElement* select = toHTMLOptionElement(node)->ownerSelectElement(); 205 HTMLSelectElement* select = toHTMLOptionElement(node)->ownerSelectElement();
206 if (!select) 206 if (!select)
207 return false; 207 return false;
208 LayoutObject* layoutObject = select->layoutObject(); 208 LayoutObject* layoutObject = select->layoutObject();
209 return layoutObject && layoutObject->isMenuList(); 209 return layoutObject && layoutObject->isMenuList();
210 } 210 }
211 211
212 AXObject* AXObjectCacheImpl::get(Node* node) { 212 AXObject* AXObjectCacheImpl::get(Node* node) {
213 if (!node) 213 if (!node)
214 return 0; 214 return 0;
215 215
216 // Menu list option and HTML area elements are indexed by DOM node, never by 216 // Menu list option and HTML area elements are indexed by DOM node, never by
217 // layout object. 217 // layout object.
218 LayoutObject* layoutObject = node->layoutObject(); 218 LayoutObject* layoutObject = node->layoutObject();
219 if (isMenuListOption(node) || isHTMLAreaElement(node)) 219 if (isMenuListOption(node) || isHTMLAreaElement(node))
220 layoutObject = nullptr; 220 layoutObject = nullptr;
221 221
222 AXID layoutID = layoutObject ? m_layoutObjectMapping.get(layoutObject) : 0; 222 AXID layoutID = layoutObject ? m_layoutObjectMapping.at(layoutObject) : 0;
223 ASSERT(!HashTraits<AXID>::isDeletedValue(layoutID)); 223 ASSERT(!HashTraits<AXID>::isDeletedValue(layoutID));
224 224
225 AXID nodeID = m_nodeObjectMapping.get(node); 225 AXID nodeID = m_nodeObjectMapping.at(node);
226 ASSERT(!HashTraits<AXID>::isDeletedValue(nodeID)); 226 ASSERT(!HashTraits<AXID>::isDeletedValue(nodeID));
227 227
228 if (layoutObject && nodeID && !layoutID) { 228 if (layoutObject && nodeID && !layoutID) {
229 // This can happen if an AXNodeObject is created for a node that's not 229 // This can happen if an AXNodeObject is created for a node that's not
230 // laid out, but later something changes and it gets a layoutObject (like if 230 // laid out, but later something changes and it gets a layoutObject (like if
231 // it's reparented). 231 // it's reparented).
232 remove(nodeID); 232 remove(nodeID);
233 return 0; 233 return 0;
234 } 234 }
235 235
236 if (layoutID) 236 if (layoutID)
237 return m_objects.get(layoutID); 237 return m_objects.at(layoutID);
238 238
239 if (!nodeID) 239 if (!nodeID)
240 return 0; 240 return 0;
241 241
242 return m_objects.get(nodeID); 242 return m_objects.at(nodeID);
243 } 243 }
244 244
245 AXObject* AXObjectCacheImpl::get(AbstractInlineTextBox* inlineTextBox) { 245 AXObject* AXObjectCacheImpl::get(AbstractInlineTextBox* inlineTextBox) {
246 if (!inlineTextBox) 246 if (!inlineTextBox)
247 return 0; 247 return 0;
248 248
249 AXID axID = m_inlineTextBoxObjectMapping.get(inlineTextBox); 249 AXID axID = m_inlineTextBoxObjectMapping.at(inlineTextBox);
250 ASSERT(!HashTraits<AXID>::isDeletedValue(axID)); 250 ASSERT(!HashTraits<AXID>::isDeletedValue(axID));
251 if (!axID) 251 if (!axID)
252 return 0; 252 return 0;
253 253
254 return m_objects.get(axID); 254 return m_objects.at(axID);
255 } 255 }
256 256
257 // FIXME: This probably belongs on Node. 257 // FIXME: This probably belongs on Node.
258 // FIXME: This should take a const char*, but one caller passes nullAtom. 258 // FIXME: This should take a const char*, but one caller passes nullAtom.
259 bool nodeHasRole(Node* node, const String& role) { 259 bool nodeHasRole(Node* node, const String& role) {
260 if (!node || !node->isElementNode()) 260 if (!node || !node->isElementNode())
261 return false; 261 return false;
262 262
263 return equalIgnoringCase(toElement(node)->getAttribute(roleAttr), role); 263 return equalIgnoringCase(toElement(node)->getAttribute(roleAttr), role);
264 } 264 }
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 m_objects.set(obj->axObjectID(), obj); 463 m_objects.set(obj->axObjectID(), obj);
464 obj->init(); 464 obj->init();
465 return obj; 465 return obj;
466 } 466 }
467 467
468 void AXObjectCacheImpl::remove(AXID axID) { 468 void AXObjectCacheImpl::remove(AXID axID) {
469 if (!axID) 469 if (!axID)
470 return; 470 return;
471 471
472 // first fetch object to operate some cleanup functions on it 472 // first fetch object to operate some cleanup functions on it
473 AXObject* obj = m_objects.get(axID); 473 AXObject* obj = m_objects.at(axID);
474 if (!obj) 474 if (!obj)
475 return; 475 return;
476 476
477 obj->detach(); 477 obj->detach();
478 removeAXID(obj); 478 removeAXID(obj);
479 479
480 // finally remove the object 480 // finally remove the object
481 if (!m_objects.take(axID)) 481 if (!m_objects.take(axID))
482 return; 482 return;
483 483
484 ASSERT(m_objects.size() >= m_idsInUse.size()); 484 ASSERT(m_objects.size() >= m_idsInUse.size());
485 } 485 }
486 486
487 void AXObjectCacheImpl::remove(LayoutObject* layoutObject) { 487 void AXObjectCacheImpl::remove(LayoutObject* layoutObject) {
488 if (!layoutObject) 488 if (!layoutObject)
489 return; 489 return;
490 490
491 AXID axID = m_layoutObjectMapping.get(layoutObject); 491 AXID axID = m_layoutObjectMapping.at(layoutObject);
492 remove(axID); 492 remove(axID);
493 m_layoutObjectMapping.erase(layoutObject); 493 m_layoutObjectMapping.erase(layoutObject);
494 } 494 }
495 495
496 void AXObjectCacheImpl::remove(Node* node) { 496 void AXObjectCacheImpl::remove(Node* node) {
497 if (!node) 497 if (!node)
498 return; 498 return;
499 499
500 // This is all safe even if we didn't have a mapping. 500 // This is all safe even if we didn't have a mapping.
501 AXID axID = m_nodeObjectMapping.get(node); 501 AXID axID = m_nodeObjectMapping.at(node);
502 remove(axID); 502 remove(axID);
503 m_nodeObjectMapping.erase(node); 503 m_nodeObjectMapping.erase(node);
504 504
505 if (node->layoutObject()) { 505 if (node->layoutObject()) {
506 remove(node->layoutObject()); 506 remove(node->layoutObject());
507 return; 507 return;
508 } 508 }
509 } 509 }
510 510
511 void AXObjectCacheImpl::remove(AbstractInlineTextBox* inlineTextBox) { 511 void AXObjectCacheImpl::remove(AbstractInlineTextBox* inlineTextBox) {
512 if (!inlineTextBox) 512 if (!inlineTextBox)
513 return; 513 return;
514 514
515 AXID axID = m_inlineTextBoxObjectMapping.get(inlineTextBox); 515 AXID axID = m_inlineTextBoxObjectMapping.at(inlineTextBox);
516 remove(axID); 516 remove(axID);
517 m_inlineTextBoxObjectMapping.erase(inlineTextBox); 517 m_inlineTextBoxObjectMapping.erase(inlineTextBox);
518 } 518 }
519 519
520 AXID AXObjectCacheImpl::platformGenerateAXID() const { 520 AXID AXObjectCacheImpl::platformGenerateAXID() const {
521 static AXID lastUsedID = 0; 521 static AXID lastUsedID = 0;
522 522
523 // Generate a new ID. 523 // Generate a new ID.
524 AXID objID = lastUsedID; 524 AXID objID = lastUsedID;
525 do { 525 do {
(...skipping 28 matching lines...) Expand all
554 554
555 AXID objID = object->axObjectID(); 555 AXID objID = object->axObjectID();
556 if (!objID) 556 if (!objID)
557 return; 557 return;
558 ASSERT(!HashTraits<AXID>::isDeletedValue(objID)); 558 ASSERT(!HashTraits<AXID>::isDeletedValue(objID));
559 ASSERT(m_idsInUse.contains(objID)); 559 ASSERT(m_idsInUse.contains(objID));
560 object->setAXObjectID(0); 560 object->setAXObjectID(0);
561 m_idsInUse.erase(objID); 561 m_idsInUse.erase(objID);
562 562
563 if (m_ariaOwnerToChildrenMapping.contains(objID)) { 563 if (m_ariaOwnerToChildrenMapping.contains(objID)) {
564 Vector<AXID> childAXIDs = m_ariaOwnerToChildrenMapping.get(objID); 564 Vector<AXID> childAXIDs = m_ariaOwnerToChildrenMapping.at(objID);
565 for (size_t i = 0; i < childAXIDs.size(); ++i) 565 for (size_t i = 0; i < childAXIDs.size(); ++i)
566 m_ariaOwnedChildToOwnerMapping.erase(childAXIDs[i]); 566 m_ariaOwnedChildToOwnerMapping.erase(childAXIDs[i]);
567 m_ariaOwnerToChildrenMapping.erase(objID); 567 m_ariaOwnerToChildrenMapping.erase(objID);
568 } 568 }
569 m_ariaOwnedChildToOwnerMapping.erase(objID); 569 m_ariaOwnedChildToOwnerMapping.erase(objID);
570 m_ariaOwnedChildToRealParentMapping.erase(objID); 570 m_ariaOwnedChildToRealParentMapping.erase(objID);
571 m_ariaOwnerToIdsMapping.erase(objID); 571 m_ariaOwnerToIdsMapping.erase(objID);
572 } 572 }
573 573
574 void AXObjectCacheImpl::selectionChanged(Node* node) { 574 void AXObjectCacheImpl::selectionChanged(Node* node) {
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 m_notificationsToPost.push_back(std::make_pair(object, notification)); 684 m_notificationsToPost.push_back(std::make_pair(object, notification));
685 if (!m_notificationPostTimer.isActive()) 685 if (!m_notificationPostTimer.isActive())
686 m_notificationPostTimer.startOneShot(0, BLINK_FROM_HERE); 686 m_notificationPostTimer.startOneShot(0, BLINK_FROM_HERE);
687 } 687 }
688 688
689 bool AXObjectCacheImpl::isAriaOwned(const AXObject* child) const { 689 bool AXObjectCacheImpl::isAriaOwned(const AXObject* child) const {
690 return m_ariaOwnedChildToOwnerMapping.contains(child->axObjectID()); 690 return m_ariaOwnedChildToOwnerMapping.contains(child->axObjectID());
691 } 691 }
692 692
693 AXObject* AXObjectCacheImpl::getAriaOwnedParent(const AXObject* child) const { 693 AXObject* AXObjectCacheImpl::getAriaOwnedParent(const AXObject* child) const {
694 return objectFromAXID( 694 return objectFromAXID(m_ariaOwnedChildToOwnerMapping.at(child->axObjectID()));
695 m_ariaOwnedChildToOwnerMapping.get(child->axObjectID()));
696 } 695 }
697 696
698 void AXObjectCacheImpl::updateAriaOwns( 697 void AXObjectCacheImpl::updateAriaOwns(
699 const AXObject* owner, 698 const AXObject* owner,
700 const Vector<String>& idVector, 699 const Vector<String>& idVector,
701 HeapVector<Member<AXObject>>& ownedChildren) { 700 HeapVector<Member<AXObject>>& ownedChildren) {
702 // 701 //
703 // Update the map from the AXID of this element to the ids of the owned 702 // Update the map from the AXID of this element to the ids of the owned
704 // children, and the reverse map from ids to possible AXID owners. 703 // children, and the reverse map from ids to possible AXID owners.
705 // 704 //
706 705
707 HashSet<String> currentIds = m_ariaOwnerToIdsMapping.get(owner->axObjectID()); 706 HashSet<String> currentIds = m_ariaOwnerToIdsMapping.at(owner->axObjectID());
708 HashSet<String> newIds; 707 HashSet<String> newIds;
709 bool idsChanged = false; 708 bool idsChanged = false;
710 for (const String& id : idVector) { 709 for (const String& id : idVector) {
711 newIds.insert(id); 710 newIds.insert(id);
712 if (!currentIds.contains(id)) { 711 if (!currentIds.contains(id)) {
713 idsChanged = true; 712 idsChanged = true;
714 HashSet<AXID>* owners = m_idToAriaOwnersMapping.get(id); 713 HashSet<AXID>* owners = m_idToAriaOwnersMapping.at(id);
715 if (!owners) { 714 if (!owners) {
716 owners = new HashSet<AXID>(); 715 owners = new HashSet<AXID>();
717 m_idToAriaOwnersMapping.set(id, WTF::wrapUnique(owners)); 716 m_idToAriaOwnersMapping.set(id, WTF::wrapUnique(owners));
718 } 717 }
719 owners->insert(owner->axObjectID()); 718 owners->insert(owner->axObjectID());
720 } 719 }
721 } 720 }
722 for (const String& id : currentIds) { 721 for (const String& id : currentIds) {
723 if (!newIds.contains(id)) { 722 if (!newIds.contains(id)) {
724 idsChanged = true; 723 idsChanged = true;
725 HashSet<AXID>* owners = m_idToAriaOwnersMapping.get(id); 724 HashSet<AXID>* owners = m_idToAriaOwnersMapping.at(id);
726 if (owners) { 725 if (owners) {
727 owners->erase(owner->axObjectID()); 726 owners->erase(owner->axObjectID());
728 if (owners->isEmpty()) 727 if (owners->isEmpty())
729 m_idToAriaOwnersMapping.erase(id); 728 m_idToAriaOwnersMapping.erase(id);
730 } 729 }
731 } 730 }
732 } 731 }
733 if (idsChanged) 732 if (idsChanged)
734 m_ariaOwnerToIdsMapping.set(owner->axObjectID(), newIds); 733 m_ariaOwnerToIdsMapping.set(owner->axObjectID(), newIds);
735 734
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
773 if (foundCycle) 772 if (foundCycle)
774 continue; 773 continue;
775 774
776 newChildAXIDs.push_back(child->axObjectID()); 775 newChildAXIDs.push_back(child->axObjectID());
777 ownedChildren.push_back(child); 776 ownedChildren.push_back(child);
778 } 777 }
779 778
780 // Compare this to the current list of owned children, and exit early if there 779 // Compare this to the current list of owned children, and exit early if there
781 // are no changes. 780 // are no changes.
782 Vector<AXID> currentChildAXIDs = 781 Vector<AXID> currentChildAXIDs =
783 m_ariaOwnerToChildrenMapping.get(owner->axObjectID()); 782 m_ariaOwnerToChildrenMapping.at(owner->axObjectID());
784 bool same = true; 783 bool same = true;
785 if (currentChildAXIDs.size() != newChildAXIDs.size()) { 784 if (currentChildAXIDs.size() != newChildAXIDs.size()) {
786 same = false; 785 same = false;
787 } else { 786 } else {
788 for (size_t i = 0; i < currentChildAXIDs.size() && same; ++i) { 787 for (size_t i = 0; i < currentChildAXIDs.size() && same; ++i) {
789 if (currentChildAXIDs[i] != newChildAXIDs[i]) 788 if (currentChildAXIDs[i] != newChildAXIDs[i])
790 same = false; 789 same = false;
791 } 790 }
792 } 791 }
793 if (same) 792 if (same)
(...skipping 15 matching lines...) Expand all
809 // Remove it from the child -> owner mapping so it's not owned by this owner 808 // Remove it from the child -> owner mapping so it's not owned by this owner
810 // anymore. 809 // anymore.
811 m_ariaOwnedChildToOwnerMapping.erase(removedChildID); 810 m_ariaOwnedChildToOwnerMapping.erase(removedChildID);
812 811
813 if (removedChild) { 812 if (removedChild) {
814 // If the child still exists, find its "real" parent, and reparent it back 813 // If the child still exists, find its "real" parent, and reparent it back
815 // to its real parent in the tree by detaching it from its current parent 814 // to its real parent in the tree by detaching it from its current parent
816 // and calling childrenChanged on its real parent. 815 // and calling childrenChanged on its real parent.
817 removedChild->detachFromParent(); 816 removedChild->detachFromParent();
818 AXID realParentID = 817 AXID realParentID =
819 m_ariaOwnedChildToRealParentMapping.get(removedChildID); 818 m_ariaOwnedChildToRealParentMapping.at(removedChildID);
820 AXObject* realParent = objectFromAXID(realParentID); 819 AXObject* realParent = objectFromAXID(realParentID);
821 childrenChanged(realParent); 820 childrenChanged(realParent);
822 } 821 }
823 822
824 // Remove the child -> original parent mapping too since this object has now 823 // Remove the child -> original parent mapping too since this object has now
825 // been reparented back to its original parent. 824 // been reparented back to its original parent.
826 m_ariaOwnedChildToRealParentMapping.erase(removedChildID); 825 m_ariaOwnedChildToRealParentMapping.erase(removedChildID);
827 } 826 }
828 827
829 for (size_t i = 0; i < newChildAXIDs.size(); ++i) { 828 for (size_t i = 0; i < newChildAXIDs.size(); ++i) {
(...skipping 19 matching lines...) Expand all
849 848
850 // Finally, update the mapping from the owner to the list of child IDs. 849 // Finally, update the mapping from the owner to the list of child IDs.
851 m_ariaOwnerToChildrenMapping.set(owner->axObjectID(), newChildAXIDs); 850 m_ariaOwnerToChildrenMapping.set(owner->axObjectID(), newChildAXIDs);
852 } 851 }
853 852
854 void AXObjectCacheImpl::updateTreeIfElementIdIsAriaOwned(Element* element) { 853 void AXObjectCacheImpl::updateTreeIfElementIdIsAriaOwned(Element* element) {
855 if (!element->hasID()) 854 if (!element->hasID())
856 return; 855 return;
857 856
858 String id = element->getIdAttribute(); 857 String id = element->getIdAttribute();
859 HashSet<AXID>* owners = m_idToAriaOwnersMapping.get(id); 858 HashSet<AXID>* owners = m_idToAriaOwnersMapping.at(id);
860 if (!owners) 859 if (!owners)
861 return; 860 return;
862 861
863 AXObject* axElement = getOrCreate(element); 862 AXObject* axElement = getOrCreate(element);
864 if (!axElement) 863 if (!axElement)
865 return; 864 return;
866 865
867 // If it's already owned, call childrenChanged on the owner to make sure it's 866 // If it's already owned, call childrenChanged on the owner to make sure it's
868 // still an owner. 867 // still an owner.
869 if (isAriaOwned(axElement)) { 868 if (isAriaOwned(axElement)) {
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
1248 visitor->trace(m_document); 1247 visitor->trace(m_document);
1249 visitor->trace(m_nodeObjectMapping); 1248 visitor->trace(m_nodeObjectMapping);
1250 1249
1251 visitor->trace(m_objects); 1250 visitor->trace(m_objects);
1252 visitor->trace(m_notificationsToPost); 1251 visitor->trace(m_notificationsToPost);
1253 1252
1254 AXObjectCache::trace(visitor); 1253 AXObjectCache::trace(visitor);
1255 } 1254 }
1256 1255
1257 } // namespace blink 1256 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698