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