summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpinkerton@google.com <pinkerton@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-17 14:45:48 +0000
committerpinkerton@google.com <pinkerton@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-17 14:45:48 +0000
commitc3fac8bf704df395a6359e9da9edeca28ff34de0 (patch)
tree165cec5b2e3e50c2666d8205bbc661d17242cd21
parent0c4bfbd9655bc99c0fd92f6476c3c2915cca0004 (diff)
downloadchromium_src-c3fac8bf704df395a6359e9da9edeca28ff34de0.zip
chromium_src-c3fac8bf704df395a6359e9da9edeca28ff34de0.tar.gz
chromium_src-c3fac8bf704df395a6359e9da9edeca28ff34de0.tar.bz2
Implement the WebSmartPaste pasteboard type on Mac, stub it out on Linux, remove the platform ifdefs in common code.
Review URL: http://codereview.chromium.org/10955 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@5559 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/clipboard.cc2
-rw-r--r--base/clipboard.h2
-rw-r--r--base/clipboard_linux.cc12
-rw-r--r--base/clipboard_mac.mm17
-rw-r--r--base/scoped_clipboard_writer.cc2
-rw-r--r--base/scoped_clipboard_writer.h2
-rw-r--r--webkit/glue/chromium_bridge_impl.cc13
7 files changed, 37 insertions, 13 deletions
diff --git a/base/clipboard.cc b/base/clipboard.cc
index 7380341..21b00fc 100644
--- a/base/clipboard.cc
+++ b/base/clipboard.cc
@@ -36,11 +36,11 @@ void Clipboard::DispatchObject(ObjectType type, const ObjectMapParams& params) {
break;
#endif // defined(OS_WIN) || defined(OS_MACOSX)
-#if defined(OS_WIN)
case CBF_WEBKIT:
WriteWebSmartPaste();
break;
+#if defined(OS_WIN)
case CBF_BITMAP:
WriteBitmap(&(params[0].front()), &(params[1].front()));
break;
diff --git a/base/clipboard.h b/base/clipboard.h
index af1ac5a..14ee655 100644
--- a/base/clipboard.h
+++ b/base/clipboard.h
@@ -120,6 +120,7 @@ class Clipboard {
static FormatType GetPlainTextWFormatType();
static FormatType GetFilenameFormatType();
static FormatType GetFilenameWFormatType();
+ static FormatType GetWebKitSmartPasteFormatType();
// Win: MS HTML Format, Other: Generic HTML format
static FormatType GetHtmlFormatType();
#if defined(OS_WIN)
@@ -129,7 +130,6 @@ class Clipboard {
static FormatType GetCFHDropFormatType();
static FormatType GetFileDescriptorFormatType();
static FormatType GetFileContentFormatZeroType();
- static FormatType GetWebKitSmartPasteFormatType();
#endif
private:
diff --git a/base/clipboard_linux.cc b/base/clipboard_linux.cc
index 427ec13..5906319 100644
--- a/base/clipboard_linux.cc
+++ b/base/clipboard_linux.cc
@@ -15,6 +15,7 @@ namespace {
static const char* kMimeHtml = "text/html";
static const char* kMimeText = "text/plain";
+static const char* kMimeWebkitSmartPaste = "chrome-internal/webkit-paste";
// GtkClipboardGetFunc callback.
// GTK will call this when an application wants data we copied to the clipboard.
@@ -140,6 +141,12 @@ void Clipboard::WriteHTML(const char* markup_data,
InsertMapping(kMimeHtml, data, markup_len);
}
+// Write an extra flavor that signifies WebKit was the last to modify the
+// pasteboard. This flavor has no data.
+void Clipboard::WriteWebSmartPaste() {
+ InsertMapping(kMimeWebkitSmartPaste, NULL, 0);
+}
+
// We do not use gtk_clipboard_wait_is_target_available because of
// a bug with the gtk clipboard. It caches the available targets
// and does not always refresh the cache when it is appropriate.
@@ -227,6 +234,11 @@ Clipboard::FormatType Clipboard::GetHtmlFormatType() {
return gdk_atom_intern(kMimeHtml, false);
}
+// static
+Clipboard::FormatType Clipboard::GetWebKitSmartPasteFormatType() {
+ return gdk_atom_intern(kMimeWebkitSmartPaste, false);
+}
+
// Insert the key/value pair in the clipboard_data structure. If
// the mapping already exists, it frees the associated data. Don't worry
// about double freeing because if the same key is inserted into the
diff --git a/base/clipboard_mac.mm b/base/clipboard_mac.mm
index 10fd91a..e16a795 100644
--- a/base/clipboard_mac.mm
+++ b/base/clipboard_mac.mm
@@ -15,6 +15,10 @@ namespace {
// Would be nice if this were in UTCoreTypes.h, but it isn't
const NSString* kUTTypeURLName = @"public.url-name";
+// Tells us if WebKit was the last to write to the pasteboard. There's no
+// actual data associated with this type.
+const NSString *kWebSmartPastePboardType = @"NeXT smart paste pasteboard type";
+
NSPasteboard* GetPasteboard() {
// The pasteboard should not be nil in a UI session, but this handy DCHECK
// can help track down problems if someone tries using clipboard code outside
@@ -121,6 +125,14 @@ void Clipboard::WriteFiles(const char* file_data, size_t file_len) {
[pb setPropertyList:fileList forType:NSFilenamesPboardType];
}
+// Write an extra flavor that signifies WebKit was the last to modify the
+// pasteboard. This flavor has no data.
+void Clipboard::WriteWebSmartPaste() {
+ NSPasteboard* pb = GetPasteboard();
+ [pb addTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil];
+ [pb setData:nil forType:GetWebKitSmartPasteFormatType()];
+}
+
bool Clipboard::IsFormatAvailable(NSString* format) const {
NSPasteboard* pb = GetPasteboard();
NSArray* types = [pb types];
@@ -250,3 +262,8 @@ Clipboard::FormatType Clipboard::GetFilenameWFormatType() {
Clipboard::FormatType Clipboard::GetHtmlFormatType() {
return NSHTMLPboardType;
}
+
+// static
+Clipboard::FormatType Clipboard::GetWebKitSmartPasteFormatType() {
+ return kWebSmartPastePboardType;
+}
diff --git a/base/scoped_clipboard_writer.cc b/base/scoped_clipboard_writer.cc
index a570981..9711f216 100644
--- a/base/scoped_clipboard_writer.cc
+++ b/base/scoped_clipboard_writer.cc
@@ -104,11 +104,11 @@ void ScopedClipboardWriter::WriteFiles(const std::vector<std::wstring>& files) {
objects_[Clipboard::CBF_FILES] = params;
}
-#if defined(OS_WIN)
void ScopedClipboardWriter::WriteWebSmartPaste() {
objects_[Clipboard::CBF_WEBKIT] = Clipboard::ObjectMapParams();
}
+#if defined(OS_WIN)
void ScopedClipboardWriter::WriteBitmapFromPixels(const void* pixels,
const gfx::Size& size) {
Clipboard::ObjectMapParam param1, param2;
diff --git a/base/scoped_clipboard_writer.h b/base/scoped_clipboard_writer.h
index 08a36fd..932c334 100644
--- a/base/scoped_clipboard_writer.h
+++ b/base/scoped_clipboard_writer.h
@@ -40,10 +40,10 @@ class ScopedClipboardWriter {
void WriteFile(const std::wstring& file);
void WriteFiles(const std::vector<std::wstring>& files);
-#if defined(OS_WIN)
// Used by WebKit to determine whether WebKit wrote the clipboard last
void WriteWebSmartPaste();
+#if defined(OS_WIN)
// Adds a bitmap to the clipboard
// This is the slowest way to copy a bitmap to the clipboard as we must first
// memcpy the pixels into GDI and the blit the bitmap to the clipboard.
diff --git a/webkit/glue/chromium_bridge_impl.cc b/webkit/glue/chromium_bridge_impl.cc
index bb8efd0..b817d95c 100644
--- a/webkit/glue/chromium_bridge_impl.cc
+++ b/webkit/glue/chromium_bridge_impl.cc
@@ -85,19 +85,16 @@ bool ChromiumBridge::clipboardIsFormatAvailable(
return webkit_glue::ClipboardIsFormatAvailable(
::Clipboard::GetHtmlFormatType());
+ case PasteboardPrivate::WebSmartPasteFormat:
+ return webkit_glue::ClipboardIsFormatAvailable(
+ ::Clipboard::GetWebKitSmartPasteFormatType());
+
case PasteboardPrivate::BookmarkFormat:
#if defined(OS_WIN) || defined(OS_MACOSX)
return webkit_glue::ClipboardIsFormatAvailable(
::Clipboard::GetUrlWFormatType());
#endif
-#if defined(OS_WIN)
- // TODO(tc): This should work for linux/mac too.
- case PasteboardPrivate::WebSmartPasteFormat:
- return webkit_glue::ClipboardIsFormatAvailable(
- ::Clipboard::GetWebKitSmartPasteFormatType());
-#endif
-
default:
NOTREACHED();
return false;
@@ -141,10 +138,8 @@ void ChromiumBridge::clipboardWriteSelection(const String& html,
webkit_glue::CStringToStdString(url.utf8String()));
scw.WriteText(webkit_glue::StringToStdWString(plain_text));
-#if defined(OS_WIN)
if (can_smart_copy_or_delete)
scw.WriteWebSmartPaste();
-#endif
}
void ChromiumBridge::clipboardWriteURL(const KURL& url, const String& title) {