Commit ebc16b65 authored by Shawn Gallea's avatar Shawn Gallea Committed by Commit Bot

EXO: Refactor WaylandTouchDelegate into its own file

Move WaylandTouchDelegate out of server.cc
This CL only moves code around.

Bug: 896710
Test: Built on ChromeOS
Change-Id: I8fc2cb3d52c76bdcc4d52c70e63beeb6cd403894
Reviewed-on: https://chromium-review.googlesource.com/c/1318737
Commit-Queue: Shawn Gallea <sagallea@google.com>
Reviewed-by: default avatarDaniele Castagna <dcastagna@chromium.org>
Reviewed-by: default avatarDaniel Nicoara <dnicoara@chromium.org>
Cr-Commit-Position: refs/heads/master@{#608211}
parent 1a2066fb
......@@ -41,6 +41,8 @@ source_set("wayland") {
"wayland_keyboard_delegate.h",
"wayland_pointer_delegate.cc",
"wayland_pointer_delegate.h",
"wayland_touch_delegate.cc",
"wayland_touch_delegate.h",
"zcr_notification_shell.cc",
"zcr_notification_shell.h",
"zwp_text_input_manager.cc",
......
......@@ -98,6 +98,7 @@
#include "components/exo/wayland/wayland_input_delegate.h"
#include "components/exo/wayland/wayland_keyboard_delegate.h"
#include "components/exo/wayland/wayland_pointer_delegate.h"
#include "components/exo/wayland/wayland_touch_delegate.h"
#include "components/exo/wayland/zcr_notification_shell.h"
#include "components/exo/wayland/zwp_text_input_manager.h"
#include "components/exo/wm_helper.h"
......@@ -3596,80 +3597,6 @@ const struct wl_keyboard_interface keyboard_implementation = {keyboard_release};
////////////////////////////////////////////////////////////////////////////////
// wl_touch_interface:
// Touch delegate class that accepts events for surfaces owned by the same
// client as a touch resource.
class WaylandTouchDelegate : public WaylandInputDelegate, public TouchDelegate {
public:
explicit WaylandTouchDelegate(wl_resource* touch_resource)
: touch_resource_(touch_resource) {}
// Overridden from TouchDelegate:
void OnTouchDestroying(Touch* touch) override { delete this; }
bool CanAcceptTouchEventsForSurface(Surface* surface) const override {
wl_resource* surface_resource = GetSurfaceResource(surface);
// We can accept events for this surface if the client is the same as the
// touch resource.
return surface_resource &&
wl_resource_get_client(surface_resource) == client();
}
void OnTouchDown(Surface* surface,
base::TimeTicks time_stamp,
int id,
const gfx::PointF& location) override {
wl_resource* surface_resource = GetSurfaceResource(surface);
DCHECK(surface_resource);
SendTimestamp(time_stamp);
wl_touch_send_down(touch_resource_, next_serial(),
TimeTicksToMilliseconds(time_stamp), surface_resource,
id, wl_fixed_from_double(location.x()),
wl_fixed_from_double(location.y()));
}
void OnTouchUp(base::TimeTicks time_stamp, int id) override {
SendTimestamp(time_stamp);
wl_touch_send_up(touch_resource_, next_serial(),
TimeTicksToMilliseconds(time_stamp), id);
}
void OnTouchMotion(base::TimeTicks time_stamp,
int id,
const gfx::PointF& location) override {
SendTimestamp(time_stamp);
wl_touch_send_motion(touch_resource_, TimeTicksToMilliseconds(time_stamp),
id, wl_fixed_from_double(location.x()),
wl_fixed_from_double(location.y()));
}
void OnTouchShape(int id, float major, float minor) override {
if (wl_resource_get_version(touch_resource_) >=
WL_TOUCH_SHAPE_SINCE_VERSION) {
wl_touch_send_shape(touch_resource_, id, wl_fixed_from_double(major),
wl_fixed_from_double(minor));
}
}
void OnTouchFrame() override {
if (wl_resource_get_version(touch_resource_) >=
WL_TOUCH_FRAME_SINCE_VERSION) {
wl_touch_send_frame(touch_resource_);
}
wl_client_flush(client());
}
void OnTouchCancel() override {
wl_touch_send_cancel(touch_resource_);
}
private:
// The client who own this touch instance.
wl_client* client() const { return wl_resource_get_client(touch_resource_); }
// Returns the next serial to use for keyboard events.
uint32_t next_serial() const {
return wl_display_next_serial(wl_client_get_display(client()));
}
// The touch resource associated with the touch.
wl_resource* const touch_resource_;
DISALLOW_COPY_AND_ASSIGN(WaylandTouchDelegate);
};
void touch_release(wl_client* client, wl_resource* resource) {
wl_resource_destroy(resource);
}
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/exo/wayland/wayland_touch_delegate.h"
#include <wayland-server-core.h>
#include <wayland-server-protocol-core.h>
#include "components/exo/touch.h"
#include "components/exo/wayland/server_util.h"
namespace exo {
namespace wayland {
WaylandTouchDelegate::WaylandTouchDelegate(wl_resource* touch_resource)
: touch_resource_(touch_resource) {}
void WaylandTouchDelegate::OnTouchDestroying(Touch* touch) {
delete this;
}
bool WaylandTouchDelegate::CanAcceptTouchEventsForSurface(
Surface* surface) const {
wl_resource* surface_resource = GetSurfaceResource(surface);
// We can accept events for this surface if the client is the same as the
// touch resource.
return surface_resource &&
wl_resource_get_client(surface_resource) == client();
}
void WaylandTouchDelegate::OnTouchDown(Surface* surface,
base::TimeTicks time_stamp,
int id,
const gfx::PointF& location) {
wl_resource* surface_resource = GetSurfaceResource(surface);
DCHECK(surface_resource);
SendTimestamp(time_stamp);
wl_touch_send_down(touch_resource_, next_serial(),
TimeTicksToMilliseconds(time_stamp), surface_resource, id,
wl_fixed_from_double(location.x()),
wl_fixed_from_double(location.y()));
}
void WaylandTouchDelegate::OnTouchUp(base::TimeTicks time_stamp, int id) {
SendTimestamp(time_stamp);
wl_touch_send_up(touch_resource_, next_serial(),
TimeTicksToMilliseconds(time_stamp), id);
}
void WaylandTouchDelegate::OnTouchMotion(base::TimeTicks time_stamp,
int id,
const gfx::PointF& location) {
SendTimestamp(time_stamp);
wl_touch_send_motion(touch_resource_, TimeTicksToMilliseconds(time_stamp), id,
wl_fixed_from_double(location.x()),
wl_fixed_from_double(location.y()));
}
void WaylandTouchDelegate::OnTouchShape(int id, float major, float minor) {
if (wl_resource_get_version(touch_resource_) >=
WL_TOUCH_SHAPE_SINCE_VERSION) {
wl_touch_send_shape(touch_resource_, id, wl_fixed_from_double(major),
wl_fixed_from_double(minor));
}
}
void WaylandTouchDelegate::OnTouchFrame() {
if (wl_resource_get_version(touch_resource_) >=
WL_TOUCH_FRAME_SINCE_VERSION) {
wl_touch_send_frame(touch_resource_);
}
wl_client_flush(client());
}
void WaylandTouchDelegate::OnTouchCancel() {
wl_touch_send_cancel(touch_resource_);
}
wl_client* WaylandTouchDelegate::client() const {
return wl_resource_get_client(touch_resource_);
}
uint32_t WaylandTouchDelegate::next_serial() const {
return wl_display_next_serial(wl_client_get_display(client()));
}
} // namespace wayland
} // namespace exo
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_EXO_WAYLAND_WAYLAND_TOUCH_DELEGATE_H_
#define COMPONENTS_EXO_WAYLAND_WAYLAND_TOUCH_DELEGATE_H_
#include "components/exo/touch_delegate.h"
#include "components/exo/wayland/wayland_input_delegate.h"
struct wl_client;
struct wl_resource;
namespace exo {
namespace wayland {
// Touch delegate class that accepts events for surfaces owned by the same
// client as a touch resource.
class WaylandTouchDelegate : public WaylandInputDelegate, public TouchDelegate {
public:
explicit WaylandTouchDelegate(wl_resource* touch_resource);
// Overridden from TouchDelegate:
void OnTouchDestroying(Touch* touch) override;
bool CanAcceptTouchEventsForSurface(Surface* surface) const override;
void OnTouchDown(Surface* surface,
base::TimeTicks time_stamp,
int id,
const gfx::PointF& location) override;
void OnTouchUp(base::TimeTicks time_stamp, int id) override;
void OnTouchMotion(base::TimeTicks time_stamp,
int id,
const gfx::PointF& location) override;
void OnTouchShape(int id, float major, float minor) override;
void OnTouchFrame() override;
void OnTouchCancel() override;
private:
// The client who own this touch instance.
wl_client* client() const;
// Returns the next serial to use for keyboard events.
uint32_t next_serial() const;
// The touch resource associated with the touch.
wl_resource* const touch_resource_;
DISALLOW_COPY_AND_ASSIGN(WaylandTouchDelegate);
};
} // namespace wayland
} // namespace exo
#endif // COMPONENTS_EXO_WAYLAND_WAYLAND_TOUCH_DELEGATE_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment