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

Unified Diff: base/scoped_clipboard_writer.cc

Issue 9154: Rewrote the clipboard API to be more concurrent. Added a helper class to make... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/scoped_clipboard_writer.h ('k') | chrome/browser/autocomplete/autocomplete_edit.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/scoped_clipboard_writer.cc
===================================================================
--- base/scoped_clipboard_writer.cc (revision 0)
+++ base/scoped_clipboard_writer.cc (revision 0)
@@ -0,0 +1,130 @@
+// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/scoped_clipboard_writer.h"
+
+#include "base/clipboard.h"
+#include "base/string_util.h"
+
+ScopedClipboardWriter::ScopedClipboardWriter(Clipboard* clipboard)
+ : clipboard_(clipboard) {
+}
+
+ScopedClipboardWriter::~ScopedClipboardWriter() {
+ if (!objects_.empty() && clipboard_)
+ clipboard_->WriteObjects(objects_);
+}
+
+void ScopedClipboardWriter::WriteText(const std::wstring& text) {
+ if (text.empty())
+ return;
+
+ std::string utf8_text = WideToUTF8(text);
+
+ Clipboard::ObjectMapParams params;
+ params.push_back(Clipboard::ObjectMapParam(utf8_text.begin(),
+ utf8_text.end()));
+ objects_[Clipboard::CBF_TEXT] = params;
+}
+
+void ScopedClipboardWriter::WriteHTML(const std::wstring& markup,
+ const std::string& src_url) {
+ if (markup.empty())
+ return;
+
+ std::string utf8_markup = WideToUTF8(markup);
+
+ Clipboard::ObjectMapParams params;
+ params.push_back(
+ Clipboard::ObjectMapParam(utf8_markup.begin(),
+ utf8_markup.end()));
+ if (!src_url.empty()) {
+ params.push_back(Clipboard::ObjectMapParam(src_url.begin(),
+ src_url.end()));
+ }
+
+ objects_[Clipboard::CBF_HTML] = params;
+}
+
+void ScopedClipboardWriter::WriteBookmark(const std::wstring& title,
+ const std::string& url) {
+ if (title.empty() || url.empty())
+ return;
+
+ std::string utf8_markup = WideToUTF8(title);
+
+ Clipboard::ObjectMapParams params;
+ params.push_back(Clipboard::ObjectMapParam(utf8_markup.begin(),
+ utf8_markup.end()));
+ params.push_back(Clipboard::ObjectMapParam(url.begin(), url.end()));
+ objects_[Clipboard::CBF_BOOKMARK] = params;
+}
+
+void ScopedClipboardWriter::WriteHyperlink(const std::wstring& title,
+ const std::string& url) {
+ if (title.empty() || url.empty())
+ return;
+
+ std::string utf8_markup = WideToUTF8(title);
+
+ Clipboard::ObjectMapParams params;
+ params.push_back(Clipboard::ObjectMapParam(utf8_markup.begin(),
+ utf8_markup.end()));
+ params.push_back(Clipboard::ObjectMapParam(url.begin(), url.end()));
+ objects_[Clipboard::CBF_LINK] = params;
+}
+
+void ScopedClipboardWriter::WriteFile(const std::wstring& file) {
+ WriteFiles(std::vector<std::wstring>(1, file));
+}
+
+// Save the filenames as a string separated by nulls and terminated with an
+// extra null.
+void ScopedClipboardWriter::WriteFiles(const std::vector<std::wstring>& files) {
+ if (files.empty())
+ return;
+
+ Clipboard::ObjectMapParam param;
+
+ for (std::vector<std::wstring>::const_iterator iter = files.begin();
+ iter != files.end(); ++iter) {
+ std::string filename = WideToUTF8(*iter);
+ for (std::string::const_iterator filename_iter = filename.begin();
+ filename_iter != filename.end(); ++filename_iter) {
+ param.push_back(*filename_iter);
+ }
+ param.push_back('\0');
+ }
+
+ param.push_back('\0');
+
+ Clipboard::ObjectMapParams params;
+ params.push_back(param);
+ objects_[Clipboard::CBF_FILES] = params;
+}
+
+#if defined(OS_WIN)
+void ScopedClipboardWriter::WriteWebSmartPaste() {
+ objects_[Clipboard::CBF_WEBKIT] = Clipboard::ObjectMapParams();
+}
+
+void ScopedClipboardWriter::WriteBitmapFromPixels(const void* pixels,
+ const gfx::Size& size) {
+ Clipboard::ObjectMapParam param1, param2;
+ const char* pixels_data = reinterpret_cast<const char*>(pixels);
+ size_t pixels_len = 4 * size.width() * size.height();
+ for (size_t i = 0; i < pixels_len; i++)
+ param1.push_back(pixels_data[i]);
+
+ const char* size_data = reinterpret_cast<const char*>(&size);
+ size_t size_len = sizeof(gfx::Size);
+ for (size_t i = 0; i < size_len; i++)
+ param2.push_back(size_data[i]);
+
+ Clipboard::ObjectMapParams params;
+ params.push_back(param1);
+ params.push_back(param2);
+ objects_[Clipboard::CBF_BITMAP] = params;
+}
+#endif // defined(OS_WIN)
« no previous file with comments | « base/scoped_clipboard_writer.h ('k') | chrome/browser/autocomplete/autocomplete_edit.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698