• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 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 CHROME_BROWSER_UI_GTK_TAB_CONTENTS_DRAG_SOURCE_H_
6 #define CHROME_BROWSER_UI_GTK_TAB_CONTENTS_DRAG_SOURCE_H_
7 #pragma once
8 
9 #include <gtk/gtk.h>
10 
11 #include "base/basictypes.h"
12 #include "base/file_path.h"
13 #include "base/message_loop.h"
14 #include "base/string16.h"
15 #include "googleurl/src/gurl.h"
16 #include "third_party/WebKit/Source/WebKit/chromium/public/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/point.h"
21 
22 class SkBitmap;
23 class TabContents;
24 class TabContentsView;
25 struct WebDropData;
26 
27 // TabContentsDragSource takes care of managing the drag from a TabContents
28 // with Gtk.
29 class TabContentsDragSource : public MessageLoopForUI::Observer {
30  public:
31   explicit TabContentsDragSource(TabContentsView* tab_contents_view);
32   ~TabContentsDragSource();
33 
34   TabContents* tab_contents() const;
35 
36   // Starts a drag for the tab contents this TabContentsDragSource was
37   // created for.
38   void StartDragging(const WebDropData& drop_data,
39                      WebKit::WebDragOperationsMask allowed_ops,
40                      GdkEventButton* last_mouse_down,
41                      const SkBitmap& image,
42                      const gfx::Point& image_offset);
43 
44   // MessageLoop::Observer implementation:
45   virtual void WillProcessEvent(GdkEvent* event);
46   virtual void DidProcessEvent(GdkEvent* event);
47 
48  private:
49   CHROMEGTK_CALLBACK_2(TabContentsDragSource, gboolean, OnDragFailed,
50                        GdkDragContext*, GtkDragResult);
51   CHROMEGTK_CALLBACK_1(TabContentsDragSource, void, OnDragBegin,
52                        GdkDragContext*);
53   CHROMEGTK_CALLBACK_1(TabContentsDragSource, void, OnDragEnd,
54                        GdkDragContext*);
55   CHROMEGTK_CALLBACK_4(TabContentsDragSource, void, OnDragDataGet,
56                        GdkDragContext*, GtkSelectionData*, guint, guint);
57   CHROMEGTK_CALLBACK_1(TabContentsDragSource, gboolean, OnDragIconExpose,
58                        GdkEventExpose*);
59 
60   gfx::NativeView GetContentNativeView() const;
61 
62   // The view we're manging the drag for.
63   TabContentsView* tab_contents_view_;
64 
65   // The drop data for the current drag (for drags that originate in the render
66   // view). Non-NULL iff there is a current drag.
67   scoped_ptr<WebDropData> drop_data_;
68 
69   // The image used for depicting the drag, and the offset between the cursor
70   // and the top left pixel.
71   GdkPixbuf* drag_pixbuf_;
72   gfx::Point image_offset_;
73 
74   // The mime type for the file contents of the current drag (if any).
75   GdkAtom drag_file_mime_type_;
76 
77   // Whether the current drag has failed. Meaningless if we are not the source
78   // for a current drag.
79   bool drag_failed_;
80 
81   // This is the widget we use to initiate drags. Since we don't use the
82   // renderer widget, we can persist drags even when our contents is switched
83   // out. We can't use an OwnedWidgetGtk because the GtkInvisible widget
84   // initialization code sinks the reference.
85   GtkWidget* drag_widget_;
86 
87   // Context created once drag starts.  A NULL value indicates that there is
88   // no drag currently in progress.
89   GdkDragContext* drag_context_;
90 
91   // The file mime type for a drag-out download.
92   string16 wide_download_mime_type_;
93 
94   // The file name to be saved to for a drag-out download.
95   FilePath download_file_name_;
96 
97   // The URL to download from for a drag-out download.
98   GURL download_url_;
99 
100   // The widget that provides visual feedback for the drag. We can't use
101   // an OwnedWidgetGtk because the GtkWindow initialization code sinks
102   // the reference.
103   GtkWidget* drag_icon_;
104 
105   ui::GtkSignalRegistrar signals_;
106 
107   DISALLOW_COPY_AND_ASSIGN(TabContentsDragSource);
108 };
109 
110 #endif  // CHROME_BROWSER_UI_GTK_TAB_CONTENTS_DRAG_SOURCE_H_
111