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

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
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(Buffer buffer, const std::string& utf8_text) {
236 gtk_clipboard_set_text(primary_selection_, utf8_text.c_str(), 236 if (buffer == BUFFER_STANDARD) {
237 utf8_text.length()); 237 gtk_clipboard_set_text(primary_selection_, utf8_text.c_str(),
238 utf8_text.length());
239 }
238 } 240 }
239 241
240 // Take ownership of the GTK clipboard and inform it of the targets we support. 242 // Take ownership of the GTK clipboard and inform it of the targets we support.
241 void Clipboard::SetGtkClipboard() { 243 void Clipboard::SetGtkClipboard(Buffer buffer) {
242 scoped_array<GtkTargetEntry> targets( 244 scoped_array<GtkTargetEntry> targets(
243 new GtkTargetEntry[clipboard_data_->size()]); 245 new GtkTargetEntry[clipboard_data_->size()]);
244 246
245 int i = 0; 247 int i = 0;
246 for (Clipboard::TargetMap::iterator iter = clipboard_data_->begin(); 248 for (Clipboard::TargetMap::iterator iter = clipboard_data_->begin();
247 iter != clipboard_data_->end(); ++iter, ++i) { 249 iter != clipboard_data_->end(); ++iter, ++i) {
248 targets[i].target = const_cast<char*>(iter->first.c_str()); 250 targets[i].target = const_cast<char*>(iter->first.c_str());
249 targets[i].flags = 0; 251 targets[i].flags = 0;
250 targets[i].info = 0; 252 targets[i].info = 0;
251 } 253 }
252 254
253 if (gtk_clipboard_set_with_data(clipboard_, targets.get(), 255 GtkClipboard *clipboard = LookupBackingClipboard(buffer);
256
257 if (gtk_clipboard_set_with_data(clipboard, targets.get(),
254 clipboard_data_->size(), 258 clipboard_data_->size(),
255 GetData, ClearData, 259 GetData, ClearData,
256 clipboard_data_)) { 260 clipboard_data_)) {
257 gtk_clipboard_set_can_store(clipboard_, 261 gtk_clipboard_set_can_store(clipboard,
258 targets.get(), 262 targets.get(),
259 clipboard_data_->size()); 263 clipboard_data_->size());
260 } 264 }
261 265
262 // clipboard_data_ now owned by the GtkClipboard. 266 // clipboard_data_ now owned by the GtkClipboard.
263 clipboard_data_ = NULL; 267 clipboard_data_ = NULL;
264 } 268 }
265 269
266 void Clipboard::WriteText(const char* text_data, size_t text_len) { 270 void Clipboard::WriteText(const char* text_data, size_t text_len) {
267 char* data = new char[text_len]; 271 char* data = new char[text_len];
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 return clipboard_; 622 return clipboard_;
619 case BUFFER_SELECTION: 623 case BUFFER_SELECTION:
620 return primary_selection_; 624 return primary_selection_;
621 default: 625 default:
622 NOTREACHED(); 626 NOTREACHED();
623 return NULL; 627 return NULL;
624 } 628 }
625 } 629 }
626 630
627 } // namespace ui 631 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698