summaryrefslogtreecommitdiffstats
path: root/base/clipboard_linux.cc
diff options
context:
space:
mode:
authoravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-10 22:01:15 +0000
committeravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-10 22:01:15 +0000
commitc033cbe94c504d2346c5e99c1ac12fda41f3f46a (patch)
tree85e1dae7db66e8cf0cc56edb64d15d4a59a70010 /base/clipboard_linux.cc
parent75d52ac5b9e0c0531b17095a5750918c281a7f0d (diff)
downloadchromium_src-c033cbe94c504d2346c5e99c1ac12fda41f3f46a.zip
chromium_src-c033cbe94c504d2346c5e99c1ac12fda41f3f46a.tar.gz
chromium_src-c033cbe94c504d2346c5e99c1ac12fda41f3f46a.tar.bz2
This changes the base clipboard class, as accomplishing paste requires that Clipboard::FormatType be IPC-able. The lowest-common denominator of unsigned int, NSString*, and GdkAtom is string, so string it is. (Linux changes by estade.)
Review URL: http://codereview.chromium.org/41012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@11383 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/clipboard_linux.cc')
-rw-r--r--base/clipboard_linux.cc27
1 files changed, 20 insertions, 7 deletions
diff --git a/base/clipboard_linux.cc b/base/clipboard_linux.cc
index 17ecf6c..0f4bd36 100644
--- a/base/clipboard_linux.cc
+++ b/base/clipboard_linux.cc
@@ -17,6 +17,17 @@ static const char* kMimeHtml = "text/html";
static const char* kMimeText = "text/plain";
static const char* kMimeWebkitSmartPaste = "chrome-internal/webkit-paste";
+std::string GdkAtomToString(const GdkAtom& atom) {
+ gchar* name = gdk_atom_name(atom);
+ std::string rv(name);
+ g_free(name);
+ return rv;
+}
+
+GdkAtom StringToGdkAtom(const std::string& str) {
+ return gdk_atom_intern(str.c_str(), false);
+}
+
// GtkClipboardGetFunc callback.
// GTK will call this when an application wants data we copied to the clipboard.
void GetData(GtkClipboard* clipboard,
@@ -27,7 +38,7 @@ void GetData(GtkClipboard* clipboard,
reinterpret_cast<Clipboard::TargetMap*>(user_data);
Clipboard::TargetMap::iterator iter =
- data_map->find(std::string(gdk_atom_name(selection_data->target)));
+ data_map->find(GdkAtomToString(selection_data->target));
if (iter == data_map->end())
return;
@@ -174,7 +185,7 @@ void Clipboard::WriteFiles(const char* file_data, size_t file_len) {
// to use gtk_clipboard_wait_is_target_available. Also, catch requests
// for plain text and change them to gtk_clipboard_wait_is_text_available
// (which checks for several standard text targets).
-bool Clipboard::IsFormatAvailable(Clipboard::FormatType format) const {
+bool Clipboard::IsFormatAvailable(const Clipboard::FormatType& format) const {
bool retval = false;
GdkAtom* targets = NULL;
GtkSelectionData* data =
@@ -187,8 +198,10 @@ bool Clipboard::IsFormatAvailable(Clipboard::FormatType format) const {
int num = 0;
gtk_selection_data_get_targets(data, &targets, &num);
+ GdkAtom format_atom = StringToGdkAtom(format);
+
for (int i = 0; i < num; i++) {
- if (targets[i] == format) {
+ if (targets[i] == format_atom) {
retval = true;
break;
}
@@ -232,7 +245,7 @@ void Clipboard::ReadHTML(string16* markup, std::string* src_url) const {
markup->clear();
GtkSelectionData* data = gtk_clipboard_wait_for_contents(clipboard_,
- GetHtmlFormatType());
+ StringToGdkAtom(GetHtmlFormatType()));
if (!data)
return;
@@ -245,7 +258,7 @@ void Clipboard::ReadHTML(string16* markup, std::string* src_url) const {
// static
Clipboard::FormatType Clipboard::GetPlainTextFormatType() {
- return GDK_TARGET_STRING;
+ return GdkAtomToString(GDK_TARGET_STRING);
}
// static
@@ -255,12 +268,12 @@ Clipboard::FormatType Clipboard::GetPlainTextWFormatType() {
// static
Clipboard::FormatType Clipboard::GetHtmlFormatType() {
- return gdk_atom_intern(kMimeHtml, false);
+ return std::string(kMimeHtml);
}
// static
Clipboard::FormatType Clipboard::GetWebKitSmartPasteFormatType() {
- return gdk_atom_intern(kMimeWebkitSmartPaste, false);
+ return std::string(kMimeWebkitSmartPaste);
}
// Insert the key/value pair in the clipboard_data structure. If