Skip to content

Commit

Permalink
Implement the WebSmartPaste pasteboard type on Mac, stub it out on Li…
Browse files Browse the repository at this point in the history
…nux, 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
  • Loading branch information
pinkerton@google.com committed Nov 17, 2008
1 parent 0c4bfbd commit c3fac8b
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 13 deletions.
2 changes: 1 addition & 1 deletion base/clipboard.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion base/clipboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -129,7 +130,6 @@ class Clipboard {
static FormatType GetCFHDropFormatType();
static FormatType GetFileDescriptorFormatType();
static FormatType GetFileContentFormatZeroType();
static FormatType GetWebKitSmartPasteFormatType();
#endif

private:
Expand Down
12 changes: 12 additions & 0 deletions base/clipboard_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions base/clipboard_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
// 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
Expand Down Expand Up @@ -121,6 +125,14 @@
[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];
Expand Down Expand Up @@ -250,3 +262,8 @@
Clipboard::FormatType Clipboard::GetHtmlFormatType() {
return NSHTMLPboardType;
}

// static
Clipboard::FormatType Clipboard::GetWebKitSmartPasteFormatType() {
return kWebSmartPastePboardType;
}
2 changes: 1 addition & 1 deletion base/scoped_clipboard_writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion base/scoped_clipboard_writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 4 additions & 9 deletions webkit/glue/chromium_bridge_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit c3fac8b

Please sign in to comment.