Upstream version 7.35.144.0
[platform/framework/web/crosswalk.git] / src / ui / base / dragdrop / gtk_dnd_util.h
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_BASE_DRAGDROP_GTK_DND_UTIL_H_
6 #define UI_BASE_DRAGDROP_GTK_DND_UTIL_H_
7
8 #include <gtk/gtk.h>
9
10 #include <vector>
11
12 #include "base/strings/string16.h"
13 #include "ui/base/ui_base_export.h"
14
15 class GURL;
16
17 namespace ui {
18
19 // Registry of all internal int codes for drag and drop.
20 enum {
21   // Intra-application types.
22   CHROME_TAB = 1 << 0,
23   CHROME_BOOKMARK_ITEM = 1 << 1,
24   CHROME_WEBDROP_FILE_CONTENTS = 1 << 2,
25   CHROME_NAMED_URL = 1 << 3,
26
27   // Standard types.
28   TEXT_PLAIN = 1 << 4,
29   TEXT_URI_LIST = 1 << 5,
30   TEXT_HTML = 1 << 6,
31
32   // Other types.  NETSCAPE_URL is provided for compatibility with other
33   // apps.
34   NETSCAPE_URL = 1 << 7,
35
36   // Used for drag-out download.
37   TEXT_PLAIN_NO_CHARSET = 1 << 8,
38   DIRECT_SAVE_FILE = 1 << 9,
39
40   // Custom data for web drag/drop.
41   CUSTOM_DATA = 1 << 10,
42
43   // Tracks if the drag originated from the renderer.
44   RENDERER_TAINT = 1 << 11,
45
46   INVALID_TARGET = 1 << 12,
47 };
48
49 // Get the atom for a given target (of the above enum type). Will return NULL
50 // for non-custom targets, such as CHROME_TEXT_PLAIN.
51 UI_BASE_EXPORT GdkAtom GetAtomForTarget(int target);
52
53 // Creates a target list from the given mask. The mask should be an OR of
54 // CHROME_* values. The target list is returned with ref count 1; the caller
55 // is responsible for calling gtk_target_list_unref() when it is no longer
56 // needed.
57 // Since the MIME type for WEBDROP_FILE_CONTENTS depends on the file's
58 // contents, that flag is ignored by this function. It is the responsibility
59 // of the client code to do the right thing.
60 UI_BASE_EXPORT GtkTargetList* GetTargetListFromCodeMask(int code_mask);
61
62 // Set the drag target list for |source| with the target list that
63 // corresponds to |code_mask|.
64 UI_BASE_EXPORT void SetSourceTargetListFromCodeMask(GtkWidget* source,
65                                                     int code_mask);
66
67 // Set the accepted targets list for |dest|. The |target_codes| array should
68 // be sorted in preference order and should be terminated with -1.
69 UI_BASE_EXPORT void SetDestTargetList(GtkWidget* dest, const int* target_codes);
70
71 // Write a URL to the selection in the given type.
72 UI_BASE_EXPORT void WriteURLWithName(GtkSelectionData* selection_data,
73                                      const GURL& url,
74                                      base::string16 title,
75                                      int type);
76
77 // Extracts data of type CHROME_NAMED_URL from |selection_data| into
78 // |url| and |title|. Returns true if the url/title were safely extracted
79 // and the url is valid.
80 UI_BASE_EXPORT bool ExtractNamedURL(GtkSelectionData* selection_data,
81                                     GURL* url,
82                                     base::string16* title);
83
84 // Extracts data of type TEXT_URI_LIST from |selection_data| into |urls|.
85 UI_BASE_EXPORT bool ExtractURIList(GtkSelectionData* selection_data,
86                                    std::vector<GURL>* urls);
87
88 // Extracts a Netscape URL (url\ntitle) from |selection_data|.
89 UI_BASE_EXPORT bool ExtractNetscapeURL(GtkSelectionData* selection_data,
90                                        GURL* url,
91                                        base::string16* title);
92
93 }  // namespace ui
94
95 #endif  // UI_BASE_DRAGDROP_GTK_DND_UTIL_H_