Another take on menu's. This uses the hosting menu scroll view container as a menuba...
[chromium-blink-merge.git] / app / gtk_dnd_util.h
blob79ae2a5161f236eabb24110d7c962305963f3b4c
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_
7 #pragma once
9 #include <gtk/gtk.h>
11 #include <vector>
13 #include "base/string16.h"
14 #include "third_party/WebKit/WebKit/chromium/public/WebDragOperation.h"
16 class GURL;
18 namespace gtk_dnd_util {
20 // Registry of all internal int codes for drag and drop.
21 enum {
22 // Intra-application types.
23 CHROME_TAB = 1 << 0,
24 CHROME_BOOKMARK_ITEM = 1 << 1,
25 CHROME_WEBDROP_FILE_CONTENTS = 1 << 2,
26 CHROME_NAMED_URL = 1 << 3,
28 // Standard types.
29 TEXT_PLAIN = 1 << 4,
30 TEXT_URI_LIST = 1 << 5,
31 TEXT_HTML = 1 << 6,
33 // Other types. NETSCAPE_URL is provided for compatibility with other
34 // apps.
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
51 // needed.
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,
67 const GURL& url,
68 const string16& title,
69 int type);
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,
75 GURL* url,
76 string16* title);
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
83 // equivalent.
84 GdkDragAction WebDragOpToGdkDragAction(WebKit::WebDragOperationsMask op);
85 WebKit::WebDragOperationsMask GdkDragActionToWebDragOp(GdkDragAction action);
87 } // namespace gtk_dnd_util
89 #endif // APP_GTK_DND_UTIL_H_