| OLD | NEW |
| 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 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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(buffer); | 229 SetGtkClipboard(buffer); |
| 230 } | 230 } |
| 231 | 231 |
| 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 | |
| 234 // matches other linux browsers. | |
| 235 void Clipboard::DidWriteURL(const std::string& utf8_text) { | |
| 236 DCHECK(CalledOnValidThread()); | |
| 237 gtk_clipboard_set_text(primary_selection_, utf8_text.c_str(), | |
| 238 utf8_text.length()); | |
| 239 } | |
| 240 | |
| 241 // Take ownership of the GTK clipboard and inform it of the targets we support. | 232 // Take ownership of the GTK clipboard and inform it of the targets we support. |
| 242 void Clipboard::SetGtkClipboard(Buffer buffer) { | 233 void Clipboard::SetGtkClipboard(Buffer buffer) { |
| 243 scoped_array<GtkTargetEntry> targets( | 234 scoped_array<GtkTargetEntry> targets( |
| 244 new GtkTargetEntry[clipboard_data_->size()]); | 235 new GtkTargetEntry[clipboard_data_->size()]); |
| 245 | 236 |
| 246 int i = 0; | 237 int i = 0; |
| 247 for (Clipboard::TargetMap::iterator iter = clipboard_data_->begin(); | 238 for (Clipboard::TargetMap::iterator iter = clipboard_data_->begin(); |
| 248 iter != clipboard_data_->end(); ++iter, ++i) { | 239 iter != clipboard_data_->end(); ++iter, ++i) { |
| 249 targets[i].target = const_cast<char*>(iter->first.c_str()); | 240 targets[i].target = const_cast<char*>(iter->first.c_str()); |
| 250 targets[i].flags = 0; | 241 targets[i].flags = 0; |
| 251 targets[i].info = 0; | 242 targets[i].info = 0; |
| 252 } | 243 } |
| 253 | 244 |
| 254 GtkClipboard *clipboard = LookupBackingClipboard(buffer); | 245 GtkClipboard *clipboard = LookupBackingClipboard(buffer); |
| 255 | 246 |
| 256 if (gtk_clipboard_set_with_data(clipboard, targets.get(), | 247 if (gtk_clipboard_set_with_data(clipboard, targets.get(), |
| 257 clipboard_data_->size(), | 248 clipboard_data_->size(), |
| 258 GetData, ClearData, | 249 GetData, ClearData, |
| 259 clipboard_data_)) { | 250 clipboard_data_)) { |
| 260 gtk_clipboard_set_can_store(clipboard, | 251 gtk_clipboard_set_can_store(clipboard, |
| 261 targets.get(), | 252 targets.get(), |
| 262 clipboard_data_->size()); | 253 clipboard_data_->size()); |
| 263 } | 254 } |
| 264 | 255 |
| 256 if (buffer == BUFFER_STANDARD) { |
| 257 Clipboard::TargetMap::iterator text_iter = clipboard_data_->find("TEXT"); |
| 258 if (text_iter != clipboard_data_->end()) { |
| 259 gtk_clipboard_set_text(primary_selection_, text_iter->second.first, |
| 260 text_iter->second.second); |
| 261 } |
| 262 } |
| 263 |
| 265 // clipboard_data_ now owned by the GtkClipboard. | 264 // clipboard_data_ now owned by the GtkClipboard. |
| 266 clipboard_data_ = NULL; | 265 clipboard_data_ = NULL; |
| 267 } | 266 } |
| 268 | 267 |
| 269 void Clipboard::WriteText(const char* text_data, size_t text_len) { | 268 void Clipboard::WriteText(const char* text_data, size_t text_len) { |
| 270 char* data = new char[text_len]; | 269 char* data = new char[text_len]; |
| 271 memcpy(data, text_data, text_len); | 270 memcpy(data, text_data, text_len); |
| 272 | 271 |
| 273 InsertMapping(kMimeTypeText, data, text_len); | 272 InsertMapping(kMimeTypeText, data, text_len); |
| 274 InsertMapping("TEXT", data, text_len); | 273 InsertMapping("TEXT", data, text_len); |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 return clipboard_; | 669 return clipboard_; |
| 671 case BUFFER_SELECTION: | 670 case BUFFER_SELECTION: |
| 672 return primary_selection_; | 671 return primary_selection_; |
| 673 default: | 672 default: |
| 674 NOTREACHED(); | 673 NOTREACHED(); |
| 675 return NULL; | 674 return NULL; |
| 676 } | 675 } |
| 677 } | 676 } |
| 678 | 677 |
| 679 } // namespace ui | 678 } // namespace ui |
| OLD | NEW |