Commit 0f4e2cd9 authored by Shawn Gallea's avatar Shawn Gallea Committed by Commit Bot

EXO: Move WaylandPointerDelegate out of server.cc

This CL only moves code around.

Bug: 896710
Test: Built on ChromeOS
Change-Id: Id9567918d751a9768d00489b5532a1abea3490e6
Reviewed-on: https://chromium-review.googlesource.com/c/1318083
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@{#608106}
parent fa9be289
......@@ -37,6 +37,8 @@ source_set("wayland") {
"server_util.h",
"wayland_input_delegate.cc",
"wayland_input_delegate.h",
"wayland_pointer_delegate.cc",
"wayland_pointer_delegate.h",
"zcr_notification_shell.cc",
"zcr_notification_shell.h",
"zwp_text_input_manager.cc",
......
......@@ -96,6 +96,7 @@
#include "components/exo/touch_stylus_delegate.h"
#include "components/exo/wayland/server_util.h"
#include "components/exo/wayland/wayland_input_delegate.h"
#include "components/exo/wayland/wayland_pointer_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"
......@@ -3559,133 +3560,6 @@ void bind_data_device_manager(wl_client* client,
////////////////////////////////////////////////////////////////////////////////
// wl_pointer_interface:
// Pointer delegate class that accepts events for surfaces owned by the same
// client as a pointer resource.
class WaylandPointerDelegate : public WaylandInputDelegate,
public PointerDelegate {
public:
explicit WaylandPointerDelegate(wl_resource* pointer_resource)
: pointer_resource_(pointer_resource) {}
// Overridden from PointerDelegate:
void OnPointerDestroying(Pointer* pointer) override { delete this; }
bool CanAcceptPointerEventsForSurface(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
// pointer.
return surface_resource &&
wl_resource_get_client(surface_resource) == client();
}
void OnPointerEnter(Surface* surface,
const gfx::PointF& location,
int button_flags) override {
wl_resource* surface_resource = GetSurfaceResource(surface);
DCHECK(surface_resource);
// Should we be sending button events to the client before the enter event
// if client's pressed button state is different from |button_flags|?
wl_pointer_send_enter(pointer_resource_, next_serial(), surface_resource,
wl_fixed_from_double(location.x()),
wl_fixed_from_double(location.y()));
}
void OnPointerLeave(Surface* surface) override {
wl_resource* surface_resource = GetSurfaceResource(surface);
DCHECK(surface_resource);
wl_pointer_send_leave(pointer_resource_, next_serial(), surface_resource);
}
void OnPointerMotion(base::TimeTicks time_stamp,
const gfx::PointF& location) override {
SendTimestamp(time_stamp);
wl_pointer_send_motion(
pointer_resource_, TimeTicksToMilliseconds(time_stamp),
wl_fixed_from_double(location.x()), wl_fixed_from_double(location.y()));
}
void OnPointerButton(base::TimeTicks time_stamp,
int button_flags,
bool pressed) override {
struct {
ui::EventFlags flag;
uint32_t value;
} buttons[] = {
{ui::EF_LEFT_MOUSE_BUTTON, BTN_LEFT},
{ui::EF_RIGHT_MOUSE_BUTTON, BTN_RIGHT},
{ui::EF_MIDDLE_MOUSE_BUTTON, BTN_MIDDLE},
{ui::EF_FORWARD_MOUSE_BUTTON, BTN_FORWARD},
{ui::EF_BACK_MOUSE_BUTTON, BTN_BACK},
};
uint32_t serial = next_serial();
for (auto button : buttons) {
if (button_flags & button.flag) {
SendTimestamp(time_stamp);
wl_pointer_send_button(
pointer_resource_, serial, TimeTicksToMilliseconds(time_stamp),
button.value, pressed ? WL_POINTER_BUTTON_STATE_PRESSED
: WL_POINTER_BUTTON_STATE_RELEASED);
}
}
}
void OnPointerScroll(base::TimeTicks time_stamp,
const gfx::Vector2dF& offset,
bool discrete) override {
// Same as Weston, the reference compositor.
const double kAxisStepDistance = 10.0 / ui::MouseWheelEvent::kWheelDelta;
if (wl_resource_get_version(pointer_resource_) >=
WL_POINTER_AXIS_SOURCE_SINCE_VERSION) {
int32_t axis_source = discrete ? WL_POINTER_AXIS_SOURCE_WHEEL
: WL_POINTER_AXIS_SOURCE_FINGER;
wl_pointer_send_axis_source(pointer_resource_, axis_source);
}
double x_value = offset.x() * kAxisStepDistance;
SendTimestamp(time_stamp);
wl_pointer_send_axis(pointer_resource_, TimeTicksToMilliseconds(time_stamp),
WL_POINTER_AXIS_HORIZONTAL_SCROLL,
wl_fixed_from_double(-x_value));
double y_value = offset.y() * kAxisStepDistance;
SendTimestamp(time_stamp);
wl_pointer_send_axis(pointer_resource_, TimeTicksToMilliseconds(time_stamp),
WL_POINTER_AXIS_VERTICAL_SCROLL,
wl_fixed_from_double(-y_value));
}
void OnPointerScrollStop(base::TimeTicks time_stamp) override {
if (wl_resource_get_version(pointer_resource_) >=
WL_POINTER_AXIS_STOP_SINCE_VERSION) {
SendTimestamp(time_stamp);
wl_pointer_send_axis_stop(pointer_resource_,
TimeTicksToMilliseconds(time_stamp),
WL_POINTER_AXIS_HORIZONTAL_SCROLL);
SendTimestamp(time_stamp);
wl_pointer_send_axis_stop(pointer_resource_,
TimeTicksToMilliseconds(time_stamp),
WL_POINTER_AXIS_VERTICAL_SCROLL);
}
}
void OnPointerFrame() override {
if (wl_resource_get_version(pointer_resource_) >=
WL_POINTER_FRAME_SINCE_VERSION) {
wl_pointer_send_frame(pointer_resource_);
}
wl_client_flush(client());
}
private:
// The client who own this pointer instance.
wl_client* client() const {
return wl_resource_get_client(pointer_resource_);
}
// Returns the next serial to use for pointer events.
uint32_t next_serial() const {
return wl_display_next_serial(wl_client_get_display(client()));
}
// The pointer resource associated with the pointer.
wl_resource* const pointer_resource_;
DISALLOW_COPY_AND_ASSIGN(WaylandPointerDelegate);
};
void pointer_set_cursor(wl_client* client,
wl_resource* resource,
uint32_t serial,
......
// 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_pointer_delegate.h"
#include <linux/input.h>
#include <wayland-server-core.h>
#include <wayland-server-protocol-core.h>
#include "components/exo/pointer.h"
#include "components/exo/wayland/server_util.h"
#include "ui/events/event_constants.h"
namespace exo {
namespace wayland {
WaylandPointerDelegate::WaylandPointerDelegate(wl_resource* pointer_resource)
: pointer_resource_(pointer_resource) {}
void WaylandPointerDelegate::OnPointerDestroying(Pointer* pointer) {
delete this;
}
bool WaylandPointerDelegate::CanAcceptPointerEventsForSurface(
Surface* surface) const {
wl_resource* surface_resource = GetSurfaceResource(surface);
// We can accept events for this surface if the client is the same as the
// pointer.
return surface_resource &&
wl_resource_get_client(surface_resource) == client();
}
void WaylandPointerDelegate::OnPointerEnter(Surface* surface,
const gfx::PointF& location,
int button_flags) {
wl_resource* surface_resource = GetSurfaceResource(surface);
DCHECK(surface_resource);
// Should we be sending button events to the client before the enter event
// if client's pressed button state is different from |button_flags|?
wl_pointer_send_enter(pointer_resource_, next_serial(), surface_resource,
wl_fixed_from_double(location.x()),
wl_fixed_from_double(location.y()));
}
void WaylandPointerDelegate::OnPointerLeave(Surface* surface) {
wl_resource* surface_resource = GetSurfaceResource(surface);
DCHECK(surface_resource);
wl_pointer_send_leave(pointer_resource_, next_serial(), surface_resource);
}
void WaylandPointerDelegate::OnPointerMotion(base::TimeTicks time_stamp,
const gfx::PointF& location) {
SendTimestamp(time_stamp);
wl_pointer_send_motion(pointer_resource_, TimeTicksToMilliseconds(time_stamp),
wl_fixed_from_double(location.x()),
wl_fixed_from_double(location.y()));
}
void WaylandPointerDelegate::OnPointerButton(base::TimeTicks time_stamp,
int button_flags,
bool pressed) {
struct {
ui::EventFlags flag;
uint32_t value;
} buttons[] = {
{ui::EF_LEFT_MOUSE_BUTTON, BTN_LEFT},
{ui::EF_RIGHT_MOUSE_BUTTON, BTN_RIGHT},
{ui::EF_MIDDLE_MOUSE_BUTTON, BTN_MIDDLE},
{ui::EF_FORWARD_MOUSE_BUTTON, BTN_FORWARD},
{ui::EF_BACK_MOUSE_BUTTON, BTN_BACK},
};
uint32_t serial = next_serial();
for (auto button : buttons) {
if (button_flags & button.flag) {
SendTimestamp(time_stamp);
wl_pointer_send_button(pointer_resource_, serial,
TimeTicksToMilliseconds(time_stamp), button.value,
pressed ? WL_POINTER_BUTTON_STATE_PRESSED
: WL_POINTER_BUTTON_STATE_RELEASED);
}
}
}
void WaylandPointerDelegate::OnPointerScroll(base::TimeTicks time_stamp,
const gfx::Vector2dF& offset,
bool discrete) {
// Same as Weston, the reference compositor.
const double kAxisStepDistance = 10.0 / ui::MouseWheelEvent::kWheelDelta;
if (wl_resource_get_version(pointer_resource_) >=
WL_POINTER_AXIS_SOURCE_SINCE_VERSION) {
int32_t axis_source =
discrete ? WL_POINTER_AXIS_SOURCE_WHEEL : WL_POINTER_AXIS_SOURCE_FINGER;
wl_pointer_send_axis_source(pointer_resource_, axis_source);
}
double x_value = offset.x() * kAxisStepDistance;
SendTimestamp(time_stamp);
wl_pointer_send_axis(pointer_resource_, TimeTicksToMilliseconds(time_stamp),
WL_POINTER_AXIS_HORIZONTAL_SCROLL,
wl_fixed_from_double(-x_value));
double y_value = offset.y() * kAxisStepDistance;
SendTimestamp(time_stamp);
wl_pointer_send_axis(pointer_resource_, TimeTicksToMilliseconds(time_stamp),
WL_POINTER_AXIS_VERTICAL_SCROLL,
wl_fixed_from_double(-y_value));
}
void WaylandPointerDelegate::OnPointerScrollStop(base::TimeTicks time_stamp) {
if (wl_resource_get_version(pointer_resource_) >=
WL_POINTER_AXIS_STOP_SINCE_VERSION) {
SendTimestamp(time_stamp);
wl_pointer_send_axis_stop(pointer_resource_,
TimeTicksToMilliseconds(time_stamp),
WL_POINTER_AXIS_HORIZONTAL_SCROLL);
SendTimestamp(time_stamp);
wl_pointer_send_axis_stop(pointer_resource_,
TimeTicksToMilliseconds(time_stamp),
WL_POINTER_AXIS_VERTICAL_SCROLL);
}
}
void WaylandPointerDelegate::OnPointerFrame() {
if (wl_resource_get_version(pointer_resource_) >=
WL_POINTER_FRAME_SINCE_VERSION) {
wl_pointer_send_frame(pointer_resource_);
}
wl_client_flush(client());
}
wl_client* WaylandPointerDelegate::client() const {
return wl_resource_get_client(pointer_resource_);
}
uint32_t WaylandPointerDelegate::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_POINTER_DELEGATE_H_
#define COMPONENTS_EXO_WAYLAND_WAYLAND_POINTER_DELEGATE_H_
#include "components/exo/pointer_delegate.h"
#include "components/exo/wayland/wayland_input_delegate.h"
struct wl_client;
struct wl_resource;
namespace exo {
namespace wayland {
// Pointer delegate class that accepts events for surfaces owned by the same
// client as a pointer resource.
class WaylandPointerDelegate : public WaylandInputDelegate,
public PointerDelegate {
public:
explicit WaylandPointerDelegate(wl_resource* pointer_resource);
// Overridden from PointerDelegate:
void OnPointerDestroying(Pointer* pointer) override;
bool CanAcceptPointerEventsForSurface(Surface* surface) const override;
void OnPointerEnter(Surface* surface,
const gfx::PointF& location,
int button_flags) override;
void OnPointerLeave(Surface* surface) override;
void OnPointerMotion(base::TimeTicks time_stamp,
const gfx::PointF& location) override;
void OnPointerButton(base::TimeTicks time_stamp,
int button_flags,
bool pressed) override;
void OnPointerScroll(base::TimeTicks time_stamp,
const gfx::Vector2dF& offset,
bool discrete) override;
void OnPointerScrollStop(base::TimeTicks time_stamp) override;
void OnPointerFrame() override;
private:
// The client who own this pointer instance.
wl_client* client() const;
// Returns the next serial to use for pointer events.
uint32_t next_serial() const;
// The pointer resource associated with the pointer.
wl_resource* const pointer_resource_;
DISALLOW_COPY_AND_ASSIGN(WaylandPointerDelegate);
};
} // namespace wayland
} // namespace exo
#endif // COMPONENTS_EXO_WAYLAND_WAYLAND_POINTER_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