- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / gtk / bookmarks / bookmark_drag_drop_gtk.cc
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/bookmarks/bookmark_drag_drop.h"
6
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
47
48 namespace chrome {
49
50 void DragBookmarks(Profile* profile,
51                    const std::vector<const BookmarkNode*>& nodes,
52                    gfx::NativeView view) {
53   DCHECK(!nodes.empty());
54
55   // This starts the drag process, the lifetime of this object is tied to the
56   // system drag.
57   new BookmarkDrag(profile, nodes);
58 }
59
60 }  // namespace chrome