1// Copyright (c) 2012 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 8#include <string> 9#include <vector> 10 11#include "base/strings/string16.h" 12#include "ui/base/glib/glib_integers.h" 13 14class BookmarkModel; 15class BookmarkNode; 16class GtkThemeService; 17class GURL; 18class Profile; 19 20typedef struct _GdkDragContext GdkDragContext; 21typedef struct _GdkPixbuf GdkPixbuf; 22typedef struct _GtkSelectionData GtkSelectionData; 23typedef struct _GtkWidget GtkWidget; 24 25namespace bookmark_utils { 26 27extern 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(). 31GdkPixbuf* 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(). 36GtkWidget* GetDragRepresentation(GdkPixbuf* pixbuf, 37 const string16& title, 38 GtkThemeService* provider); 39GtkWidget* 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|. 45void ConfigureButtonForNode(const BookmarkNode* node, BookmarkModel* model, 46 GtkWidget* button, GtkThemeService* provider); 47 48// Helper function to set the visual properties for the apps page shortcut 49// |button|. 50void ConfigureAppsShortcutButton(GtkWidget* button, GtkThemeService* provider); 51 52// Returns the tooltip. 53std::string BuildTooltipFor(const BookmarkNode* node); 54 55// Returns the label that should be in pull down menus. 56std::string BuildMenuLabelFor(const BookmarkNode* node); 57 58// Returns the "bookmark-node" property of |widget| casted to the correct type. 59const BookmarkNode* BookmarkNodeForWidget(GtkWidget* widget); 60 61// Set the colors on |label| as per the theme. 62void SetButtonTextColors(GtkWidget* label, GtkThemeService* provider); 63 64// Drag and drop. -------------------------------------------------------------- 65 66// Get the DnD target mask for a bookmark drag. This will vary based on whether 67// the node in question is a folder. 68int GetCodeMask(bool folder); 69 70// Pickle a node into a GtkSelection. 71void WriteBookmarkToSelection(const BookmarkNode* node, 72 GtkSelectionData* selection_data, 73 guint target_type, 74 Profile* profile); 75 76// Pickle a vector of nodes into a GtkSelection. 77void WriteBookmarksToSelection(const std::vector<const BookmarkNode*>& nodes, 78 GtkSelectionData* selection_data, 79 guint target_type, 80 Profile* profile); 81 82// Un-pickle node(s) from a GtkSelection. 83// The last two arguments are out parameters. 84std::vector<const BookmarkNode*> GetNodesFromSelection( 85 GdkDragContext* context, 86 GtkSelectionData* selection_data, 87 guint target_type, 88 Profile* profile, 89 gboolean* delete_selection_data, 90 gboolean* dnd_success); 91 92// Unpickle a new bookmark of the CHROME_NAMED_URL drag type, and put it in 93// the appropriate location in the model. 94bool CreateNewBookmarkFromNamedUrl( 95 GtkSelectionData* selection_data, 96 BookmarkModel* model, 97 const BookmarkNode* parent, 98 int idx); 99 100// Add the URIs in |selection_data| into the model at the given position. They 101// will be added whether or not the URL is valid. 102bool CreateNewBookmarksFromURIList( 103 GtkSelectionData* selection_data, 104 BookmarkModel* model, 105 const BookmarkNode* parent, 106 int idx); 107 108// Add the "url\ntitle" combination into the model at the given position. 109bool CreateNewBookmarkFromNetscapeURL( 110 GtkSelectionData* selection_data, 111 BookmarkModel* model, 112 const BookmarkNode* parent, 113 int idx); 114 115// Returns a name for the given URL. Used for drags into bookmark areas when 116// the source doesn't specify a title. 117string16 GetNameForURL(const GURL& url); 118 119} // namespace bookmark_utils 120 121#endif // CHROME_BROWSER_UI_GTK_BOOKMARKS_BOOKMARK_UTILS_GTK_H_ 122