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

Side by Side Diff: ui/base/clipboard/clipboard_aurax11.cc

Issue 8801038: Make Clipboard::FormatType an opaque handle type. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix Linux build too? Created 9 years 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 "ui/base/clipboard/clipboard.h" 5 #include "ui/base/clipboard/clipboard.h"
6 6
7 #include "base/basictypes.h"
7 #include "base/logging.h" 8 #include "base/logging.h"
8 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
9 #include "third_party/skia/include/core/SkBitmap.h" 10 #include "third_party/skia/include/core/SkBitmap.h"
10 #include "ui/gfx/linux_util.h" 11 #include "ui/gfx/linux_util.h"
11 #include "ui/gfx/size.h" 12 #include "ui/gfx/size.h"
12 13
13 namespace ui { 14 namespace ui {
14 15
15 namespace { 16 namespace {
16 const char kMimeTypeBitmap[] = "image/bmp"; 17 const char kMimeTypeBitmap[] = "image/bmp";
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 129
129 } // namespace 130 } // namespace
130 131
131 // TODO(varunjain): Complete implementation: 132 // TODO(varunjain): Complete implementation:
132 // 1. Handle different types of BUFFERs. 133 // 1. Handle different types of BUFFERs.
133 // 2. Do we need to care about concurrency here? Can there be multiple instances 134 // 2. Do we need to care about concurrency here? Can there be multiple instances
134 // of ui::Clipboard? Ask oshima. 135 // of ui::Clipboard? Ask oshima.
135 // 3. Implement File types. 136 // 3. Implement File types.
136 // 4. Handle conversion between types. 137 // 4. Handle conversion between types.
137 138
139 Clipboard::FormatType::FormatType() {
140 }
141
142 Clipboard::FormatType::FormatType(const std::string& native_format)
143 : data_(native_format) {
144 }
145
146 Clipboard::FormatType::~FormatType() {
147 }
148
138 Clipboard::Clipboard() { 149 Clipboard::Clipboard() {
139 // Make sure clipboard is created. 150 // Make sure clipboard is created.
140 GetClipboardData(); 151 GetClipboardData();
141 } 152 }
142 153
143 Clipboard::~Clipboard() { 154 Clipboard::~Clipboard() {
144 } 155 }
145 156
146 void Clipboard::WriteObjects(const ObjectMap& objects) { 157 void Clipboard::WriteObjects(const ObjectMap& objects) {
147 // We need to overwrite previous data. Probably best to just delete 158 // We need to overwrite previous data. Probably best to just delete
148 // everything and start fresh. 159 // everything and start fresh.
149 DeleteClipboardData(); 160 DeleteClipboardData();
150 for (ObjectMap::const_iterator iter = objects.begin(); 161 for (ObjectMap::const_iterator iter = objects.begin();
151 iter != objects.end(); ++iter) { 162 iter != objects.end(); ++iter) {
152 DispatchObject(static_cast<ObjectType>(iter->first), iter->second); 163 DispatchObject(static_cast<ObjectType>(iter->first), iter->second);
153 } 164 }
154 } 165 }
155 166
156 bool Clipboard::IsFormatAvailable(const FormatType& format, 167 bool Clipboard::IsFormatAvailable(const FormatType& format,
157 Buffer buffer) const { 168 Buffer buffer) const {
158 ClipboardData* data = GetClipboardData(); 169 ClipboardData* data = GetClipboardData();
159 if (GetPlainTextFormatType() == format) 170 if (GetPlainTextFormatType().data() == format.data())
tony 2011/12/06 18:58:29 Would it be worth adding an Equals method to Forma
dcheng 2011/12/06 22:57:02 Done (for both).
160 return !data->text().empty(); 171 return !data->text().empty();
161 else if (GetHtmlFormatType() == format) 172 else if (GetHtmlFormatType().data() == format.data())
162 return !data->markup_data().empty() || !data->url().empty(); 173 return !data->markup_data().empty() || !data->url().empty();
163 else if (GetBitmapFormatType() == format) 174 else if (GetBitmapFormatType().data() == format.data())
164 return !!data->bitmap_data(); 175 return !!data->bitmap_data();
165 else if (GetWebKitSmartPasteFormatType() == format) 176 else if (GetWebKitSmartPasteFormatType().data() == format.data())
166 return data->web_smart_paste(); 177 return data->web_smart_paste();
167 else if (data->custom_data_format() == format) 178 else if (data->custom_data_format() == format.data())
168 return true; 179 return true;
169 return false; 180 return false;
170 } 181 }
171 182
172 bool Clipboard::IsFormatAvailableByString(const std::string& format,
173 Buffer buffer) const {
174 return IsFormatAvailable(format, buffer);
175 }
176
177 void Clipboard::ReadAvailableTypes(Buffer buffer, std::vector<string16>* types, 183 void Clipboard::ReadAvailableTypes(Buffer buffer, std::vector<string16>* types,
178 bool* contains_filenames) const { 184 bool* contains_filenames) const {
179 if (!types || !contains_filenames) { 185 if (!types || !contains_filenames) {
180 NOTREACHED(); 186 NOTREACHED();
181 return; 187 return;
182 } 188 }
183 189
184 types->clear(); 190 types->clear();
185 if (IsFormatAvailable(GetPlainTextFormatType(), buffer)) 191 if (IsFormatAvailable(GetPlainTextFormatType(), buffer))
186 types->push_back(UTF8ToUTF16(GetPlainTextFormatType())); 192 types->push_back(UTF8ToUTF16(GetPlainTextFormatType().data()));
187 if (IsFormatAvailable(GetHtmlFormatType(), buffer)) 193 if (IsFormatAvailable(GetHtmlFormatType(), buffer))
188 types->push_back(UTF8ToUTF16(GetHtmlFormatType())); 194 types->push_back(UTF8ToUTF16(GetHtmlFormatType().data()));
189 if (IsFormatAvailable(GetBitmapFormatType(), buffer)) 195 if (IsFormatAvailable(GetBitmapFormatType(), buffer))
190 types->push_back(UTF8ToUTF16(GetBitmapFormatType())); 196 types->push_back(UTF8ToUTF16(GetBitmapFormatType().data()));
191 if (IsFormatAvailable(GetWebKitSmartPasteFormatType(), buffer))
192 types->push_back(UTF8ToUTF16(GetWebKitSmartPasteFormatType()));
193 *contains_filenames = false; 197 *contains_filenames = false;
194 } 198 }
195 199
196 void Clipboard::ReadText(Buffer buffer, string16* result) const { 200 void Clipboard::ReadText(Buffer buffer, string16* result) const {
197 *result = UTF8ToUTF16(GetClipboardData()->text()); 201 *result = UTF8ToUTF16(GetClipboardData()->text());
198 } 202 }
199 203
200 void Clipboard::ReadAsciiText(Buffer buffer, std::string* result) const { 204 void Clipboard::ReadAsciiText(Buffer buffer, std::string* result) const {
201 *result = GetClipboardData()->text(); 205 *result = GetClipboardData()->text();
202 } 206 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 } 259 }
256 260
257 void Clipboard::ReadFile(FilePath* file) const { 261 void Clipboard::ReadFile(FilePath* file) const {
258 NOTIMPLEMENTED(); 262 NOTIMPLEMENTED();
259 } 263 }
260 264
261 void Clipboard::ReadFiles(std::vector<FilePath>* files) const { 265 void Clipboard::ReadFiles(std::vector<FilePath>* files) const {
262 NOTIMPLEMENTED(); 266 NOTIMPLEMENTED();
263 } 267 }
264 268
265 void Clipboard::ReadData(const std::string& format, std::string* result) const { 269 void Clipboard::ReadData(const FormatType& format, std::string* result) const {
266 result->clear(); 270 result->clear();
267 ClipboardData* data = GetClipboardData(); 271 ClipboardData* data = GetClipboardData();
268 if (data->custom_data_format() == format) 272 if (data->custom_data_format() == format.data())
269 *result = std::string(data->custom_data_data(), data->custom_data_len()); 273 *result = std::string(data->custom_data_data(), data->custom_data_len());
270 } 274 }
271 275
272 uint64 Clipboard::GetSequenceNumber(Buffer buffer) { 276 uint64 Clipboard::GetSequenceNumber(Buffer buffer) {
273 NOTIMPLEMENTED(); 277 NOTIMPLEMENTED();
274 return 0; 278 return 0;
275 } 279 }
276 280
277 void Clipboard::WriteText(const char* text_data, size_t text_len) { 281 void Clipboard::WriteText(const char* text_data, size_t text_len) {
278 GetClipboardData()->set_text(std::string(text_data, text_len)); 282 GetClipboardData()->set_text(std::string(text_data, text_len));
(...skipping 16 matching lines...) Expand all
295 } 299 }
296 300
297 void Clipboard::WriteWebSmartPaste() { 301 void Clipboard::WriteWebSmartPaste() {
298 GetClipboardData()->set_web_smart_paste(true); 302 GetClipboardData()->set_web_smart_paste(true);
299 } 303 }
300 304
301 void Clipboard::WriteBitmap(const char* pixel_data, const char* size_data) { 305 void Clipboard::WriteBitmap(const char* pixel_data, const char* size_data) {
302 GetClipboardData()->SetBitmapData(pixel_data, size_data); 306 GetClipboardData()->SetBitmapData(pixel_data, size_data);
303 } 307 }
304 308
305 void Clipboard::WriteData(const char* format_name, size_t format_len, 309 void Clipboard::WriteData(const FormatType& format,
306 const char* data_data, size_t data_len) { 310 const char* data_data,
307 GetClipboardData()->SetCustomData(std::string(format_name, format_len), 311 size_t data_len) {
308 data_data, data_len); 312 GetClipboardData()->SetCustomData(format.data(), data_data, data_len);
309 } 313 }
310 314
311 // static 315 // static
312 Clipboard::FormatType Clipboard::GetPlainTextFormatType() { 316 Clipboard::FormatType Clipboard::RegisterFormatType(
313 return std::string(kMimeTypeText); 317 const std::string& format_string) {
318 return StringToFormatType(format_string);
319 }
320
321 std::string Clipboard::FormatTypeToString(const FormatType& type) {
322 return type.data();
323 }
324
325 Clipboard::FormatType Clipboard::StringToFormatType(
326 const std::string& format_string) {
327 return FormatType(format_string);
314 } 328 }
315 329
316 // static 330 // static
317 Clipboard::FormatType Clipboard::GetPlainTextWFormatType() { 331 const Clipboard::FormatType& Clipboard::GetPlainTextFormatType() {
332 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeText));
333 return type;
334 }
335
336 // static
337 const Clipboard::FormatType& Clipboard::GetPlainTextWFormatType() {
318 return GetPlainTextFormatType(); 338 return GetPlainTextFormatType();
319 } 339 }
320 340
321 // static 341 // static
322 Clipboard::FormatType Clipboard::GetHtmlFormatType() { 342 const Clipboard::FormatType& Clipboard::GetHtmlFormatType() {
323 return std::string(kMimeTypeHTML); 343 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeHTML));
344 return type;
324 } 345 }
325 346
326 // static 347 // static
327 Clipboard::FormatType Clipboard::GetBitmapFormatType() { 348 const Clipboard::FormatType& Clipboard::GetBitmapFormatType() {
328 return std::string(kMimeTypeBitmap); 349 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeBitmap));
350 return type;
329 } 351 }
330 352
331 // static 353 // static
332 Clipboard::FormatType Clipboard::GetWebKitSmartPasteFormatType() { 354 const Clipboard::FormatType& Clipboard::GetWebKitSmartPasteFormatType() {
333 return std::string(kMimeTypeWebkitSmartPaste); 355 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeWebkitSmartPaste));
356 return type;
334 } 357 }
335 358
336 // static 359 // static
337 Clipboard::FormatType Clipboard::GetWebCustomDataFormatType() { 360 const Clipboard::FormatType& Clipboard::GetWebCustomDataFormatType() {
338 return std::string(kMimeTypeWebCustomData); 361 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeWebCustomData));
362 return type;
339 } 363 }
340 364
341 } // namespace ui 365 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698