Skip to content

Commit

Permalink
Merge pull request #506 from msisov/clipboard-impl
Browse files Browse the repository at this point in the history
Clipboard Ozone implementation
  • Loading branch information
msisov authored Nov 30, 2018
2 parents e57aab9 + 4ee6ebb commit 8bdadf8
Show file tree
Hide file tree
Showing 12 changed files with 726 additions and 89 deletions.
4 changes: 4 additions & 0 deletions chrome/test/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -4787,6 +4787,10 @@ if (!is_android) {
if (is_linux) {
data += [ "$root_out_dir/libppapi_tests.so" ]
}

if (use_ozone) {
sources += [ "//ui/base/clipboard/mock_clipboard_delegate.h", ]
}

defines = [ "HAS_OUT_OF_PROC_TEST_RUNNER" ]
ldflags = []
Expand Down
20 changes: 15 additions & 5 deletions ui/base/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -650,11 +650,21 @@ jumbo_component("base") {

if (use_aura) {
# Aura clipboard.
if (use_x11 && is_desktop_linux) {
sources += [
"clipboard/clipboard_aurax11.cc",
"clipboard/clipboard_aurax11.h",
]
if (is_desktop_linux) {
if (use_x11 || use_ozone) {
sources += [ "clipboard/clipboard_linux.cc" ]
}
if (use_ozone) {
sources += [
"clipboard/clipboard_ozone.cc",
"clipboard/clipboard_ozone.h",
]
} else if (use_x11) {
sources += [
"clipboard/clipboard_aurax11.cc",
"clipboard/clipboard_aurax11.h",
]
}
} else if (!is_win) {
# This file is used for all non-X11, non-Windows aura Builds.
sources += [
Expand Down
4 changes: 4 additions & 0 deletions ui/base/clipboard/clipboard.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ base::Time Clipboard::GetLastModifiedTime() const {

void Clipboard::ClearLastModifiedTime() {}

#if defined(USE_OZONE)
void Clipboard::SetDelegate(ClipboardDelegate* delegate) {}
#endif

void Clipboard::DispatchObject(ObjectType type, const ObjectMapParams& params) {
// Ignore writes with empty parameters.
for (const auto& param : params) {
Expand Down
15 changes: 15 additions & 0 deletions ui/base/clipboard/clipboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
#include <objidl.h>
#endif

#if defined(USE_OZONE)
#include "ui/ozone/public/clipboard_delegate.h"
#endif

class SkBitmap;

#ifdef __OBJC__
Expand Down Expand Up @@ -214,6 +218,17 @@ class UI_BASE_EXPORT Clipboard : public base::ThreadChecker {
// Resets the clipboard last modified time to Time::Time().
virtual void ClearLastModifiedTime();

#if defined(USE_OZONE)
// ui/base cannot add ui/ozone in deps in order to be able to get a
// ClipboardDelegate by calling OzonePlatform::GetInstance as long as it adds
// a circular dependency. Thus, set a delegate from the WaylandConnection, for
// example, whenever a data manager is available.
// TODO(tonikitoo, jkim, msisov): find a better solution? But it will require
// refactoring the ui/base in order to avoid ui/ozone depending on the whole
// ui/base and just add to deps the components it needs.
virtual void SetDelegate(ClipboardDelegate* delegate);
#endif

// Gets the FormatType corresponding to an arbitrary format string,
// registering it with the system if needed. Due to Windows/Linux
// limitiations, |format_string| must never be controlled by the user.
Expand Down
83 changes: 0 additions & 83 deletions ui/base/clipboard/clipboard_aurax11.cc
Original file line number Diff line number Diff line change
Expand Up @@ -540,89 +540,6 @@ uint32_t ClipboardAuraX11::AuraX11Details::DispatchEvent(
return POST_DISPATCH_NONE;
}

///////////////////////////////////////////////////////////////////////////////
// Various predefined FormatTypes.
// static
Clipboard::FormatType Clipboard::GetFormatType(
const std::string& format_string) {
return FormatType::Deserialize(format_string);
}

// static
const Clipboard::FormatType& Clipboard::GetUrlFormatType() {
static base::NoDestructor<FormatType> type(kMimeTypeURIList);
return *type;
}

// static
const Clipboard::FormatType& Clipboard::GetUrlWFormatType() {
return GetUrlFormatType();
}

// static
const Clipboard::FormatType& Clipboard::GetMozUrlFormatType() {
static base::NoDestructor<FormatType> type(kMimeTypeMozillaURL);
return *type;
}

// static
const Clipboard::FormatType& Clipboard::GetPlainTextFormatType() {
static base::NoDestructor<FormatType> type(kMimeTypeText);
return *type;
}

// static
const Clipboard::FormatType& Clipboard::GetPlainTextWFormatType() {
return GetPlainTextFormatType();
}

// static
const Clipboard::FormatType& Clipboard::GetFilenameFormatType() {
static base::NoDestructor<FormatType> type(kMimeTypeFilename);
return *type;
}

// static
const Clipboard::FormatType& Clipboard::GetFilenameWFormatType() {
return Clipboard::GetFilenameFormatType();
}

// static
const Clipboard::FormatType& Clipboard::GetHtmlFormatType() {
static base::NoDestructor<FormatType> type(kMimeTypeHTML);
return *type;
}

// static
const Clipboard::FormatType& Clipboard::GetRtfFormatType() {
static base::NoDestructor<FormatType> type(kMimeTypeRTF);
return *type;
}

// static
const Clipboard::FormatType& Clipboard::GetBitmapFormatType() {
static base::NoDestructor<FormatType> type(kMimeTypePNG);
return *type;
}

// static
const Clipboard::FormatType& Clipboard::GetWebKitSmartPasteFormatType() {
static base::NoDestructor<FormatType> type(kMimeTypeWebkitSmartPaste);
return *type;
}

// static
const Clipboard::FormatType& Clipboard::GetWebCustomDataFormatType() {
static base::NoDestructor<FormatType> type(kMimeTypeWebCustomData);
return *type;
}

// static
const Clipboard::FormatType& Clipboard::GetPepperCustomDataFormatType() {
static base::NoDestructor<FormatType> type(kMimeTypePepperCustomData);
return *type;
}

///////////////////////////////////////////////////////////////////////////////
// Clipboard factory method.
Clipboard* Clipboard::Create() {
Expand Down
120 changes: 120 additions & 0 deletions ui/base/clipboard/clipboard_linux.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
// 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/base/clipboard/clipboard.h"

namespace ui {

constexpr char kClipboard[] = "CLIPBOARD";
constexpr char kClipboardManager[] = "CLIPBOARD_MANAGER";
constexpr char kMimeTypeFilename[] = "chromium/filename";

Clipboard::FormatType::FormatType() {}

Clipboard::FormatType::FormatType(const std::string& native_format)
: data_(native_format) {}

Clipboard::FormatType::~FormatType() {}

std::string Clipboard::FormatType::Serialize() const {
return data_;
}

// static
Clipboard::FormatType Clipboard::FormatType::Deserialize(
const std::string& serialization) {
return FormatType(serialization);
}

bool Clipboard::FormatType::operator<(const FormatType& other) const {
return data_ < other.data_;
}

bool Clipboard::FormatType::Equals(const FormatType& other) const {
return data_ == other.data_;
}

// Various predefined FormatTypes.
// static
Clipboard::FormatType Clipboard::GetFormatType(
const std::string& format_string) {
return FormatType::Deserialize(format_string);
}

// static
const Clipboard::FormatType& Clipboard::GetUrlFormatType() {
static base::NoDestructor<FormatType> type(kMimeTypeURIList);
return *type;
}

// static
const Clipboard::FormatType& Clipboard::GetUrlWFormatType() {
return GetUrlFormatType();
}

// static
const Clipboard::FormatType& Clipboard::GetMozUrlFormatType() {
static base::NoDestructor<FormatType> type(kMimeTypeMozillaURL);
return *type;
}

// static
const Clipboard::FormatType& Clipboard::GetPlainTextFormatType() {
static base::NoDestructor<FormatType> type(kMimeTypeText);
return *type;
}

// static
const Clipboard::FormatType& Clipboard::GetPlainTextWFormatType() {
return GetPlainTextFormatType();
}

// static
const Clipboard::FormatType& Clipboard::GetFilenameFormatType() {
static base::NoDestructor<FormatType> type(kMimeTypeFilename);
return *type;
}

// static
const Clipboard::FormatType& Clipboard::GetFilenameWFormatType() {
return Clipboard::GetFilenameFormatType();
}

// static
const Clipboard::FormatType& Clipboard::GetHtmlFormatType() {
static base::NoDestructor<FormatType> type(kMimeTypeHTML);
return *type;
}

// static
const Clipboard::FormatType& Clipboard::GetRtfFormatType() {
static base::NoDestructor<FormatType> type(kMimeTypeRTF);
return *type;
}

// static
const Clipboard::FormatType& Clipboard::GetBitmapFormatType() {
static base::NoDestructor<FormatType> type(kMimeTypePNG);
return *type;
}

// static
const Clipboard::FormatType& Clipboard::GetWebKitSmartPasteFormatType() {
static base::NoDestructor<FormatType> type(kMimeTypeWebkitSmartPaste);
return *type;
}

// static
const Clipboard::FormatType& Clipboard::GetWebCustomDataFormatType() {
static base::NoDestructor<FormatType> type(kMimeTypeWebCustomData);
return *type;
}

// static
const Clipboard::FormatType& Clipboard::GetPepperCustomDataFormatType() {
static base::NoDestructor<FormatType> type(kMimeTypePepperCustomData);
return *type;
}

} // namespace ui
Loading

0 comments on commit 8bdadf8

Please sign in to comment.