Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: chrome/browser/ui/gtk/custom_drag.h

Issue 23646006: gtk: Split CustomDrag into multiple pieces. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixes Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_UI_GTK_CUSTOM_DRAG_H_ 5 #ifndef CHROME_BROWSER_UI_GTK_CUSTOM_DRAG_H_
6 #define CHROME_BROWSER_UI_GTK_CUSTOM_DRAG_H_ 6 #define CHROME_BROWSER_UI_GTK_CUSTOM_DRAG_H_
7 7
8 #include <gtk/gtk.h> 8 #include <gtk/gtk.h>
9 #include <vector>
10 9
11 #include "base/basictypes.h" 10 #include "base/basictypes.h"
12 #include "base/compiler_specific.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "ui/base/gtk/gtk_signal.h" 11 #include "ui/base/gtk/gtk_signal.h"
15 12
16 class BookmarkNode;
17 class Profile;
18
19 namespace content {
20 class DownloadItem;
21 }
22
23 namespace gfx { 13 namespace gfx {
24 class Image; 14 class Image;
25 } 15 }
26 16
27 // Base class for programatically generated drags. 17 // Base class for programatically generated drags.
28 class CustomDrag { 18 class CustomDrag {
29 protected: 19 protected:
30 CustomDrag(gfx::Image* icon, int code_mask, GdkDragAction action); 20 CustomDrag(gfx::Image* icon, int code_mask, GdkDragAction action);
31 virtual ~CustomDrag(); 21 virtual ~CustomDrag();
32 22
33 virtual void OnDragDataGet(GtkWidget* widget, GdkDragContext* context, 23 virtual void OnDragDataGet(GtkWidget* widget,
24 GdkDragContext* context,
34 GtkSelectionData* selection_data, 25 GtkSelectionData* selection_data,
35 guint target_type, guint time) = 0; 26 guint target_type,
27 guint time) = 0;
36 28
37 private: 29 private:
38 CHROMEGTK_CALLBACK_1(CustomDrag, void, OnDragBegin, GdkDragContext*); 30 CHROMEGTK_CALLBACK_1(CustomDrag, void, OnDragBegin, GdkDragContext*);
39 CHROMEGTK_CALLBACK_1(CustomDrag, void, OnDragEnd, GdkDragContext*); 31 CHROMEGTK_CALLBACK_1(CustomDrag, void, OnDragEnd, GdkDragContext*);
40 32
41 // Since this uses a virtual function, we can't use a macro. 33 // Since this uses a virtual function, we can't use a macro.
42 static void OnDragDataGetThunk(GtkWidget* widget, GdkDragContext* context, 34 static void OnDragDataGetThunk(GtkWidget* widget, GdkDragContext* context,
43 GtkSelectionData* selection_data, 35 GtkSelectionData* selection_data,
44 guint target_type, guint time, 36 guint target_type, guint time,
45 CustomDrag* custom_drag) { 37 CustomDrag* custom_drag) {
46 return custom_drag->OnDragDataGet(widget, context, selection_data, 38 return custom_drag->OnDragDataGet(widget, context, selection_data,
47 target_type, time); 39 target_type, time);
48 } 40 }
49 41
50 // Can't use a OwnedWidgetGtk because the initialization of GtkInvisible 42 // Can't use a OwnedWidgetGtk because the initialization of GtkInvisible
51 // sinks the reference. 43 // sinks the reference.
52 GtkWidget* drag_widget_; 44 GtkWidget* drag_widget_;
53 45
54 // The image for the drag. The lifetime of the image should be managed outside 46 // The image for the drag. The lifetime of the image should be managed outside
55 // this object. Most icons are owned by the IconManager. 47 // this object. Most icons are owned by the IconManager.
56 gfx::Image* image_; 48 gfx::Image* image_;
57 49
58 DISALLOW_COPY_AND_ASSIGN(CustomDrag); 50 DISALLOW_COPY_AND_ASSIGN(CustomDrag);
59 }; 51 };
60 52
61 // Encapsulates functionality for drags of download items.
62 class DownloadItemDrag : public CustomDrag {
63 public:
64 // Sets |widget| as a source for drags pertaining to |item|. No
65 // DownloadItemDrag object is created.
66 // It is safe to call this multiple times with different values of |icon|.
67 static void SetSource(GtkWidget* widget,
68 const content::DownloadItem* item,
69 gfx::Image* icon);
70
71 // Creates a new DownloadItemDrag, the lifetime of which is tied to the
72 // system drag.
73 static void BeginDrag(const content::DownloadItem* item, gfx::Image* icon);
74
75 private:
76 class DragData;
77
78 DownloadItemDrag(const content::DownloadItem* item, gfx::Image* icon);
79 virtual ~DownloadItemDrag();
80
81 virtual void OnDragDataGet(GtkWidget* widget, GdkDragContext* context,
82 GtkSelectionData* selection_data,
83 guint target_type, guint time) OVERRIDE;
84
85 scoped_ptr<DragData> drag_data_;
86
87 DISALLOW_COPY_AND_ASSIGN(DownloadItemDrag);
88 };
89
90 // Encapsulates functionality for drags of one or more bookmarks.
91 class BookmarkDrag : public CustomDrag {
92 public:
93 // Creates a new BookmarkDrag, the lifetime of which is tied to the
94 // system drag.
95 static void BeginDrag(Profile* profile,
96 const std::vector<const BookmarkNode*>& nodes);
97
98 private:
99 BookmarkDrag(Profile* profile,
100 const std::vector<const BookmarkNode*>& nodes);
101 virtual ~BookmarkDrag();
102
103 virtual void OnDragDataGet(GtkWidget* widget, GdkDragContext* context,
104 GtkSelectionData* selection_data,
105 guint target_type, guint time) OVERRIDE;
106
107 Profile* profile_;
108 std::vector<const BookmarkNode*> nodes_;
109
110 DISALLOW_COPY_AND_ASSIGN(BookmarkDrag);
111 };
112
113 #endif // CHROME_BROWSER_UI_GTK_CUSTOM_DRAG_H_ 53 #endif // CHROME_BROWSER_UI_GTK_CUSTOM_DRAG_H_
OLDNEW
« no previous file with comments | « chrome/browser/ui/gtk/bookmarks/bookmark_drag_drop_gtk.cc ('k') | chrome/browser/ui/gtk/custom_drag.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698