Home | History | Annotate | Download | only in bookmarks
      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 CHROME_BROWSER_UI_GTK_BOOKMARKS_BOOKMARK_UTILS_GTK_H_
      6 #define CHROME_BROWSER_UI_GTK_BOOKMARKS_BOOKMARK_UTILS_GTK_H_
      7 #pragma once
      8 
      9 #include <string>
     10 #include <vector>
     11 
     12 #include "base/string16.h"
     13 #include "ui/base/gtk/gtk_integers.h"
     14 
     15 class BookmarkModel;
     16 class BookmarkNode;
     17 class GtkThemeService;
     18 class Profile;
     19 
     20 typedef struct _GdkDragContext GdkDragContext;
     21 typedef struct _GdkPixbuf GdkPixbuf;
     22 typedef struct _GtkSelectionData GtkSelectionData;
     23 typedef struct _GtkWidget GtkWidget;
     24 
     25 namespace bookmark_utils {
     26 
     27 extern const char kBookmarkNode[];
     28 
     29 // Get the image that is used to represent the node. This function adds a ref
     30 // to the returned pixbuf, so it requires a matching call to g_object_unref().
     31 GdkPixbuf* GetPixbufForNode(const BookmarkNode* node, BookmarkModel* model,
     32                             bool native);
     33 
     34 // Returns a GtkWindow with a visual hierarchy for passing to
     35 // gtk_drag_set_icon_widget().
     36 GtkWidget* GetDragRepresentation(GdkPixbuf* pixbuf,
     37                                  const string16& title,
     38                                  GtkThemeService* provider);
     39 GtkWidget* GetDragRepresentationForNode(const BookmarkNode* node,
     40                                         BookmarkModel* model,
     41                                         GtkThemeService* provider);
     42 
     43 // Helper function that sets visual properties of GtkButton |button| to the
     44 // contents of |node|.
     45 void ConfigureButtonForNode(const BookmarkNode* node, BookmarkModel* model,
     46                             GtkWidget* button, GtkThemeService* provider);
     47 
     48 // Returns the tooltip.
     49 std::string BuildTooltipFor(const BookmarkNode* node);
     50 
     51 // Returns the "bookmark-node" property of |widget| casted to the correct type.
     52 const BookmarkNode* BookmarkNodeForWidget(GtkWidget* widget);
     53 
     54 // Set the colors on |label| as per the theme.
     55 void SetButtonTextColors(GtkWidget* label, GtkThemeService* provider);
     56 
     57 // Drag and drop. --------------------------------------------------------------
     58 
     59 // Get the DnD target mask for a bookmark drag. This will vary based on whether
     60 // the node in question is a folder.
     61 int GetCodeMask(bool folder);
     62 
     63 // Pickle a node into a GtkSelection.
     64 void WriteBookmarkToSelection(const BookmarkNode* node,
     65                               GtkSelectionData* selection_data,
     66                               guint target_type,
     67                               Profile* profile);
     68 
     69 // Pickle a vector of nodes into a GtkSelection.
     70 void WriteBookmarksToSelection(const std::vector<const BookmarkNode*>& nodes,
     71                                GtkSelectionData* selection_data,
     72                                guint target_type,
     73                                Profile* profile);
     74 
     75 // Un-pickle node(s) from a GtkSelection.
     76 // The last two arguments are out parameters.
     77 std::vector<const BookmarkNode*> GetNodesFromSelection(
     78     GdkDragContext* context,
     79     GtkSelectionData* selection_data,
     80     guint target_type,
     81     Profile* profile,
     82     gboolean* delete_selection_data,
     83     gboolean* dnd_success);
     84 
     85 // Unpickle a new bookmark of the CHROME_NAMED_URL drag type, and put it in
     86 // the appropriate location in the model.
     87 bool CreateNewBookmarkFromNamedUrl(
     88     GtkSelectionData* selection_data,
     89     BookmarkModel* model,
     90     const BookmarkNode* parent,
     91     int idx);
     92 
     93 // Add the URIs in |selection_data| into the model at the given position. They
     94 // will be added whether or not the URL is valid.
     95 bool CreateNewBookmarksFromURIList(
     96     GtkSelectionData* selection_data,
     97     BookmarkModel* model,
     98     const BookmarkNode* parent,
     99     int idx);
    100 
    101 // Add the "url\ntitle" combination into the model at the given position.
    102 bool CreateNewBookmarkFromNetscapeURL(
    103     GtkSelectionData* selection_data,
    104     BookmarkModel* model,
    105     const BookmarkNode* parent,
    106     int idx);
    107 
    108 }  // namespace bookmark_utils
    109 
    110 #endif  // CHROME_BROWSER_UI_GTK_BOOKMARKS_BOOKMARK_UTILS_GTK_H_
    111