Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 79 html.append("\">"); | 79 html.append("\">"); |
| 80 html.append(net::EscapeForHTML(base::UTF16ToUTF8(anchor_text))); | 80 html.append(net::EscapeForHTML(base::UTF16ToUTF8(anchor_text))); |
| 81 html.append("</a>"); | 81 html.append("</a>"); |
| 82 WriteHTML(base::UTF8ToUTF16(html), std::string()); | 82 WriteHTML(base::UTF8ToUTF16(html), std::string()); |
| 83 } | 83 } |
| 84 | 84 |
| 85 void ScopedClipboardWriter::WriteWebSmartPaste() { | 85 void ScopedClipboardWriter::WriteWebSmartPaste() { |
| 86 objects_[Clipboard::CBF_WEBKIT] = Clipboard::ObjectMapParams(); | 86 objects_[Clipboard::CBF_WEBKIT] = Clipboard::ObjectMapParams(); |
| 87 } | 87 } |
| 88 | 88 |
| 89 void ScopedClipboardWriter::WriteImage(const SkBitmap& bitmap) { | |
| 90 if (bitmap.drawsNothing()) { | |
| 91 NOTREACHED(); | |
| 92 return; | |
| 93 } | |
| 94 bitmap_ = bitmap; | |
| 95 // TODO(dcheng): This is slightly less horrible than what we used to do, but | |
| 96 // only very slightly less. | |
| 97 SkBitmap* bitmap_pointer = &bitmap_; | |
| 98 Clipboard::ObjectMapParam packed_pointer; | |
| 99 for (size_t i = 0; i < sizeof(bitmap_pointer); ++i) { | |
|
sky
2014/09/18 19:47:53
nit: no {}
dcheng
2014/09/18 21:06:00
Done.
| |
| 100 packed_pointer.push_back(reinterpret_cast<uint8_t*>(&bitmap_pointer)[i]); | |
| 101 } | |
| 102 Clipboard::ObjectMapParams parameters; | |
| 103 parameters.push_back(packed_pointer); | |
| 104 objects_[Clipboard::CBF_SMBITMAP] = parameters; | |
| 105 } | |
| 106 | |
| 89 void ScopedClipboardWriter::WritePickledData( | 107 void ScopedClipboardWriter::WritePickledData( |
| 90 const Pickle& pickle, const Clipboard::FormatType& format) { | 108 const Pickle& pickle, const Clipboard::FormatType& format) { |
| 91 std::string format_string = format.Serialize(); | 109 std::string format_string = format.Serialize(); |
| 92 Clipboard::ObjectMapParam format_parameter(format_string.begin(), | 110 Clipboard::ObjectMapParam format_parameter(format_string.begin(), |
| 93 format_string.end()); | 111 format_string.end()); |
| 94 Clipboard::ObjectMapParam data_parameter; | 112 Clipboard::ObjectMapParam data_parameter; |
| 95 | 113 |
| 96 data_parameter.resize(pickle.size()); | 114 data_parameter.resize(pickle.size()); |
| 97 memcpy(const_cast<char*>(&data_parameter.front()), | 115 memcpy(const_cast<char*>(&data_parameter.front()), |
| 98 pickle.data(), pickle.size()); | 116 pickle.data(), pickle.size()); |
| 99 | 117 |
| 100 Clipboard::ObjectMapParams parameters; | 118 Clipboard::ObjectMapParams parameters; |
| 101 parameters.push_back(format_parameter); | 119 parameters.push_back(format_parameter); |
| 102 parameters.push_back(data_parameter); | 120 parameters.push_back(data_parameter); |
| 103 objects_[Clipboard::CBF_DATA] = parameters; | 121 objects_[Clipboard::CBF_DATA] = parameters; |
| 104 } | 122 } |
| 105 | 123 |
| 106 void ScopedClipboardWriter::Reset() { | 124 void ScopedClipboardWriter::Reset() { |
| 107 url_text_.clear(); | 125 url_text_.clear(); |
| 108 objects_.clear(); | 126 objects_.clear(); |
| 127 bitmap_.reset(); | |
| 109 } | 128 } |
| 110 | 129 |
| 111 void ScopedClipboardWriter::WriteTextOrURL(const base::string16& text, | 130 void ScopedClipboardWriter::WriteTextOrURL(const base::string16& text, |
| 112 bool is_url) { | 131 bool is_url) { |
| 113 std::string utf8_text = base::UTF16ToUTF8(text); | 132 std::string utf8_text = base::UTF16ToUTF8(text); |
| 114 | 133 |
| 115 Clipboard::ObjectMapParams parameters; | 134 Clipboard::ObjectMapParams parameters; |
| 116 parameters.push_back(Clipboard::ObjectMapParam(utf8_text.begin(), | 135 parameters.push_back(Clipboard::ObjectMapParam(utf8_text.begin(), |
| 117 utf8_text.end())); | 136 utf8_text.end())); |
| 118 objects_[Clipboard::CBF_TEXT] = parameters; | 137 objects_[Clipboard::CBF_TEXT] = parameters; |
| 119 | 138 |
| 120 if (is_url) { | 139 if (is_url) { |
| 121 url_text_ = utf8_text; | 140 url_text_ = utf8_text; |
| 122 } else { | 141 } else { |
| 123 url_text_.clear(); | 142 url_text_.clear(); |
| 124 } | 143 } |
| 125 } | 144 } |
| 126 | 145 |
| 127 } // namespace ui | 146 } // namespace ui |
| OLD | NEW |