ax_live_region_tracker.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright 2021 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef UI_ACCESSIBILITY_AX_LIVE_REGION_TRACKER_H_
  5. #define UI_ACCESSIBILITY_AX_LIVE_REGION_TRACKER_H_
  6. #include <map>
  7. #include <set>
  8. #include "ui/accessibility/ax_node_data.h"
  9. #include "ui/accessibility/ax_tree.h"
  10. namespace ui {
  11. // Class that works with `AXEventGenerator` to track live regions in
  12. // an `AXTree`, by maintaining a map from each node to the root of
  13. // its live region. This map is used to trigger events on live region
  14. // roots when a node in a live region changes.
  15. class AXLiveRegionTracker {
  16. public:
  17. static bool IsLiveRegionRoot(const AXNode& node);
  18. explicit AXLiveRegionTracker(const AXTree& tree);
  19. virtual ~AXLiveRegionTracker();
  20. AXLiveRegionTracker(const AXLiveRegionTracker& other) = delete;
  21. AXLiveRegionTracker& operator=(const AXLiveRegionTracker& other) = delete;
  22. // Walk upwards in the tree and determine the live root for this node,
  23. // overriding any previously assigned live root.
  24. void UpdateCachedLiveRootForNode(const AXNode& node);
  25. void OnNodeWillBeDeleted(const AXNode& node);
  26. void OnAtomicUpdateFinished();
  27. AXNode* GetLiveRoot(const AXNode& node) const;
  28. AXNode* GetLiveRootIfNotBusy(const AXNode& node) const;
  29. const std::set<AXNodeID>& live_region_roots_with_changes() const {
  30. return live_region_roots_with_changes_;
  31. }
  32. private:
  33. void WalkTreeAndAssignLiveRootsToNodes(const AXNode& node,
  34. const AXNode* current_root);
  35. void QueueChangeEventForDeletedNode(const AXNode& root);
  36. const AXTree& tree_;
  37. // Map from live region node to its live region root ID.
  38. std::map<const AXNodeID, AXNodeID> live_region_node_to_root_id_;
  39. std::set<AXNodeID> deleted_node_ids_;
  40. std::set<AXNodeID> live_region_roots_with_changes_;
  41. };
  42. } // namespace ui
  43. #endif // UI_ACCESSIBILITY_AX_LIVE_REGION_TRACKER_H_