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

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
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 const char kMimeTypeWebCustomData[] = "chromium/x-web-custom-data";
tony 2011/12/05 20:24:50 Please file a bug that this name is temporary and
dcheng 2011/12/05 20:51:04 Done.
109 111
110 std::string GdkAtomToString(const GdkAtom& atom) { 112 std::string GdkAtomToString(const GdkAtom& atom) {
111 gchar* name = gdk_atom_name(atom); 113 gchar* name = gdk_atom_name(atom);
112 std::string rv(name); 114 std::string rv(name);
113 g_free(name); 115 g_free(name);
114 return rv; 116 return rv;
115 } 117 }
116 118
117 GdkAtom StringToGdkAtom(const std::string& str) { 119 GdkAtom StringToGdkAtom(const std::string& str) {
118 return gdk_atom_intern(str.c_str(), FALSE); 120 return gdk_atom_intern(str.c_str(), FALSE);
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 } 385 }
384 386
385 types->clear(); 387 types->clear();
386 if (IsFormatAvailable(GetPlainTextFormatType(), buffer)) 388 if (IsFormatAvailable(GetPlainTextFormatType(), buffer))
387 types->push_back(UTF8ToUTF16(kMimeTypeText)); 389 types->push_back(UTF8ToUTF16(kMimeTypeText));
388 if (IsFormatAvailable(GetHtmlFormatType(), buffer)) 390 if (IsFormatAvailable(GetHtmlFormatType(), buffer))
389 types->push_back(UTF8ToUTF16(kMimeTypeHTML)); 391 types->push_back(UTF8ToUTF16(kMimeTypeHTML));
390 if (IsFormatAvailable(GetBitmapFormatType(), buffer)) 392 if (IsFormatAvailable(GetBitmapFormatType(), buffer))
391 types->push_back(UTF8ToUTF16(kMimeTypePNG)); 393 types->push_back(UTF8ToUTF16(kMimeTypePNG));
392 *contains_filenames = false; 394 *contains_filenames = false;
395
396 GtkClipboard* clipboard = LookupBackingClipboard(buffer);
397 DCHECK(clipboard);
tony 2011/12/05 20:24:50 Nit: Should we handle a NULL clipboard case in rel
dcheng 2011/12/05 20:51:04 Done.
398 GtkSelectionData* data = gtk_clipboard_wait_for_contents(
399 clipboard, StringToGdkAtom(GetWebCustomDataFormatType()));
400 if (!data)
401 return;
402 ReadCustomDataTypes(data->data, data->length, types);
403 gtk_selection_data_free(data);
393 } 404 }
394 405
395 406
396 void Clipboard::ReadText(Clipboard::Buffer buffer, string16* result) const { 407 void Clipboard::ReadText(Clipboard::Buffer buffer, string16* result) const {
397 GtkClipboard* clipboard = LookupBackingClipboard(buffer); 408 GtkClipboard* clipboard = LookupBackingClipboard(buffer);
398 if (clipboard == NULL) 409 if (clipboard == NULL)
399 return; 410 return;
400 411
401 result->clear(); 412 result->clear();
402 gchar* text = gtk_clipboard_wait_for_text(clipboard); 413 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(); 495 cairo_t* context = scoped_platform_paint.GetPlatformSurface();
485 gdk_cairo_set_source_pixbuf(context, pixbuf.get(), 0.0, 0.0); 496 gdk_cairo_set_source_pixbuf(context, pixbuf.get(), 0.0, 0.0);
486 cairo_paint(context); 497 cairo_paint(context);
487 } 498 }
488 return canvas.ExtractBitmap(); 499 return canvas.ExtractBitmap();
489 } 500 }
490 501
491 void Clipboard::ReadCustomData(Buffer buffer, 502 void Clipboard::ReadCustomData(Buffer buffer,
492 const string16& type, 503 const string16& type,
493 string16* result) const { 504 string16* result) const {
494 // TODO(dcheng): Implement this. 505 GtkClipboard* clipboard = LookupBackingClipboard(buffer);
495 NOTIMPLEMENTED(); 506 if (!clipboard)
507 return;
508
509 GtkSelectionData* data = gtk_clipboard_wait_for_contents(
510 clipboard, StringToGdkAtom(GetWebCustomDataFormatType()));
511 if (!data)
512 return;
513 ReadCustomDataForType(data->data, data->length, type, result);
514 gtk_selection_data_free(data);
496 } 515 }
497 516
498 void Clipboard::ReadBookmark(string16* title, std::string* url) const { 517 void Clipboard::ReadBookmark(string16* title, std::string* url) const {
499 // TODO(estade): implement this. 518 // TODO(estade): implement this.
500 NOTIMPLEMENTED(); 519 NOTIMPLEMENTED();
501 } 520 }
502 521
503 void Clipboard::ReadData(const std::string& format, std::string* result) const { 522 void Clipboard::ReadData(const std::string& format, std::string* result) const {
504 GtkSelectionData* data = 523 GtkSelectionData* data =
505 gtk_clipboard_wait_for_contents(clipboard_, StringToGdkAtom(format)); 524 gtk_clipboard_wait_for_contents(clipboard_, StringToGdkAtom(format));
(...skipping 28 matching lines...) Expand all
534 // static 553 // static
535 Clipboard::FormatType Clipboard::GetBitmapFormatType() { 554 Clipboard::FormatType Clipboard::GetBitmapFormatType() {
536 return std::string(kMimeTypeBitmap); 555 return std::string(kMimeTypeBitmap);
537 } 556 }
538 557
539 // static 558 // static
540 Clipboard::FormatType Clipboard::GetWebKitSmartPasteFormatType() { 559 Clipboard::FormatType Clipboard::GetWebKitSmartPasteFormatType() {
541 return std::string(kMimeTypeWebkitSmartPaste); 560 return std::string(kMimeTypeWebkitSmartPaste);
542 } 561 }
543 562
563 // static
564 Clipboard::FormatType Clipboard::GetWebCustomDataFormatType() {
565 return std::string(kMimeTypeWebCustomData);
566 }
567
544 void Clipboard::InsertMapping(const char* key, 568 void Clipboard::InsertMapping(const char* key,
545 char* data, 569 char* data,
546 size_t data_len) { 570 size_t data_len) {
547 DCHECK(clipboard_data_->find(key) == clipboard_data_->end()); 571 DCHECK(clipboard_data_->find(key) == clipboard_data_->end());
548 (*clipboard_data_)[key] = std::make_pair(data, data_len); 572 (*clipboard_data_)[key] = std::make_pair(data, data_len);
549 } 573 }
550 574
551 GtkClipboard* Clipboard::LookupBackingClipboard(Buffer clipboard) const { 575 GtkClipboard* Clipboard::LookupBackingClipboard(Buffer clipboard) const {
552 switch (clipboard) { 576 switch (clipboard) {
553 case BUFFER_STANDARD: 577 case BUFFER_STANDARD:
554 return clipboard_; 578 return clipboard_;
555 case BUFFER_SELECTION: 579 case BUFFER_SELECTION:
556 return primary_selection_; 580 return primary_selection_;
557 default: 581 default:
558 NOTREACHED(); 582 NOTREACHED();
559 return NULL; 583 return NULL;
560 } 584 }
561 } 585 }
562 586
563 } // namespace ui 587 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698