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/nix/mime_util_xdg.h" | 9 #include "base/nix/mime_util_xdg.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #include "base/threading/thread_restrictions.h" | 11 #include "base/threading/thread_restrictions.h" |
12 #include "content/browser/download/drag_download_file.h" | 12 #include "content/browser/download/drag_download_file.h" |
13 #include "content/browser/download/drag_download_util.h" | 13 #include "content/browser/download/drag_download_util.h" |
14 #include "content/browser/renderer_host/render_view_host_delegate.h" | 14 #include "content/browser/renderer_host/render_view_host_delegate.h" |
15 #include "content/browser/renderer_host/render_view_host_impl.h" | 15 #include "content/browser/renderer_host/render_view_host_impl.h" |
16 #include "content/browser/web_contents/drag_utils_gtk.h" | 16 #include "content/browser/web_contents/drag_utils_gtk.h" |
17 #include "content/browser/web_contents/web_contents_impl.h" | 17 #include "content/browser/web_contents/web_contents_impl.h" |
18 #include "content/public/browser/content_browser_client.h" | 18 #include "content/public/browser/content_browser_client.h" |
19 #include "content/public/browser/web_contents_view.h" | 19 #include "content/public/browser/web_contents_view.h" |
20 #include "content/public/common/content_client.h" | 20 #include "content/public/common/content_client.h" |
| 21 #include "content/public/common/drop_data.h" |
21 #include "net/base/file_stream.h" | 22 #include "net/base/file_stream.h" |
22 #include "net/base/net_util.h" | 23 #include "net/base/net_util.h" |
23 #include "third_party/skia/include/core/SkBitmap.h" | 24 #include "third_party/skia/include/core/SkBitmap.h" |
24 #include "ui/base/clipboard/custom_data_helper.h" | 25 #include "ui/base/clipboard/custom_data_helper.h" |
25 #include "ui/base/dragdrop/gtk_dnd_util.h" | 26 #include "ui/base/dragdrop/gtk_dnd_util.h" |
26 #include "ui/base/gtk/gtk_compat.h" | 27 #include "ui/base/gtk/gtk_compat.h" |
27 #include "ui/base/gtk/gtk_screen_util.h" | 28 #include "ui/base/gtk/gtk_screen_util.h" |
28 #include "ui/gfx/gtk_util.h" | 29 #include "ui/gfx/gtk_util.h" |
29 #include "webkit/common/webdropdata.h" | |
30 | 30 |
31 using WebKit::WebDragOperation; | 31 using WebKit::WebDragOperation; |
32 using WebKit::WebDragOperationsMask; | 32 using WebKit::WebDragOperationsMask; |
33 using WebKit::WebDragOperationNone; | 33 using WebKit::WebDragOperationNone; |
34 | 34 |
35 namespace content { | 35 namespace content { |
36 | 36 |
37 WebDragSourceGtk::WebDragSourceGtk(WebContents* web_contents) | 37 WebDragSourceGtk::WebDragSourceGtk(WebContents* web_contents) |
38 : web_contents_(static_cast<WebContentsImpl*>(web_contents)), | 38 : web_contents_(static_cast<WebContentsImpl*>(web_contents)), |
39 drag_pixbuf_(NULL), | 39 drag_pixbuf_(NULL), |
(...skipping 21 matching lines...) Expand all Loading... |
61 gtk_grab_add(drag_widget_); | 61 gtk_grab_add(drag_widget_); |
62 gtk_grab_remove(drag_widget_); | 62 gtk_grab_remove(drag_widget_); |
63 base::MessageLoopForUI::current()->RemoveObserver(this); | 63 base::MessageLoopForUI::current()->RemoveObserver(this); |
64 drop_data_.reset(); | 64 drop_data_.reset(); |
65 } | 65 } |
66 | 66 |
67 gtk_widget_destroy(drag_widget_); | 67 gtk_widget_destroy(drag_widget_); |
68 gtk_widget_destroy(drag_icon_); | 68 gtk_widget_destroy(drag_icon_); |
69 } | 69 } |
70 | 70 |
71 bool WebDragSourceGtk::StartDragging(const WebDropData& drop_data, | 71 bool WebDragSourceGtk::StartDragging(const DropData& drop_data, |
72 WebDragOperationsMask allowed_ops, | 72 WebDragOperationsMask allowed_ops, |
73 GdkEventButton* last_mouse_down, | 73 GdkEventButton* last_mouse_down, |
74 const SkBitmap& image, | 74 const SkBitmap& image, |
75 const gfx::Vector2d& image_offset) { | 75 const gfx::Vector2d& image_offset) { |
76 // Guard against re-starting before previous drag completed. | 76 // Guard against re-starting before previous drag completed. |
77 if (drag_context_) { | 77 if (drag_context_) { |
78 NOTREACHED(); | 78 NOTREACHED(); |
79 return false; | 79 return false; |
80 } | 80 } |
81 | 81 |
(...skipping 16 matching lines...) Expand all Loading... |
98 &download_file_name_, | 98 &download_file_name_, |
99 &download_url_)) { | 99 &download_url_)) { |
100 targets_mask |= ui::DIRECT_SAVE_FILE; | 100 targets_mask |= ui::DIRECT_SAVE_FILE; |
101 } | 101 } |
102 if (!drop_data.custom_data.empty()) | 102 if (!drop_data.custom_data.empty()) |
103 targets_mask |= ui::CUSTOM_DATA; | 103 targets_mask |= ui::CUSTOM_DATA; |
104 | 104 |
105 // NOTE: Begin a drag even if no targets present. Otherwise, things like | 105 // NOTE: Begin a drag even if no targets present. Otherwise, things like |
106 // draggable list elements will not work. | 106 // draggable list elements will not work. |
107 | 107 |
108 drop_data_.reset(new WebDropData(drop_data)); | 108 drop_data_.reset(new DropData(drop_data)); |
109 | 109 |
110 // The image we get from WebKit makes heavy use of alpha-shading. This looks | 110 // The image we get from WebKit makes heavy use of alpha-shading. This looks |
111 // bad on non-compositing WMs. Fall back to the default drag icon. | 111 // bad on non-compositing WMs. Fall back to the default drag icon. |
112 if (!image.isNull() && ui::IsScreenComposited()) | 112 if (!image.isNull() && ui::IsScreenComposited()) |
113 drag_pixbuf_ = gfx::GdkPixbufFromSkBitmap(image); | 113 drag_pixbuf_ = gfx::GdkPixbufFromSkBitmap(image); |
114 image_offset_ = image_offset; | 114 image_offset_ = image_offset; |
115 | 115 |
116 GtkTargetList* list = ui::GetTargetListFromCodeMask(targets_mask); | 116 GtkTargetList* list = ui::GetTargetListFromCodeMask(targets_mask); |
117 if (targets_mask & ui::CHROME_WEBDROP_FILE_CONTENTS) { | 117 if (targets_mask & ui::CHROME_WEBDROP_FILE_CONTENTS) { |
118 // Looking up the mime type can hit the disk. http://crbug.com/84896 | 118 // Looking up the mime type can hit the disk. http://crbug.com/84896 |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 cairo_clip(cr); | 394 cairo_clip(cr); |
395 cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); | 395 cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
396 gdk_cairo_set_source_pixbuf(cr, drag_pixbuf_, 0, 0); | 396 gdk_cairo_set_source_pixbuf(cr, drag_pixbuf_, 0, 0); |
397 cairo_paint(cr); | 397 cairo_paint(cr); |
398 cairo_destroy(cr); | 398 cairo_destroy(cr); |
399 | 399 |
400 return TRUE; | 400 return TRUE; |
401 } | 401 } |
402 | 402 |
403 } // namespace content | 403 } // namespace content |
OLD | NEW |