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

Side by Side Diff: base/clipboard_linux.cc

Issue 194052: Clipboard:... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fixes Created 11 years, 3 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/clipboard_mac.mm » ('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 6
7 #include <gtk/gtk.h> 7 #include <gtk/gtk.h>
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
11 #include <utility> 11 #include <utility>
12 12
13 #include "base/file_path.h" 13 #include "base/file_path.h"
14 #include "base/gfx/size.h" 14 #include "base/gfx/size.h"
15 #include "base/scoped_ptr.h" 15 #include "base/scoped_ptr.h"
16 #include "base/linux_util.h" 16 #include "base/linux_util.h"
17 #include "base/string_util.h" 17 #include "base/string_util.h"
18 18
19 namespace { 19 namespace {
20 20
21 const char kMimeBmp[] = "image/bmp"; 21 const char kMimeBmp[] = "image/bmp";
22 const char kMimeHtml[] = "text/html"; 22 const char kMimeHtml[] = "text/html";
23 const char kMimeText[] = "text/plain"; 23 const char kMimeText[] = "text/plain";
24 const char kMimeURI[] = "text/uri-list";
24 const char kMimeWebkitSmartPaste[] = "chromium/x-webkit-paste"; 25 const char kMimeWebkitSmartPaste[] = "chromium/x-webkit-paste";
25 26
26 std::string GdkAtomToString(const GdkAtom& atom) { 27 std::string GdkAtomToString(const GdkAtom& atom) {
27 gchar* name = gdk_atom_name(atom); 28 gchar* name = gdk_atom_name(atom);
28 std::string rv(name); 29 std::string rv(name);
29 g_free(name); 30 g_free(name);
30 return rv; 31 return rv;
31 } 32 }
32 33
33 GdkAtom StringToGdkAtom(const std::string& str) { 34 GdkAtom StringToGdkAtom(const std::string& str) {
(...skipping 11 matching lines...) Expand all
45 46
46 std::string target_string = GdkAtomToString(selection_data->target); 47 std::string target_string = GdkAtomToString(selection_data->target);
47 Clipboard::TargetMap::iterator iter = data_map->find(target_string); 48 Clipboard::TargetMap::iterator iter = data_map->find(target_string);
48 49
49 if (iter == data_map->end()) 50 if (iter == data_map->end())
50 return; 51 return;
51 52
52 if (target_string == kMimeBmp) { 53 if (target_string == kMimeBmp) {
53 gtk_selection_data_set_pixbuf(selection_data, 54 gtk_selection_data_set_pixbuf(selection_data,
54 reinterpret_cast<GdkPixbuf*>(iter->second.first)); 55 reinterpret_cast<GdkPixbuf*>(iter->second.first));
56 } else if (target_string == kMimeURI) {
57 gchar* uri_list[2];
58 uri_list[0] = reinterpret_cast<gchar*>(iter->second.first);
59 uri_list[1] = NULL;
60 gtk_selection_data_set_uris(selection_data, uri_list);
55 } else { 61 } else {
56 gtk_selection_data_set(selection_data, selection_data->target, 8, 62 gtk_selection_data_set(selection_data, selection_data->target, 8,
57 reinterpret_cast<guchar*>(iter->second.first), 63 reinterpret_cast<guchar*>(iter->second.first),
58 iter->second.second); 64 iter->second.second);
59 } 65 }
60 } 66 }
61 67
62 // GtkClipboardClearFunc callback. 68 // GtkClipboardClearFunc callback.
63 // We are guaranteed this will be called exactly once for each call to 69 // We are guaranteed this will be called exactly once for each call to
64 // gtk_clipboard_set_with_data 70 // gtk_clipboard_set_with_data
65 void ClearData(GtkClipboard* clipboard, 71 void ClearData(GtkClipboard* clipboard,
66 gpointer user_data) { 72 gpointer user_data) {
67 Clipboard::TargetMap* map = 73 Clipboard::TargetMap* map =
68 reinterpret_cast<Clipboard::TargetMap*>(user_data); 74 reinterpret_cast<Clipboard::TargetMap*>(user_data);
69 std::set<char*> ptrs; 75 std::set<char*> ptrs;
70 76
71 for (Clipboard::TargetMap::iterator iter = map->begin(); 77 for (Clipboard::TargetMap::iterator iter = map->begin();
72 iter != map->end(); ++iter) { 78 iter != map->end(); ++iter) {
73 if (iter->first == kMimeBmp) 79 if (iter->first == kMimeBmp)
74 g_object_unref(reinterpret_cast<GdkPixbuf*>(iter->second.first)); 80 g_object_unref(reinterpret_cast<GdkPixbuf*>(iter->second.first));
75 else 81 else
76 ptrs.insert(iter->second.first); 82 ptrs.insert(iter->second.first);
77 } 83 }
78 84
79 for (std::set<char*>::iterator iter = ptrs.begin(); 85 for (std::set<char*>::iterator iter = ptrs.begin();
80 iter != ptrs.end(); ++iter) 86 iter != ptrs.end(); ++iter) {
81 delete[] *iter; 87 delete[] *iter;
88 }
82 89
83 delete map; 90 delete map;
84 } 91 }
85 92
86 // Called on GdkPixbuf destruction; see WriteBitmap(). 93 // Called on GdkPixbuf destruction; see WriteBitmap().
87 void GdkPixbufFree(guchar* pixels, gpointer data) { 94 void GdkPixbufFree(guchar* pixels, gpointer data) {
88 free(pixels); 95 free(pixels);
89 } 96 }
90 97
91 } // namespace 98 } // namespace
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 8, size->width(), size->height(), 183 8, size->width(), size->height(),
177 size->width() * 4, GdkPixbufFree, NULL); 184 size->width() * 4, GdkPixbufFree, NULL);
178 // We store the GdkPixbuf*, and the size_t half of the pair is meaningless. 185 // We store the GdkPixbuf*, and the size_t half of the pair is meaningless.
179 // Note that this contrasts with the vast majority of entries in our target 186 // Note that this contrasts with the vast majority of entries in our target
180 // map, which directly store the data and its length. 187 // map, which directly store the data and its length.
181 InsertMapping(kMimeBmp, reinterpret_cast<char*>(pixbuf), 0); 188 InsertMapping(kMimeBmp, reinterpret_cast<char*>(pixbuf), 0);
182 } 189 }
183 190
184 void Clipboard::WriteBookmark(const char* title_data, size_t title_len, 191 void Clipboard::WriteBookmark(const char* title_data, size_t title_len,
185 const char* url_data, size_t url_len) { 192 const char* url_data, size_t url_len) {
186 // TODO(estade): implement this, but for now fail silently so we do not 193 // Write as plain text.
187 // write error output during layout tests. 194 WriteText(url_data, url_len);
188 // NOTIMPLEMENTED();
189 }
190 195
191 void Clipboard::WriteHyperlink(const char* title_data, size_t title_len, 196 // Write as a URI.
192 const char* url_data, size_t url_len) { 197 char* data = new char[url_len + 1];
193 NOTIMPLEMENTED(); 198 memcpy(data, url_data, url_len);
199 data[url_len] = NULL;
200 InsertMapping(kMimeURI, data, url_len + 1);
194 } 201 }
195 202
196 void Clipboard::WriteFiles(const char* file_data, size_t file_len) { 203 void Clipboard::WriteFiles(const char* file_data, size_t file_len) {
197 NOTIMPLEMENTED(); 204 NOTIMPLEMENTED();
198 } 205 }
199 206
200 void Clipboard::WriteData(const char* format_name, size_t format_len, 207 void Clipboard::WriteData(const char* format_name, size_t format_len,
201 const char* data_data, size_t data_len) { 208 const char* data_data, size_t data_len) {
202 char* data = new char[data_len]; 209 char* data = new char[data_len];
203 memcpy(data, data_data, data_len); 210 memcpy(data, data_data, data_len);
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 case BUFFER_SELECTION: 393 case BUFFER_SELECTION:
387 result = primary_selection_; 394 result = primary_selection_;
388 break; 395 break;
389 default: 396 default:
390 NOTREACHED(); 397 NOTREACHED();
391 result = NULL; 398 result = NULL;
392 break; 399 break;
393 } 400 }
394 return result; 401 return result;
395 } 402 }
396
OLDNEW
« no previous file with comments | « base/clipboard.cc ('k') | base/clipboard_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698