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

Side by Side Diff: webkit/tools/test_shell/simple_clipboard_impl.cc

Issue 8591030: Move clipboard-related webkit_glue embedder functions into a ClipboardClient interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include "webkit/glue/webkit_glue.h" 5 #include "webkit/tools/test_shell/simple_clipboard_impl.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
11 #include "base/string16.h" 11 #include "base/string16.h"
12 #include "googleurl/src/gurl.h" 12 #include "googleurl/src/gurl.h"
13 #include "third_party/skia/include/core/SkBitmap.h" 13 #include "third_party/skia/include/core/SkBitmap.h"
14 #include "third_party/zlib/zlib.h" 14 #include "third_party/zlib/zlib.h"
15 #include "ui/base/clipboard/clipboard.h" 15 #include "ui/base/clipboard/clipboard.h"
16 #include "ui/gfx/codec/png_codec.h" 16 #include "ui/gfx/codec/png_codec.h"
17 #include "ui/gfx/size.h" 17 #include "ui/gfx/size.h"
18 #include "webkit/glue/scoped_clipboard_writer_glue.h" 18 #include "webkit/glue/webkit_glue.h"
19 19
20 // Clipboard glue 20 namespace {
21
22 void ScopedClipboardWriterGlue::WriteBitmapFromPixels(
23 const void* pixels, const gfx::Size& size) {
24 ScopedClipboardWriter::WriteBitmapFromPixels(pixels, size);
25 }
26
27 ScopedClipboardWriterGlue::~ScopedClipboardWriterGlue() {
28 }
29
30 namespace webkit_glue {
31 21
32 base::LazyInstance<ui::Clipboard> clipboard = LAZY_INSTANCE_INITIALIZER; 22 base::LazyInstance<ui::Clipboard> clipboard = LAZY_INSTANCE_INITIALIZER;
33 23
34 ui::Clipboard* ClipboardGetClipboard() { 24 } // anonymous namespace
25
26 SimpleClipboardClient::SimpleClipboardClient() {
27 }
28
29 SimpleClipboardClient::~SimpleClipboardClient() {
30 }
31
32
33 ui::Clipboard* SimpleClipboardClient::GetClipboard() {
35 return clipboard.Pointer(); 34 return clipboard.Pointer();
36 } 35 }
37 36
38 uint64 ClipboardGetSequenceNumber(ui::Clipboard::Buffer buffer) { 37 uint64 SimpleClipboardClient::GetSequenceNumber(ui::Clipboard::Buffer buffer) {
39 return ClipboardGetClipboard()->GetSequenceNumber(buffer); 38 return GetClipboard()->GetSequenceNumber(buffer);
40 } 39 }
41 40
42 bool ClipboardIsFormatAvailable(const ui::Clipboard::FormatType& format, 41 bool SimpleClipboardClient::IsFormatAvailable(
43 ui::Clipboard::Buffer buffer) { 42 const ui::Clipboard::FormatType& format,
44 return ClipboardGetClipboard()->IsFormatAvailable(format, buffer); 43 ui::Clipboard::Buffer buffer) {
44 return GetClipboard()->IsFormatAvailable(format, buffer);
45 } 45 }
46 46
47 void ClipboardReadAvailableTypes(ui::Clipboard::Buffer buffer, 47 void SimpleClipboardClient::ReadAvailableTypes(ui::Clipboard::Buffer buffer,
48 std::vector<string16>* types, 48 std::vector<string16>* types,
49 bool* contains_filenames) { 49 bool* contains_filenames) {
50 return ClipboardGetClipboard()->ReadAvailableTypes(buffer, types, 50 return GetClipboard()->ReadAvailableTypes(buffer, types,
51 contains_filenames); 51 contains_filenames);
52 } 52 }
53 53
54 void ClipboardReadText(ui::Clipboard::Buffer buffer, string16* result) { 54 void SimpleClipboardClient::ReadText(ui::Clipboard::Buffer buffer,
55 ClipboardGetClipboard()->ReadText(buffer, result); 55 string16* result) {
56 GetClipboard()->ReadText(buffer, result);
56 } 57 }
57 58
58 void ClipboardReadAsciiText(ui::Clipboard::Buffer buffer, std::string* result) { 59 void SimpleClipboardClient::ReadAsciiText(ui::Clipboard::Buffer buffer,
59 ClipboardGetClipboard()->ReadAsciiText(buffer, result); 60 std::string* result) {
61 GetClipboard()->ReadAsciiText(buffer, result);
60 } 62 }
61 63
62 void ClipboardReadHTML(ui::Clipboard::Buffer buffer, string16* markup, 64 void SimpleClipboardClient::ReadHTML(ui::Clipboard::Buffer buffer,
63 GURL* url, uint32* fragment_start, 65 string16* markup,
64 uint32* fragment_end) { 66 GURL* url, uint32* fragment_start,
67 uint32* fragment_end) {
65 std::string url_str; 68 std::string url_str;
66 ClipboardGetClipboard()->ReadHTML(buffer, markup, url ? &url_str : NULL, 69 GetClipboard()->ReadHTML(buffer, markup, url ? &url_str : NULL,
67 fragment_start, fragment_end); 70 fragment_start, fragment_end);
68 if (url) 71 if (url)
69 *url = GURL(url_str); 72 *url = GURL(url_str);
70 } 73 }
71 74
72 void ClipboardReadImage(ui::Clipboard::Buffer buffer, std::string* data) { 75 void SimpleClipboardClient::ReadImage(ui::Clipboard::Buffer buffer,
73 SkBitmap bitmap = ClipboardGetClipboard()->ReadImage(buffer); 76 std::string* data) {
77 SkBitmap bitmap = GetClipboard()->ReadImage(buffer);
74 if (bitmap.isNull()) 78 if (bitmap.isNull())
75 return; 79 return;
76 80
77 std::vector<unsigned char> png_data; 81 std::vector<unsigned char> png_data;
78 SkAutoLockPixels lock(bitmap); 82 SkAutoLockPixels lock(bitmap);
79 if (gfx::PNGCodec::EncodeWithCompressionLevel( 83 if (gfx::PNGCodec::EncodeWithCompressionLevel(
80 static_cast<const unsigned char*>(bitmap.getPixels()), 84 static_cast<const unsigned char*>(bitmap.getPixels()),
81 gfx::PNGCodec::FORMAT_BGRA, 85 gfx::PNGCodec::FORMAT_BGRA,
82 gfx::Size(bitmap.width(), bitmap.height()), 86 gfx::Size(bitmap.width(), bitmap.height()),
83 bitmap.rowBytes(), 87 bitmap.rowBytes(),
84 false, 88 false,
85 std::vector<gfx::PNGCodec::Comment>(), 89 std::vector<gfx::PNGCodec::Comment>(),
86 Z_BEST_SPEED, 90 Z_BEST_SPEED,
87 &png_data)) { 91 &png_data)) {
88 data->assign(reinterpret_cast<char*>(vector_as_array(&png_data)), 92 data->assign(reinterpret_cast<char*>(vector_as_array(&png_data)),
89 png_data.size()); 93 png_data.size());
90 } 94 }
91 } 95 }
92 96
93 } // namespace webkit_glue 97 webkit_glue::ClipboardClient::WriteContext*
98 SimpleClipboardClient::CreateWriteContext() {
99 return NULL;
100 }
101
OLDNEW
« no previous file with comments | « webkit/tools/test_shell/simple_clipboard_impl.h ('k') | webkit/tools/test_shell/test_shell_webkit_init.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698