ax_tree_source.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // Copyright 2013 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_TREE_SOURCE_H_
  5. #define UI_ACCESSIBILITY_AX_TREE_SOURCE_H_
  6. #include <stdint.h>
  7. #include <string>
  8. #include <vector>
  9. #include "base/notreached.h"
  10. #include "third_party/skia/include/core/SkBitmap.h"
  11. #include "ui/accessibility/ax_node_data.h"
  12. #include "ui/accessibility/ax_tree_data.h"
  13. #include "ui/accessibility/ax_tree_source_observer.h"
  14. namespace ui {
  15. // An AXTreeSource is an abstract interface for a serializable
  16. // accessibility tree. The tree may be in some other format or
  17. // may be computed dynamically, but maintains the properties that
  18. // it's a strict tree, it has a unique id for each node, and all
  19. // of the accessibility information about a node can be serialized
  20. // as an AXNodeData. This is the primary interface to use when
  21. // an accessibility tree will be sent over an IPC before being
  22. // consumed.
  23. template <typename AXNodeSource>
  24. class AXTreeSource {
  25. public:
  26. virtual ~AXTreeSource() = default;
  27. // Get the tree data and returns true if there is any data to copy.
  28. virtual bool GetTreeData(AXTreeData* data) const = 0;
  29. // Get the root of the tree.
  30. virtual AXNodeSource GetRoot() const = 0;
  31. // Get a node by its id. If no node by that id exists in the tree, return a
  32. // null node, i.e. one that will return false if you call IsValid on it.
  33. virtual AXNodeSource GetFromId(AXNodeID id) const = 0;
  34. // Return the id of a node. All ids must be positive integers; 0 is not a
  35. // valid ID. IDs are unique only across the current tree source, not across
  36. // tree sources.
  37. virtual AXNodeID GetId(AXNodeSource node) const = 0;
  38. // Append all children of |node| to |out_children|.
  39. virtual void GetChildren(AXNodeSource node,
  40. std::vector<AXNodeSource>* out_children) const = 0;
  41. // Get the parent of |node|.
  42. virtual AXNodeSource GetParent(AXNodeSource node) const = 0;
  43. // Returns true if |node| is valid, and false if it's a null pointer or a
  44. // node object representing the null pointer.
  45. virtual bool IsValid(AXNodeSource node) const = 0;
  46. // Returns true if |node| is an ignored node
  47. virtual bool IsIgnored(AXNodeSource node) const = 0;
  48. // Returns true if two nodes are equal.
  49. virtual bool IsEqual(AXNodeSource node1,
  50. AXNodeSource node2) const = 0;
  51. // Return a AXNodeSource representing null.
  52. virtual AXNodeSource GetNull() const = 0;
  53. // Serialize one node in the tree.
  54. virtual void SerializeNode(AXNodeSource node, AXNodeData* out_data) const = 0;
  55. // Return a string useful for debugging a node.
  56. virtual std::string GetDebugString(AXNodeSource node) const {
  57. AXNodeData node_data;
  58. SerializeNode(node, &node_data);
  59. return node_data.ToString();
  60. }
  61. // This is called by AXTreeSerializer when it serializes a tree and
  62. // discovers that a node previously in the tree is no longer part of
  63. // the tree. It can be used to allow an AXTreeSource to keep a cache
  64. // indexed by node ID and delete nodes when they're no longer needed.
  65. virtual void SerializerClearedNode(AXNodeID node_id) {}
  66. // The following methods should be overridden in order to add or remove an
  67. // `AXTreeSourceObserver`, which is notified when nodes are added, removed or
  68. // updated in this tree source.
  69. virtual void AddObserver(ui::AXTreeSourceObserver<AXNodeSource>* observer) {
  70. NOTIMPLEMENTED();
  71. }
  72. virtual void RemoveObserver(
  73. ui::AXTreeSourceObserver<AXNodeSource>* observer) {
  74. NOTIMPLEMENTED();
  75. }
  76. protected:
  77. AXTreeSource() {}
  78. };
  79. } // namespace ui
  80. #endif // UI_ACCESSIBILITY_AX_TREE_SOURCE_H_