Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "app/clipboard/clipboard.h" | 5 #include "app/clipboard/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> |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 94 } | 94 } |
| 95 | 95 |
| 96 } // namespace | 96 } // namespace |
| 97 | 97 |
| 98 Clipboard::Clipboard() : clipboard_data_(NULL) { | 98 Clipboard::Clipboard() : clipboard_data_(NULL) { |
| 99 clipboard_ = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); | 99 clipboard_ = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); |
| 100 primary_selection_ = gtk_clipboard_get(GDK_SELECTION_PRIMARY); | 100 primary_selection_ = gtk_clipboard_get(GDK_SELECTION_PRIMARY); |
| 101 } | 101 } |
| 102 | 102 |
| 103 Clipboard::~Clipboard() { | 103 Clipboard::~Clipboard() { |
| 104 // TODO(estade): do we want to save clipboard data after we exit? | 104 gtk_clipboard_store(clipboard_); |
|
Evan Stade
2010/11/30 21:37:11
shouldn't we only call this if we own the clipboar
Elliot Glaysher
2010/11/30 21:50:29
I'm not sure I understand. What does that mean and
Elliot Glaysher
2010/11/30 22:03:36
OK, I don't think so. I did the following test:
-
Evan Stade
2010/11/30 22:05:00
actually, this might not be the right place to cal
| |
| 105 // gtk_clipboard_set_can_store and gtk_clipboard_store work | |
| 106 // but have strangely awful performance. | |
| 107 } | 105 } |
| 108 | 106 |
| 109 void Clipboard::WriteObjects(const ObjectMap& objects) { | 107 void Clipboard::WriteObjects(const ObjectMap& objects) { |
| 110 clipboard_data_ = new TargetMap(); | 108 clipboard_data_ = new TargetMap(); |
| 111 | 109 |
| 112 for (ObjectMap::const_iterator iter = objects.begin(); | 110 for (ObjectMap::const_iterator iter = objects.begin(); |
| 113 iter != objects.end(); ++iter) { | 111 iter != objects.end(); ++iter) { |
| 114 DispatchObject(static_cast<ObjectType>(iter->first), iter->second); | 112 DispatchObject(static_cast<ObjectType>(iter->first), iter->second); |
| 115 } | 113 } |
| 116 | 114 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 131 new GtkTargetEntry[clipboard_data_->size()]); | 129 new GtkTargetEntry[clipboard_data_->size()]); |
| 132 | 130 |
| 133 int i = 0; | 131 int i = 0; |
| 134 for (Clipboard::TargetMap::iterator iter = clipboard_data_->begin(); | 132 for (Clipboard::TargetMap::iterator iter = clipboard_data_->begin(); |
| 135 iter != clipboard_data_->end(); ++iter, ++i) { | 133 iter != clipboard_data_->end(); ++iter, ++i) { |
| 136 targets[i].target = const_cast<char*>(iter->first.c_str()); | 134 targets[i].target = const_cast<char*>(iter->first.c_str()); |
| 137 targets[i].flags = 0; | 135 targets[i].flags = 0; |
| 138 targets[i].info = 0; | 136 targets[i].info = 0; |
| 139 } | 137 } |
| 140 | 138 |
| 141 gtk_clipboard_set_with_data(clipboard_, targets.get(), | 139 if (gtk_clipboard_set_with_data(clipboard_, targets.get(), |
| 142 clipboard_data_->size(), | 140 clipboard_data_->size(), |
| 143 GetData, ClearData, | 141 GetData, ClearData, |
| 144 clipboard_data_); | 142 clipboard_data_)) { |
| 143 gtk_clipboard_set_can_store(clipboard_, | |
| 144 targets.get(), | |
| 145 clipboard_data_->size()); | |
| 146 } | |
| 145 | 147 |
| 146 // clipboard_data_ now owned by the GtkClipboard. | 148 // clipboard_data_ now owned by the GtkClipboard. |
| 147 clipboard_data_ = NULL; | 149 clipboard_data_ = NULL; |
| 148 } | 150 } |
| 149 | 151 |
| 150 void Clipboard::WriteText(const char* text_data, size_t text_len) { | 152 void Clipboard::WriteText(const char* text_data, size_t text_len) { |
| 151 char* data = new char[text_len]; | 153 char* data = new char[text_len]; |
| 152 memcpy(data, text_data, text_len); | 154 memcpy(data, text_data, text_len); |
| 153 | 155 |
| 154 InsertMapping(kMimeText, data, text_len); | 156 InsertMapping(kMimeText, data, text_len); |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 406 switch (clipboard) { | 408 switch (clipboard) { |
| 407 case BUFFER_STANDARD: | 409 case BUFFER_STANDARD: |
| 408 return clipboard_; | 410 return clipboard_; |
| 409 case BUFFER_SELECTION: | 411 case BUFFER_SELECTION: |
| 410 return primary_selection_; | 412 return primary_selection_; |
| 411 default: | 413 default: |
| 412 NOTREACHED(); | 414 NOTREACHED(); |
| 413 return NULL; | 415 return NULL; |
| 414 } | 416 } |
| 415 } | 417 } |
| OLD | NEW |