Skip to content

Commit

Permalink
[ozone/wayland] Factor "data device manager" out of WaylandConnection
Browse files Browse the repository at this point in the history
CL adds a WaylandDataDeviceManager class and moves that handle
wl_data_device_manager logic out of WaylandConnection into it.

It brings no functionality change, but makes it easier to be extended
to support primary selection (middle-click to paste).

BUG=578890

Change-Id: I8c04035bf4d3e9de5a0c2cac5c83d4552912cc0d
Reviewed-on: https://chromium-review.googlesource.com/1035943
Reviewed-by: Michael Spang <spang@chromium.org>
Commit-Queue: Antonio Gomes <tonikitoo@igalia.com>
Cr-Commit-Position: refs/heads/master@{#554910}
  • Loading branch information
tonikitoo authored and Commit Bot committed Apr 30, 2018
1 parent 73a64ff commit d3730d7
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 6 deletions.
2 changes: 2 additions & 0 deletions ui/ozone/platform/wayland/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ source_set("wayland") {
"wayland_cursor.h",
"wayland_data_device.cc",
"wayland_data_device.h",
"wayland_data_device_manager.cc",
"wayland_data_device_manager.h",
"wayland_data_offer.cc",
"wayland_data_offer.h",
"wayland_data_source.cc",
Expand Down
15 changes: 10 additions & 5 deletions ui/ozone/platform/wayland/wayland_connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ void WaylandConnection::OfferClipboardData(
const ClipboardDelegate::DataMap& data_map,
ClipboardDelegate::OfferDataClosure callback) {
if (!data_source_) {
wl_data_source* data_source =
wl_data_device_manager_create_data_source(data_device_manager_.get());
wl_data_source* data_source = data_device_manager_->CreateSource();
data_source_.reset(new WaylandDataSource(data_source));
data_source_->set_connection(this);
data_source_->WriteToClipboard(data_map);
Expand Down Expand Up @@ -264,8 +263,7 @@ void WaylandConnection::Global(void* data,
<< "No data device manager. Clipboard won't be fully functional";
return;
}
wl_data_device* data_device = wl_data_device_manager_get_data_device(
connection->data_device_manager_.get(), connection->seat_.get());
wl_data_device* data_device = connection->data_device_manager_->GetDevice();
connection->data_device_.reset(
new WaylandDataDevice(connection, data_device));
} else if (!connection->shell_v6_ &&
Expand Down Expand Up @@ -305,8 +303,15 @@ void WaylandConnection::Global(void* data,
base::WrapUnique(new WaylandOutput(output.release())));
} else if (!connection->data_device_manager_ &&
strcmp(interface, "wl_data_device_manager") == 0) {
connection->data_device_manager_ =
wl::Object<wl_data_device_manager> data_device_manager =
wl::Bind<wl_data_device_manager>(registry, name, 1);
if (!data_device_manager) {
LOG(ERROR) << "Failed to bind to wl_data_device_manager global";
return;
}
connection->data_device_manager_.reset(
new WaylandDataDeviceManager(data_device_manager.release()));
connection->data_device_manager_->set_connection(connection);
}

connection->ScheduleFlush();
Expand Down
4 changes: 3 additions & 1 deletion ui/ozone/platform/wayland/wayland_connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "ui/events/platform/platform_event_source.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/ozone/platform/wayland/wayland_data_device.h"
#include "ui/ozone/platform/wayland/wayland_data_device_manager.h"
#include "ui/ozone/platform/wayland/wayland_data_source.h"
#include "ui/ozone/platform/wayland/wayland_keyboard.h"
#include "ui/ozone/platform/wayland/wayland_object.h"
Expand Down Expand Up @@ -41,6 +42,7 @@ class WaylandConnection : public PlatformEventSource,
wl_shm* shm() { return shm_.get(); }
xdg_shell* shell() { return shell_.get(); }
zxdg_shell_v6* shell_v6() { return shell_v6_.get(); }
wl_seat* seat() { return seat_.get(); }
wl_data_device* data_device() { return data_device_->data_device(); }

WaylandWindow* GetWindow(gfx::AcceleratedWidget widget);
Expand Down Expand Up @@ -111,14 +113,14 @@ class WaylandConnection : public PlatformEventSource,
std::map<gfx::AcceleratedWidget, WaylandWindow*> window_map_;

wl::Object<wl_display> display_;
wl::Object<wl_data_device_manager> data_device_manager_;
wl::Object<wl_registry> registry_;
wl::Object<wl_compositor> compositor_;
wl::Object<wl_seat> seat_;
wl::Object<wl_shm> shm_;
wl::Object<xdg_shell> shell_;
wl::Object<zxdg_shell_v6> shell_v6_;

std::unique_ptr<WaylandDataDeviceManager> data_device_manager_;
std::unique_ptr<WaylandDataDevice> data_device_;
std::unique_ptr<WaylandDataSource> data_source_;
std::unique_ptr<WaylandPointer> pointer_;
Expand Down
27 changes: 27 additions & 0 deletions ui/ozone/platform/wayland/wayland_data_device_manager.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// 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 "ui/ozone/platform/wayland/wayland_data_device_manager.h"

#include "ui/ozone/platform/wayland/wayland_connection.h"

namespace ui {

WaylandDataDeviceManager::WaylandDataDeviceManager(
wl_data_device_manager* device_manager)
: device_manager_(device_manager) {}

WaylandDataDeviceManager::~WaylandDataDeviceManager() = default;

wl_data_device* WaylandDataDeviceManager::GetDevice() {
DCHECK(connection_->seat());
return wl_data_device_manager_get_data_device(device_manager_,
connection_->seat());
}

wl_data_source* WaylandDataDeviceManager::CreateSource() {
return wl_data_device_manager_create_data_source(device_manager_);
}

} // namespace ui
40 changes: 40 additions & 0 deletions ui/ozone/platform/wayland/wayland_data_device_manager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// 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 UI_OZONE_PLATFORM_WAYLAND_WAYLAND_DATA_DEVICE_MANAGER_H_
#define UI_OZONE_PLATFORM_WAYLAND_WAYLAND_DATA_DEVICE_MANAGER_H_

#include <wayland-client.h>

#include "base/logging.h"
#include "base/macros.h"

namespace ui {

class WaylandConnection;

class WaylandDataDeviceManager {
public:
explicit WaylandDataDeviceManager(wl_data_device_manager* device_manager);
~WaylandDataDeviceManager();

wl_data_device* GetDevice();
wl_data_source* CreateSource();

void set_connection(WaylandConnection* connection) {
DCHECK(connection);
connection_ = connection;
}

private:
wl_data_device_manager* device_manager_;

WaylandConnection* connection_ = nullptr;

DISALLOW_COPY_AND_ASSIGN(WaylandDataDeviceManager);
};

} // namespace ui

#endif // UI_OZONE_PLATFORM_WAYLAND_WAYLAND_DATA_DEVICE_MANAGER_H_

0 comments on commit d3730d7

Please sign in to comment.