diff --git a/ui/ozone/platform/wayland/BUILD.gn b/ui/ozone/platform/wayland/BUILD.gn index d58a4acdca904d..fe23e765054f15 100644 --- a/ui/ozone/platform/wayland/BUILD.gn +++ b/ui/ozone/platform/wayland/BUILD.gn @@ -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", diff --git a/ui/ozone/platform/wayland/wayland_connection.cc b/ui/ozone/platform/wayland/wayland_connection.cc index 6ec9ae5898a0e3..5d5e2c802cc562 100644 --- a/ui/ozone/platform/wayland/wayland_connection.cc +++ b/ui/ozone/platform/wayland/wayland_connection.cc @@ -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); @@ -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_ && @@ -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 data_device_manager = wl::Bind(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(); diff --git a/ui/ozone/platform/wayland/wayland_connection.h b/ui/ozone/platform/wayland/wayland_connection.h index f18333200040d2..ac80f54cf24911 100644 --- a/ui/ozone/platform/wayland/wayland_connection.h +++ b/ui/ozone/platform/wayland/wayland_connection.h @@ -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" @@ -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); @@ -111,7 +113,6 @@ class WaylandConnection : public PlatformEventSource, std::map window_map_; wl::Object display_; - wl::Object data_device_manager_; wl::Object registry_; wl::Object compositor_; wl::Object seat_; @@ -119,6 +120,7 @@ class WaylandConnection : public PlatformEventSource, wl::Object shell_; wl::Object shell_v6_; + std::unique_ptr data_device_manager_; std::unique_ptr data_device_; std::unique_ptr data_source_; std::unique_ptr pointer_; diff --git a/ui/ozone/platform/wayland/wayland_data_device_manager.cc b/ui/ozone/platform/wayland/wayland_data_device_manager.cc new file mode 100644 index 00000000000000..6d78523c639a5c --- /dev/null +++ b/ui/ozone/platform/wayland/wayland_data_device_manager.cc @@ -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 diff --git a/ui/ozone/platform/wayland/wayland_data_device_manager.h b/ui/ozone/platform/wayland/wayland_data_device_manager.h new file mode 100644 index 00000000000000..ed358742e8295b --- /dev/null +++ b/ui/ozone/platform/wayland/wayland_data_device_manager.h @@ -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 + +#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_