diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-08 21:49:16 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-08 21:49:16 +0000 |
commit | 0d726c521db7f2f456e04223ef71a1c8c28764f1 (patch) | |
tree | 2c6bcde57b5b98ca38bd337ccbea08dc9f9d6f74 /chrome/browser/tab_contents/web_drag_dest_gtk.h | |
parent | 4a99e834fe351c8e81a70ea571d52b3cdde40af1 (diff) | |
download | chromium_src-0d726c521db7f2f456e04223ef71a1c8c28764f1.zip chromium_src-0d726c521db7f2f456e04223ef71a1c8c28764f1.tar.gz chromium_src-0d726c521db7f2f456e04223ef71a1c8c28764f1.tar.bz2 |
Pulls WebDragDest out of TabContentsViewGtk so that it can be used by
both views and gtk.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/265041
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28457 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/tab_contents/web_drag_dest_gtk.h')
-rw-r--r-- | chrome/browser/tab_contents/web_drag_dest_gtk.h | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/chrome/browser/tab_contents/web_drag_dest_gtk.h b/chrome/browser/tab_contents/web_drag_dest_gtk.h new file mode 100644 index 0000000..8bba71e --- /dev/null +++ b/chrome/browser/tab_contents/web_drag_dest_gtk.h @@ -0,0 +1,105 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_TAB_CONTENTS_WEB_DRAG_DEST_GTK_H_ +#define CHROME_BROWSER_TAB_CONTENTS_WEB_DRAG_DEST_GTK_H_ + +#include <gtk/gtk.h> + +#include "base/scoped_ptr.h" +#include "base/task.h" +#include "webkit/api/public/WebDragOperation.h" +#include "webkit/glue/webdropdata.h" + +class TabContents; + +// A helper class that handles DnD for drops in the renderer. In GTK parlance, +// this handles destination-side DnD, but not source-side DnD. +class WebDragDestGtk { + public: + WebDragDestGtk(TabContents* tab_contents, GtkWidget* widget); + ~WebDragDestGtk(); + + // This is called when the renderer responds to a drag motion event. We must + // update the system drag cursor. + void UpdateDragStatus(WebKit::WebDragOperation operation); + + // Informs the renderer when a system drag has left the render view. + // See OnDragLeave(). + void DragLeave(); + + private: + static gboolean OnDragMotionThunk( + GtkWidget* widget, GdkDragContext* drag_context, gint x, gint y, + guint time, WebDragDestGtk* dest) { + return dest->OnDragMotion(drag_context, x, y, time); + } + static void OnDragLeaveThunk( + GtkWidget* widget, GdkDragContext* drag_context, guint time, + WebDragDestGtk* dest) { + dest->OnDragLeave(drag_context, time); + } + static gboolean OnDragDropThunk( + GtkWidget* widget, GdkDragContext* drag_context, gint x, gint y, + guint time, WebDragDestGtk* dest) { + return dest->OnDragDrop(drag_context, x, y, time); + } + static void OnDragDataReceivedThunk( + GtkWidget* widget, GdkDragContext* drag_context, gint x, gint y, + GtkSelectionData* data, guint info, guint time, WebDragDestGtk* dest) { + dest->OnDragDataReceived(drag_context, x, y, data, info, time); + } + + // Called when a system drag crosses over the render view. As there is no drag + // enter event, we treat it as an enter event (and not a regular motion event) + // when |context_| is NULL. + gboolean OnDragMotion(GdkDragContext* context, gint x, gint y, guint time); + + // We make a series of requests for the drag data when the drag first enters + // the render view. This is the callback that is used to give us the data + // for each individual target. When |data_requests_| reaches 0, we know we + // have attained all the data, and we can finally tell the renderer about the + // drag. + void OnDragDataReceived(GdkDragContext* context, gint x, gint y, + GtkSelectionData* data, guint info, guint time); + + // The drag has left our widget; forward this information to the renderer. + void OnDragLeave(GdkDragContext* context, guint time); + + // Called by GTK when the user releases the mouse, executing a drop. + gboolean OnDragDrop(GdkDragContext* context, gint x, gint y, guint time); + + + TabContents* tab_contents_; + // The render view. + GtkWidget* widget_; + // The current drag context for system drags over our render view, or NULL if + // there is no system drag or the system drag is not over our render view. + GdkDragContext* context_; + // The data for the current drag, or NULL if |context_| is NULL. + scoped_ptr<WebDropData> drop_data_; + + // The number of outstanding drag data requests we have sent to the drag + // source. + int data_requests_; + + // The last time we sent a message to the renderer related to a drag motion. + gint drag_over_time_; + + // Whether the cursor is over a drop target, according to the last message we + // got from the renderer. + bool is_drop_target_; + + // Handler ID for the destroy signal handler. We connect to the destroy + // signal handler so that we won't call dest_unset on it after it is + // destroyed, but we have to cancel the handler if we are destroyed before + // |widget_| is. + int destroy_handler_; + + ScopedRunnableMethodFactory<WebDragDestGtk> method_factory_; + + DISALLOW_COPY_AND_ASSIGN(WebDragDestGtk); +}; + +#endif // CHROME_BROWSER_TAB_CONTENTS_WEB_DRAG_DEST_GTK_H_ |