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

Side by Side Diff: chrome/browser/gtk/tab_contents_drag_source.cc

Issue 1708013: GTK: make more use of gtk_signal convenience macros/signal registrar. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Created 10 years, 8 months 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
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "chrome/browser/gtk/tab_contents_drag_source.h" 5 #include "chrome/browser/gtk/tab_contents_drag_source.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "app/gtk_dnd_util.h" 9 #include "app/gtk_dnd_util.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 14 matching lines...) Expand all
25 25
26 using WebKit::WebDragOperation; 26 using WebKit::WebDragOperation;
27 using WebKit::WebDragOperationsMask; 27 using WebKit::WebDragOperationsMask;
28 using WebKit::WebDragOperationNone; 28 using WebKit::WebDragOperationNone;
29 29
30 TabContentsDragSource::TabContentsDragSource( 30 TabContentsDragSource::TabContentsDragSource(
31 TabContentsView* tab_contents_view) 31 TabContentsView* tab_contents_view)
32 : tab_contents_view_(tab_contents_view), 32 : tab_contents_view_(tab_contents_view),
33 drag_pixbuf_(NULL), 33 drag_pixbuf_(NULL),
34 drag_failed_(false), 34 drag_failed_(false),
35 drag_widget_(NULL), 35 drag_widget_(gtk_invisible_new()),
36 drag_icon_(NULL) { 36 drag_icon_(gtk_window_new(GTK_WINDOW_POPUP)) {
37 drag_widget_ = gtk_invisible_new(); 37 g_object_ref(drag_widget_);
38 g_signal_connect(drag_widget_, "drag-failed", 38 signals_.Connect(drag_widget_, "drag-failed",
39 G_CALLBACK(OnDragFailedThunk), this); 39 G_CALLBACK(OnDragFailedThunk), this);
40 g_signal_connect(drag_widget_, "drag-begin", G_CALLBACK(OnDragBeginThunk), 40 signals_.Connect(drag_widget_, "drag-begin",
41 G_CALLBACK(OnDragBeginThunk),
41 this); 42 this);
42 g_signal_connect(drag_widget_, "drag-end", G_CALLBACK(OnDragEndThunk), this); 43 signals_.Connect(drag_widget_, "drag-end",
43 g_signal_connect(drag_widget_, "drag-data-get", 44 G_CALLBACK(OnDragEndThunk), this);
45 signals_.Connect(drag_widget_, "drag-data-get",
44 G_CALLBACK(OnDragDataGetThunk), this); 46 G_CALLBACK(OnDragDataGetThunk), this);
45 g_object_ref_sink(drag_widget_); 47
48 g_object_ref(drag_icon_);
49 signals_.Connect(drag_icon_, "expose-event",
50 G_CALLBACK(OnDragIconExposeThunk), this);
46 } 51 }
47 52
48 TabContentsDragSource::~TabContentsDragSource() { 53 TabContentsDragSource::~TabContentsDragSource() {
49 g_signal_handlers_disconnect_by_func(drag_widget_,
50 reinterpret_cast<gpointer>(OnDragFailedThunk), this);
51 g_signal_handlers_disconnect_by_func(drag_widget_,
52 reinterpret_cast<gpointer>(OnDragBeginThunk), this);
53 g_signal_handlers_disconnect_by_func(drag_widget_,
54 reinterpret_cast<gpointer>(OnDragEndThunk), this);
55 g_signal_handlers_disconnect_by_func(drag_widget_,
56 reinterpret_cast<gpointer>(OnDragDataGetThunk), this);
57
58 // Break the current drag, if any. 54 // Break the current drag, if any.
59 if (drop_data_.get()) { 55 if (drop_data_.get()) {
60 gtk_grab_add(drag_widget_); 56 gtk_grab_add(drag_widget_);
61 gtk_grab_remove(drag_widget_); 57 gtk_grab_remove(drag_widget_);
62 MessageLoopForUI::current()->RemoveObserver(this); 58 MessageLoopForUI::current()->RemoveObserver(this);
63 drop_data_.reset(); 59 drop_data_.reset();
64 } 60 }
65 61
66 gtk_widget_destroy(drag_widget_);
67 g_object_unref(drag_widget_); 62 g_object_unref(drag_widget_);
68 drag_widget_ = NULL; 63 g_object_unref(drag_icon_);
69 } 64 }
70 65
71 TabContents* TabContentsDragSource::tab_contents() const { 66 TabContents* TabContentsDragSource::tab_contents() const {
72 return tab_contents_view_->tab_contents(); 67 return tab_contents_view_->tab_contents();
73 } 68 }
74 69
75 void TabContentsDragSource::StartDragging(const WebDropData& drop_data, 70 void TabContentsDragSource::StartDragging(const WebDropData& drop_data,
76 WebDragOperationsMask allowed_ops, 71 WebDragOperationsMask allowed_ops,
77 GdkEventButton* last_mouse_down, 72 GdkEventButton* last_mouse_down,
78 const SkBitmap& image, 73 const SkBitmap& image,
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 gtk_dnd_util::GetAtomForTarget( 307 gtk_dnd_util::GetAtomForTarget(
313 gtk_dnd_util::TEXT_PLAIN_NO_CHARSET), 308 gtk_dnd_util::TEXT_PLAIN_NO_CHARSET),
314 8, 309 8,
315 GDK_PROP_MODE_REPLACE, 310 GDK_PROP_MODE_REPLACE,
316 reinterpret_cast<const guchar*>( 311 reinterpret_cast<const guchar*>(
317 generated_download_file_name.value().c_str()), 312 generated_download_file_name.value().c_str()),
318 generated_download_file_name.value().length()); 313 generated_download_file_name.value().length());
319 } 314 }
320 315
321 if (drag_pixbuf_) { 316 if (drag_pixbuf_) {
322 drag_icon_ = gtk_window_new(GTK_WINDOW_POPUP);
323 g_object_ref_sink(drag_icon_);
324 g_signal_connect(drag_icon_, "expose-event",
325 G_CALLBACK(OnDragIconExposeThunk), this);
326 gtk_widget_set_size_request(drag_icon_, 317 gtk_widget_set_size_request(drag_icon_,
327 gdk_pixbuf_get_width(drag_pixbuf_), 318 gdk_pixbuf_get_width(drag_pixbuf_),
328 gdk_pixbuf_get_height(drag_pixbuf_)); 319 gdk_pixbuf_get_height(drag_pixbuf_));
329 320
330 GdkScreen* screen = gtk_widget_get_screen(GTK_WIDGET(drag_icon_)); 321 GdkScreen* screen = gtk_widget_get_screen(drag_icon_);
331 GdkColormap* rgba = gdk_screen_get_rgba_colormap(screen); 322 GdkColormap* rgba = gdk_screen_get_rgba_colormap(screen);
332 if (rgba) 323 if (rgba)
333 gtk_widget_set_colormap(GTK_WIDGET(drag_icon_), rgba); 324 gtk_widget_set_colormap(drag_icon_, rgba);
334 325
335 gtk_drag_set_icon_widget(drag_context, drag_icon_, 326 gtk_drag_set_icon_widget(drag_context, drag_icon_,
336 image_offset_.x(), image_offset_.y()); 327 image_offset_.x(), image_offset_.y());
337 } 328 }
338 } 329 }
339 330
340 void TabContentsDragSource::OnDragEnd(GtkWidget* sender, 331 void TabContentsDragSource::OnDragEnd(GtkWidget* sender,
341 GdkDragContext* drag_context) { 332 GdkDragContext* drag_context) {
342 if (drag_icon_) {
343 g_object_unref(drag_icon_);
344 drag_icon_ = NULL;
345 }
346 if (drag_pixbuf_) { 333 if (drag_pixbuf_) {
347 g_object_unref(drag_pixbuf_); 334 g_object_unref(drag_pixbuf_);
348 drag_pixbuf_ = NULL; 335 drag_pixbuf_ = NULL;
349 } 336 }
350 337
351 MessageLoopForUI::current()->RemoveObserver(this); 338 MessageLoopForUI::current()->RemoveObserver(this);
352 339
353 if (!download_url_.is_empty()) { 340 if (!download_url_.is_empty()) {
354 gdk_property_delete(drag_context->source_window, 341 gdk_property_delete(drag_context->source_window,
355 gtk_dnd_util::GetAtomForTarget( 342 gtk_dnd_util::GetAtomForTarget(
(...skipping 26 matching lines...) Expand all
382 cairo_t* cr = gdk_cairo_create(event->window); 369 cairo_t* cr = gdk_cairo_create(event->window);
383 gdk_cairo_rectangle(cr, &event->area); 370 gdk_cairo_rectangle(cr, &event->area);
384 cairo_clip(cr); 371 cairo_clip(cr);
385 cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); 372 cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
386 gdk_cairo_set_source_pixbuf(cr, drag_pixbuf_, 0, 0); 373 gdk_cairo_set_source_pixbuf(cr, drag_pixbuf_, 0, 0);
387 cairo_paint(cr); 374 cairo_paint(cr);
388 cairo_destroy(cr); 375 cairo_destroy(cr);
389 376
390 return TRUE; 377 return TRUE;
391 } 378 }
OLDNEW
« chrome/browser/gtk/hover_controller_gtk.cc ('K') | « chrome/browser/gtk/tab_contents_drag_source.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698