| 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 #include "ui/base/clipboard/clipboard.h" | 5 #include "ui/base/clipboard/clipboard.h" |
| 6 | 6 |
| 7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
| 8 #include <X11/extensions/Xfixes.h> | 8 #include <X11/extensions/Xfixes.h> |
| 9 #include <X11/Xatom.h> | 9 #include <X11/Xatom.h> |
| 10 #include <map> | 10 #include <map> |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 | 310 |
| 311 // We store the GdkPixbuf*, and the size_t half of the pair is meaningless. | 311 // We store the GdkPixbuf*, and the size_t half of the pair is meaningless. |
| 312 // Note that this contrasts with the vast majority of entries in our target | 312 // Note that this contrasts with the vast majority of entries in our target |
| 313 // map, which directly store the data and its length. | 313 // map, which directly store the data and its length. |
| 314 InsertMapping(kMimeTypeBitmap, reinterpret_cast<char*>(pixbuf), 0); | 314 InsertMapping(kMimeTypeBitmap, reinterpret_cast<char*>(pixbuf), 0); |
| 315 } | 315 } |
| 316 | 316 |
| 317 void Clipboard::WriteBookmark(const char* title_data, size_t title_len, | 317 void Clipboard::WriteBookmark(const char* title_data, size_t title_len, |
| 318 const char* url_data, size_t url_len) { | 318 const char* url_data, size_t url_len) { |
| 319 // Write as a mozilla url (UTF16: URL, newline, title). | 319 // Write as a mozilla url (UTF16: URL, newline, title). |
| 320 string16 url = UTF8ToUTF16(std::string(url_data, url_len) + "\n"); | 320 base::string16 url = UTF8ToUTF16(std::string(url_data, url_len) + "\n"); |
| 321 string16 title = UTF8ToUTF16(std::string(title_data, title_len)); | 321 base::string16 title = UTF8ToUTF16(std::string(title_data, title_len)); |
| 322 if (title.length() >= std::numeric_limits<size_t>::max() / 4 || | 322 if (title.length() >= std::numeric_limits<size_t>::max() / 4 || |
| 323 url.length() >= std::numeric_limits<size_t>::max() / 4) | 323 url.length() >= std::numeric_limits<size_t>::max() / 4) |
| 324 return; | 324 return; |
| 325 size_t data_len = 2 * (title.length() + url.length()); | 325 size_t data_len = 2 * (title.length() + url.length()); |
| 326 | 326 |
| 327 char* data = new char[data_len]; | 327 char* data = new char[data_len]; |
| 328 memcpy(data, url.data(), 2 * url.length()); | 328 memcpy(data, url.data(), 2 * url.length()); |
| 329 memcpy(data + 2 * url.length(), title.data(), 2 * title.length()); | 329 memcpy(data + 2 * url.length(), title.data(), 2 * title.length()); |
| 330 InsertMapping(kMimeTypeMozillaURL, data, data_len); | 330 InsertMapping(kMimeTypeMozillaURL, data, data_len); |
| 331 } | 331 } |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 | 400 |
| 401 void Clipboard::Clear(ClipboardType type) { | 401 void Clipboard::Clear(ClipboardType type) { |
| 402 DCHECK(CalledOnValidThread()); | 402 DCHECK(CalledOnValidThread()); |
| 403 GtkClipboard* clipboard = LookupBackingClipboard(type); | 403 GtkClipboard* clipboard = LookupBackingClipboard(type); |
| 404 if (clipboard == NULL) | 404 if (clipboard == NULL) |
| 405 return; | 405 return; |
| 406 gtk_clipboard_clear(clipboard); | 406 gtk_clipboard_clear(clipboard); |
| 407 } | 407 } |
| 408 | 408 |
| 409 void Clipboard::ReadAvailableTypes(ClipboardType type, | 409 void Clipboard::ReadAvailableTypes(ClipboardType type, |
| 410 std::vector<string16>* types, | 410 std::vector<base::string16>* types, |
| 411 bool* contains_filenames) const { | 411 bool* contains_filenames) const { |
| 412 DCHECK(CalledOnValidThread()); | 412 DCHECK(CalledOnValidThread()); |
| 413 if (!types || !contains_filenames) { | 413 if (!types || !contains_filenames) { |
| 414 NOTREACHED(); | 414 NOTREACHED(); |
| 415 return; | 415 return; |
| 416 } | 416 } |
| 417 | 417 |
| 418 types->clear(); | 418 types->clear(); |
| 419 if (IsFormatAvailable(GetPlainTextFormatType(), type)) | 419 if (IsFormatAvailable(GetPlainTextFormatType(), type)) |
| 420 types->push_back(UTF8ToUTF16(kMimeTypeText)); | 420 types->push_back(UTF8ToUTF16(kMimeTypeText)); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 434 clipboard, GetWebCustomDataFormatType().ToGdkAtom()); | 434 clipboard, GetWebCustomDataFormatType().ToGdkAtom()); |
| 435 if (!data) | 435 if (!data) |
| 436 return; | 436 return; |
| 437 ReadCustomDataTypes(gtk_selection_data_get_data(data), | 437 ReadCustomDataTypes(gtk_selection_data_get_data(data), |
| 438 gtk_selection_data_get_length(data), | 438 gtk_selection_data_get_length(data), |
| 439 types); | 439 types); |
| 440 gtk_selection_data_free(data); | 440 gtk_selection_data_free(data); |
| 441 } | 441 } |
| 442 | 442 |
| 443 | 443 |
| 444 void Clipboard::ReadText(ClipboardType type, string16* result) const { | 444 void Clipboard::ReadText(ClipboardType type, base::string16* result) const { |
| 445 DCHECK(CalledOnValidThread()); | 445 DCHECK(CalledOnValidThread()); |
| 446 GtkClipboard* clipboard = LookupBackingClipboard(type); | 446 GtkClipboard* clipboard = LookupBackingClipboard(type); |
| 447 if (clipboard == NULL) | 447 if (clipboard == NULL) |
| 448 return; | 448 return; |
| 449 | 449 |
| 450 result->clear(); | 450 result->clear(); |
| 451 gchar* text = gtk_clipboard_wait_for_text(clipboard); | 451 gchar* text = gtk_clipboard_wait_for_text(clipboard); |
| 452 | 452 |
| 453 if (text == NULL) | 453 if (text == NULL) |
| 454 return; | 454 return; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 471 if (text == NULL) | 471 if (text == NULL) |
| 472 return; | 472 return; |
| 473 | 473 |
| 474 result->assign(text); | 474 result->assign(text); |
| 475 g_free(text); | 475 g_free(text); |
| 476 } | 476 } |
| 477 | 477 |
| 478 // TODO(estade): handle different charsets. | 478 // TODO(estade): handle different charsets. |
| 479 // TODO(port): set *src_url. | 479 // TODO(port): set *src_url. |
| 480 void Clipboard::ReadHTML(ClipboardType type, | 480 void Clipboard::ReadHTML(ClipboardType type, |
| 481 string16* markup, | 481 base::string16* markup, |
| 482 std::string* src_url, | 482 std::string* src_url, |
| 483 uint32* fragment_start, | 483 uint32* fragment_start, |
| 484 uint32* fragment_end) const { | 484 uint32* fragment_end) const { |
| 485 DCHECK(CalledOnValidThread()); | 485 DCHECK(CalledOnValidThread()); |
| 486 markup->clear(); | 486 markup->clear(); |
| 487 if (src_url) | 487 if (src_url) |
| 488 src_url->clear(); | 488 src_url->clear(); |
| 489 *fragment_start = 0; | 489 *fragment_start = 0; |
| 490 *fragment_end = 0; | 490 *fragment_end = 0; |
| 491 | 491 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 { | 540 { |
| 541 skia::ScopedPlatformPaint scoped_platform_paint(canvas.sk_canvas()); | 541 skia::ScopedPlatformPaint scoped_platform_paint(canvas.sk_canvas()); |
| 542 cairo_t* context = scoped_platform_paint.GetPlatformSurface(); | 542 cairo_t* context = scoped_platform_paint.GetPlatformSurface(); |
| 543 gdk_cairo_set_source_pixbuf(context, pixbuf.get(), 0.0, 0.0); | 543 gdk_cairo_set_source_pixbuf(context, pixbuf.get(), 0.0, 0.0); |
| 544 cairo_paint(context); | 544 cairo_paint(context); |
| 545 } | 545 } |
| 546 return canvas.ExtractImageRep().sk_bitmap(); | 546 return canvas.ExtractImageRep().sk_bitmap(); |
| 547 } | 547 } |
| 548 | 548 |
| 549 void Clipboard::ReadCustomData(ClipboardType clipboard_type, | 549 void Clipboard::ReadCustomData(ClipboardType clipboard_type, |
| 550 const string16& type, | 550 const base::string16& type, |
| 551 string16* result) const { | 551 base::string16* result) const { |
| 552 DCHECK(CalledOnValidThread()); | 552 DCHECK(CalledOnValidThread()); |
| 553 GtkClipboard* clipboard = LookupBackingClipboard(clipboard_type); | 553 GtkClipboard* clipboard = LookupBackingClipboard(clipboard_type); |
| 554 if (!clipboard) | 554 if (!clipboard) |
| 555 return; | 555 return; |
| 556 | 556 |
| 557 GtkSelectionData* data = gtk_clipboard_wait_for_contents( | 557 GtkSelectionData* data = gtk_clipboard_wait_for_contents( |
| 558 clipboard, GetWebCustomDataFormatType().ToGdkAtom()); | 558 clipboard, GetWebCustomDataFormatType().ToGdkAtom()); |
| 559 if (!data) | 559 if (!data) |
| 560 return; | 560 return; |
| 561 ReadCustomDataForType(gtk_selection_data_get_data(data), | 561 ReadCustomDataForType(gtk_selection_data_get_data(data), |
| 562 gtk_selection_data_get_length(data), | 562 gtk_selection_data_get_length(data), |
| 563 type, result); | 563 type, result); |
| 564 gtk_selection_data_free(data); | 564 gtk_selection_data_free(data); |
| 565 } | 565 } |
| 566 | 566 |
| 567 void Clipboard::ReadBookmark(string16* title, std::string* url) const { | 567 void Clipboard::ReadBookmark(base::string16* title, std::string* url) const { |
| 568 // TODO(estade): implement this. | 568 // TODO(estade): implement this. |
| 569 NOTIMPLEMENTED(); | 569 NOTIMPLEMENTED(); |
| 570 } | 570 } |
| 571 | 571 |
| 572 void Clipboard::ReadData(const FormatType& format, std::string* result) const { | 572 void Clipboard::ReadData(const FormatType& format, std::string* result) const { |
| 573 DCHECK(CalledOnValidThread()); | 573 DCHECK(CalledOnValidThread()); |
| 574 result->clear(); | 574 result->clear(); |
| 575 GtkSelectionData* data = | 575 GtkSelectionData* data = |
| 576 gtk_clipboard_wait_for_contents(clipboard_, format.ToGdkAtom()); | 576 gtk_clipboard_wait_for_contents(clipboard_, format.ToGdkAtom()); |
| 577 if (!data) | 577 if (!data) |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 667 return clipboard_; | 667 return clipboard_; |
| 668 case CLIPBOARD_TYPE_SELECTION: | 668 case CLIPBOARD_TYPE_SELECTION: |
| 669 return primary_selection_; | 669 return primary_selection_; |
| 670 default: | 670 default: |
| 671 NOTREACHED(); | 671 NOTREACHED(); |
| 672 return NULL; | 672 return NULL; |
| 673 } | 673 } |
| 674 } | 674 } |
| 675 | 675 |
| 676 } // namespace ui | 676 } // namespace ui |
| OLD | NEW |