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
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_WEB_CONTENTS_WEB_DRAG_SOURCE_GTK_H_
6 #define CONTENT_BROWSER_WEB_CONTENTS_WEB_DRAG_SOURCE_GTK_H_
10 #include "base/basictypes.h"
11 #include "base/files/file_path.h"
12 #include "base/message_loop/message_loop.h"
13 #include "base/strings/string16.h"
14 #include "content/common/content_export.h"
15 #include "content/public/browser/web_contents.h"
16 #include "third_party/WebKit/public/web/WebDragOperation.h"
17 #include "ui/base/gtk/gtk_signal.h"
18 #include "ui/base/gtk/gtk_signal_registrar.h"
19 #include "ui/gfx/native_widget_types.h"
20 #include "ui/gfx/vector2d.h"
27 class RenderViewHostImpl
;
28 class WebContentsImpl
;
31 // WebDragSourceGtk takes care of managing the drag from a WebContents
33 class CONTENT_EXPORT WebDragSourceGtk
:
34 public base::MessageLoopForUI::Observer
{
36 explicit WebDragSourceGtk(WebContents
* web_contents
);
37 virtual ~WebDragSourceGtk();
39 // Starts a drag for the WebContents this WebDragSourceGtk was created for.
40 // Returns false if the drag could not be started.
41 bool StartDragging(const DropData
& drop_data
,
42 blink::WebDragOperationsMask allowed_ops
,
43 GdkEventButton
* last_mouse_down
,
44 const SkBitmap
& image
,
45 const gfx::Vector2d
& image_offset
);
47 // MessageLoop::Observer implementation:
48 virtual void WillProcessEvent(GdkEvent
* event
) OVERRIDE
;
49 virtual void DidProcessEvent(GdkEvent
* event
) OVERRIDE
;
52 CHROMEGTK_CALLBACK_2(WebDragSourceGtk
, gboolean
, OnDragFailed
,
53 GdkDragContext
*, GtkDragResult
);
54 CHROMEGTK_CALLBACK_1(WebDragSourceGtk
, void, OnDragBegin
,
56 CHROMEGTK_CALLBACK_1(WebDragSourceGtk
, void, OnDragEnd
,
58 CHROMEGTK_CALLBACK_4(WebDragSourceGtk
, void, OnDragDataGet
,
59 GdkDragContext
*, GtkSelectionData
*, guint
, guint
);
60 CHROMEGTK_CALLBACK_1(WebDragSourceGtk
, gboolean
, OnDragIconExpose
,
63 gfx::NativeView
GetContentNativeView() const;
65 // The tab we're manging the drag for.
66 WebContentsImpl
* web_contents_
;
68 // The drop data for the current drag (for drags that originate in the render
69 // view). Non-NULL iff there is a current drag.
70 scoped_ptr
<DropData
> drop_data_
;
72 // The image used for depicting the drag, and the offset between the cursor
73 // and the top left pixel.
74 GdkPixbuf
* drag_pixbuf_
;
75 gfx::Vector2d image_offset_
;
77 // The mime type for the file contents of the current drag (if any).
78 GdkAtom drag_file_mime_type_
;
80 // Whether the current drag has failed. Meaningless if we are not the source
81 // for a current drag.
84 // This is the widget we use to initiate drags. Since we don't use the
85 // renderer widget, we can persist drags even when our contents is switched
86 // out. We can't use an OwnedWidgetGtk because the GtkInvisible widget
87 // initialization code sinks the reference.
88 GtkWidget
* drag_widget_
;
90 // Context created once drag starts. A NULL value indicates that there is
91 // no drag currently in progress.
92 GdkDragContext
* drag_context_
;
94 // The file mime type for a drag-out download.
95 base::string16 wide_download_mime_type_
;
97 // The file name to be saved to for a drag-out download.
98 base::FilePath download_file_name_
;
100 // The URL to download from for a drag-out download.
103 // The widget that provides visual feedback for the drag. We can't use
104 // an OwnedWidgetGtk because the GtkWindow initialization code sinks
106 GtkWidget
* drag_icon_
;
108 ui::GtkSignalRegistrar signals_
;
110 DISALLOW_COPY_AND_ASSIGN(WebDragSourceGtk
);
113 } // namespace content
115 #endif // CONTENT_BROWSER_WEB_CONTENTS_WEB_DRAG_SOURCE_GTK_H_