1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
|
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_EXO_WAYLAND_TEST_SHELL_CLIENT_DATA_H_
#define COMPONENTS_EXO_WAYLAND_TEST_SHELL_CLIENT_DATA_H_
#include <wayland-client.h>
#include <xdg-shell-client-protocol.h>
#include <memory>
#include "base/memory/raw_ptr.h"
#include "components/exo/wayland/test/test_client.h"
struct wl_surface;
struct xdg_surface;
struct xdg_toplevel;
struct zaura_toplevel;
struct zcr_remote_surface_v2;
struct wl_data_device;
struct wl_data_source;
namespace gfx {
class Size;
class Rect;
class PointF;
} // namespace gfx
namespace exo::wayland::test {
struct ResourceKey;
class TestBuffer;
class InputListener {
public:
InputListener() = default;
virtual ~InputListener() = default;
// Input events.
virtual void OnEnter(uint32_t serial,
wl_surface* surface,
const gfx::PointF& point) {}
virtual void OnLeave(uint32_t serial, wl_surface* surface) {}
virtual void OnButtonPressed(uint32_t serial, uint32_t button) {}
virtual void OnButtonReleased(uint32_t serial, uint32_t button) {}
virtual void OnMotion(const gfx::PointF& point) {}
// Touch events.
virtual void OnTouchDown(uint32_t serial,
wl_surface* surface,
int32_t id,
const gfx::PointF& point) {}
virtual void OnTouchUp(uint32_t serial, int32_t id) {}
};
// A custom shell object which can act as xdg toplevel or remote surface.
// TODO(oshima): Implement more key events complete and move to a separate file.
class ShellClientData : public test::TestClient::CustomData {
public:
explicit ShellClientData(test::TestClient* client);
~ShellClientData() override;
void CreateXdgToplevel();
void CreateRemoteSurface();
void Pin();
void UnsetSnap();
// Common to both xdg toplevel and remote surface.
void CreateAndAttachBuffer(const gfx::Size& size);
void Commit();
void DestroySurface();
// zaura_shell methods.
void RequestWindowBounds(const gfx::Rect& bounds, wl_output* target_output);
void set_input_listener(std::unique_ptr<InputListener> input_listener) {
input_listener_ = std::move(input_listener);
}
InputListener* input_listener() { return input_listener_.get(); }
// Start Drag and Drop operation.
void StartDrag(uint32_t serial);
void DestroyDataSource();
void Close();
ResourceKey GetSurfaceResourceKey() const;
bool close_called() const { return close_called_; }
void set_data_offer(
std::unique_ptr<wl_data_offer, decltype(&wl_data_offer_destroy)>
data_offer) {
data_offer_ = std::move(data_offer);
}
private:
bool close_called_ = false;
const raw_ptr<TestClient> client_;
std::unique_ptr<wl_pointer, decltype(&wl_pointer_destroy)> pointer_;
std::unique_ptr<wl_touch, decltype(&wl_touch_destroy)> touch_;
std::unique_ptr<wl_surface, decltype(&wl_surface_destroy)> surface_;
std::unique_ptr<xdg_surface, decltype(&xdg_surface_destroy)> xdg_surface_;
std::unique_ptr<xdg_toplevel, decltype(&xdg_toplevel_destroy)> xdg_toplevel_;
std::unique_ptr<zaura_toplevel, decltype(&zaura_toplevel_destroy)>
aura_toplevel_;
std::unique_ptr<zcr_remote_surface_v2,
decltype(&zcr_remote_surface_v2_destroy)>
remote_surface_;
std::unique_ptr<TestBuffer> buffer_;
std::unique_ptr<wl_data_device, decltype(&wl_data_device_destroy)>
data_device_;
std::unique_ptr<wl_data_source, decltype(&wl_data_source_destroy)>
data_source_;
std::unique_ptr<wl_data_offer, decltype(&wl_data_offer_destroy)> data_offer_;
std::unique_ptr<InputListener> input_listener_;
};
} // namespace exo::wayland::test
#endif // COMPONENTS_EXO_WAYLAND_TEST_SHELL_CLIENT_DATA_H_
|