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 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_OZONE_PLATFORM_WAYLAND_HOST_WAYLAND_POINTER_H_
#define UI_OZONE_PLATFORM_WAYLAND_HOST_WAYLAND_POINTER_H_
#include <cstdint>
#include <optional>
#include "base/memory/raw_ptr.h"
#include "ui/events/event_constants.h"
#include "ui/events/types/event_type.h"
#include "ui/ozone/platform/wayland/common/wayland_object.h"
namespace base {
class TimeTicks;
}
namespace gfx {
class PointF;
class Vector2dF;
} // namespace gfx
namespace wl {
enum class EventDispatchPolicy;
} // namespace wl
namespace ui {
class WaylandConnection;
class WaylandWindow;
// Wraps the wl_pointer object and injects event data through
// |WaylandPointer::Delegate| interface.
class WaylandPointer {
public:
class Delegate;
WaylandPointer(wl_pointer* pointer,
WaylandConnection* connection,
Delegate* delegate);
WaylandPointer(const WaylandPointer&) = delete;
WaylandPointer& operator=(const WaylandPointer&) = delete;
virtual ~WaylandPointer();
uint32_t id() const { return obj_.id(); }
wl_pointer* wl_object() const { return obj_.get(); }
private:
// wl_pointer_listener callbacks:
static void OnEnter(void* data,
wl_pointer* obj,
uint32_t serial,
wl_surface* surface,
wl_fixed_t surface_x,
wl_fixed_t surface_y);
static void OnLeave(void* data,
wl_pointer* obj,
uint32_t serial,
wl_surface* surface);
static void OnMotion(void* data,
wl_pointer* obj,
uint32_t time,
wl_fixed_t surface_x,
wl_fixed_t surface_y);
static void OnButton(void* data,
wl_pointer* obj,
uint32_t serial,
uint32_t time,
uint32_t button,
uint32_t state);
static void OnAxis(void* data,
wl_pointer* obj,
uint32_t time,
uint32_t axis,
wl_fixed_t value);
static void OnFrame(void* data, wl_pointer* obj);
static void OnAxisSource(void* data, wl_pointer* obj, uint32_t axis_source);
static void OnAxisStop(void* data,
wl_pointer* obj,
uint32_t time,
uint32_t axis);
static void OnAxisDiscrete(void* data,
wl_pointer* obj,
uint32_t axis,
int32_t discrete);
static void OnAxisValue120(void* data,
wl_pointer* obj,
uint32_t axis,
int32_t value120);
void OnAxisImpl(double delta,
uint32_t axis,
std::optional<base::TimeTicks> timestamp,
bool is_high_resolution);
wl::Object<wl_pointer> obj_;
const raw_ptr<WaylandConnection> connection_;
const raw_ptr<Delegate> delegate_;
// Whether the axis source event has been received for the current frame.
//
// The axis source event is optional, and the frame event can be sent with no
// source set previously. However, the delegate expects the axis source to be
// set explicitly for the axis events. Hence, we set the default source when
// possible so that the sequence of pointer events has it set.
bool axis_source_received_ = false;
};
class WaylandPointer::Delegate {
public:
virtual void OnPointerFocusChanged(
WaylandWindow* window,
const gfx::PointF& location,
base::TimeTicks timestamp,
wl::EventDispatchPolicy dispatch_policy) = 0;
virtual void OnPointerButtonEvent(EventType evtype,
int changed_button,
base::TimeTicks timestamp,
WaylandWindow* window,
wl::EventDispatchPolicy dispatch_policy,
bool allow_release_of_unpressed_button,
bool is_synthesized) = 0;
virtual void OnPointerMotionEvent(const gfx::PointF& location,
base::TimeTicks timestamp,
wl::EventDispatchPolicy dispatch_policy,
bool is_synthesized) = 0;
virtual void OnPointerAxisEvent(const gfx::Vector2dF& offset,
std::optional<base::TimeTicks> timestamp,
bool is_high_resolution) = 0;
virtual void OnPointerFrameEvent() = 0;
virtual void OnPointerAxisSourceEvent(uint32_t axis_source) = 0;
virtual void OnPointerAxisStopEvent(uint32_t axis,
base::TimeTicks timestamp) = 0;
virtual const gfx::PointF& GetPointerLocation() const = 0;
virtual bool IsPointerButtonPressed(EventFlags button) const = 0;
virtual void ReleasePressedPointerButtons(WaylandWindow* window,
base::TimeTicks timestamp) = 0;
};
} // namespace ui
#endif // UI_OZONE_PLATFORM_WAYLAND_HOST_WAYLAND_POINTER_H_
|