| 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 <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> |
| 11 #include <set> | 11 #include <set> |
| 12 #include <string> | 12 #include <string> |
| 13 #include <utility> | 13 #include <utility> |
| 14 | 14 |
| 15 #include "base/file_path.h" | 15 #include "base/file_path.h" |
| 16 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "base/memory/singleton.h" | 17 #include "base/memory/singleton.h" |
| 18 #include "base/utf_string_conversions.h" | 18 #include "base/utf_string_conversions.h" |
| 19 #include "third_party/skia/include/core/SkBitmap.h" | 19 #include "third_party/skia/include/core/SkBitmap.h" |
| 20 #include "ui/base/clipboard/custom_data_helper.h" | |
| 21 #include "ui/base/gtk/gtk_signal.h" | 20 #include "ui/base/gtk/gtk_signal.h" |
| 22 #include "ui/base/x/x11_util.h" | 21 #include "ui/base/x/x11_util.h" |
| 23 #include "ui/gfx/canvas_skia.h" | 22 #include "ui/gfx/canvas_skia.h" |
| 24 #include "ui/gfx/gtk_util.h" | 23 #include "ui/gfx/gtk_util.h" |
| 25 #include "ui/gfx/size.h" | 24 #include "ui/gfx/size.h" |
| 26 | 25 |
| 27 namespace ui { | 26 namespace ui { |
| 28 | 27 |
| 29 namespace { | 28 namespace { |
| 30 | 29 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 } else { | 99 } else { |
| 101 DLOG(ERROR) << "Unexpected selection atom: " << ev->selection; | 100 DLOG(ERROR) << "Unexpected selection atom: " << ev->selection; |
| 102 } | 101 } |
| 103 } | 102 } |
| 104 return GDK_FILTER_CONTINUE; | 103 return GDK_FILTER_CONTINUE; |
| 105 } | 104 } |
| 106 | 105 |
| 107 const char kMimeTypeBitmap[] = "image/bmp"; | 106 const char kMimeTypeBitmap[] = "image/bmp"; |
| 108 const char kMimeTypeMozillaURL[] = "text/x-moz-url"; | 107 const char kMimeTypeMozillaURL[] = "text/x-moz-url"; |
| 109 const char kMimeTypeWebkitSmartPaste[] = "chromium/x-webkit-paste"; | 108 const char kMimeTypeWebkitSmartPaste[] = "chromium/x-webkit-paste"; |
| 110 // TODO(dcheng): This name is temporary. See crbug.com/106449 | |
| 111 const char kMimeTypeWebCustomData[] = "chromium/x-web-custom-data"; | |
| 112 | 109 |
| 113 std::string GdkAtomToString(const GdkAtom& atom) { | 110 std::string GdkAtomToString(const GdkAtom& atom) { |
| 114 gchar* name = gdk_atom_name(atom); | 111 gchar* name = gdk_atom_name(atom); |
| 115 std::string rv(name); | 112 std::string rv(name); |
| 116 g_free(name); | 113 g_free(name); |
| 117 return rv; | 114 return rv; |
| 118 } | 115 } |
| 119 | 116 |
| 120 GdkAtom StringToGdkAtom(const std::string& str) { | 117 GdkAtom StringToGdkAtom(const std::string& str) { |
| 121 return gdk_atom_intern(str.c_str(), FALSE); | 118 return gdk_atom_intern(str.c_str(), FALSE); |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 } | 383 } |
| 387 | 384 |
| 388 types->clear(); | 385 types->clear(); |
| 389 if (IsFormatAvailable(GetPlainTextFormatType(), buffer)) | 386 if (IsFormatAvailable(GetPlainTextFormatType(), buffer)) |
| 390 types->push_back(UTF8ToUTF16(kMimeTypeText)); | 387 types->push_back(UTF8ToUTF16(kMimeTypeText)); |
| 391 if (IsFormatAvailable(GetHtmlFormatType(), buffer)) | 388 if (IsFormatAvailable(GetHtmlFormatType(), buffer)) |
| 392 types->push_back(UTF8ToUTF16(kMimeTypeHTML)); | 389 types->push_back(UTF8ToUTF16(kMimeTypeHTML)); |
| 393 if (IsFormatAvailable(GetBitmapFormatType(), buffer)) | 390 if (IsFormatAvailable(GetBitmapFormatType(), buffer)) |
| 394 types->push_back(UTF8ToUTF16(kMimeTypePNG)); | 391 types->push_back(UTF8ToUTF16(kMimeTypePNG)); |
| 395 *contains_filenames = false; | 392 *contains_filenames = false; |
| 396 | |
| 397 GtkClipboard* clipboard = LookupBackingClipboard(buffer); | |
| 398 if (!clipboard) | |
| 399 return; | |
| 400 | |
| 401 GtkSelectionData* data = gtk_clipboard_wait_for_contents( | |
| 402 clipboard, StringToGdkAtom(GetWebCustomDataFormatType())); | |
| 403 if (!data) | |
| 404 return; | |
| 405 ReadCustomDataTypes(data->data, data->length, types); | |
| 406 gtk_selection_data_free(data); | |
| 407 } | 393 } |
| 408 | 394 |
| 409 | 395 |
| 410 void Clipboard::ReadText(Clipboard::Buffer buffer, string16* result) const { | 396 void Clipboard::ReadText(Clipboard::Buffer buffer, string16* result) const { |
| 411 GtkClipboard* clipboard = LookupBackingClipboard(buffer); | 397 GtkClipboard* clipboard = LookupBackingClipboard(buffer); |
| 412 if (clipboard == NULL) | 398 if (clipboard == NULL) |
| 413 return; | 399 return; |
| 414 | 400 |
| 415 result->clear(); | 401 result->clear(); |
| 416 gchar* text = gtk_clipboard_wait_for_text(clipboard); | 402 gchar* text = gtk_clipboard_wait_for_text(clipboard); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 cairo_t* context = scoped_platform_paint.GetPlatformSurface(); | 484 cairo_t* context = scoped_platform_paint.GetPlatformSurface(); |
| 499 gdk_cairo_set_source_pixbuf(context, pixbuf.get(), 0.0, 0.0); | 485 gdk_cairo_set_source_pixbuf(context, pixbuf.get(), 0.0, 0.0); |
| 500 cairo_paint(context); | 486 cairo_paint(context); |
| 501 } | 487 } |
| 502 return canvas.ExtractBitmap(); | 488 return canvas.ExtractBitmap(); |
| 503 } | 489 } |
| 504 | 490 |
| 505 void Clipboard::ReadCustomData(Buffer buffer, | 491 void Clipboard::ReadCustomData(Buffer buffer, |
| 506 const string16& type, | 492 const string16& type, |
| 507 string16* result) const { | 493 string16* result) const { |
| 508 GtkClipboard* clipboard = LookupBackingClipboard(buffer); | 494 // TODO(dcheng): Implement this. |
| 509 if (!clipboard) | 495 NOTIMPLEMENTED(); |
| 510 return; | |
| 511 | |
| 512 GtkSelectionData* data = gtk_clipboard_wait_for_contents( | |
| 513 clipboard, StringToGdkAtom(GetWebCustomDataFormatType())); | |
| 514 if (!data) | |
| 515 return; | |
| 516 ReadCustomDataForType(data->data, data->length, type, result); | |
| 517 gtk_selection_data_free(data); | |
| 518 } | 496 } |
| 519 | 497 |
| 520 void Clipboard::ReadBookmark(string16* title, std::string* url) const { | 498 void Clipboard::ReadBookmark(string16* title, std::string* url) const { |
| 521 // TODO(estade): implement this. | 499 // TODO(estade): implement this. |
| 522 NOTIMPLEMENTED(); | 500 NOTIMPLEMENTED(); |
| 523 } | 501 } |
| 524 | 502 |
| 525 void Clipboard::ReadData(const std::string& format, std::string* result) const { | 503 void Clipboard::ReadData(const std::string& format, std::string* result) const { |
| 526 GtkSelectionData* data = | 504 GtkSelectionData* data = |
| 527 gtk_clipboard_wait_for_contents(clipboard_, StringToGdkAtom(format)); | 505 gtk_clipboard_wait_for_contents(clipboard_, StringToGdkAtom(format)); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 556 // static | 534 // static |
| 557 Clipboard::FormatType Clipboard::GetBitmapFormatType() { | 535 Clipboard::FormatType Clipboard::GetBitmapFormatType() { |
| 558 return std::string(kMimeTypeBitmap); | 536 return std::string(kMimeTypeBitmap); |
| 559 } | 537 } |
| 560 | 538 |
| 561 // static | 539 // static |
| 562 Clipboard::FormatType Clipboard::GetWebKitSmartPasteFormatType() { | 540 Clipboard::FormatType Clipboard::GetWebKitSmartPasteFormatType() { |
| 563 return std::string(kMimeTypeWebkitSmartPaste); | 541 return std::string(kMimeTypeWebkitSmartPaste); |
| 564 } | 542 } |
| 565 | 543 |
| 566 // static | |
| 567 Clipboard::FormatType Clipboard::GetWebCustomDataFormatType() { | |
| 568 return std::string(kMimeTypeWebCustomData); | |
| 569 } | |
| 570 | |
| 571 void Clipboard::InsertMapping(const char* key, | 544 void Clipboard::InsertMapping(const char* key, |
| 572 char* data, | 545 char* data, |
| 573 size_t data_len) { | 546 size_t data_len) { |
| 574 DCHECK(clipboard_data_->find(key) == clipboard_data_->end()); | 547 DCHECK(clipboard_data_->find(key) == clipboard_data_->end()); |
| 575 (*clipboard_data_)[key] = std::make_pair(data, data_len); | 548 (*clipboard_data_)[key] = std::make_pair(data, data_len); |
| 576 } | 549 } |
| 577 | 550 |
| 578 GtkClipboard* Clipboard::LookupBackingClipboard(Buffer clipboard) const { | 551 GtkClipboard* Clipboard::LookupBackingClipboard(Buffer clipboard) const { |
| 579 switch (clipboard) { | 552 switch (clipboard) { |
| 580 case BUFFER_STANDARD: | 553 case BUFFER_STANDARD: |
| 581 return clipboard_; | 554 return clipboard_; |
| 582 case BUFFER_SELECTION: | 555 case BUFFER_SELECTION: |
| 583 return primary_selection_; | 556 return primary_selection_; |
| 584 default: | 557 default: |
| 585 NOTREACHED(); | 558 NOTREACHED(); |
| 586 return NULL; | 559 return NULL; |
| 587 } | 560 } |
| 588 } | 561 } |
| 589 | 562 |
| 590 } // namespace ui | 563 } // namespace ui |
| OLD | NEW |