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; | |
|
jamesr
2014/09/22 22:38:41
can you use bit_cast<Clipboard::ObjectMapParam>(&b
dcheng
2014/09/22 23:06:25
I don't think I can use bit_cast directly here, be
| |
| 99 for (size_t i = 0; i < sizeof(bitmap_pointer); ++i) | |
|
jamesr
2014/09/22 22:38:41
oh god
dcheng
2014/09/22 23:06:25
Yeah... I think that is the only appropriate respo
| |
| 100 packed_pointer.push_back(reinterpret_cast<uint8_t*>(&bitmap_pointer)[i]); | |
| 101 Clipboard::ObjectMapParams parameters; | |
| 102 parameters.push_back(packed_pointer); | |
| 103 objects_[Clipboard::CBF_SMBITMAP] = parameters; | |
| 104 } | |
| 105 | |
| 89 void ScopedClipboardWriter::WritePickledData( | 106 void ScopedClipboardWriter::WritePickledData( |
| 90 const Pickle& pickle, const Clipboard::FormatType& format) { | 107 const Pickle& pickle, const Clipboard::FormatType& format) { |
| 91 std::string format_string = format.Serialize(); | 108 std::string format_string = format.Serialize(); |
| 92 Clipboard::ObjectMapParam format_parameter(format_string.begin(), | 109 Clipboard::ObjectMapParam format_parameter(format_string.begin(), |
| 93 format_string.end()); | 110 format_string.end()); |
| 94 Clipboard::ObjectMapParam data_parameter; | 111 Clipboard::ObjectMapParam data_parameter; |
| 95 | 112 |
| 96 data_parameter.resize(pickle.size()); | 113 data_parameter.resize(pickle.size()); |
| 97 memcpy(const_cast<char*>(&data_parameter.front()), | 114 memcpy(const_cast<char*>(&data_parameter.front()), |
| 98 pickle.data(), pickle.size()); | 115 pickle.data(), pickle.size()); |
| 99 | 116 |
| 100 Clipboard::ObjectMapParams parameters; | 117 Clipboard::ObjectMapParams parameters; |
| 101 parameters.push_back(format_parameter); | 118 parameters.push_back(format_parameter); |
| 102 parameters.push_back(data_parameter); | 119 parameters.push_back(data_parameter); |
| 103 objects_[Clipboard::CBF_DATA] = parameters; | 120 objects_[Clipboard::CBF_DATA] = parameters; |
| 104 } | 121 } |
| 105 | 122 |
| 106 void ScopedClipboardWriter::Reset() { | 123 void ScopedClipboardWriter::Reset() { |
| 107 url_text_.clear(); | 124 url_text_.clear(); |
| 108 objects_.clear(); | 125 objects_.clear(); |
| 126 bitmap_.reset(); | |
| 109 } | 127 } |
| 110 | 128 |
| 111 void ScopedClipboardWriter::WriteTextOrURL(const base::string16& text, | 129 void ScopedClipboardWriter::WriteTextOrURL(const base::string16& text, |
| 112 bool is_url) { | 130 bool is_url) { |
| 113 std::string utf8_text = base::UTF16ToUTF8(text); | 131 std::string utf8_text = base::UTF16ToUTF8(text); |
| 114 | 132 |
| 115 Clipboard::ObjectMapParams parameters; | 133 Clipboard::ObjectMapParams parameters; |
| 116 parameters.push_back(Clipboard::ObjectMapParam(utf8_text.begin(), | 134 parameters.push_back(Clipboard::ObjectMapParam(utf8_text.begin(), |
| 117 utf8_text.end())); | 135 utf8_text.end())); |
| 118 objects_[Clipboard::CBF_TEXT] = parameters; | 136 objects_[Clipboard::CBF_TEXT] = parameters; |
| 119 | 137 |
| 120 if (is_url) { | 138 if (is_url) { |
| 121 url_text_ = utf8_text; | 139 url_text_ = utf8_text; |
| 122 } else { | 140 } else { |
| 123 url_text_.clear(); | 141 url_text_.clear(); |
| 124 } | 142 } |
| 125 } | 143 } |
| 126 | 144 |
| 127 } // namespace ui | 145 } // namespace ui |
| OLD | NEW |