Skip to content

Commit

Permalink
Add support for text/html to bookmarks gtk drag/drop.
Browse files Browse the repository at this point in the history
R=estade@chromium.org
BUG=none
TEST=BookmarkUtilsGtkTest.WriteBookmarkToSelectionHTML


Review URL: http://codereview.chromium.org/7377003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@92744 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
gbillock@chromium.org committed Jul 15, 2011
1 parent c667c32 commit 88cda49
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
13 changes: 13 additions & 0 deletions chrome/browser/ui/gtk/bookmarks/bookmark_utils_gtk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ int GetCodeMask(bool folder) {
int rv = ui::CHROME_BOOKMARK_ITEM;
if (!folder) {
rv |= ui::TEXT_URI_LIST |
ui::TEXT_HTML |
ui::TEXT_PLAIN |
ui::NETSCAPE_URL;
}
Expand Down Expand Up @@ -351,6 +352,18 @@ void WriteBookmarksToSelection(const std::vector<const BookmarkNode*>& nodes,
free(uris);
break;
}
case ui::TEXT_HTML: {
std::string utf8_title = UTF16ToUTF8(nodes[0]->GetTitle());
std::string utf8_html = StringPrintf("<a href=\"%s\">%s</a>",
nodes[0]->GetURL().spec().c_str(),
utf8_title.c_str());
gtk_selection_data_set(selection_data,
GetAtomForTarget(ui::TEXT_HTML),
kBitsInAByte,
reinterpret_cast<const guchar*>(utf8_html.data()),
utf8_html.size());
break;
}
case ui::TEXT_PLAIN: {
gtk_selection_data_set_text(selection_data,
nodes[0]->GetURL().spec().c_str(), -1);
Expand Down
15 changes: 15 additions & 0 deletions chrome/browser/ui/gtk/bookmarks/bookmark_utils_gtk_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <string>
#include "base/utf_string_conversions.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
#include "chrome/browser/ui/gtk/bookmarks/bookmark_utils_gtk.h"
#include "googleurl/src/gurl.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/dragdrop/gtk_dnd_util.h"

Expand Down Expand Up @@ -36,3 +40,14 @@ TEST(BookmarkUtilsGtkTest, GetNodesFromSelectionInvalid) {
ui::CHROME_BOOKMARK_ITEM, NULL, NULL, NULL);
EXPECT_EQ(0u, nodes.size());
}

TEST(BookmarkUtilsGtkTest, WriteBookmarkToSelectionHTML) {
BookmarkNode x(GURL("http://www.google.com"));
x.set_title(string16(ASCIIToUTF16("Google")));
GtkSelectionData data;
data.data = NULL;
data.length = 0;
bookmark_utils::WriteBookmarkToSelection(&x, &data, ui::TEXT_HTML, NULL);
std::string selection(reinterpret_cast<char*>(data.data), data.length);
EXPECT_EQ("<a href=\"http://www.google.com/\">Google</a>", selection);
}

0 comments on commit 88cda49

Please sign in to comment.