OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 #include "chrome/browser/ui/bookmarks/bookmark_drag_drop.h" | 5 #include "chrome/browser/ui/bookmarks/bookmark_drag_drop.h" |
6 | 6 |
7 #include "chrome/browser/ui/gtk/bookmarks/bookmark_drag.h" | 7 #include <vector> |
| 8 |
| 9 #include "base/compiler_specific.h" |
| 10 #include "chrome/browser/ui/gtk/bookmarks/bookmark_utils_gtk.h" |
| 11 #include "chrome/browser/ui/gtk/custom_drag.h" |
| 12 |
| 13 namespace { |
| 14 |
| 15 const GdkDragAction kBookmarkDragAction = |
| 16 static_cast<GdkDragAction>(GDK_ACTION_COPY | GDK_ACTION_MOVE); |
| 17 |
| 18 // Encapsulates functionality for drags of one or more bookmarks. |
| 19 class BookmarkDrag : public CustomDrag { |
| 20 public: |
| 21 BookmarkDrag(Profile* profile, const std::vector<const BookmarkNode*>& nodes); |
| 22 |
| 23 private: |
| 24 virtual ~BookmarkDrag() {} |
| 25 |
| 26 virtual void OnDragDataGet(GtkWidget* widget, |
| 27 GdkDragContext* context, |
| 28 GtkSelectionData* selection_data, |
| 29 guint target_type, |
| 30 guint time) OVERRIDE { |
| 31 WriteBookmarksToSelection(nodes_, selection_data, target_type, profile_); |
| 32 } |
| 33 |
| 34 Profile* profile_; |
| 35 std::vector<const BookmarkNode*> nodes_; |
| 36 |
| 37 DISALLOW_COPY_AND_ASSIGN(BookmarkDrag); |
| 38 }; |
| 39 |
| 40 BookmarkDrag::BookmarkDrag(Profile* profile, |
| 41 const std::vector<const BookmarkNode*>& nodes) |
| 42 : CustomDrag(NULL, GetCodeMask(false), kBookmarkDragAction), |
| 43 profile_(profile), |
| 44 nodes_(nodes) {} |
| 45 |
| 46 } // namespace |
8 | 47 |
9 namespace chrome { | 48 namespace chrome { |
10 | 49 |
11 void DragBookmarks(Profile* profile, | 50 void DragBookmarks(Profile* profile, |
12 const std::vector<const BookmarkNode*>& nodes, | 51 const std::vector<const BookmarkNode*>& nodes, |
13 gfx::NativeView view) { | 52 gfx::NativeView view) { |
14 DCHECK(!nodes.empty()); | 53 DCHECK(!nodes.empty()); |
15 | 54 |
16 BookmarkDrag::BeginDrag(profile, nodes); | 55 // This starts the drag process, the lifetime of this object is tied to the |
| 56 // system drag. |
| 57 new BookmarkDrag(profile, nodes); |
17 } | 58 } |
18 | 59 |
19 } // namespace chrome | 60 } // namespace chrome |
OLD | NEW |