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

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

Issue 8802004: Enable custom MIME types in web copy/paste. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . 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
« no previous file with comments | « ui/base/clipboard/clipboard_aurax11.cc ('k') | ui/base/clipboard/clipboard_mac.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <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"
20 #include "ui/base/gtk/gtk_signal.h" 21 #include "ui/base/gtk/gtk_signal.h"
21 #include "ui/base/x/x11_util.h" 22 #include "ui/base/x/x11_util.h"
22 #include "ui/gfx/canvas_skia.h" 23 #include "ui/gfx/canvas_skia.h"
23 #include "ui/gfx/gtk_util.h" 24 #include "ui/gfx/gtk_util.h"
24 #include "ui/gfx/size.h" 25 #include "ui/gfx/size.h"
25 26
26 namespace ui { 27 namespace ui {
27 28
28 namespace { 29 namespace {
29 30
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 } else { 100 } else {
100 DLOG(ERROR) << "Unexpected selection atom: " << ev->selection; 101 DLOG(ERROR) << "Unexpected selection atom: " << ev->selection;
101 } 102 }
102 } 103 }
103 return GDK_FILTER_CONTINUE; 104 return GDK_FILTER_CONTINUE;
104 } 105 }
105 106
106 const char kMimeTypeBitmap[] = "image/bmp"; 107 const char kMimeTypeBitmap[] = "image/bmp";
107 const char kMimeTypeMozillaURL[] = "text/x-moz-url"; 108 const char kMimeTypeMozillaURL[] = "text/x-moz-url";
108 const char kMimeTypeWebkitSmartPaste[] = "chromium/x-webkit-paste"; 109 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";
109 112
110 std::string GdkAtomToString(const GdkAtom& atom) { 113 std::string GdkAtomToString(const GdkAtom& atom) {
111 gchar* name = gdk_atom_name(atom); 114 gchar* name = gdk_atom_name(atom);
112 std::string rv(name); 115 std::string rv(name);
113 g_free(name); 116 g_free(name);
114 return rv; 117 return rv;
115 } 118 }
116 119
117 GdkAtom StringToGdkAtom(const std::string& str) { 120 GdkAtom StringToGdkAtom(const std::string& str) {
118 return gdk_atom_intern(str.c_str(), FALSE); 121 return gdk_atom_intern(str.c_str(), FALSE);
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 } 386 }
384 387
385 types->clear(); 388 types->clear();
386 if (IsFormatAvailable(GetPlainTextFormatType(), buffer)) 389 if (IsFormatAvailable(GetPlainTextFormatType(), buffer))
387 types->push_back(UTF8ToUTF16(kMimeTypeText)); 390 types->push_back(UTF8ToUTF16(kMimeTypeText));
388 if (IsFormatAvailable(GetHtmlFormatType(), buffer)) 391 if (IsFormatAvailable(GetHtmlFormatType(), buffer))
389 types->push_back(UTF8ToUTF16(kMimeTypeHTML)); 392 types->push_back(UTF8ToUTF16(kMimeTypeHTML));
390 if (IsFormatAvailable(GetBitmapFormatType(), buffer)) 393 if (IsFormatAvailable(GetBitmapFormatType(), buffer))
391 types->push_back(UTF8ToUTF16(kMimeTypePNG)); 394 types->push_back(UTF8ToUTF16(kMimeTypePNG));
392 *contains_filenames = false; 395 *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);
393 } 407 }
394 408
395 409
396 void Clipboard::ReadText(Clipboard::Buffer buffer, string16* result) const { 410 void Clipboard::ReadText(Clipboard::Buffer buffer, string16* result) const {
397 GtkClipboard* clipboard = LookupBackingClipboard(buffer); 411 GtkClipboard* clipboard = LookupBackingClipboard(buffer);
398 if (clipboard == NULL) 412 if (clipboard == NULL)
399 return; 413 return;
400 414
401 result->clear(); 415 result->clear();
402 gchar* text = gtk_clipboard_wait_for_text(clipboard); 416 gchar* text = gtk_clipboard_wait_for_text(clipboard);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 cairo_t* context = scoped_platform_paint.GetPlatformSurface(); 498 cairo_t* context = scoped_platform_paint.GetPlatformSurface();
485 gdk_cairo_set_source_pixbuf(context, pixbuf.get(), 0.0, 0.0); 499 gdk_cairo_set_source_pixbuf(context, pixbuf.get(), 0.0, 0.0);
486 cairo_paint(context); 500 cairo_paint(context);
487 } 501 }
488 return canvas.ExtractBitmap(); 502 return canvas.ExtractBitmap();
489 } 503 }
490 504
491 void Clipboard::ReadCustomData(Buffer buffer, 505 void Clipboard::ReadCustomData(Buffer buffer,
492 const string16& type, 506 const string16& type,
493 string16* result) const { 507 string16* result) const {
494 // TODO(dcheng): Implement this. 508 GtkClipboard* clipboard = LookupBackingClipboard(buffer);
495 NOTIMPLEMENTED(); 509 if (!clipboard)
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);
496 } 518 }
497 519
498 void Clipboard::ReadBookmark(string16* title, std::string* url) const { 520 void Clipboard::ReadBookmark(string16* title, std::string* url) const {
499 // TODO(estade): implement this. 521 // TODO(estade): implement this.
500 NOTIMPLEMENTED(); 522 NOTIMPLEMENTED();
501 } 523 }
502 524
503 void Clipboard::ReadData(const std::string& format, std::string* result) const { 525 void Clipboard::ReadData(const std::string& format, std::string* result) const {
504 GtkSelectionData* data = 526 GtkSelectionData* data =
505 gtk_clipboard_wait_for_contents(clipboard_, StringToGdkAtom(format)); 527 gtk_clipboard_wait_for_contents(clipboard_, StringToGdkAtom(format));
(...skipping 28 matching lines...) Expand all
534 // static 556 // static
535 Clipboard::FormatType Clipboard::GetBitmapFormatType() { 557 Clipboard::FormatType Clipboard::GetBitmapFormatType() {
536 return std::string(kMimeTypeBitmap); 558 return std::string(kMimeTypeBitmap);
537 } 559 }
538 560
539 // static 561 // static
540 Clipboard::FormatType Clipboard::GetWebKitSmartPasteFormatType() { 562 Clipboard::FormatType Clipboard::GetWebKitSmartPasteFormatType() {
541 return std::string(kMimeTypeWebkitSmartPaste); 563 return std::string(kMimeTypeWebkitSmartPaste);
542 } 564 }
543 565
566 // static
567 Clipboard::FormatType Clipboard::GetWebCustomDataFormatType() {
568 return std::string(kMimeTypeWebCustomData);
569 }
570
544 void Clipboard::InsertMapping(const char* key, 571 void Clipboard::InsertMapping(const char* key,
545 char* data, 572 char* data,
546 size_t data_len) { 573 size_t data_len) {
547 DCHECK(clipboard_data_->find(key) == clipboard_data_->end()); 574 DCHECK(clipboard_data_->find(key) == clipboard_data_->end());
548 (*clipboard_data_)[key] = std::make_pair(data, data_len); 575 (*clipboard_data_)[key] = std::make_pair(data, data_len);
549 } 576 }
550 577
551 GtkClipboard* Clipboard::LookupBackingClipboard(Buffer clipboard) const { 578 GtkClipboard* Clipboard::LookupBackingClipboard(Buffer clipboard) const {
552 switch (clipboard) { 579 switch (clipboard) {
553 case BUFFER_STANDARD: 580 case BUFFER_STANDARD:
554 return clipboard_; 581 return clipboard_;
555 case BUFFER_SELECTION: 582 case BUFFER_SELECTION:
556 return primary_selection_; 583 return primary_selection_;
557 default: 584 default:
558 NOTREACHED(); 585 NOTREACHED();
559 return NULL; 586 return NULL;
560 } 587 }
561 } 588 }
562 589
563 } // namespace ui 590 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/clipboard/clipboard_aurax11.cc ('k') | ui/base/clipboard/clipboard_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698