Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(627)

Side by Side Diff: base/clipboard_linux.cc

Issue 42592: Linux: write images to clipboard.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/clipboard.cc ('k') | base/scoped_clipboard_writer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/clipboard.h" 5 #include "base/clipboard.h"
6 #include "base/string_util.h"
7 6
8 #include <gtk/gtk.h> 7 #include <gtk/gtk.h>
9 #include <map> 8 #include <map>
10 #include <set> 9 #include <set>
11 #include <string> 10 #include <string>
12 #include <utility> 11 #include <utility>
13 12
13 #include "base/gfx/png_encoder.h"
14 #include "base/string_util.h"
15
14 namespace { 16 namespace {
15 17
16 static const char* kMimeHtml = "text/html"; 18 const char* kMimePng = "image/png";
17 static const char* kMimeText = "text/plain"; 19 const char* kMimeHtml = "text/html";
18 static const char* kMimeWebkitSmartPaste = "chrome-internal/webkit-paste"; 20 const char* kMimeText = "text/plain";
21 const char* kMimeWebkitSmartPaste = "chromium-internal/webkit-paste";
19 22
20 std::string GdkAtomToString(const GdkAtom& atom) { 23 std::string GdkAtomToString(const GdkAtom& atom) {
21 gchar* name = gdk_atom_name(atom); 24 gchar* name = gdk_atom_name(atom);
22 std::string rv(name); 25 std::string rv(name);
23 g_free(name); 26 g_free(name);
24 return rv; 27 return rv;
25 } 28 }
26 29
27 GdkAtom StringToGdkAtom(const std::string& str) { 30 GdkAtom StringToGdkAtom(const std::string& str) {
28 return gdk_atom_intern(str.c_str(), false); 31 return gdk_atom_intern(str.c_str(), false);
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 154
152 InsertMapping(kMimeHtml, data, markup_len); 155 InsertMapping(kMimeHtml, data, markup_len);
153 } 156 }
154 157
155 // Write an extra flavor that signifies WebKit was the last to modify the 158 // Write an extra flavor that signifies WebKit was the last to modify the
156 // pasteboard. This flavor has no data. 159 // pasteboard. This flavor has no data.
157 void Clipboard::WriteWebSmartPaste() { 160 void Clipboard::WriteWebSmartPaste() {
158 InsertMapping(kMimeWebkitSmartPaste, NULL, 0); 161 InsertMapping(kMimeWebkitSmartPaste, NULL, 0);
159 } 162 }
160 163
164 // We have to convert the image to a PNG because gtk_clipboard_request_image()
165 // only works with PNGs. Warning: this is an internal implementation detail of
166 // gtk_clipboard_request_image() and might change in the future.
161 void Clipboard::WriteBitmap(const char* pixel_data, const char* size_data) { 167 void Clipboard::WriteBitmap(const char* pixel_data, const char* size_data) {
162 NOTIMPLEMENTED(); 168 const gfx::Size* size = reinterpret_cast<const gfx::Size*>(size_data);
169
170 std::vector<unsigned char> png_data;
171 if (!PNGEncoder::Encode(
172 reinterpret_cast<const unsigned char*>(pixel_data),
173 PNGEncoder::FORMAT_BGRA, size->width(), size->height(),
174 size->width() * 4, false, &png_data)) {
175 DLOG(ERROR) << "Failed to encode bitmap for clipboard.";
176 return;
177 }
178 char* data = new char[png_data.size()];
179 memcpy(data, png_data.data(), png_data.size());
180
181 InsertMapping(kMimePng, data, png_data.size());
163 } 182 }
164 183
165 void Clipboard::WriteBookmark(const char* title_data, size_t title_len, 184 void Clipboard::WriteBookmark(const char* title_data, size_t title_len,
166 const char* url_data, size_t url_len) { 185 const char* url_data, size_t url_len) {
167 // TODO(estade): implement this, but for now fail silently so we do not 186 // TODO(estade): implement this, but for now fail silently so we do not
168 // write error output during layout tests. 187 // write error output during layout tests.
169 // NOTIMPLEMENTED(); 188 // NOTIMPLEMENTED();
170 } 189 }
171 190
172 void Clipboard::WriteHyperlink(const char* title_data, size_t title_len, 191 void Clipboard::WriteHyperlink(const char* title_data, size_t title_len,
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 void Clipboard::InsertMapping(const char* key, 303 void Clipboard::InsertMapping(const char* key,
285 char* data, 304 char* data,
286 size_t data_len) { 305 size_t data_len) {
287 TargetMap::iterator iter = clipboard_data_->find(key); 306 TargetMap::iterator iter = clipboard_data_->find(key);
288 307
289 if (iter != clipboard_data_->end()) 308 if (iter != clipboard_data_->end())
290 delete[] iter->second.first; 309 delete[] iter->second.first;
291 310
292 (*clipboard_data_)[key] = std::make_pair(data, data_len); 311 (*clipboard_data_)[key] = std::make_pair(data, data_len);
293 } 312 }
OLDNEW
« no previous file with comments | « base/clipboard.cc ('k') | base/scoped_clipboard_writer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698