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

Side by Side Diff: ui/base/clipboard/clipboard_gtk.cc

Issue 9232075: Have ScopedClipboardWriter and Clipboard::WriteObjects take a buffer parameter. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Fix build error. Created 8 years, 10 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 | « ui/base/clipboard/clipboard_aurax11.cc ('k') | ui/base/clipboard/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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/base/clipboard/clipboard.h" 5 #include "ui/base/clipboard/clipboard.h"
6 6
7 #include <gtk/gtk.h> 7 #include <gtk/gtk.h>
8 #include <X11/extensions/Xfixes.h> 8 #include <X11/extensions/Xfixes.h>
9 #include <X11/Xatom.h> 9 #include <X11/Xatom.h>
10 #include <map> 10 #include <map>
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 211
212 Clipboard::Clipboard() : clipboard_data_(NULL) { 212 Clipboard::Clipboard() : clipboard_data_(NULL) {
213 clipboard_ = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); 213 clipboard_ = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
214 primary_selection_ = gtk_clipboard_get(GDK_SELECTION_PRIMARY); 214 primary_selection_ = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
215 } 215 }
216 216
217 Clipboard::~Clipboard() { 217 Clipboard::~Clipboard() {
218 gtk_clipboard_store(clipboard_); 218 gtk_clipboard_store(clipboard_);
219 } 219 }
220 220
221 void Clipboard::WriteObjects(const ObjectMap& objects) { 221 void Clipboard::WriteObjects(Buffer buffer, const ObjectMap& objects) {
222 clipboard_data_ = new TargetMap(); 222 clipboard_data_ = new TargetMap();
223 223
224 for (ObjectMap::const_iterator iter = objects.begin(); 224 for (ObjectMap::const_iterator iter = objects.begin();
225 iter != objects.end(); ++iter) { 225 iter != objects.end(); ++iter) {
226 DispatchObject(static_cast<ObjectType>(iter->first), iter->second); 226 DispatchObject(static_cast<ObjectType>(iter->first), iter->second);
227 } 227 }
228 228
229 SetGtkClipboard(); 229 SetGtkClipboard(buffer);
230 } 230 }
231 231
232 // When a URL is copied from a render view context menu (via "copy link 232 // When a URL is copied from a render view context menu (via "copy link
233 // location", for example), we additionally stick it in the X clipboard. This 233 // location", for example), we additionally stick it in the X clipboard. This
234 // matches other linux browsers. 234 // matches other linux browsers.
235 void Clipboard::DidWriteURL(const std::string& utf8_text) { 235 void Clipboard::DidWriteURL(const std::string& utf8_text) {
236 gtk_clipboard_set_text(primary_selection_, utf8_text.c_str(), 236 gtk_clipboard_set_text(primary_selection_, utf8_text.c_str(),
237 utf8_text.length()); 237 utf8_text.length());
238 } 238 }
239 239
240 // Take ownership of the GTK clipboard and inform it of the targets we support. 240 // Take ownership of the GTK clipboard and inform it of the targets we support.
241 void Clipboard::SetGtkClipboard() { 241 void Clipboard::SetGtkClipboard(Buffer buffer) {
242 scoped_array<GtkTargetEntry> targets( 242 scoped_array<GtkTargetEntry> targets(
243 new GtkTargetEntry[clipboard_data_->size()]); 243 new GtkTargetEntry[clipboard_data_->size()]);
244 244
245 int i = 0; 245 int i = 0;
246 for (Clipboard::TargetMap::iterator iter = clipboard_data_->begin(); 246 for (Clipboard::TargetMap::iterator iter = clipboard_data_->begin();
247 iter != clipboard_data_->end(); ++iter, ++i) { 247 iter != clipboard_data_->end(); ++iter, ++i) {
248 targets[i].target = const_cast<char*>(iter->first.c_str()); 248 targets[i].target = const_cast<char*>(iter->first.c_str());
249 targets[i].flags = 0; 249 targets[i].flags = 0;
250 targets[i].info = 0; 250 targets[i].info = 0;
251 } 251 }
252 252
253 if (gtk_clipboard_set_with_data(clipboard_, targets.get(), 253 GtkClipboard *clipboard = LookupBackingClipboard(buffer);
254
255 if (gtk_clipboard_set_with_data(clipboard, targets.get(),
254 clipboard_data_->size(), 256 clipboard_data_->size(),
255 GetData, ClearData, 257 GetData, ClearData,
256 clipboard_data_)) { 258 clipboard_data_)) {
257 gtk_clipboard_set_can_store(clipboard_, 259 gtk_clipboard_set_can_store(clipboard,
258 targets.get(), 260 targets.get(),
259 clipboard_data_->size()); 261 clipboard_data_->size());
260 } 262 }
261 263
262 // clipboard_data_ now owned by the GtkClipboard. 264 // clipboard_data_ now owned by the GtkClipboard.
263 clipboard_data_ = NULL; 265 clipboard_data_ = NULL;
264 } 266 }
265 267
266 void Clipboard::WriteText(const char* text_data, size_t text_len) { 268 void Clipboard::WriteText(const char* text_data, size_t text_len) {
267 char* data = new char[text_len]; 269 char* data = new char[text_len];
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 return clipboard_; 616 return clipboard_;
615 case BUFFER_SELECTION: 617 case BUFFER_SELECTION:
616 return primary_selection_; 618 return primary_selection_;
617 default: 619 default:
618 NOTREACHED(); 620 NOTREACHED();
619 return NULL; 621 return NULL;
620 } 622 }
621 } 623 }
622 624
623 } // namespace ui 625 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/clipboard/clipboard_aurax11.cc ('k') | ui/base/clipboard/clipboard_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698