summaryrefslogtreecommitdiffstats
path: root/views/widget/drop_target_gtk.h
diff options
context:
space:
mode:
Diffstat (limited to 'views/widget/drop_target_gtk.h')
-rw-r--r--views/widget/drop_target_gtk.h113
1 files changed, 113 insertions, 0 deletions
diff --git a/views/widget/drop_target_gtk.h b/views/widget/drop_target_gtk.h
new file mode 100644
index 0000000..b4a5c56
--- /dev/null
+++ b/views/widget/drop_target_gtk.h
@@ -0,0 +1,113 @@
+// 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 VIEWS_WIDGET_DROP_TARGET_GTK_H_
+#define VIEWS_WIDGET_DROP_TARGET_GTK_H_
+
+#include <gtk/gtk.h>
+#include <set>
+
+#include "app/os_exchange_data.h"
+#include "base/scoped_ptr.h"
+#include "views/widget/drop_helper.h"
+
+class OSExchangeDataProviderGtk;
+
+namespace views {
+
+class RootView;
+class View;
+
+// DropTarget implementation for Gtk.
+//
+// The data for a drop is not immediately available on X. As such we lazily
+// ask for data as necessary. Some Views require data before they can determine
+// if the drop is going to be allowed. When such a View is encountered the
+// relevant data is requested from the drag source. When the data is available
+// the target is notified. Similarly if the drop completes and the data has
+// not yet been fetched, it is fetched and the target then notified.
+//
+// When a drop finishes this class calls back to the containing WidgetGtk
+// which results in deleting the DropTargetGtk.
+class DropTargetGtk {
+ public:
+ explicit DropTargetGtk(RootView* root_view,
+ GdkDragContext* context);
+ ~DropTargetGtk();
+
+ // If a drag and drop is underway and |view| is the current drop target, the
+ // drop target is set to null.
+ // This is invoked when a View is removed from the RootView to make sure
+ // we don't target a view that was removed during dnd.
+ void ResetTargetViewIfEquals(View* view);
+
+ // Drop methods from Gtk. These are forwarded from the containing WidgetGtk.
+ void OnDragDataReceived(GdkDragContext* context,
+ gint x,
+ gint y,
+ GtkSelectionData* data,
+ guint info,
+ guint time);
+ gboolean OnDragDrop(GdkDragContext* context,
+ gint x,
+ gint y,
+ guint time);
+ void OnDragLeave(GdkDragContext* context, guint time);
+ gboolean OnDragMotion(GdkDragContext* context,
+ gint x,
+ gint y,
+ guint time);
+
+ private:
+ // Invoked when the drop finishes AND all the data is available.
+ void FinishDrop(GdkDragContext* context, gint x, gint y, guint time);
+
+ // Returns in |f2| and |cf2| the intersection of |f1| |f2| and
+ // |cf1|, |cf2|.
+ void IntersectFormats(int f1, const std::set<GdkAtom>& cf1,
+ int* f2, std::set<GdkAtom>* cf2);
+
+ // Requests the formats in |formats| and the custom formats in
+ // |custom_formats|.
+ void RequestFormats(GdkDragContext* context,
+ int formats,
+ const std::set<GdkAtom>& custom_formats,
+ guint time);
+
+ // Reutrns the Provider of the OSExchangeData we created.
+ OSExchangeDataProviderGtk& data_provider() const;
+
+ // Manages sending the appropriate drop methods to the view the drop is over.
+ DropHelper helper_;
+
+ // The formats we've requested from the drag source.
+ //
+ // NOTE: these formats are the intersection of the formats requested by the
+ // drop target and the formats provided by the source.
+ int requested_formats_;
+ std::set<GdkAtom> requested_custom_formats_;
+
+ // The data.
+ scoped_ptr<OSExchangeData> data_;
+
+ // Are we waiting for data from the source before we can notify the view?
+ // This is set in two distinct ways: when the view requires the data before
+ // it can answer Can Drop (that is, AreDropTypesRequired returns true) and
+ // when the user dropped the data but we didn't get it all yet.
+ bool waiting_for_data_;
+
+ // Has OnDragDrop been invoked?
+ bool received_drop_;
+
+ // The view under the mouse. This is not necessarily the same as
+ // helper_.target_view(). The two differ if the view under the mouse requires
+ // the data.
+ View* pending_view_;
+
+ DISALLOW_COPY_AND_ASSIGN(DropTargetGtk);
+};
+
+} // namespace views
+
+#endif // VIEWS_WIDGET_DROP_TARGET_GTK_H_