Home | History | Annotate | Download | only in dragdrop
      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_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   INVALID_TARGET = 1 << 11,
     44 };
     45 
     46 // 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.
     48 UI_EXPORT GdkAtom GetAtomForTarget(int target);
     49 
     50 // 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
     52 // is responsible for calling gtk_target_list_unref() when it is no longer
     53 // needed.
     54 // 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
     56 // of the client code to do the right thing.
     57 UI_EXPORT GtkTargetList* GetTargetListFromCodeMask(int code_mask);
     58 
     59 // Set the drag target list for |source| with the target list that
     60 // corresponds to |code_mask|.
     61 UI_EXPORT void SetSourceTargetListFromCodeMask(GtkWidget* source,
     62                                                int code_mask);
     63 
     64 // Set the accepted targets list for |dest|. The |target_codes| array should
     65 // be sorted in preference order and should be terminated with -1.
     66 UI_EXPORT void SetDestTargetList(GtkWidget* dest, const int* target_codes);
     67 
     68 // Write a URL to the selection in the given type.
     69 UI_EXPORT void WriteURLWithName(GtkSelectionData* selection_data,
     70                                 const GURL& url,
     71                                 base::string16 title,
     72                                 int type);
     73 
     74 // Extracts data of type CHROME_NAMED_URL from |selection_data| into
     75 // |url| and |title|. Returns true if the url/title were safely extracted
     76 // and the url is valid.
     77 UI_EXPORT bool ExtractNamedURL(GtkSelectionData* selection_data,
     78                                GURL* url,
     79                                base::string16* title);
     80 
     81 // Extracts data of type TEXT_URI_LIST from |selection_data| into |urls|.
     82 UI_EXPORT bool ExtractURIList(GtkSelectionData* selection_data,
     83                               std::vector<GURL>* urls);
     84 
     85 // Extracts a Netscape URL (url\ntitle) from |selection_data|.
     86 UI_EXPORT bool ExtractNetscapeURL(GtkSelectionData* selection_data,
     87                                   GURL* url,
     88                                   base::string16* title);
     89 
     90 }  // namespace ui
     91 
     92 #endif  // UI_BASE_DRAGDROP_GTK_DND_UTIL_H_
     93