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