Upstream version 5.34.92.0
[platform/framework/web/crosswalk.git] / src / content / browser / web_contents / web_drag_source_gtk.h
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.
4
5 #ifndef CONTENT_BROWSER_WEB_CONTENTS_WEB_DRAG_SOURCE_GTK_H_
6 #define CONTENT_BROWSER_WEB_CONTENTS_WEB_DRAG_SOURCE_GTK_H_
7
8 #include <gtk/gtk.h>
9
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"
21 #include "url/gurl.h"
22
23 class SkBitmap;
24
25 namespace content {
26
27 class RenderViewHostImpl;
28 class WebContentsImpl;
29 struct DropData;
30
31 // WebDragSourceGtk takes care of managing the drag from a WebContents
32 // with Gtk.
33 class CONTENT_EXPORT WebDragSourceGtk :
34     public base::MessageLoopForUI::Observer {
35  public:
36   explicit WebDragSourceGtk(WebContents* web_contents);
37   virtual ~WebDragSourceGtk();
38
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);
46
47   // MessageLoop::Observer implementation:
48   virtual void WillProcessEvent(GdkEvent* event) OVERRIDE;
49   virtual void DidProcessEvent(GdkEvent* event) OVERRIDE;
50
51  private:
52   CHROMEGTK_CALLBACK_2(WebDragSourceGtk, gboolean, OnDragFailed,
53                        GdkDragContext*, GtkDragResult);
54   CHROMEGTK_CALLBACK_1(WebDragSourceGtk, void, OnDragBegin,
55                        GdkDragContext*);
56   CHROMEGTK_CALLBACK_1(WebDragSourceGtk, void, OnDragEnd,
57                        GdkDragContext*);
58   CHROMEGTK_CALLBACK_4(WebDragSourceGtk, void, OnDragDataGet,
59                        GdkDragContext*, GtkSelectionData*, guint, guint);
60   CHROMEGTK_CALLBACK_1(WebDragSourceGtk, gboolean, OnDragIconExpose,
61                        GdkEventExpose*);
62
63   gfx::NativeView GetContentNativeView() const;
64
65   // The tab we're manging the drag for.
66   WebContentsImpl* web_contents_;
67
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_;
71
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_;
76
77   // The mime type for the file contents of the current drag (if any).
78   GdkAtom drag_file_mime_type_;
79
80   // Whether the current drag has failed. Meaningless if we are not the source
81   // for a current drag.
82   bool drag_failed_;
83
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_;
89
90   // Context created once drag starts.  A NULL value indicates that there is
91   // no drag currently in progress.
92   GdkDragContext* drag_context_;
93
94   // The file mime type for a drag-out download.
95   base::string16 wide_download_mime_type_;
96
97   // The file name to be saved to for a drag-out download.
98   base::FilePath download_file_name_;
99
100   // The URL to download from for a drag-out download.
101   GURL download_url_;
102
103   // The widget that provides visual feedback for the drag. We can't use
104   // an OwnedWidgetGtk because the GtkWindow initialization code sinks
105   // the reference.
106   GtkWidget* drag_icon_;
107
108   ui::GtkSignalRegistrar signals_;
109
110   DISALLOW_COPY_AND_ASSIGN(WebDragSourceGtk);
111 };
112
113 }  // namespace content
114
115 #endif  // CONTENT_BROWSER_WEB_CONTENTS_WEB_DRAG_SOURCE_GTK_H_