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