1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
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_
|