OLD | NEW |
---|---|
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 "ui/base/clipboard/clipboard.h" | 5 #include "ui/base/clipboard/clipboard.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/utf_string_conversions.h" | |
8 #include "third_party/skia/include/core/SkBitmap.h" | 9 #include "third_party/skia/include/core/SkBitmap.h" |
9 | 10 |
10 namespace ui { | 11 namespace ui { |
11 | 12 |
12 namespace { | 13 namespace { |
13 const char kMimeTypeBitmap[] = "image/bmp"; | 14 const char kMimeTypeBitmap[] = "image/bmp"; |
14 const char kMimeTypeWebkitSmartPaste[] = "chromium/x-webkit-paste"; | 15 const char kMimeTypeWebkitSmartPaste[] = "chromium/x-webkit-paste"; |
16 | |
17 // A mimimum clipboard implementation for simple text cut&paste. | |
18 class ClipboardData { | |
19 public: | |
20 ClipboardData() {} | |
21 virtual ~ClipboardData() {} | |
22 | |
23 const std::string& text() const { return utf8_text_; } | |
24 | |
25 void set_text(const std::string& text) { | |
26 utf8_text_ = text; | |
27 } | |
28 | |
29 private: | |
30 std::string utf8_text_; | |
31 | |
32 DISALLOW_COPY_AND_ASSIGN(ClipboardData); | |
33 }; | |
34 | |
35 ClipboardData* data = NULL; | |
msw
2011/10/06 21:52:17
This is okay as a namespace global raw pointer? Sh
oshima
2011/10/06 22:53:47
This is in anonymous namespace, so this is allowed
| |
36 | |
37 ClipboardData* GetClipboardData() { | |
38 if (!data) | |
39 data = new ClipboardData(); | |
40 return data; | |
15 } | 41 } |
16 | 42 |
43 } // namespace | |
44 | |
17 Clipboard::Clipboard() { | 45 Clipboard::Clipboard() { |
18 NOTIMPLEMENTED(); | 46 NOTIMPLEMENTED(); |
19 } | 47 } |
20 | 48 |
21 Clipboard::~Clipboard() { | 49 Clipboard::~Clipboard() { |
22 } | 50 } |
23 | 51 |
24 void Clipboard::WriteObjects(const ObjectMap& objects) { | 52 void Clipboard::WriteObjects(const ObjectMap& objects) { |
25 NOTIMPLEMENTED(); | 53 for (ObjectMap::const_iterator iter = objects.begin(); |
54 iter != objects.end(); ++iter) { | |
55 DispatchObject(static_cast<ObjectType>(iter->first), iter->second); | |
56 } | |
26 } | 57 } |
27 | 58 |
28 | 59 |
29 void Clipboard::WriteObjects(const ObjectMap& objects, | 60 void Clipboard::WriteObjects(const ObjectMap& objects, |
30 base::ProcessHandle process) { | 61 base::ProcessHandle process) { |
31 NOTIMPLEMENTED(); | 62 NOTIMPLEMENTED(); |
32 } | 63 } |
33 | 64 |
34 void Clipboard::DidWriteURL(const std::string& utf8_text) { | 65 void Clipboard::DidWriteURL(const std::string& utf8_text) { |
35 NOTIMPLEMENTED(); | 66 NOTIMPLEMENTED(); |
(...skipping 10 matching lines...) Expand all Loading... | |
46 NOTIMPLEMENTED(); | 77 NOTIMPLEMENTED(); |
47 return false; | 78 return false; |
48 } | 79 } |
49 | 80 |
50 void Clipboard::ReadAvailableTypes(Buffer buffer, std::vector<string16>* types, | 81 void Clipboard::ReadAvailableTypes(Buffer buffer, std::vector<string16>* types, |
51 bool* contains_filenames) const { | 82 bool* contains_filenames) const { |
52 NOTIMPLEMENTED(); | 83 NOTIMPLEMENTED(); |
53 } | 84 } |
54 | 85 |
55 void Clipboard::ReadText(Buffer buffer, string16* result) const { | 86 void Clipboard::ReadText(Buffer buffer, string16* result) const { |
56 NOTIMPLEMENTED(); | 87 *result = UTF8ToUTF16(GetClipboardData()->text()); |
57 } | 88 } |
58 | 89 |
59 void Clipboard::ReadAsciiText(Buffer buffer, std::string* result) const { | 90 void Clipboard::ReadAsciiText(Buffer buffer, std::string* result) const { |
60 NOTIMPLEMENTED(); | 91 *result = GetClipboardData()->text(); |
61 } | 92 } |
62 | 93 |
63 void Clipboard::ReadHTML(Buffer buffer, string16* markup, | 94 void Clipboard::ReadHTML(Buffer buffer, string16* markup, |
64 std::string* src_url) const { | 95 std::string* src_url) const { |
65 NOTIMPLEMENTED(); | 96 NOTIMPLEMENTED(); |
66 } | 97 } |
67 | 98 |
68 SkBitmap Clipboard::ReadImage(Buffer buffer) const { | 99 SkBitmap Clipboard::ReadImage(Buffer buffer) const { |
69 NOTIMPLEMENTED(); | 100 NOTIMPLEMENTED(); |
70 return SkBitmap(); | 101 return SkBitmap(); |
(...skipping 14 matching lines...) Expand all Loading... | |
85 void Clipboard::ReadData(const std::string& format, std::string* result) { | 116 void Clipboard::ReadData(const std::string& format, std::string* result) { |
86 NOTIMPLEMENTED(); | 117 NOTIMPLEMENTED(); |
87 } | 118 } |
88 | 119 |
89 uint64 Clipboard::GetSequenceNumber() { | 120 uint64 Clipboard::GetSequenceNumber() { |
90 NOTIMPLEMENTED(); | 121 NOTIMPLEMENTED(); |
91 return 0; | 122 return 0; |
92 } | 123 } |
93 | 124 |
94 void Clipboard::WriteText(const char* text_data, size_t text_len) { | 125 void Clipboard::WriteText(const char* text_data, size_t text_len) { |
95 NOTIMPLEMENTED(); | 126 GetClipboardData()->set_text(std::string(text_data, text_len)); |
96 } | 127 } |
97 | 128 |
98 void Clipboard::WriteHTML(const char* markup_data, | 129 void Clipboard::WriteHTML(const char* markup_data, |
99 size_t markup_len, | 130 size_t markup_len, |
100 const char* url_data, | 131 const char* url_data, |
101 size_t url_len) { | 132 size_t url_len) { |
102 NOTIMPLEMENTED(); | 133 NOTIMPLEMENTED(); |
103 } | 134 } |
104 | 135 |
105 void Clipboard::WriteBookmark(const char* title_data, | 136 void Clipboard::WriteBookmark(const char* title_data, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
141 Clipboard::FormatType Clipboard::GetBitmapFormatType() { | 172 Clipboard::FormatType Clipboard::GetBitmapFormatType() { |
142 return std::string(kMimeTypeBitmap); | 173 return std::string(kMimeTypeBitmap); |
143 } | 174 } |
144 | 175 |
145 // static | 176 // static |
146 Clipboard::FormatType Clipboard::GetWebKitSmartPasteFormatType() { | 177 Clipboard::FormatType Clipboard::GetWebKitSmartPasteFormatType() { |
147 return std::string(kMimeTypeWebkitSmartPaste); | 178 return std::string(kMimeTypeWebkitSmartPaste); |
148 } | 179 } |
149 | 180 |
150 } // namespace ui | 181 } // namespace ui |
OLD | NEW |