| OLD | NEW |
| 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 12 matching lines...) Expand all Loading... |
| 23 // Used in gtk_selection_data_set(). (I assume from this parameter that gtk has | 23 // Used in gtk_selection_data_set(). (I assume from this parameter that gtk has |
| 24 // to some really exotic hardware...) | 24 // to some really exotic hardware...) |
| 25 const int kBitsInAByte = 8; | 25 const int kBitsInAByte = 8; |
| 26 | 26 |
| 27 // Maximum number of characters on a bookmark button. | 27 // Maximum number of characters on a bookmark button. |
| 28 const size_t kMaxCharsOnAButton = 15; | 28 const size_t kMaxCharsOnAButton = 15; |
| 29 | 29 |
| 30 // Only used for the background of the drag widget. | 30 // Only used for the background of the drag widget. |
| 31 const GdkColor kBackgroundColor = GDK_COLOR_RGB(0xe6, 0xed, 0xf4); | 31 const GdkColor kBackgroundColor = GDK_COLOR_RGB(0xe6, 0xed, 0xf4); |
| 32 | 32 |
| 33 // Padding between the chrome button highlight border and the contents (favicon, |
| 34 // text). |
| 35 // TODO(estade): we need to adjust the top and bottom padding, but first we need |
| 36 // to give the bookmark bar more space (at the expense of the toolbar). |
| 37 const int kButtonPaddingTop = 0; |
| 38 const int kButtonPaddingBottom = 0; |
| 39 const int kButtonPaddingLeft = 2; |
| 40 const int kButtonPaddingRight = 0; |
| 41 |
| 33 void* AsVoid(const BookmarkNode* node) { | 42 void* AsVoid(const BookmarkNode* node) { |
| 34 return const_cast<BookmarkNode*>(node); | 43 return const_cast<BookmarkNode*>(node); |
| 35 } | 44 } |
| 36 | 45 |
| 37 } // namespace | 46 } // namespace |
| 38 | 47 |
| 39 namespace bookmark_utils { | 48 namespace bookmark_utils { |
| 40 | 49 |
| 41 const char kBookmarkNode[] = "bookmark-node"; | 50 const char kBookmarkNode[] = "bookmark-node"; |
| 42 | 51 |
| 52 // Spacing between the buttons on the bar. |
| 43 const int kBarButtonPadding = 4; | 53 const int kBarButtonPadding = 4; |
| 44 | 54 |
| 45 GdkPixbuf* GetFolderIcon() { | 55 GdkPixbuf* GetFolderIcon() { |
| 46 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 56 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 47 static GdkPixbuf* default_folder_icon = rb.GetPixbufNamed( | 57 static GdkPixbuf* default_folder_icon = rb.GetPixbufNamed( |
| 48 IDR_BOOKMARK_BAR_FOLDER); | 58 IDR_BOOKMARK_BAR_FOLDER); |
| 49 return default_folder_icon; | 59 return default_folder_icon; |
| 50 } | 60 } |
| 51 | 61 |
| 52 GdkPixbuf* GetDefaultFavicon() { | 62 GdkPixbuf* GetDefaultFavicon() { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 GtkWidget* image = gtk_image_new_from_pixbuf(pixbuf); | 126 GtkWidget* image = gtk_image_new_from_pixbuf(pixbuf); |
| 117 g_object_unref(pixbuf); | 127 g_object_unref(pixbuf); |
| 118 | 128 |
| 119 GtkWidget* label = gtk_label_new(WideToUTF8(node->GetTitle()).c_str()); | 129 GtkWidget* label = gtk_label_new(WideToUTF8(node->GetTitle()).c_str()); |
| 120 gtk_label_set_max_width_chars(GTK_LABEL(label), kMaxCharsOnAButton); | 130 gtk_label_set_max_width_chars(GTK_LABEL(label), kMaxCharsOnAButton); |
| 121 gtk_label_set_ellipsize(GTK_LABEL(label), PANGO_ELLIPSIZE_END); | 131 gtk_label_set_ellipsize(GTK_LABEL(label), PANGO_ELLIPSIZE_END); |
| 122 | 132 |
| 123 GtkWidget* box = gtk_hbox_new(FALSE, kBarButtonPadding); | 133 GtkWidget* box = gtk_hbox_new(FALSE, kBarButtonPadding); |
| 124 gtk_box_pack_start(GTK_BOX(box), image, FALSE, FALSE, 0); | 134 gtk_box_pack_start(GTK_BOX(box), image, FALSE, FALSE, 0); |
| 125 gtk_box_pack_start(GTK_BOX(box), label, FALSE, FALSE, 0); | 135 gtk_box_pack_start(GTK_BOX(box), label, FALSE, FALSE, 0); |
| 126 gtk_container_add(GTK_CONTAINER(button), box); | 136 |
| 137 GtkWidget* alignment = gtk_alignment_new(0.0, 0.0, 1.0, 1.0); |
| 138 gtk_alignment_set_padding(GTK_ALIGNMENT(alignment), |
| 139 kButtonPaddingTop, kButtonPaddingBottom, |
| 140 kButtonPaddingLeft, kButtonPaddingRight); |
| 141 gtk_container_add(GTK_CONTAINER(alignment), box); |
| 142 gtk_container_add(GTK_CONTAINER(button), alignment); |
| 127 | 143 |
| 128 SetButtonTextColors(label, properties); | 144 SetButtonTextColors(label, properties); |
| 129 g_object_set_data(G_OBJECT(button), bookmark_utils::kBookmarkNode, | 145 g_object_set_data(G_OBJECT(button), bookmark_utils::kBookmarkNode, |
| 130 AsVoid(node)); | 146 AsVoid(node)); |
| 131 | 147 |
| 132 gtk_chrome_button_set_use_gtk_rendering(GTK_CHROME_BUTTON(button), | 148 gtk_chrome_button_set_use_gtk_rendering(GTK_CHROME_BUTTON(button), |
| 133 properties->use_gtk_rendering); | 149 properties->use_gtk_rendering); |
| 134 | 150 |
| 135 gtk_widget_show_all(box); | 151 gtk_widget_show_all(alignment); |
| 136 } | 152 } |
| 137 | 153 |
| 138 std::string BuildTooltipFor(const BookmarkNode* node) { | 154 std::string BuildTooltipFor(const BookmarkNode* node) { |
| 139 // TODO(erg): Actually build the tooltip. For now, we punt and just return | 155 // TODO(erg): Actually build the tooltip. For now, we punt and just return |
| 140 // the URL. | 156 // the URL. |
| 141 return node->GetURL().possibly_invalid_spec(); | 157 return node->GetURL().possibly_invalid_spec(); |
| 142 } | 158 } |
| 143 | 159 |
| 144 const BookmarkNode* BookmarkNodeForWidget(GtkWidget* widget) { | 160 const BookmarkNode* BookmarkNodeForWidget(GtkWidget* widget) { |
| 145 return reinterpret_cast<const BookmarkNode*>( | 161 return reinterpret_cast<const BookmarkNode*>( |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 default: { | 257 default: { |
| 242 DLOG(ERROR) << "Unsupported drag received type: " << target_type; | 258 DLOG(ERROR) << "Unsupported drag received type: " << target_type; |
| 243 } | 259 } |
| 244 } | 260 } |
| 245 } | 261 } |
| 246 | 262 |
| 247 return std::vector<const BookmarkNode*>(); | 263 return std::vector<const BookmarkNode*>(); |
| 248 } | 264 } |
| 249 | 265 |
| 250 } // namespace bookmark_utils | 266 } // namespace bookmark_utils |
| OLD | NEW |