| OLD | NEW |
| (Empty) |
| 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 UI_VIEWS_WIDGET_DROP_TARGET_GTK_H_ | |
| 6 #define UI_VIEWS_WIDGET_DROP_TARGET_GTK_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <gtk/gtk.h> | |
| 10 #include <set> | |
| 11 | |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "ui/base/dragdrop/os_exchange_data.h" | |
| 14 #include "ui/views/widget/drop_helper.h" | |
| 15 | |
| 16 namespace ui { | |
| 17 class OSExchangeDataProviderGtk; | |
| 18 } | |
| 19 using ui::OSExchangeData; | |
| 20 using ui::OSExchangeDataProviderGtk; | |
| 21 | |
| 22 namespace views { | |
| 23 | |
| 24 class View; | |
| 25 namespace internal { | |
| 26 class RootView; | |
| 27 } | |
| 28 | |
| 29 // DropTarget implementation for Gtk. | |
| 30 // | |
| 31 // The data for a drop is not immediately available on X. As such we lazily | |
| 32 // ask for data as necessary. Some Views require data before they can determine | |
| 33 // if the drop is going to be allowed. When such a View is encountered the | |
| 34 // relevant data is requested from the drag source. When the data is available | |
| 35 // the target is notified. Similarly if the drop completes and the data has | |
| 36 // not yet been fetched, it is fetched and the target then notified. | |
| 37 // | |
| 38 // When a drop finishes this class calls back to the containing NativeWidgetGtk | |
| 39 // which results in deleting the DropTargetGtk. | |
| 40 class DropTargetGtk { | |
| 41 public: | |
| 42 DropTargetGtk(internal::RootView* root_view, GdkDragContext* context); | |
| 43 ~DropTargetGtk(); | |
| 44 | |
| 45 // If a drag and drop is underway and |view| is the current drop target, the | |
| 46 // drop target is set to null. | |
| 47 // This is invoked when a View is removed from the RootView to make sure | |
| 48 // we don't target a view that was removed during dnd. | |
| 49 void ResetTargetViewIfEquals(View* view); | |
| 50 | |
| 51 // Drop methods from Gtk. These are forwarded from the containing | |
| 52 // NativeWidgetGtk. | |
| 53 void OnDragDataReceived(GdkDragContext* context, | |
| 54 gint x, | |
| 55 gint y, | |
| 56 GtkSelectionData* data, | |
| 57 guint info, | |
| 58 guint time); | |
| 59 gboolean OnDragDrop(GdkDragContext* context, | |
| 60 gint x, | |
| 61 gint y, | |
| 62 guint time); | |
| 63 void OnDragLeave(GdkDragContext* context, guint time); | |
| 64 gboolean OnDragMotion(GdkDragContext* context, | |
| 65 gint x, | |
| 66 gint y, | |
| 67 guint time); | |
| 68 | |
| 69 private: | |
| 70 // Invoked when the drop finishes AND all the data is available. | |
| 71 void FinishDrop(GdkDragContext* context, gint x, gint y, guint time); | |
| 72 | |
| 73 // Returns in |f2| and |cf2| the intersection of |f1| |f2| and | |
| 74 // |cf1|, |cf2|. | |
| 75 void IntersectFormats(int f1, const std::set<GdkAtom>& cf1, | |
| 76 int* f2, std::set<GdkAtom>* cf2); | |
| 77 | |
| 78 // Requests the formats in |formats| and the custom formats in | |
| 79 // |custom_formats|. | |
| 80 void RequestFormats(GdkDragContext* context, | |
| 81 int formats, | |
| 82 const std::set<GdkAtom>& custom_formats, | |
| 83 guint time); | |
| 84 | |
| 85 // Reutrns the Provider of the OSExchangeData we created. | |
| 86 OSExchangeDataProviderGtk& data_provider() const; | |
| 87 | |
| 88 // Manages sending the appropriate drop methods to the view the drop is over. | |
| 89 DropHelper helper_; | |
| 90 | |
| 91 // The formats we've requested from the drag source. | |
| 92 // | |
| 93 // NOTE: these formats are the intersection of the formats requested by the | |
| 94 // drop target and the formats provided by the source. | |
| 95 int requested_formats_; | |
| 96 std::set<GdkAtom> requested_custom_formats_; | |
| 97 | |
| 98 // The data. | |
| 99 scoped_ptr<OSExchangeData> data_; | |
| 100 | |
| 101 // Are we waiting for data from the source before we can notify the view? | |
| 102 // This is set in two distinct ways: when the view requires the data before | |
| 103 // it can answer Can Drop (that is, AreDropTypesRequired returns true) and | |
| 104 // when the user dropped the data but we didn't get it all yet. | |
| 105 bool waiting_for_data_; | |
| 106 | |
| 107 // Has OnDragDrop been invoked? | |
| 108 bool received_drop_; | |
| 109 | |
| 110 // The view under the mouse. This is not necessarily the same as | |
| 111 // helper_.target_view(). The two differ if the view under the mouse requires | |
| 112 // the data. | |
| 113 View* pending_view_; | |
| 114 | |
| 115 DISALLOW_COPY_AND_ASSIGN(DropTargetGtk); | |
| 116 }; | |
| 117 | |
| 118 } // namespace views | |
| 119 | |
| 120 #endif // UI_VIEWS_WIDGET_DROP_TARGET_GTK_H_ | |
| OLD | NEW |