wayland_positioner.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // Copyright 2019 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 COMPONENTS_EXO_WAYLAND_WAYLAND_POSITIONER_H_
  5. #define COMPONENTS_EXO_WAYLAND_WAYLAND_POSITIONER_H_
  6. #include <xdg-shell-server-protocol.h>
  7. #include "ui/gfx/geometry/point.h"
  8. #include "ui/gfx/geometry/rect.h"
  9. #include "ui/gfx/geometry/size.h"
  10. #include "ui/gfx/geometry/vector2d.h"
  11. namespace exo {
  12. namespace wayland {
  13. class WaylandPositioner {
  14. public:
  15. // Holds the result of window positioning.
  16. struct Result {
  17. gfx::Point origin;
  18. gfx::Size size;
  19. };
  20. // Represents the 1-dimensional projection of the gravity/anchor values.
  21. enum Direction { kNegative = -1, kNeutral = 0, kPositive = 1 };
  22. // Controls whether anchor and gravity are set using the unstable bitfields or
  23. // the stable enums.
  24. enum Version { UNSTABLE, STABLE };
  25. WaylandPositioner(Version v) : version_(v) {}
  26. WaylandPositioner(const WaylandPositioner&) = delete;
  27. WaylandPositioner& operator=(const WaylandPositioner&) = delete;
  28. // Calculate and return bounds from current state.
  29. Result CalculateBounds(const gfx::Rect& work_area) const;
  30. void SetSize(gfx::Size size) { size_ = std::move(size); }
  31. void SetAnchorRect(gfx::Rect anchor_rect) {
  32. anchor_rect_ = std::move(anchor_rect);
  33. }
  34. void SetAnchor(uint32_t anchor);
  35. void SetGravity(uint32_t gravity);
  36. void SetAdjustment(uint32_t adjustment) { adjustment_ = adjustment; }
  37. void SetOffset(gfx::Vector2d offset) { offset_ = std::move(offset); }
  38. private:
  39. Version version_;
  40. gfx::Size size_;
  41. gfx::Rect anchor_rect_;
  42. Direction anchor_x_ = kNeutral;
  43. Direction anchor_y_ = kNeutral;
  44. Direction gravity_x_ = kNeutral;
  45. Direction gravity_y_ = kNeutral;
  46. // A bitmask that defines the subset of modifications to the position/size
  47. // that are allowed, see zxdg_positioner.constraint_adjustment() for more
  48. // details.
  49. uint32_t adjustment_ = XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_NONE;
  50. // Defines an absolute translation (i.e. unaffected by flipping, scaling or
  51. // resizing) for the placement of the window relative to the |anchor_rect_|.
  52. // See zxdg_positioner.set_offset() for more details.
  53. gfx::Vector2d offset_;
  54. };
  55. } // namespace wayland
  56. } // namespace exo
  57. #endif // COMPONENTS_EXO_WAYLAND_WAYLAND_POSITIONER_H_