1 // Copyright (c) 2009 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 APP_GTK_DND_UTIL_H_
6 #define APP_GTK_DND_UTIL_H_
13 #include "base/string16.h"
14 #include "third_party/WebKit/WebKit/chromium/public/WebDragOperation.h"
18 namespace gtk_dnd_util
{
20 // Registry of all internal int codes for drag and drop.
22 // Intra-application types.
24 CHROME_BOOKMARK_ITEM
= 1 << 1,
25 CHROME_WEBDROP_FILE_CONTENTS
= 1 << 2,
26 CHROME_NAMED_URL
= 1 << 3,
30 TEXT_URI_LIST
= 1 << 5,
33 // Other types. NETSCAPE_URL is provided for compatibility with other
35 NETSCAPE_URL
= 1 << 7,
37 // Used for drag-out download.
38 TEXT_PLAIN_NO_CHARSET
= 1 << 8,
39 DIRECT_SAVE_FILE
= 1 << 9,
41 INVALID_TARGET
= 1 << 10,
44 // Get the atom for a given target (of the above enum type). Will return NULL
45 // for non-custom targets, such as CHROME_TEXT_PLAIN.
46 GdkAtom
GetAtomForTarget(int target
);
48 // Creates a target list from the given mask. The mask should be an OR of
49 // CHROME_* values. The target list is returned with ref count 1; the caller
50 // is responsible for calling gtk_target_list_unref() when it is no longer
52 // Since the MIME type for WEBDROP_FILE_CONTENTS depends on the file's
53 // contents, that flag is ignored by this function. It is the responsibility
54 // of the client code to do the right thing.
55 GtkTargetList
* GetTargetListFromCodeMask(int code_mask
);
57 // Set the drag target list for |source| with the target list that
58 // corresponds to |code_mask|.
59 void SetSourceTargetListFromCodeMask(GtkWidget
* source
, int code_mask
);
61 // Set the accepted targets list for |dest|. The |target_codes| array should
62 // be sorted in preference order and should be terminated with -1.
63 void SetDestTargetList(GtkWidget
* dest
, const int* target_codes
);
65 // Write a URL to the selection in the given type.
66 void WriteURLWithName(GtkSelectionData
* selection_data
,
68 const string16
& title
,
71 // Extracts data of type CHROME_NAMED_URL from |selection_data| into
72 // |url| and |title|. Returns true if the url/title were safely extracted
73 // and the url is valid.
74 bool ExtractNamedURL(GtkSelectionData
* selection_data
,
78 // Extracts data of type TEXT_URI_LIST from |selection_data| into |urls|.
79 bool ExtractURIList(GtkSelectionData
* selection_data
,
80 std::vector
<GURL
>* urls
);
82 // Convenience methods for converting between web drag operations and the GDK
84 GdkDragAction
WebDragOpToGdkDragAction(WebKit::WebDragOperationsMask op
);
85 WebKit::WebDragOperationsMask
GdkDragActionToWebDragOp(GdkDragAction action
);
87 } // namespace gtk_dnd_util
89 #endif // APP_GTK_DND_UTIL_H_