diff options
author | dcheng@chromium.org <dcheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-18 22:05:16 +0000 |
---|---|---|
committer | dcheng@chromium.org <dcheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-18 22:05:16 +0000 |
commit | 909a7ba2db3646fcda94f33fff84cbc156d8c7e6 (patch) | |
tree | f96b1ffbaaf0c7465e9ee9b74ec9d07881b0a919 /ui | |
parent | 9d6de472591113aade547801a38046f71144db32 (diff) | |
download | chromium_src-909a7ba2db3646fcda94f33fff84cbc156d8c7e6.zip chromium_src-909a7ba2db3646fcda94f33fff84cbc156d8c7e6.tar.gz chromium_src-909a7ba2db3646fcda94f33fff84cbc156d8c7e6.tar.bz2 |
Support custom MIME type data in web drag/drop for Mac and GTK.
BUG=31037
TEST=manual
Review URL: http://codereview.chromium.org/8833005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@114947 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r-- | ui/base/clipboard/clipboard_aurax11.cc | 3 | ||||
-rw-r--r-- | ui/base/clipboard/clipboard_gtk.cc | 2 | ||||
-rw-r--r-- | ui/base/clipboard/clipboard_mac.mm | 13 | ||||
-rw-r--r-- | ui/base/clipboard/custom_data_helper.h | 14 | ||||
-rw-r--r-- | ui/base/clipboard/custom_data_helper_mac.mm | 14 | ||||
-rw-r--r-- | ui/base/clipboard/custom_data_helper_x.cc | 12 | ||||
-rw-r--r-- | ui/base/dragdrop/gtk_dnd_util.cc | 65 | ||||
-rw-r--r-- | ui/base/dragdrop/gtk_dnd_util.h | 5 | ||||
-rw-r--r-- | ui/ui.gyp | 2 |
9 files changed, 90 insertions, 40 deletions
diff --git a/ui/base/clipboard/clipboard_aurax11.cc b/ui/base/clipboard/clipboard_aurax11.cc index 5782d85..44fd4d2 100644 --- a/ui/base/clipboard/clipboard_aurax11.cc +++ b/ui/base/clipboard/clipboard_aurax11.cc @@ -8,6 +8,7 @@ #include "base/logging.h" #include "base/utf_string_conversions.h" #include "third_party/skia/include/core/SkBitmap.h" +#include "ui/base/clipboard/custom_data_helper.h" #include "ui/gfx/linux_util.h" #include "ui/gfx/size.h" @@ -16,8 +17,6 @@ namespace ui { namespace { const char kMimeTypeBitmap[] = "image/bmp"; const char kMimeTypeWebkitSmartPaste[] = "chromium/x-webkit-paste"; -// TODO(dcheng): This name is temporary. See crbug.com/106449 -const char kMimeTypeWebCustomData[] = "chromium/x-web-custom-data"; // ClipboardData contains data copied to the Clipboard for a variety of formats. // It mostly just provides APIs to cleanly access and manipulate this data. diff --git a/ui/base/clipboard/clipboard_gtk.cc b/ui/base/clipboard/clipboard_gtk.cc index 78fd155..7e3a56b 100644 --- a/ui/base/clipboard/clipboard_gtk.cc +++ b/ui/base/clipboard/clipboard_gtk.cc @@ -108,8 +108,6 @@ GdkFilterReturn SelectionChangeObserver::OnXEvent(GdkXEvent* xevent, const char kMimeTypeBitmap[] = "image/bmp"; const char kMimeTypeMozillaURL[] = "text/x-moz-url"; const char kMimeTypeWebkitSmartPaste[] = "chromium/x-webkit-paste"; -// TODO(dcheng): This name is temporary. See crbug.com/106449 -const char kMimeTypeWebCustomData[] = "chromium/x-web-custom-data"; std::string GdkAtomToString(const GdkAtom& atom) { gchar* name = gdk_atom_name(atom); diff --git a/ui/base/clipboard/clipboard_mac.mm b/ui/base/clipboard/clipboard_mac.mm index c700139..b8e1491 100644 --- a/ui/base/clipboard/clipboard_mac.mm +++ b/ui/base/clipboard/clipboard_mac.mm @@ -33,9 +33,6 @@ NSString* const kUTTypeURLName = @"public.url-name"; // actual data associated with this type. NSString* const kWebSmartPastePboardType = @"NeXT smart paste pasteboard type"; -// TODO(dcheng): This name is temporary. See crbug.com/106449. -NSString* const kWebCustomDataType = @"org.chromium.web-custom-data"; - 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 @@ -247,8 +244,8 @@ void Clipboard::ReadAvailableTypes(Clipboard::Buffer buffer, *contains_filenames = false; NSPasteboard* pb = GetPasteboard(); - if ([[pb types] containsObject:kWebCustomDataType]) { - NSData* data = [pb dataForType:kWebCustomDataType]; + if ([[pb types] containsObject:kWebCustomDataPboardType]) { + NSData* data = [pb dataForType:kWebCustomDataPboardType]; if ([data length]) ReadCustomDataTypes([data bytes], [data length], types); } @@ -340,8 +337,8 @@ void Clipboard::ReadCustomData(Buffer buffer, DCHECK_EQ(buffer, BUFFER_STANDARD); NSPasteboard* pb = GetPasteboard(); - if ([[pb types] containsObject:kWebCustomDataType]) { - NSData* data = [pb dataForType:kWebCustomDataType]; + if ([[pb types] containsObject:kWebCustomDataPboardType]) { + NSData* data = [pb dataForType:kWebCustomDataPboardType]; if ([data length]) ReadCustomDataForType([data bytes], [data length], type, result); } @@ -464,7 +461,7 @@ const Clipboard::FormatType& Clipboard::GetWebKitSmartPasteFormatType() { // static const Clipboard::FormatType& Clipboard::GetWebCustomDataFormatType() { - CR_DEFINE_STATIC_LOCAL(FormatType, type, (kWebCustomDataType)); + CR_DEFINE_STATIC_LOCAL(FormatType, type, (kWebCustomDataPboardType)); return type; } diff --git a/ui/base/clipboard/custom_data_helper.h b/ui/base/clipboard/custom_data_helper.h index 3294f51..3b9e0e1 100644 --- a/ui/base/clipboard/custom_data_helper.h +++ b/ui/base/clipboard/custom_data_helper.h @@ -19,8 +19,22 @@ class Pickle; +#if defined(OS_MACOSX) +#ifdef __OBJC__ +@class NSString; +#else +class NSString; +#endif +#endif // defined(OS_MACOSX) + namespace ui { +#if (!defined(OS_WIN) && defined(USE_AURA)) || defined(TOOLKIT_USES_GTK) +UI_EXPORT extern const char kMimeTypeWebCustomData[]; +#elif defined(OS_MACOSX) +UI_EXPORT extern NSString* const kWebCustomDataPboardType; +#endif + UI_EXPORT void ReadCustomDataTypes(const void* data, size_t data_length, std::vector<string16>* types); diff --git a/ui/base/clipboard/custom_data_helper_mac.mm b/ui/base/clipboard/custom_data_helper_mac.mm new file mode 100644 index 0000000..5447ae3 --- /dev/null +++ b/ui/base/clipboard/custom_data_helper_mac.mm @@ -0,0 +1,14 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/base/clipboard/custom_data_helper.h" + +#import <Foundation/Foundation.h> + +namespace ui { + +// TODO(dcheng): This name is temporary. See crbug.com/106449. +NSString* const kWebCustomDataPboardType = @"org.chromium.web-custom-data"; + +} // namespace ui diff --git a/ui/base/clipboard/custom_data_helper_x.cc b/ui/base/clipboard/custom_data_helper_x.cc new file mode 100644 index 0000000..87ebd39 --- /dev/null +++ b/ui/base/clipboard/custom_data_helper_x.cc @@ -0,0 +1,12 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/base/clipboard/custom_data_helper.h" + +namespace ui { + +// TODO(dcheng): This name is temporary. See crbug.com/106449 +const char kMimeTypeWebCustomData[] = "chromium/x-web-custom-data"; + +} // namespace ui diff --git a/ui/base/dragdrop/gtk_dnd_util.cc b/ui/base/dragdrop/gtk_dnd_util.cc index d9fea82..165d91b 100644 --- a/ui/base/dragdrop/gtk_dnd_util.cc +++ b/ui/base/dragdrop/gtk_dnd_util.cc @@ -10,6 +10,7 @@ #include "base/pickle.h" #include "base/utf_string_conversions.h" #include "googleurl/src/gurl.h" +#include "ui/base/clipboard/custom_data_helper.h" static const int kBitsPerByte = 8; @@ -49,6 +50,11 @@ void AddTargetToList(GtkTargetList* targets, int target_code) { ui::GetAtomForTarget(ui::DIRECT_SAVE_FILE), 0, ui::DIRECT_SAVE_FILE); break; + case ui::CUSTOM_DATA: + gtk_target_list_add(targets, + ui::GetAtomForTarget(ui::CUSTOM_DATA), 0, ui::CUSTOM_DATA); + break; + default: NOTREACHED() << " Unexpected target code: " << target_code; } @@ -59,49 +65,54 @@ void AddTargetToList(GtkTargetList* targets, int target_code) { GdkAtom GetAtomForTarget(int target) { switch (target) { case CHROME_TAB: - static GdkAtom tab_atom = gdk_atom_intern( - const_cast<char*>("application/x-chrome-tab"), false); - return tab_atom; + static const GdkAtom kTabAtom = gdk_atom_intern( + "application/x-chrome-tab", false); + return kTabAtom; case TEXT_HTML: - static GdkAtom html_atom = gdk_atom_intern( - const_cast<char*>("text/html"), false); - return html_atom; + static const GdkAtom kHtmlAtom = gdk_atom_intern( + "text/html", false); + return kHtmlAtom; case CHROME_BOOKMARK_ITEM: - static GdkAtom bookmark_atom = gdk_atom_intern( - const_cast<char*>("application/x-chrome-bookmark-item"), false); - return bookmark_atom; + static const GdkAtom kBookmarkAtom = gdk_atom_intern( + "application/x-chrome-bookmark-item", false); + return kBookmarkAtom; case TEXT_PLAIN: - static GdkAtom text_atom = gdk_atom_intern( - const_cast<char*>("text/plain;charset=utf-8"), false); - return text_atom; + static const GdkAtom kTextAtom= gdk_atom_intern( + "text/plain;charset=utf-8", false); + return kTextAtom; case TEXT_URI_LIST: - static GdkAtom uris_atom = gdk_atom_intern( - const_cast<char*>("text/uri-list"), false); - return uris_atom; + static const GdkAtom kUrisAtom = gdk_atom_intern( + "text/uri-list", false); + return kUrisAtom; case CHROME_NAMED_URL: - static GdkAtom named_url = gdk_atom_intern( - const_cast<char*>("application/x-chrome-named-url"), false); - return named_url; + static const GdkAtom kNamedUrl = gdk_atom_intern( + "application/x-chrome-named-url", false); + return kNamedUrl; case NETSCAPE_URL: - static GdkAtom netscape_url = gdk_atom_intern( - const_cast<char*>("_NETSCAPE_URL"), false); - return netscape_url; + static const GdkAtom kNetscapeUrl = gdk_atom_intern( + "_NETSCAPE_URL", false); + return kNetscapeUrl; case TEXT_PLAIN_NO_CHARSET: - static GdkAtom text_no_charset_atom = gdk_atom_intern( - const_cast<char*>("text/plain"), false); - return text_no_charset_atom; + static const GdkAtom kTextNoCharsetAtom = gdk_atom_intern( + "text/plain", false); + return kTextNoCharsetAtom; case DIRECT_SAVE_FILE: - static GdkAtom xds_atom = gdk_atom_intern( - const_cast<char*>("XdndDirectSave0"), false); - return xds_atom; + static const GdkAtom kXdsAtom = gdk_atom_intern( + "XdndDirectSave0", false); + return kXdsAtom; + + case CUSTOM_DATA: + static const GdkAtom kCustomData = gdk_atom_intern( + kMimeTypeWebCustomData, false); + return kCustomData; default: NOTREACHED(); diff --git a/ui/base/dragdrop/gtk_dnd_util.h b/ui/base/dragdrop/gtk_dnd_util.h index 7703428..0f0d29a 100644 --- a/ui/base/dragdrop/gtk_dnd_util.h +++ b/ui/base/dragdrop/gtk_dnd_util.h @@ -38,7 +38,10 @@ enum { TEXT_PLAIN_NO_CHARSET = 1 << 8, DIRECT_SAVE_FILE = 1 << 9, - INVALID_TARGET = 1 << 10, + // Custom data for web drag/drop. + CUSTOM_DATA = 1 << 10, + + INVALID_TARGET = 1 << 11, }; // Get the atom for a given target (of the above enum type). Will return NULL @@ -79,6 +79,8 @@ 'base/clipboard/clipboard_win.cc', 'base/clipboard/custom_data_helper.cc', 'base/clipboard/custom_data_helper.h', + 'base/clipboard/custom_data_helper_mac.mm', + 'base/clipboard/custom_data_helper_x.cc', 'base/clipboard/scoped_clipboard_writer.cc', 'base/clipboard/scoped_clipboard_writer.h', 'base/cocoa/base_view.h', |