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 147 148
|
// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/ozone/platform/wayland/host/wayland_touch.h"
#include "base/logging.h"
#include "base/notreached.h"
#include "base/time/time.h"
#include "ui/events/types/event_type.h"
#include "ui/gfx/geometry/point_f.h"
#include "ui/ozone/common/features.h"
#include "ui/ozone/platform/wayland/common/wayland_util.h"
#include "ui/ozone/platform/wayland/host/wayland_connection.h"
#include "ui/ozone/platform/wayland/host/wayland_serial_tracker.h"
#include "ui/ozone/platform/wayland/host/wayland_window.h"
namespace ui {
namespace {
// See TODO in //ui/ozone/common/features.cc
wl::EventDispatchPolicy GetEventDispatchPolicy() {
return IsDispatchTouchEventsOnFrameEventEnabled()
? wl::EventDispatchPolicy::kOnFrame
: wl::EventDispatchPolicy::kImmediate;
}
} // namespace
WaylandTouch::WaylandTouch(wl_touch* touch,
WaylandConnection* connection,
Delegate* delegate)
: obj_(touch), connection_(connection), delegate_(delegate) {
static constexpr wl_touch_listener kTouchListener = {
.down = &OnTouchDown,
.up = &OnTouchUp,
.motion = &OnTouchMotion,
.frame = &OnTouchFrame,
.cancel = &OnTouchCancel,
.shape = &OnTouchShape,
.orientation = &OnTouchOrientation,
};
wl_touch_add_listener(obj_.get(), &kTouchListener, this);
}
WaylandTouch::~WaylandTouch() {
delegate_->OnTouchCancelEvent();
}
// static
void WaylandTouch::OnTouchDown(void* data,
wl_touch* touch,
uint32_t serial,
uint32_t time,
struct wl_surface* surface,
int32_t id,
wl_fixed_t x,
wl_fixed_t y) {
if (!surface)
return;
auto* self = static_cast<WaylandTouch*>(data);
DCHECK(self);
self->connection_->serial_tracker().UpdateSerial(wl::SerialType::kTouchPress,
serial);
WaylandWindow* window = wl::RootWindowFromWlSurface(surface);
if (!window) {
return;
}
self->delegate_->OnTouchPressEvent(
window, gfx::PointF(wl_fixed_to_double(x), wl_fixed_to_double(y)),
wl::EventMillisecondsToTimeTicks(time), id, GetEventDispatchPolicy());
}
// static
void WaylandTouch::OnTouchUp(void* data,
wl_touch* touch,
uint32_t serial,
uint32_t time,
int32_t id) {
auto* self = static_cast<WaylandTouch*>(data);
DCHECK(self);
self->delegate_->OnTouchReleaseEvent(wl::EventMillisecondsToTimeTicks(time),
id, GetEventDispatchPolicy(),
/*is_synthesized=*/false);
}
// static
void WaylandTouch::OnTouchMotion(void* data,
wl_touch* touch,
uint32_t time,
int32_t id,
wl_fixed_t x,
wl_fixed_t y) {
auto* self = static_cast<WaylandTouch*>(data);
DCHECK(self);
const WaylandWindow* target = self->delegate_->GetTouchTarget(id);
if (!target) {
LOG(WARNING) << "Touch event fired with wrong id";
return;
}
self->delegate_->OnTouchMotionEvent(
gfx::PointF(wl_fixed_to_double(x), wl_fixed_to_double(y)),
wl::EventMillisecondsToTimeTicks(time), id, GetEventDispatchPolicy(),
/*is_synthesized=*/false);
}
// static
void WaylandTouch::OnTouchShape(void* data,
wl_touch* touch,
int32_t id,
wl_fixed_t major,
wl_fixed_t minor) {
NOTIMPLEMENTED_LOG_ONCE();
}
// static
void WaylandTouch::OnTouchOrientation(void* data,
wl_touch* touch,
int32_t id,
wl_fixed_t orientation) {
NOTIMPLEMENTED_LOG_ONCE();
}
// static
void WaylandTouch::OnTouchCancel(void* data, wl_touch* touch) {
auto* self = static_cast<WaylandTouch*>(data);
DCHECK(self);
self->delegate_->OnTouchCancelEvent();
}
// static
void WaylandTouch::OnTouchFrame(void* data, wl_touch* touch) {
auto* self = static_cast<WaylandTouch*>(data);
DCHECK(self);
self->delegate_->OnTouchFrame();
}
} // namespace ui
|