OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef CHROME_BROWSER_TAB_CONTENTS_WEB_DRAG_DEST_GTK_H_ | 5 #ifndef CHROME_BROWSER_TAB_CONTENTS_WEB_DRAG_DEST_GTK_H_ |
6 #define CHROME_BROWSER_TAB_CONTENTS_WEB_DRAG_DEST_GTK_H_ | 6 #define CHROME_BROWSER_TAB_CONTENTS_WEB_DRAG_DEST_GTK_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <gtk/gtk.h> | 9 #include <gtk/gtk.h> |
10 | 10 |
11 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/task.h" | 13 #include "base/task.h" |
14 #include "chrome/browser/bookmarks/bookmark_node_data.h" | |
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDragOperation.h" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDragOperation.h" |
16 #include "ui/base/gtk/gtk_signal.h" | 15 #include "ui/base/gtk/gtk_signal.h" |
17 #include "webkit/glue/webdropdata.h" | 16 #include "webkit/glue/webdropdata.h" |
18 | 17 |
19 class TabContents; | 18 class TabContents; |
20 class TabContentsWrapper; | 19 class WebDragDestDelegateGtk; |
21 | 20 |
22 // A helper class that handles DnD for drops in the renderer. In GTK parlance, | 21 // A helper class that handles DnD for drops in the renderer. In GTK parlance, |
23 // this handles destination-side DnD, but not source-side DnD. | 22 // this handles destination-side DnD, but not source-side DnD. |
24 class WebDragDestGtk { | 23 class WebDragDestGtk { |
25 public: | 24 public: |
26 WebDragDestGtk(TabContents* tab_contents, GtkWidget* widget); | 25 WebDragDestGtk(TabContents* tab_contents, GtkWidget* widget); |
27 virtual ~WebDragDestGtk(); | 26 virtual ~WebDragDestGtk(); |
28 | 27 |
29 // This is called when the renderer responds to a drag motion event. We must | 28 // This is called when the renderer responds to a drag motion event. We must |
30 // update the system drag cursor. | 29 // update the system drag cursor. |
31 void UpdateDragStatus(WebKit::WebDragOperation operation); | 30 void UpdateDragStatus(WebKit::WebDragOperation operation); |
32 | 31 |
33 // Informs the renderer when a system drag has left the render view. | 32 // Informs the renderer when a system drag has left the render view. |
34 // See OnDragLeave(). | 33 // See OnDragLeave(). |
35 void DragLeave(); | 34 void DragLeave(); |
36 | 35 |
| 36 WebDragDestDelegateGtk* delegate() const { return delegate_; } |
| 37 void set_delegate(WebDragDestDelegateGtk* delegate) { delegate_ = delegate; } |
| 38 |
37 private: | 39 private: |
38 FRIEND_TEST_ALL_PREFIXES(WebDragDestGtkTest, NoTabContentsWrapper); | |
39 | |
40 // Called when a system drag crosses over the render view. As there is no drag | 40 // Called when a system drag crosses over the render view. As there is no drag |
41 // enter event, we treat it as an enter event (and not a regular motion event) | 41 // enter event, we treat it as an enter event (and not a regular motion event) |
42 // when |context_| is NULL. | 42 // when |context_| is NULL. |
43 CHROMEGTK_CALLBACK_4(WebDragDestGtk, gboolean, OnDragMotion, GdkDragContext*, | 43 CHROMEGTK_CALLBACK_4(WebDragDestGtk, gboolean, OnDragMotion, GdkDragContext*, |
44 gint, gint, guint); | 44 gint, gint, guint); |
45 | 45 |
46 // We make a series of requests for the drag data when the drag first enters | 46 // We make a series of requests for the drag data when the drag first enters |
47 // the render view. This is the callback that is used to give us the data | 47 // the render view. This is the callback that is used to give us the data |
48 // for each individual target. When |data_requests_| reaches 0, we know we | 48 // for each individual target. When |data_requests_| reaches 0, we know we |
49 // have attained all the data, and we can finally tell the renderer about the | 49 // have attained all the data, and we can finally tell the renderer about the |
50 // drag. | 50 // drag. |
51 CHROMEGTK_CALLBACK_6(WebDragDestGtk, void, OnDragDataReceived, | 51 CHROMEGTK_CALLBACK_6(WebDragDestGtk, void, OnDragDataReceived, |
52 GdkDragContext*, gint, gint, GtkSelectionData*, | 52 GdkDragContext*, gint, gint, GtkSelectionData*, |
53 guint, guint); | 53 guint, guint); |
54 | 54 |
55 // The drag has left our widget; forward this information to the renderer. | 55 // The drag has left our widget; forward this information to the renderer. |
56 CHROMEGTK_CALLBACK_2(WebDragDestGtk, void, OnDragLeave, GdkDragContext*, | 56 CHROMEGTK_CALLBACK_2(WebDragDestGtk, void, OnDragLeave, GdkDragContext*, |
57 guint); | 57 guint); |
58 | 58 |
59 // Called by GTK when the user releases the mouse, executing a drop. | 59 // Called by GTK when the user releases the mouse, executing a drop. |
60 CHROMEGTK_CALLBACK_4(WebDragDestGtk, gboolean, OnDragDrop, GdkDragContext*, | 60 CHROMEGTK_CALLBACK_4(WebDragDestGtk, gboolean, OnDragDrop, GdkDragContext*, |
61 gint, gint, guint); | 61 gint, gint, guint); |
62 | 62 |
63 TabContents* tab_contents_; | 63 TabContents* tab_contents_; |
64 | 64 |
65 // The TabContentsWrapper for |tab_contents_|. | |
66 // Weak reference; may be NULL if the contents aren't contained in a wrapper | |
67 // (e.g. WebUI dialogs). | |
68 TabContentsWrapper* tab_; | |
69 | |
70 // The render view. | 65 // The render view. |
71 GtkWidget* widget_; | 66 GtkWidget* widget_; |
72 | 67 |
73 // The current drag context for system drags over our render view, or NULL if | 68 // The current drag context for system drags over our render view, or NULL if |
74 // there is no system drag or the system drag is not over our render view. | 69 // there is no system drag or the system drag is not over our render view. |
75 GdkDragContext* context_; | 70 GdkDragContext* context_; |
76 | 71 |
77 // The data for the current drag, or NULL if |context_| is NULL. | 72 // The data for the current drag, or NULL if |context_| is NULL. |
78 scoped_ptr<WebDropData> drop_data_; | 73 scoped_ptr<WebDropData> drop_data_; |
79 | 74 |
80 // The number of outstanding drag data requests we have sent to the drag | 75 // The number of outstanding drag data requests we have sent to the drag |
81 // source. | 76 // source. |
82 int data_requests_; | 77 int data_requests_; |
83 | 78 |
84 // The last time we sent a message to the renderer related to a drag motion. | 79 // The last time we sent a message to the renderer related to a drag motion. |
85 gint drag_over_time_; | 80 gint drag_over_time_; |
86 | 81 |
87 // Whether the cursor is over a drop target, according to the last message we | 82 // Whether the cursor is over a drop target, according to the last message we |
88 // got from the renderer. | 83 // got from the renderer. |
89 bool is_drop_target_; | 84 bool is_drop_target_; |
90 | 85 |
91 // Handler ID for the destroy signal handler. We connect to the destroy | 86 // Handler ID for the destroy signal handler. We connect to the destroy |
92 // signal handler so that we won't call dest_unset on it after it is | 87 // signal handler so that we won't call dest_unset on it after it is |
93 // destroyed, but we have to cancel the handler if we are destroyed before | 88 // destroyed, but we have to cancel the handler if we are destroyed before |
94 // |widget_| is. | 89 // |widget_| is. |
95 int destroy_handler_; | 90 int destroy_handler_; |
96 | 91 |
97 // The bookmark data for the current tab. This will be empty if there is not | 92 // A delegate that can receive drag information about drag events. |
98 // a native bookmark drag (or we haven't gotten the data from the source yet). | 93 WebDragDestDelegateGtk* delegate_; |
99 BookmarkNodeData bookmark_drag_data_; | |
100 | 94 |
101 ScopedRunnableMethodFactory<WebDragDestGtk> method_factory_; | 95 ScopedRunnableMethodFactory<WebDragDestGtk> method_factory_; |
102 | 96 |
103 DISALLOW_COPY_AND_ASSIGN(WebDragDestGtk); | 97 DISALLOW_COPY_AND_ASSIGN(WebDragDestGtk); |
104 }; | 98 }; |
105 | 99 |
106 #endif // CHROME_BROWSER_TAB_CONTENTS_WEB_DRAG_DEST_GTK_H_ | 100 #endif // CHROME_BROWSER_TAB_CONTENTS_WEB_DRAG_DEST_GTK_H_ |
OLD | NEW |