Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(564)

Side by Side Diff: ui/base/clipboard/scoped_clipboard_writer.cc

Issue 10532168: Allow empty strings to be written to the clipboard (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comment fix Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/common/drag_messages.h ('k') | webkit/glue/webclipboard_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // This file implements the ScopedClipboardWriter class. Documentation on its 5 // This file implements the ScopedClipboardWriter class. Documentation on its
6 // purpose can be found in our header. Documentation on the format of the 6 // purpose can be found in our header. Documentation on the format of the
7 // parameters for each clipboard target can be found in clipboard.h. 7 // parameters for each clipboard target can be found in clipboard.h.
8 8
9 #include "ui/base/clipboard/scoped_clipboard_writer.h" 9 #include "ui/base/clipboard/scoped_clipboard_writer.h"
10 10
(...skipping 20 matching lines...) Expand all
31 void ScopedClipboardWriter::WriteText(const string16& text) { 31 void ScopedClipboardWriter::WriteText(const string16& text) {
32 WriteTextOrURL(text, false); 32 WriteTextOrURL(text, false);
33 } 33 }
34 34
35 void ScopedClipboardWriter::WriteURL(const string16& text) { 35 void ScopedClipboardWriter::WriteURL(const string16& text) {
36 WriteTextOrURL(text, true); 36 WriteTextOrURL(text, true);
37 } 37 }
38 38
39 void ScopedClipboardWriter::WriteHTML(const string16& markup, 39 void ScopedClipboardWriter::WriteHTML(const string16& markup,
40 const std::string& source_url) { 40 const std::string& source_url) {
41 if (markup.empty())
42 return;
43
44 std::string utf8_markup = UTF16ToUTF8(markup); 41 std::string utf8_markup = UTF16ToUTF8(markup);
45 42
46 Clipboard::ObjectMapParams parameters; 43 Clipboard::ObjectMapParams parameters;
47 parameters.push_back( 44 parameters.push_back(
48 Clipboard::ObjectMapParam(utf8_markup.begin(), 45 Clipboard::ObjectMapParam(utf8_markup.begin(),
49 utf8_markup.end())); 46 utf8_markup.end()));
50 if (!source_url.empty()) { 47 if (!source_url.empty()) {
51 parameters.push_back(Clipboard::ObjectMapParam(source_url.begin(), 48 parameters.push_back(Clipboard::ObjectMapParam(source_url.begin(),
52 source_url.end())); 49 source_url.end()));
53 } 50 }
54 51
55 objects_[Clipboard::CBF_HTML] = parameters; 52 objects_[Clipboard::CBF_HTML] = parameters;
56 } 53 }
57 54
58 void ScopedClipboardWriter::WriteRTF(const std::string& rtf_data) { 55 void ScopedClipboardWriter::WriteRTF(const std::string& rtf_data) {
59 if (rtf_data.empty())
60 return;
61
62 Clipboard::ObjectMapParams parameters; 56 Clipboard::ObjectMapParams parameters;
63 parameters.push_back(Clipboard::ObjectMapParam(rtf_data.begin(), 57 parameters.push_back(Clipboard::ObjectMapParam(rtf_data.begin(),
64 rtf_data.end())); 58 rtf_data.end()));
65 objects_[Clipboard::CBF_RTF] = parameters; 59 objects_[Clipboard::CBF_RTF] = parameters;
66 } 60 }
67 61
68 void ScopedClipboardWriter::WriteBookmark(const string16& bookmark_title, 62 void ScopedClipboardWriter::WriteBookmark(const string16& bookmark_title,
69 const std::string& url) { 63 const std::string& url) {
70 if (bookmark_title.empty() || url.empty()) 64 if (bookmark_title.empty() || url.empty())
71 return; 65 return;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 parameters.push_back(data_parameter); 126 parameters.push_back(data_parameter);
133 objects_[Clipboard::CBF_DATA] = parameters; 127 objects_[Clipboard::CBF_DATA] = parameters;
134 } 128 }
135 129
136 void ScopedClipboardWriter::Reset() { 130 void ScopedClipboardWriter::Reset() {
137 url_text_.clear(); 131 url_text_.clear();
138 objects_.clear(); 132 objects_.clear();
139 } 133 }
140 134
141 void ScopedClipboardWriter::WriteTextOrURL(const string16& text, bool is_url) { 135 void ScopedClipboardWriter::WriteTextOrURL(const string16& text, bool is_url) {
142 if (text.empty())
143 return;
144
145 std::string utf8_text = UTF16ToUTF8(text); 136 std::string utf8_text = UTF16ToUTF8(text);
146 137
147 Clipboard::ObjectMapParams parameters; 138 Clipboard::ObjectMapParams parameters;
148 parameters.push_back(Clipboard::ObjectMapParam(utf8_text.begin(), 139 parameters.push_back(Clipboard::ObjectMapParam(utf8_text.begin(),
149 utf8_text.end())); 140 utf8_text.end()));
150 objects_[Clipboard::CBF_TEXT] = parameters; 141 objects_[Clipboard::CBF_TEXT] = parameters;
151 142
152 if (is_url) { 143 if (is_url) {
153 url_text_ = utf8_text; 144 url_text_ = utf8_text;
154 } else { 145 } else {
155 url_text_.clear(); 146 url_text_.clear();
156 } 147 }
157 } 148 }
158 149
159 } // namespace ui 150 } // namespace ui
OLDNEW
« no previous file with comments | « content/common/drag_messages.h ('k') | webkit/glue/webclipboard_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698