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 
5 #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_POSITIONER_H_
6 #define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_POSITIONER_H_
7 
8 #include <utility>
9 
10 #include <xdg-shell-server-protocol.h>
11 #include <xdg-shell-unstable-v6-server-protocol.h>
12 
13 #include "base/macros.h"
14 #include "ui/gfx/geometry/rect.h"
15 #include "ui/gfx/geometry/size.h"
16 #include "ui/ozone/platform/wayland/test/server_object.h"
17 
18 struct wl_resource;
19 
20 namespace wl {
21 
22 extern const struct xdg_positioner_interface kTestXdgPositionerImpl;
23 extern const struct zxdg_positioner_v6_interface kTestZxdgPositionerV6Impl;
24 
25 // A simple positioner object that provides a collection of rules of a child
26 // surface relative to a parent surface.
27 class TestPositioner : public ServerObject {
28  public:
29   struct PopupPosition {
30     gfx::Rect anchor_rect;
31     gfx::Size size;
32     uint32_t anchor = 0;
33     uint32_t gravity = 0;
34     uint32_t constraint_adjustment = 0;
35   };
36 
37   explicit TestPositioner(wl_resource* resource);
38   ~TestPositioner() override;
39 
position()40   PopupPosition position() { return std::move(position_); }
set_size(gfx::Size size)41   void set_size(gfx::Size size) { position_.size = size; }
set_anchor_rect(gfx::Rect anchor_rect)42   void set_anchor_rect(gfx::Rect anchor_rect) {
43     position_.anchor_rect = anchor_rect;
44   }
set_anchor(uint32_t anchor)45   void set_anchor(uint32_t anchor) { position_.anchor = anchor; }
set_gravity(uint32_t gravity)46   void set_gravity(uint32_t gravity) { position_.gravity = gravity; }
set_constraint_adjustment(uint32_t constraint_adjustment)47   void set_constraint_adjustment(uint32_t constraint_adjustment) {
48     position_.constraint_adjustment = constraint_adjustment;
49   }
50 
51  private:
52   PopupPosition position_;
53 
54   DISALLOW_COPY_AND_ASSIGN(TestPositioner);
55 };
56 
57 }  // namespace wl
58 
59 #endif  // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_POSITIONER_H_
60