Commit 31fc62a9 authored by Joel Hockey's avatar Joel Hockey Committed by Commit Bot

Implement X11 clipboard for ozone x11

Supports only CLIPBOARD selection and not PRIMARY (for now) since
ozone only supports a single clipboard.

Regisers to receive XFixesSetSelectionOwnerNotify events and
prefetches and caches supported mime types whenever ownership
changes.  Also prefetches clipboard contents as 'text/plain'
since that is the most likely type to be requested.  If clients
request a different type, it will be fetched at the time of
requesting.

Converts text/plain[;charset=utf-8] <=> [UTF8_]STRING to
allow interoperability with other applications which do not
use the same mime types as chrome.

This code can be patched into linux-chromeos (chrome os running
on a linux desktop) by modifying the build file:
 sed -i s/is_desktop_linux/is_linux/ ui/base/clipboard/BUILD.gn

Bug: 985187
Change-Id: I4277f903ab8f11e0f5ad14d095eb099cf775f771
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1736619Reviewed-by: default avatarkylechar <kylechar@chromium.org>
Commit-Queue: Joel Hockey <joelhockey@chromium.org>
Cr-Commit-Position: refs/heads/master@{#691892}
parent 52c34f18
...@@ -20,8 +20,8 @@ source_set("x11") { ...@@ -20,8 +20,8 @@ source_set("x11") {
"gl_surface_glx_ozone.h", "gl_surface_glx_ozone.h",
"ozone_platform_x11.cc", "ozone_platform_x11.cc",
"ozone_platform_x11.h", "ozone_platform_x11.h",
"x11_clipboard.cc", "x11_clipboard_ozone.cc",
"x11_clipboard.h", "x11_clipboard_ozone.h",
"x11_cursor_factory_ozone.cc", "x11_cursor_factory_ozone.cc",
"x11_cursor_factory_ozone.h", "x11_cursor_factory_ozone.h",
"x11_cursor_ozone.cc", "x11_cursor_ozone.cc",
...@@ -41,6 +41,7 @@ source_set("x11") { ...@@ -41,6 +41,7 @@ source_set("x11") {
"//gpu/vulkan:buildflags", "//gpu/vulkan:buildflags",
"//skia", "//skia",
"//ui/base", "//ui/base",
"//ui/base/clipboard:clipboard_types",
"//ui/base/ime", "//ui/base/ime",
"//ui/base/x", "//ui/base/x",
"//ui/display/fake", "//ui/display/fake",
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#include "ui/events/platform/x11/x11_event_source_default.h" #include "ui/events/platform/x11/x11_event_source_default.h"
#include "ui/gfx/x/x11.h" #include "ui/gfx/x/x11.h"
#include "ui/ozone/common/stub_overlay_manager.h" #include "ui/ozone/common/stub_overlay_manager.h"
#include "ui/ozone/platform/x11/x11_clipboard.h" #include "ui/ozone/platform/x11/x11_clipboard_ozone.h"
#include "ui/ozone/platform/x11/x11_cursor_factory_ozone.h" #include "ui/ozone/platform/x11/x11_cursor_factory_ozone.h"
#include "ui/ozone/platform/x11/x11_screen_ozone.h" #include "ui/ozone/platform/x11/x11_screen_ozone.h"
#include "ui/ozone/platform/x11/x11_surface_factory.h" #include "ui/ozone/platform/x11/x11_surface_factory.h"
...@@ -126,7 +126,7 @@ class OzonePlatformX11 : public OzonePlatform { ...@@ -126,7 +126,7 @@ class OzonePlatformX11 : public OzonePlatform {
window_manager_ = std::make_unique<X11WindowManagerOzone>(); window_manager_ = std::make_unique<X11WindowManagerOzone>();
overlay_manager_ = std::make_unique<StubOverlayManager>(); overlay_manager_ = std::make_unique<StubOverlayManager>();
input_controller_ = CreateStubInputController(); input_controller_ = CreateStubInputController();
clipboard_ = std::make_unique<X11Clipboard>(); clipboard_ = std::make_unique<X11ClipboardOzone>();
cursor_factory_ozone_ = std::make_unique<X11CursorFactoryOzone>(); cursor_factory_ozone_ = std::make_unique<X11CursorFactoryOzone>();
gpu_platform_support_host_.reset(CreateStubGpuPlatformSupportHost()); gpu_platform_support_host_.reset(CreateStubGpuPlatformSupportHost());
...@@ -179,7 +179,7 @@ class OzonePlatformX11 : public OzonePlatform { ...@@ -179,7 +179,7 @@ class OzonePlatformX11 : public OzonePlatform {
std::unique_ptr<X11WindowManagerOzone> window_manager_; std::unique_ptr<X11WindowManagerOzone> window_manager_;
std::unique_ptr<OverlayManagerOzone> overlay_manager_; std::unique_ptr<OverlayManagerOzone> overlay_manager_;
std::unique_ptr<InputController> input_controller_; std::unique_ptr<InputController> input_controller_;
std::unique_ptr<X11Clipboard> clipboard_; std::unique_ptr<X11ClipboardOzone> clipboard_;
std::unique_ptr<X11CursorFactoryOzone> cursor_factory_ozone_; std::unique_ptr<X11CursorFactoryOzone> cursor_factory_ozone_;
std::unique_ptr<GpuPlatformSupportHost> gpu_platform_support_host_; std::unique_ptr<GpuPlatformSupportHost> gpu_platform_support_host_;
......
// Copyright 2019 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 <utility>
#include "ui/ozone/platform/x11/x11_clipboard.h"
namespace ui {
X11Clipboard::X11Clipboard() = default;
X11Clipboard::~X11Clipboard() = default;
void X11Clipboard::OfferClipboardData(
const PlatformClipboard::DataMap& data_map,
PlatformClipboard::OfferDataClosure callback) {
// TODO(crbug.com/973295): Implement X11Clipboard
NOTIMPLEMENTED_LOG_ONCE();
std::move(callback).Run();
}
void X11Clipboard::RequestClipboardData(
const std::string& mime_type,
PlatformClipboard::DataMap* data_map,
PlatformClipboard::RequestDataClosure callback) {
// TODO(crbug.com/973295): Implement X11Clipboard
NOTIMPLEMENTED_LOG_ONCE();
std::move(callback).Run({});
}
void X11Clipboard::GetAvailableMimeTypes(
PlatformClipboard::GetMimeTypesClosure callback) {
// TODO(crbug.com/973295): Implement X11Clipboard
NOTIMPLEMENTED_LOG_ONCE();
std::move(callback).Run({});
}
bool X11Clipboard::IsSelectionOwner() {
// TODO(crbug.com/973295): Implement X11Clipboard
NOTIMPLEMENTED_LOG_ONCE();
return false;
}
void X11Clipboard::SetSequenceNumberUpdateCb(
PlatformClipboard::SequenceNumberUpdateCb cb) {
DCHECK(update_sequence_cb_.is_null())
<< " The callback can be installed only once.";
update_sequence_cb_ = std::move(cb);
}
void X11Clipboard::UpdateSequenceNumber() {
if (!update_sequence_cb_.is_null())
update_sequence_cb_.Run();
}
} // namespace ui
// Copyright 2019 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_X11_X11_CLIPBOARD_H_
#define UI_OZONE_PLATFORM_X11_X11_CLIPBOARD_H_
#include <string>
#include "base/callback.h"
#include "ui/ozone/public/platform_clipboard.h"
namespace ui {
// Handles clipboard operations for X11 Platform
class X11Clipboard : public PlatformClipboard {
public:
X11Clipboard();
~X11Clipboard() override;
// PlatformClipboard.
void OfferClipboardData(
const PlatformClipboard::DataMap& data_map,
PlatformClipboard::OfferDataClosure callback) override;
void RequestClipboardData(
const std::string& mime_type,
PlatformClipboard::DataMap* data_map,
PlatformClipboard::RequestDataClosure callback) override;
void GetAvailableMimeTypes(
PlatformClipboard::GetMimeTypesClosure callback) override;
bool IsSelectionOwner() override;
void SetSequenceNumberUpdateCb(
PlatformClipboard::SequenceNumberUpdateCb cb) override;
private:
void UpdateSequenceNumber();
// Notifies whenever clipboard sequence number is changed.
PlatformClipboard::SequenceNumberUpdateCb update_sequence_cb_;
DISALLOW_COPY_AND_ASSIGN(X11Clipboard);
};
} // namespace ui
#endif // UI_OZONE_PLATFORM_X11_X11_CLIPBOARD_H_
This diff is collapsed.
// Copyright 2019 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_X11_X11_CLIPBOARD_OZONE_H_
#define UI_OZONE_PLATFORM_X11_X11_CLIPBOARD_OZONE_H_
#include <string>
#include <vector>
#include "base/callback.h"
#include "ui/events/platform/x11/x11_event_source.h"
#include "ui/gfx/x/x11.h"
#include "ui/gfx/x/x11_types.h"
#include "ui/ozone/public/platform_clipboard.h"
namespace ui {
// Handles clipboard operations for X11.
// Registers to receive standard X11 events, as well as
// XFixesSetSelectionOwnerNotify. When the remote owner changes, TARGETS and
// text/plain are preemptively fetched. They can then be provided immediately
// to GetAvailableMimeTypes, and RequestClipboardData when mime_type is
// text/plain. Otherwise GetAvailableMimeTypes and RequestClipboardData call
// the appropriate X11 functions and invoke callbacks when the associated events
// are received.
class X11ClipboardOzone : public PlatformClipboard, public XEventDispatcher {
public:
X11ClipboardOzone();
~X11ClipboardOzone() override;
// PlatformClipboard:
void OfferClipboardData(
const PlatformClipboard::DataMap& data_map,
PlatformClipboard::OfferDataClosure callback) override;
void RequestClipboardData(
const std::string& mime_type,
PlatformClipboard::DataMap* data_map,
PlatformClipboard::RequestDataClosure callback) override;
void GetAvailableMimeTypes(
PlatformClipboard::GetMimeTypesClosure callback) override;
bool IsSelectionOwner() override;
void SetSequenceNumberUpdateCb(
PlatformClipboard::SequenceNumberUpdateCb cb) override;
private:
// XEventDispatcher:
bool DispatchXEvent(XEvent* xev) override;
bool OnSelectionRequest(XEvent* xev);
bool OnSelectionNotify(XEvent* xev);
bool OnSetSelectionOwnerNotify(XEvent* xev);
// Queries the current clipboard owner for what mime types are available by
// sending XConvertSelection with target=TARGETS. After sending this, we
// will receive a SelectionNotify event with xselection.target=TARGETS which
// is processed in |OnSelectionNotify|.
void QueryTargets();
// Reads the contents of the remote clipboard by sending XConvertSelection
// with target=<mime-type>. After sending this, we will receive a
// SelectionNotify event with xselection.target=<mime-type> which is processed
// in |OnSelectionNotify|.
void ReadRemoteClipboard();
// Notifies whenever clipboard sequence number is changed.
PlatformClipboard::SequenceNumberUpdateCb update_sequence_cb_;
// DataMap we keep from |OfferClipboardData| to service remote requests for
// the clipboard.
PlatformClipboard::DataMap offer_data_map_;
// DataMap from |RequestClipboardData| that we write remote clipboard contents
// to before calling the completion callback.
PlatformClipboard::DataMap* request_data_map_ = nullptr;
// Mime types supported by remote clipboard.
std::vector<std::string> mime_types_;
// Data most recently read from remote clipboard.
std::vector<unsigned char> data_;
// Mime type of most recently read data from remote clipboard.
std::string data_mime_type_;
// If XFixes is unavailable, this clipboard window will not register to
// receive events and no processing will take place.
// TODO(joelhockey): Make clipboard work without xfixes.
bool using_xfixes_ = false;
// The event base returned by XFixesQueryExtension().
int xfixes_event_base_;
// Callbacks are stored when we haven't already prefetched the remote
// clipboard.
PlatformClipboard::GetMimeTypesClosure get_available_mime_types_callback_;
PlatformClipboard::RequestDataClosure request_clipboard_data_callback_;
// Local cache of atoms.
const XAtom atom_clipboard_;
const XAtom atom_targets_;
const XAtom atom_timestamp_;
// The property on |x_window_| which will receive remote clipboard contents.
const XAtom x_property_;
// Our X11 state.
Display* const x_display_;
// Input-only window used as a selection owner.
const XID x_window_;
// The time that this instance took ownership of the clipboard.
Time acquired_selection_timestamp_;
DISALLOW_COPY_AND_ASSIGN(X11ClipboardOzone);
};
} // namespace ui
#endif // UI_OZONE_PLATFORM_X11_X11_CLIPBOARD_OZONE_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