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.
5 #ifndef UI_BASE_DRAGDROP_GTK_DND_UTIL_H_
6 #define UI_BASE_DRAGDROP_GTK_DND_UTIL_H_
12 #include "base/strings/string16.h"
13 #include "ui/base/ui_base_export.h"
19 // Registry of all internal int codes for drag and drop.
21 // Intra-application types.
23 CHROME_BOOKMARK_ITEM = 1 << 1,
24 CHROME_WEBDROP_FILE_CONTENTS = 1 << 2,
25 CHROME_NAMED_URL = 1 << 3,
29 TEXT_URI_LIST = 1 << 5,
32 // Other types. NETSCAPE_URL is provided for compatibility with other
34 NETSCAPE_URL = 1 << 7,
36 // Used for drag-out download.
37 TEXT_PLAIN_NO_CHARSET = 1 << 8,
38 DIRECT_SAVE_FILE = 1 << 9,
40 // Custom data for web drag/drop.
41 CUSTOM_DATA = 1 << 10,
43 // Tracks if the drag originated from the renderer.
44 RENDERER_TAINT = 1 << 11,
46 INVALID_TARGET = 1 << 12,
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);
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
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);
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,
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);
71 // Write a URL to the selection in the given type.
72 UI_BASE_EXPORT void WriteURLWithName(GtkSelectionData* selection_data,
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,
82 base::string16* title);
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);
88 // Extracts a Netscape URL (url\ntitle) from |selection_data|.
89 UI_BASE_EXPORT bool ExtractNetscapeURL(GtkSelectionData* selection_data,
91 base::string16* title);
95 #endif // UI_BASE_DRAGDROP_GTK_DND_UTIL_H_