Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Side by Side Diff: chrome/browser/gtk/bookmark_utils_gtk.cc

Issue 165194: GTK: Use stock icons for bookmark folder and default favicon.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/gtk/bookmark_utils_gtk.h ('k') | chrome/browser/gtk/list_store_favicon_loader.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/gtk/bookmark_utils_gtk.h" 5 #include "chrome/browser/gtk/bookmark_utils_gtk.h"
6 6
7 #include "app/resource_bundle.h" 7 #include "app/resource_bundle.h"
8 #include "base/gfx/gtk_util.h" 8 #include "base/gfx/gtk_util.h"
9 #include "base/pickle.h" 9 #include "base/pickle.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 27 matching lines...) Expand all
38 // to give the bookmark bar more space (at the expense of the toolbar). 38 // to give the bookmark bar more space (at the expense of the toolbar).
39 const int kButtonPaddingTop = 0; 39 const int kButtonPaddingTop = 0;
40 const int kButtonPaddingBottom = 0; 40 const int kButtonPaddingBottom = 0;
41 const int kButtonPaddingLeft = 2; 41 const int kButtonPaddingLeft = 2;
42 const int kButtonPaddingRight = 0; 42 const int kButtonPaddingRight = 0;
43 43
44 void* AsVoid(const BookmarkNode* node) { 44 void* AsVoid(const BookmarkNode* node) {
45 return const_cast<BookmarkNode*>(node); 45 return const_cast<BookmarkNode*>(node);
46 } 46 }
47 47
48 // This is a dummy widget that only exists so we have something to pass to
49 // gtk_widget_render_icon().
50 GtkWidget* icon_widget = NULL;
51
48 } // namespace 52 } // namespace
49 53
50 namespace bookmark_utils { 54 namespace bookmark_utils {
51 55
52 const char kBookmarkNode[] = "bookmark-node"; 56 const char kBookmarkNode[] = "bookmark-node";
53 57
54 // Spacing between the buttons on the bar. 58 // Spacing between the buttons on the bar.
55 const int kBarButtonPadding = 4; 59 const int kBarButtonPadding = 4;
56 60
57 GdkPixbuf* GetFolderIcon() { 61 GdkPixbuf* GetFolderIcon(bool native) {
58 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 62 if (!native) {
59 static GdkPixbuf* default_folder_icon = rb.GetPixbufNamed( 63 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
60 IDR_BOOKMARK_BAR_FOLDER); 64 static GdkPixbuf* default_folder_icon = rb.GetPixbufNamed(
61 return default_folder_icon; 65 IDR_BOOKMARK_BAR_FOLDER);
66 return default_folder_icon;
67 } else {
68 if (!icon_widget)
69 icon_widget = gtk_fixed_new();
70 // We never release our ref, so we will leak this on program shutdown.
71 static GdkPixbuf* default_folder_icon =
72 gtk_widget_render_icon(icon_widget, GTK_STOCK_DIRECTORY,
73 GTK_ICON_SIZE_MENU, NULL);
74 return default_folder_icon;
75 }
62 } 76 }
63 77
64 GdkPixbuf* GetDefaultFavicon() { 78 GdkPixbuf* GetDefaultFavicon(bool native) {
65 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 79 if (!native) {
66 static GdkPixbuf* default_bookmark_icon = rb.GetPixbufNamed( 80 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
67 IDR_DEFAULT_FAVICON); 81 static GdkPixbuf* default_bookmark_icon = rb.GetPixbufNamed(
68 return default_bookmark_icon; 82 IDR_DEFAULT_FAVICON);
83 return default_bookmark_icon;
84 } else {
85 if (!icon_widget)
86 icon_widget = gtk_fixed_new();
87 // We never release our ref, so we will leak this on program shutdown.
88 static GdkPixbuf* default_bookmark_icon =
89 gtk_widget_render_icon(icon_widget, GTK_STOCK_FILE,
90 GTK_ICON_SIZE_MENU, NULL);
91 return default_bookmark_icon;
92 }
69 } 93 }
70 94
71 GdkPixbuf* GetPixbufForNode(const BookmarkNode* node, BookmarkModel* model) { 95 GdkPixbuf* GetPixbufForNode(const BookmarkNode* node, BookmarkModel* model,
96 bool native) {
72 GdkPixbuf* pixbuf; 97 GdkPixbuf* pixbuf;
73 98
74 if (node->is_url()) { 99 if (node->is_url()) {
75 if (model->GetFavIcon(node).width() != 0) { 100 if (model->GetFavIcon(node).width() != 0) {
76 pixbuf = gfx::GdkPixbufFromSkBitmap(&model->GetFavIcon(node)); 101 pixbuf = gfx::GdkPixbufFromSkBitmap(&model->GetFavIcon(node));
77 } else { 102 } else {
78 pixbuf = GetDefaultFavicon(); 103 pixbuf = GetDefaultFavicon(native);
79 g_object_ref(pixbuf); 104 g_object_ref(pixbuf);
80 } 105 }
81 } else { 106 } else {
82 pixbuf = GetFolderIcon(); 107 pixbuf = GetFolderIcon(native);
83 g_object_ref(pixbuf); 108 g_object_ref(pixbuf);
84 } 109 }
85 110
86 return pixbuf; 111 return pixbuf;
87 } 112 }
88 113
89 GtkWidget* GetDragRepresentation(const BookmarkNode* node, 114 GtkWidget* GetDragRepresentation(const BookmarkNode* node,
90 BookmarkModel* model, 115 BookmarkModel* model,
91 GtkThemeProvider* provider) { 116 GtkThemeProvider* provider) {
92 // Build a windowed representation for our button. 117 // Build a windowed representation for our button.
(...skipping 24 matching lines...) Expand all
117 GtkWidget* former_child = gtk_bin_get_child(GTK_BIN(button)); 142 GtkWidget* former_child = gtk_bin_get_child(GTK_BIN(button));
118 if (former_child) 143 if (former_child)
119 gtk_container_remove(GTK_CONTAINER(button), former_child); 144 gtk_container_remove(GTK_CONTAINER(button), former_child);
120 145
121 std::string tooltip = BuildTooltipFor(node); 146 std::string tooltip = BuildTooltipFor(node);
122 if (!tooltip.empty()) 147 if (!tooltip.empty())
123 gtk_widget_set_tooltip_text(button, tooltip.c_str()); 148 gtk_widget_set_tooltip_text(button, tooltip.c_str());
124 149
125 // We pack the button manually (rather than using gtk_button_set_*) so that 150 // We pack the button manually (rather than using gtk_button_set_*) so that
126 // we can have finer control over its label. 151 // we can have finer control over its label.
127 GdkPixbuf* pixbuf = bookmark_utils::GetPixbufForNode(node, model); 152 GdkPixbuf* pixbuf = bookmark_utils::GetPixbufForNode(node, model,
153 provider->UseGtkTheme());
128 GtkWidget* image = gtk_image_new_from_pixbuf(pixbuf); 154 GtkWidget* image = gtk_image_new_from_pixbuf(pixbuf);
129 g_object_unref(pixbuf); 155 g_object_unref(pixbuf);
130 156
131 GtkWidget* box = gtk_hbox_new(FALSE, kBarButtonPadding); 157 GtkWidget* box = gtk_hbox_new(FALSE, kBarButtonPadding);
132 gtk_box_pack_start(GTK_BOX(box), image, FALSE, FALSE, 0); 158 gtk_box_pack_start(GTK_BOX(box), image, FALSE, FALSE, 0);
133 159
134 std::string label_string = WideToUTF8(node->GetTitle()); 160 std::string label_string = WideToUTF8(node->GetTitle());
135 if (!label_string.empty()) { 161 if (!label_string.empty()) {
136 GtkWidget* label = gtk_label_new(label_string.c_str()); 162 GtkWidget* label = gtk_label_new(label_string.c_str());
137 gtk_label_set_max_width_chars(GTK_LABEL(label), kMaxCharsOnAButton); 163 gtk_label_set_max_width_chars(GTK_LABEL(label), kMaxCharsOnAButton);
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 GURL url(uris[i]); 318 GURL url(uris[i]);
293 std::string title = GetNameForURL(url); 319 std::string title = GetNameForURL(url);
294 model->AddURL(parent, idx++, UTF8ToWide(title), url); 320 model->AddURL(parent, idx++, UTF8ToWide(title), url);
295 } 321 }
296 322
297 g_strfreev(uris); 323 g_strfreev(uris);
298 return true; 324 return true;
299 } 325 }
300 326
301 } // namespace bookmark_utils 327 } // namespace bookmark_utils
OLDNEW
« no previous file with comments | « chrome/browser/gtk/bookmark_utils_gtk.h ('k') | chrome/browser/gtk/list_store_favicon_loader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698