Skip to content

Commit

Permalink
[DoNotCarryForward] Clipboard: move various predefined FormatTypes to…
Browse files Browse the repository at this point in the history
… common file.

Many clipboard implementations use the predefined FormatTypes
from the clipboard_aurax11. Thus, to make clipboard ozone use
them as well, move those into a separate clipboard_linux
file and include it when necessary.

Change-Id: Iec6b6aacecc567a35534a170fb50afff7e978140
  • Loading branch information
msisov authored and jkim-julie committed Dec 10, 2018
1 parent 6596541 commit 873dde0
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 119 deletions.
1 change: 1 addition & 0 deletions ui/base/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,7 @@ jumbo_component("base") {
# Aura clipboard.
if (use_x11 && is_desktop_linux) {
sources += [
"clipboard/clipboard_aura_linux.cc",
"clipboard/clipboard_aurax11.cc",
"clipboard/clipboard_aurax11.h",
]
Expand Down
125 changes: 125 additions & 0 deletions ui/base/clipboard/clipboard_aura_linux.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
// 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 {

namespace {
constexpr char kMimeTypeFilename[] = "chromium/filename";
}

// I would love for the FormatType to really be a wrapper around an X11 ::Atom,
// but there are a few problems. Chromeos unit tests spawn a new X11 server for
// each test, so Atom numeric values don't persist across tests. We could still
// maybe deal with that if we didn't have static accessor methods everywhere.

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
119 changes: 0 additions & 119 deletions ui/base/clipboard/clipboard_aurax11.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ namespace {

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

///////////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -168,41 +167,6 @@ bool TargetList::ContainsAtom(::Atom atom) const {

} // namespace

///////////////////////////////////////////////////////////////////////////////

// I would love for the FormatType to really be a wrapper around an X11 ::Atom,
// but there are a few problems. Chromeos unit tests spawn a new X11 server for
// each test, so Atom numeric values don't persist across tests. We could still
// maybe deal with that if we didn't have static accessor methods everywhere.

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_;
}

///////////////////////////////////////////////////////////////////////////////
// ClipboardAuraX11::AuraX11Details

Expand Down Expand Up @@ -540,89 +504,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

0 comments on commit 873dde0

Please sign in to comment.