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 "content/browser/web_contents/web_drag_source_gtk.h" | 5 #include "content/browser/web_contents/web_drag_source_gtk.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/nix/mime_util_xdg.h" | 10 #include "base/nix/mime_util_xdg.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 #include "ui/gfx/gtk_util.h" | 29 #include "ui/gfx/gtk_util.h" |
30 #include "webkit/glue/webdropdata.h" | 30 #include "webkit/glue/webdropdata.h" |
31 | 31 |
32 using WebKit::WebDragOperation; | 32 using WebKit::WebDragOperation; |
33 using WebKit::WebDragOperationsMask; | 33 using WebKit::WebDragOperationsMask; |
34 using WebKit::WebDragOperationNone; | 34 using WebKit::WebDragOperationNone; |
35 | 35 |
36 namespace content { | 36 namespace content { |
37 | 37 |
38 WebDragSourceGtk::WebDragSourceGtk(WebContents* web_contents) | 38 WebDragSourceGtk::WebDragSourceGtk(WebContents* web_contents) |
39 : web_contents_(web_contents), | 39 : web_contents_(static_cast<WebContentsImpl*>(web_contents)), |
40 drag_pixbuf_(NULL), | 40 drag_pixbuf_(NULL), |
41 drag_failed_(false), | 41 drag_failed_(false), |
42 drag_widget_(gtk_invisible_new()), | 42 drag_widget_(gtk_invisible_new()), |
43 drag_context_(NULL), | 43 drag_context_(NULL), |
44 drag_icon_(gtk_window_new(GTK_WINDOW_POPUP)) { | 44 drag_icon_(gtk_window_new(GTK_WINDOW_POPUP)) { |
45 signals_.Connect(drag_widget_, "drag-failed", | 45 signals_.Connect(drag_widget_, "drag-failed", |
46 G_CALLBACK(OnDragFailedThunk), this); | 46 G_CALLBACK(OnDragFailedThunk), this); |
47 signals_.Connect(drag_widget_, "drag-begin", | 47 signals_.Connect(drag_widget_, "drag-begin", |
48 G_CALLBACK(OnDragBeginThunk), | 48 G_CALLBACK(OnDragBeginThunk), |
49 this); | 49 this); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 // No-op. | 156 // No-op. |
157 } | 157 } |
158 | 158 |
159 void WebDragSourceGtk::DidProcessEvent(GdkEvent* event) { | 159 void WebDragSourceGtk::DidProcessEvent(GdkEvent* event) { |
160 if (event->type != GDK_MOTION_NOTIFY) | 160 if (event->type != GDK_MOTION_NOTIFY) |
161 return; | 161 return; |
162 | 162 |
163 GdkEventMotion* event_motion = reinterpret_cast<GdkEventMotion*>(event); | 163 GdkEventMotion* event_motion = reinterpret_cast<GdkEventMotion*>(event); |
164 gfx::Point client = ui::ClientPoint(GetContentNativeView()); | 164 gfx::Point client = ui::ClientPoint(GetContentNativeView()); |
165 | 165 |
166 if (GetRenderViewHost()) { | 166 if (web_contents_) { |
167 GetRenderViewHost()->DragSourceMovedTo( | 167 web_contents_->DragSourceMovedTo( |
168 client.x(), client.y(), | 168 client.x(), client.y(), |
169 static_cast<int>(event_motion->x_root), | 169 static_cast<int>(event_motion->x_root), |
170 static_cast<int>(event_motion->y_root)); | 170 static_cast<int>(event_motion->y_root)); |
171 } | 171 } |
172 } | 172 } |
173 | 173 |
174 void WebDragSourceGtk::OnDragDataGet(GtkWidget* sender, | 174 void WebDragSourceGtk::OnDragDataGet(GtkWidget* sender, |
175 GdkDragContext* context, | 175 GdkDragContext* context, |
176 GtkSelectionData* selection_data, | 176 GtkSelectionData* selection_data, |
177 guint target_type, | 177 guint target_type, |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 } | 292 } |
293 | 293 |
294 gboolean WebDragSourceGtk::OnDragFailed(GtkWidget* sender, | 294 gboolean WebDragSourceGtk::OnDragFailed(GtkWidget* sender, |
295 GdkDragContext* context, | 295 GdkDragContext* context, |
296 GtkDragResult result) { | 296 GtkDragResult result) { |
297 drag_failed_ = true; | 297 drag_failed_ = true; |
298 | 298 |
299 gfx::Point root = ui::ScreenPoint(GetContentNativeView()); | 299 gfx::Point root = ui::ScreenPoint(GetContentNativeView()); |
300 gfx::Point client = ui::ClientPoint(GetContentNativeView()); | 300 gfx::Point client = ui::ClientPoint(GetContentNativeView()); |
301 | 301 |
302 if (GetRenderViewHost()) { | 302 if (web_contents_) { |
303 GetRenderViewHost()->DragSourceEndedAt( | 303 web_contents_->DragSourceEndedAt( |
304 client.x(), client.y(), root.x(), root.y(), | 304 client.x(), client.y(), root.x(), root.y(), |
305 WebDragOperationNone); | 305 WebDragOperationNone); |
306 } | 306 } |
307 | 307 |
308 // Let the native failure animation run. | 308 // Let the native failure animation run. |
309 return FALSE; | 309 return FALSE; |
310 } | 310 } |
311 | 311 |
312 void WebDragSourceGtk::OnDragBegin(GtkWidget* sender, | 312 void WebDragSourceGtk::OnDragBegin(GtkWidget* sender, |
313 GdkDragContext* drag_context) { | 313 GdkDragContext* drag_context) { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 | 364 |
365 if (!download_url_.is_empty()) { | 365 if (!download_url_.is_empty()) { |
366 gdk_property_delete(drag_context->source_window, | 366 gdk_property_delete(drag_context->source_window, |
367 ui::GetAtomForTarget(ui::DIRECT_SAVE_FILE)); | 367 ui::GetAtomForTarget(ui::DIRECT_SAVE_FILE)); |
368 } | 368 } |
369 | 369 |
370 if (!drag_failed_) { | 370 if (!drag_failed_) { |
371 gfx::Point root = ui::ScreenPoint(GetContentNativeView()); | 371 gfx::Point root = ui::ScreenPoint(GetContentNativeView()); |
372 gfx::Point client = ui::ClientPoint(GetContentNativeView()); | 372 gfx::Point client = ui::ClientPoint(GetContentNativeView()); |
373 | 373 |
374 if (GetRenderViewHost()) { | 374 if (web_contents_) { |
375 GetRenderViewHost()->DragSourceEndedAt( | 375 web_contents_->DragSourceEndedAt( |
376 client.x(), client.y(), root.x(), root.y(), | 376 client.x(), client.y(), root.x(), root.y(), |
377 GdkDragActionToWebDragOp(drag_context->action)); | 377 GdkDragActionToWebDragOp(drag_context->action)); |
378 } | 378 } |
379 } | 379 } |
380 | 380 |
381 web_contents_->SystemDragEnded(); | 381 web_contents_->SystemDragEnded(); |
382 | 382 |
383 drop_data_.reset(); | 383 drop_data_.reset(); |
384 drag_context_ = NULL; | 384 drag_context_ = NULL; |
385 } | 385 } |
386 | 386 |
387 RenderViewHostImpl* WebDragSourceGtk::GetRenderViewHost() const { | |
388 return static_cast<RenderViewHostImpl*>(web_contents_->GetRenderViewHost()); | |
389 } | |
390 | |
391 gfx::NativeView WebDragSourceGtk::GetContentNativeView() const { | 387 gfx::NativeView WebDragSourceGtk::GetContentNativeView() const { |
392 return web_contents_->GetView()->GetContentNativeView(); | 388 return web_contents_->GetView()->GetContentNativeView(); |
393 } | 389 } |
394 | 390 |
395 gboolean WebDragSourceGtk::OnDragIconExpose(GtkWidget* sender, | 391 gboolean WebDragSourceGtk::OnDragIconExpose(GtkWidget* sender, |
396 GdkEventExpose* event) { | 392 GdkEventExpose* event) { |
397 cairo_t* cr = gdk_cairo_create(event->window); | 393 cairo_t* cr = gdk_cairo_create(event->window); |
398 gdk_cairo_rectangle(cr, &event->area); | 394 gdk_cairo_rectangle(cr, &event->area); |
399 cairo_clip(cr); | 395 cairo_clip(cr); |
400 cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); | 396 cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
401 gdk_cairo_set_source_pixbuf(cr, drag_pixbuf_, 0, 0); | 397 gdk_cairo_set_source_pixbuf(cr, drag_pixbuf_, 0, 0); |
402 cairo_paint(cr); | 398 cairo_paint(cr); |
403 cairo_destroy(cr); | 399 cairo_destroy(cr); |
404 | 400 |
405 return TRUE; | 401 return TRUE; |
406 } | 402 } |
407 | 403 |
408 } // namespace content | 404 } // namespace content |
OLD | NEW |