1 // Copyright 2020 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef UI_BASE_CLIPBOARD_CLIPBOARD_DATA_H_ 6 #define UI_BASE_CLIPBOARD_CLIPBOARD_DATA_H_ 7 8 #include <string> 9 #include <vector> 10 11 #include "base/component_export.h" 12 #include "third_party/skia/include/core/SkBitmap.h" 13 #include "ui/base/data_transfer_policy/data_transfer_endpoint.h" 14 15 class SkBitmap; 16 17 namespace ui { 18 19 // Clipboard data format used by ClipboardInternal. 20 enum class ClipboardInternalFormat { 21 kText = 1 << 0, 22 kHtml = 1 << 1, 23 kSvg = 1 << 2, 24 kRtf = 1 << 3, 25 kBookmark = 1 << 4, 26 kBitmap = 1 << 5, 27 kCustom = 1 << 6, 28 kWeb = 1 << 7, 29 }; 30 31 // ClipboardData contains data copied to the Clipboard for a variety of formats. 32 // It mostly just provides APIs to cleanly access and manipulate this data. COMPONENT_EXPORT(UI_BASE_CLIPBOARD)33class COMPONENT_EXPORT(UI_BASE_CLIPBOARD) ClipboardData { 34 public: 35 ClipboardData(); 36 explicit ClipboardData(const ClipboardData&); 37 ClipboardData(ClipboardData&&); 38 ClipboardData& operator=(const ClipboardData&) = delete; 39 ~ClipboardData(); 40 41 bool operator==(const ClipboardData& that) const; 42 bool operator!=(const ClipboardData& that) const; 43 44 // Bitmask of ClipboardInternalFormat types. 45 int format() const { return format_; } 46 47 const std::string& text() const { return text_; } 48 void set_text(const std::string& text) { 49 text_ = text; 50 format_ |= static_cast<int>(ClipboardInternalFormat::kText); 51 } 52 53 const std::string& markup_data() const { return markup_data_; } 54 void set_markup_data(const std::string& markup_data) { 55 markup_data_ = markup_data; 56 format_ |= static_cast<int>(ClipboardInternalFormat::kHtml); 57 } 58 59 const std::string& svg_data() const { return svg_data_; } 60 void set_svg_data(const std::string& svg_data) { 61 svg_data_ = svg_data; 62 format_ |= static_cast<int>(ClipboardInternalFormat::kSvg); 63 } 64 65 const std::string& rtf_data() const { return rtf_data_; } 66 void SetRTFData(const std::string& rtf_data) { 67 rtf_data_ = rtf_data; 68 format_ |= static_cast<int>(ClipboardInternalFormat::kRtf); 69 } 70 71 const std::string& url() const { return url_; } 72 void set_url(const std::string& url) { 73 url_ = url; 74 format_ |= static_cast<int>(ClipboardInternalFormat::kHtml); 75 } 76 77 const std::string& bookmark_title() const { return bookmark_title_; } 78 void set_bookmark_title(const std::string& bookmark_title) { 79 bookmark_title_ = bookmark_title; 80 format_ |= static_cast<int>(ClipboardInternalFormat::kBookmark); 81 } 82 83 const std::string& bookmark_url() const { return bookmark_url_; } 84 void set_bookmark_url(const std::string& bookmark_url) { 85 bookmark_url_ = bookmark_url; 86 format_ |= static_cast<int>(ClipboardInternalFormat::kBookmark); 87 } 88 89 const SkBitmap& bitmap() const { return bitmap_; } 90 void SetBitmapData(const SkBitmap& bitmap); 91 92 const std::string& custom_data_format() const { return custom_data_format_; } 93 const std::string& custom_data_data() const { return custom_data_data_; } 94 void SetCustomData(const std::string& data_format, 95 const std::string& data_data); 96 97 bool web_smart_paste() const { return web_smart_paste_; } 98 void set_web_smart_paste(bool web_smart_paste) { 99 web_smart_paste_ = web_smart_paste; 100 format_ |= static_cast<int>(ClipboardInternalFormat::kWeb); 101 } 102 103 DataTransferEndpoint* source() const { return src_.get(); } 104 105 void set_source(std::unique_ptr<DataTransferEndpoint> src) { 106 src_ = std::move(src); 107 } 108 109 private: 110 // Plain text in UTF8 format. 111 std::string text_; 112 113 // HTML markup data in UTF8 format. 114 std::string markup_data_; 115 std::string url_; 116 117 // RTF data. 118 std::string rtf_data_; 119 120 // Bookmark title in UTF8 format. 121 std::string bookmark_title_; 122 std::string bookmark_url_; 123 124 // Bitmap images. 125 SkBitmap bitmap_; 126 127 // Data with custom format. 128 std::string custom_data_format_; 129 std::string custom_data_data_; 130 131 // WebKit smart paste data. 132 bool web_smart_paste_; 133 134 // Svg data. 135 std::string svg_data_; 136 137 int format_; 138 139 // The source of the data. 140 std::unique_ptr<DataTransferEndpoint> src_ = nullptr; 141 }; 142 143 } // namespace ui 144 145 #endif // UI_BASE_CLIPBOARD_CLIPBOARD_DATA_H_ 146