From 873dde087b357ad9c3f077f5e5130679014099a3 Mon Sep 17 00:00:00 2001 From: Maksim Sisov Date: Wed, 5 Dec 2018 10:40:33 +0200 Subject: [PATCH] [DoNotCarryForward] Clipboard: move various predefined FormatTypes to 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 --- ui/base/BUILD.gn | 1 + ui/base/clipboard/clipboard_aura_linux.cc | 125 ++++++++++++++++++++++ ui/base/clipboard/clipboard_aurax11.cc | 119 -------------------- 3 files changed, 126 insertions(+), 119 deletions(-) create mode 100644 ui/base/clipboard/clipboard_aura_linux.cc diff --git a/ui/base/BUILD.gn b/ui/base/BUILD.gn index edc2e8678c177..1a81fd98a1702 100644 --- a/ui/base/BUILD.gn +++ b/ui/base/BUILD.gn @@ -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", ] diff --git a/ui/base/clipboard/clipboard_aura_linux.cc b/ui/base/clipboard/clipboard_aura_linux.cc new file mode 100644 index 0000000000000..85c7134e21f6a --- /dev/null +++ b/ui/base/clipboard/clipboard_aura_linux.cc @@ -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 type(kMimeTypeURIList); + return *type; +} + +// static +const Clipboard::FormatType& Clipboard::GetUrlWFormatType() { + return GetUrlFormatType(); +} + +// static +const Clipboard::FormatType& Clipboard::GetMozUrlFormatType() { + static base::NoDestructor type(kMimeTypeMozillaURL); + return *type; +} + +// static +const Clipboard::FormatType& Clipboard::GetPlainTextFormatType() { + static base::NoDestructor type(kMimeTypeText); + return *type; +} + +// static +const Clipboard::FormatType& Clipboard::GetPlainTextWFormatType() { + return GetPlainTextFormatType(); +} + +// static +const Clipboard::FormatType& Clipboard::GetFilenameFormatType() { + static base::NoDestructor type(kMimeTypeFilename); + return *type; +} + +// static +const Clipboard::FormatType& Clipboard::GetFilenameWFormatType() { + return Clipboard::GetFilenameFormatType(); +} + +// static +const Clipboard::FormatType& Clipboard::GetHtmlFormatType() { + static base::NoDestructor type(kMimeTypeHTML); + return *type; +} + +// static +const Clipboard::FormatType& Clipboard::GetRtfFormatType() { + static base::NoDestructor type(kMimeTypeRTF); + return *type; +} + +// static +const Clipboard::FormatType& Clipboard::GetBitmapFormatType() { + static base::NoDestructor type(kMimeTypePNG); + return *type; +} + +// static +const Clipboard::FormatType& Clipboard::GetWebKitSmartPasteFormatType() { + static base::NoDestructor type(kMimeTypeWebkitSmartPaste); + return *type; +} + +// static +const Clipboard::FormatType& Clipboard::GetWebCustomDataFormatType() { + static base::NoDestructor type(kMimeTypeWebCustomData); + return *type; +} + +// static +const Clipboard::FormatType& Clipboard::GetPepperCustomDataFormatType() { + static base::NoDestructor type(kMimeTypePepperCustomData); + return *type; +} + +} // namespace ui diff --git a/ui/base/clipboard/clipboard_aurax11.cc b/ui/base/clipboard/clipboard_aurax11.cc index 447beb5bc09c5..12ddcb2620bb4 100644 --- a/ui/base/clipboard/clipboard_aurax11.cc +++ b/ui/base/clipboard/clipboard_aurax11.cc @@ -42,7 +42,6 @@ namespace { const char kClipboard[] = "CLIPBOARD"; const char kClipboardManager[] = "CLIPBOARD_MANAGER"; -const char kMimeTypeFilename[] = "chromium/filename"; /////////////////////////////////////////////////////////////////////////////// @@ -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 @@ -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 type(kMimeTypeURIList); - return *type; -} - -// static -const Clipboard::FormatType& Clipboard::GetUrlWFormatType() { - return GetUrlFormatType(); -} - -// static -const Clipboard::FormatType& Clipboard::GetMozUrlFormatType() { - static base::NoDestructor type(kMimeTypeMozillaURL); - return *type; -} - -// static -const Clipboard::FormatType& Clipboard::GetPlainTextFormatType() { - static base::NoDestructor type(kMimeTypeText); - return *type; -} - -// static -const Clipboard::FormatType& Clipboard::GetPlainTextWFormatType() { - return GetPlainTextFormatType(); -} - -// static -const Clipboard::FormatType& Clipboard::GetFilenameFormatType() { - static base::NoDestructor type(kMimeTypeFilename); - return *type; -} - -// static -const Clipboard::FormatType& Clipboard::GetFilenameWFormatType() { - return Clipboard::GetFilenameFormatType(); -} - -// static -const Clipboard::FormatType& Clipboard::GetHtmlFormatType() { - static base::NoDestructor type(kMimeTypeHTML); - return *type; -} - -// static -const Clipboard::FormatType& Clipboard::GetRtfFormatType() { - static base::NoDestructor type(kMimeTypeRTF); - return *type; -} - -// static -const Clipboard::FormatType& Clipboard::GetBitmapFormatType() { - static base::NoDestructor type(kMimeTypePNG); - return *type; -} - -// static -const Clipboard::FormatType& Clipboard::GetWebKitSmartPasteFormatType() { - static base::NoDestructor type(kMimeTypeWebkitSmartPaste); - return *type; -} - -// static -const Clipboard::FormatType& Clipboard::GetWebCustomDataFormatType() { - static base::NoDestructor type(kMimeTypeWebCustomData); - return *type; -} - -// static -const Clipboard::FormatType& Clipboard::GetPepperCustomDataFormatType() { - static base::NoDestructor type(kMimeTypePepperCustomData); - return *type; -} - /////////////////////////////////////////////////////////////////////////////// // Clipboard factory method. Clipboard* Clipboard::Create() {