ax_relative_bounds.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright 2016 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_RELATIVE_BOUNDS_H_
  5. #define UI_ACCESSIBILITY_AX_RELATIVE_BOUNDS_H_
  6. #include <stdint.h>
  7. #include <iosfwd>
  8. #include <memory>
  9. #include "ui/accessibility/ax_base_export.h"
  10. #include "ui/accessibility/ax_enums.mojom-forward.h"
  11. #include "ui/accessibility/ax_node_id_forward.h"
  12. #include "ui/gfx/geometry/rect_f.h"
  13. #include "ui/gfx/geometry/transform.h"
  14. namespace ui {
  15. // The relative bounding box of an AXNode.
  16. //
  17. // This is an efficient, compact, serializable representation of a node's
  18. // bounding box that requires minimal changes to the tree when layers are
  19. // moved or scrolled. Computing the absolute bounding box of a node requires
  20. // walking up the tree and applying node offsets and transforms until reaching
  21. // the top.
  22. //
  23. // If the offset container id is valid, the bounds are relative
  24. // to the node with that offset container id.
  25. //
  26. // Otherwise, for a node other than the root, the bounds are relative to
  27. // the root of the tree, and for the root of a tree, the bounds are relative
  28. // to its immediate containing node.
  29. struct AX_BASE_EXPORT AXRelativeBounds final {
  30. AXRelativeBounds();
  31. virtual ~AXRelativeBounds();
  32. AXRelativeBounds(const AXRelativeBounds& other);
  33. AXRelativeBounds& operator=(AXRelativeBounds other);
  34. bool operator!=(const AXRelativeBounds& other) const;
  35. bool operator==(const AXRelativeBounds& other) const;
  36. std::string ToString() const;
  37. // The id of an ancestor node in the same AXTree that this object's
  38. // bounding box is relative to, or `kInvalidAXNodeID` if there's no offset
  39. // container.
  40. AXNodeID offset_container_id = kInvalidAXNodeID;
  41. // The relative bounding box of this node.
  42. gfx::RectF bounds;
  43. // An additional transform to apply to position this object and its subtree.
  44. // NOTE: this member is a std::unique_ptr because it's rare and gfx::Transform
  45. // takes up a fair amount of space. The assignment operator and copy
  46. // constructor both make a duplicate of the owned pointer, so it acts more
  47. // like a member than a pointer.
  48. std::unique_ptr<gfx::Transform> transform;
  49. };
  50. AX_BASE_EXPORT std::ostream& operator<<(std::ostream& stream,
  51. const AXRelativeBounds& bounds);
  52. } // namespace ui
  53. #endif // UI_ACCESSIBILITY_AX_RELATIVE_BOUNDS_H_