Commit 0a3e6153 authored by Tommy C. Li's avatar Tommy C. Li Committed by Commit Bot

Bookmarks: Update Copy/Paste bookmarks to write a hyperlink

Updates the bookmark copy to write a hyperlink. The justification to
not write a hyperlink no longer applies.

It also makes copying bookmarks more congruent with how copying from
the Omnibox will work soon. See:
https://chromium-review.googlesource.com/c/chromium/src/+/1370909

This CL also simplifies the copy API a bit.

Bug: NONE
Change-Id: Ibfd097a0ba6675a831fa8746987a15986e2337fa
Reviewed-on: https://chromium-review.googlesource.com/c/1387949Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Tommy Li <tommycli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#618399}
parent f93bb3ed
...@@ -159,10 +159,8 @@ bool BookmarkNodeData::ReadFromTuple(const GURL& url, ...@@ -159,10 +159,8 @@ bool BookmarkNodeData::ReadFromTuple(const GURL& url,
} }
#if !defined(OS_MACOSX) #if !defined(OS_MACOSX)
void BookmarkNodeData::WriteToClipboard(ui::ClipboardType clipboard_type) { void BookmarkNodeData::WriteToClipboard() {
DCHECK(clipboard_type == ui::CLIPBOARD_TYPE_COPY_PASTE || ui::ScopedClipboardWriter scw(ui::CLIPBOARD_TYPE_COPY_PASTE);
clipboard_type == ui::CLIPBOARD_TYPE_SELECTION);
ui::ScopedClipboardWriter scw(clipboard_type);
#if defined(OS_WIN) #if defined(OS_WIN)
const base::string16 kEOL(L"\r\n"); const base::string16 kEOL(L"\r\n");
...@@ -177,16 +175,7 @@ void BookmarkNodeData::WriteToClipboard(ui::ClipboardType clipboard_type) { ...@@ -177,16 +175,7 @@ void BookmarkNodeData::WriteToClipboard(ui::ClipboardType clipboard_type) {
const std::string url = elements[0].url.spec(); const std::string url = elements[0].url.spec();
scw.WriteBookmark(title, url); scw.WriteBookmark(title, url);
scw.WriteHyperlink(title, url);
// Don't call scw.WriteHyperlink() here, since some rich text editors will
// change fonts when such data is pasted in; besides, most such editors
// auto-linkify at some point anyway.
// Also write the URL to the clipboard as text so that it can be pasted
// into text fields. We use WriteText instead of WriteURL because we don't
// want to clobber the X clipboard when the user copies out of the omnibox
// on Linux (on Windows and Mac, there is no difference between these
// functions).
scw.WriteText(base::UTF8ToUTF16(url)); scw.WriteText(base::UTF8ToUTF16(url));
} else { } else {
// We have either more than one URL, a folder, or a combination of URLs // We have either more than one URL, a folder, or a combination of URLs
......
...@@ -127,7 +127,7 @@ struct BookmarkNodeData { ...@@ -127,7 +127,7 @@ struct BookmarkNodeData {
bool ReadFromTuple(const GURL& url, const base::string16& title); bool ReadFromTuple(const GURL& url, const base::string16& title);
// Writes bookmarks to the specified clipboard. // Writes bookmarks to the specified clipboard.
void WriteToClipboard(ui::ClipboardType type); void WriteToClipboard();
// Reads bookmarks from the specified clipboard. Prefers data written via // Reads bookmarks from the specified clipboard. Prefers data written via
// WriteToClipboard() but will also attempt to read a plain bookmark. // WriteToClipboard() but will also attempt to read a plain bookmark.
......
...@@ -14,7 +14,7 @@ bool BookmarkNodeData::ClipboardContainsBookmarks() { ...@@ -14,7 +14,7 @@ bool BookmarkNodeData::ClipboardContainsBookmarks() {
return false; return false;
} }
void BookmarkNodeData::WriteToClipboard(ui::ClipboardType type) { void BookmarkNodeData::WriteToClipboard() {
NOTREACHED(); NOTREACHED();
} }
......
...@@ -33,8 +33,9 @@ bool BookmarkNodeData::ClipboardContainsBookmarks() { ...@@ -33,8 +33,9 @@ bool BookmarkNodeData::ClipboardContainsBookmarks() {
return PasteboardContainsBookmarks(pb); return PasteboardContainsBookmarks(pb);
} }
void BookmarkNodeData::WriteToClipboard(ui::ClipboardType type) { void BookmarkNodeData::WriteToClipboard() {
NSPasteboard* pb = ui::ClipboardUtil::PasteboardFromType(type); NSPasteboard* pb =
ui::ClipboardUtil::PasteboardFromType(ui::CLIPBOARD_TYPE_COPY_PASTE);
WriteBookmarksToPasteboard(pb, elements, profile_path_); WriteBookmarksToPasteboard(pb, elements, profile_path_);
} }
......
...@@ -285,7 +285,7 @@ TEST_F(BookmarkNodeDataTest, WriteToClipboardURL) { ...@@ -285,7 +285,7 @@ TEST_F(BookmarkNodeDataTest, WriteToClipboardURL) {
const base::string16 title(ASCIIToUTF16("blah")); const base::string16 title(ASCIIToUTF16("blah"));
data.ReadFromTuple(url, title); data.ReadFromTuple(url, title);
data.WriteToClipboard(ui::CLIPBOARD_TYPE_COPY_PASTE); data.WriteToClipboard();
// Now read the data back in. // Now read the data back in.
base::string16 clipboard_result; base::string16 clipboard_result;
...@@ -307,7 +307,7 @@ TEST_F(BookmarkNodeDataTest, WriteToClipboardMultipleURLs) { ...@@ -307,7 +307,7 @@ TEST_F(BookmarkNodeDataTest, WriteToClipboardMultipleURLs) {
nodes.push_back(url_node2); nodes.push_back(url_node2);
data.ReadFromVector(nodes); data.ReadFromVector(nodes);
data.WriteToClipboard(ui::CLIPBOARD_TYPE_COPY_PASTE); data.WriteToClipboard();
// Now read the data back in. // Now read the data back in.
base::string16 combined_text; base::string16 combined_text;
...@@ -331,7 +331,7 @@ TEST_F(BookmarkNodeDataTest, WriteToClipboardEmptyFolder) { ...@@ -331,7 +331,7 @@ TEST_F(BookmarkNodeDataTest, WriteToClipboardEmptyFolder) {
nodes.push_back(folder); nodes.push_back(folder);
data.ReadFromVector(nodes); data.ReadFromVector(nodes);
data.WriteToClipboard(ui::CLIPBOARD_TYPE_COPY_PASTE); data.WriteToClipboard();
// Now read the data back in. // Now read the data back in.
base::string16 clipboard_result; base::string16 clipboard_result;
...@@ -350,7 +350,7 @@ TEST_F(BookmarkNodeDataTest, WriteToClipboardFolderWithChildren) { ...@@ -350,7 +350,7 @@ TEST_F(BookmarkNodeDataTest, WriteToClipboardFolderWithChildren) {
nodes.push_back(folder); nodes.push_back(folder);
data.ReadFromVector(nodes); data.ReadFromVector(nodes);
data.WriteToClipboard(ui::CLIPBOARD_TYPE_COPY_PASTE); data.WriteToClipboard();
// Now read the data back in. // Now read the data back in.
base::string16 clipboard_result; base::string16 clipboard_result;
...@@ -370,7 +370,7 @@ TEST_F(BookmarkNodeDataTest, WriteToClipboardFolderAndURL) { ...@@ -370,7 +370,7 @@ TEST_F(BookmarkNodeDataTest, WriteToClipboardFolderAndURL) {
nodes.push_back(folder); nodes.push_back(folder);
data.ReadFromVector(nodes); data.ReadFromVector(nodes);
data.WriteToClipboard(ui::CLIPBOARD_TYPE_COPY_PASTE); data.WriteToClipboard();
// Now read the data back in. // Now read the data back in.
base::string16 combined_text; base::string16 combined_text;
......
...@@ -256,8 +256,7 @@ void CopyToClipboard(BookmarkModel* model, ...@@ -256,8 +256,7 @@ void CopyToClipboard(BookmarkModel* model,
if (!HasSelectedAncestor(model, nodes, nodes[i]->parent())) if (!HasSelectedAncestor(model, nodes, nodes[i]->parent()))
filtered_nodes.push_back(nodes[i]); filtered_nodes.push_back(nodes[i]);
BookmarkNodeData(filtered_nodes). BookmarkNodeData(filtered_nodes).WriteToClipboard();
WriteToClipboard(ui::CLIPBOARD_TYPE_COPY_PASTE);
if (remove_nodes) { if (remove_nodes) {
ScopedGroupBookmarkActions group_cut(model); ScopedGroupBookmarkActions group_cut(model);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment