| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/ui/gtk/bookmarks/bookmark_utils_gtk.h" | 5 #include "chrome/browser/ui/gtk/bookmarks/bookmark_utils_gtk.h" |
| 6 | 6 |
| 7 #include "base/pickle.h" | 7 #include "base/pickle.h" |
| 8 #include "base/string16.h" | 8 #include "base/string16.h" |
| 9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "chrome/browser/bookmarks/bookmark_model.h" | 11 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 12 #include "chrome/browser/bookmarks/bookmark_node_data.h" | 12 #include "chrome/browser/bookmarks/bookmark_node_data.h" |
| 13 #include "chrome/browser/bookmarks/bookmark_utils.h" | 13 #include "chrome/browser/bookmarks/bookmark_utils.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/ui/gtk/gtk_chrome_button.h" | 15 #include "chrome/browser/ui/gtk/gtk_chrome_button.h" |
| 16 #include "chrome/browser/ui/gtk/gtk_theme_service.h" | |
| 17 #include "chrome/browser/ui/gtk/gtk_util.h" | 16 #include "chrome/browser/ui/gtk/gtk_util.h" |
| 17 #include "chrome/browser/ui/gtk/theme_service_gtk.h" |
| 18 #include "ui/base/dragdrop/gtk_dnd_util.h" | 18 #include "ui/base/dragdrop/gtk_dnd_util.h" |
| 19 #include "ui/base/gtk/gtk_hig_constants.h" | 19 #include "ui/base/gtk/gtk_hig_constants.h" |
| 20 #include "ui/base/gtk/gtk_screen_utils.h" | 20 #include "ui/base/gtk/gtk_screen_utils.h" |
| 21 #include "ui/base/resource/resource_bundle.h" | 21 #include "ui/base/resource/resource_bundle.h" |
| 22 #include "ui/base/text/text_elider.h" | 22 #include "ui/base/text/text_elider.h" |
| 23 #include "ui/gfx/canvas_skia_paint.h" | 23 #include "ui/gfx/canvas_skia_paint.h" |
| 24 #include "ui/gfx/font.h" | 24 #include "ui/gfx/font.h" |
| 25 #include "ui/gfx/gtk_util.h" | 25 #include "ui/gfx/gtk_util.h" |
| 26 #include "ui/gfx/image/image.h" | 26 #include "ui/gfx/image/image.h" |
| 27 | 27 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 46 const int kButtonPaddingBottom = 0; | 46 const int kButtonPaddingBottom = 0; |
| 47 const int kButtonPaddingLeft = 5; | 47 const int kButtonPaddingLeft = 5; |
| 48 const int kButtonPaddingRight = 0; | 48 const int kButtonPaddingRight = 0; |
| 49 | 49 |
| 50 void* AsVoid(const BookmarkNode* node) { | 50 void* AsVoid(const BookmarkNode* node) { |
| 51 return const_cast<BookmarkNode*>(node); | 51 return const_cast<BookmarkNode*>(node); |
| 52 } | 52 } |
| 53 | 53 |
| 54 // Creates the widget hierarchy for a bookmark button. | 54 // Creates the widget hierarchy for a bookmark button. |
| 55 void PackButton(GdkPixbuf* pixbuf, const string16& title, bool ellipsize, | 55 void PackButton(GdkPixbuf* pixbuf, const string16& title, bool ellipsize, |
| 56 GtkThemeService* provider, GtkWidget* button) { | 56 ThemeServiceGtk* provider, GtkWidget* button) { |
| 57 GtkWidget* former_child = gtk_bin_get_child(GTK_BIN(button)); | 57 GtkWidget* former_child = gtk_bin_get_child(GTK_BIN(button)); |
| 58 if (former_child) | 58 if (former_child) |
| 59 gtk_container_remove(GTK_CONTAINER(button), former_child); | 59 gtk_container_remove(GTK_CONTAINER(button), former_child); |
| 60 | 60 |
| 61 // We pack the button manually (rather than using gtk_button_set_*) so that | 61 // We pack the button manually (rather than using gtk_button_set_*) so that |
| 62 // we can have finer control over its label. | 62 // we can have finer control over its label. |
| 63 GtkWidget* image = gtk_image_new_from_pixbuf(pixbuf); | 63 GtkWidget* image = gtk_image_new_from_pixbuf(pixbuf); |
| 64 | 64 |
| 65 GtkWidget* box = gtk_hbox_new(FALSE, kBarButtonPadding); | 65 GtkWidget* box = gtk_hbox_new(FALSE, kBarButtonPadding); |
| 66 gtk_box_pack_start(GTK_BOX(box), image, FALSE, FALSE, 0); | 66 gtk_box_pack_start(GTK_BOX(box), image, FALSE, FALSE, 0); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 const char kBookmarkNode[] = "bookmark-node"; | 164 const char kBookmarkNode[] = "bookmark-node"; |
| 165 | 165 |
| 166 GdkPixbuf* GetPixbufForNode(const BookmarkNode* node, BookmarkModel* model, | 166 GdkPixbuf* GetPixbufForNode(const BookmarkNode* node, BookmarkModel* model, |
| 167 bool native) { | 167 bool native) { |
| 168 GdkPixbuf* pixbuf; | 168 GdkPixbuf* pixbuf; |
| 169 | 169 |
| 170 if (node->is_url()) { | 170 if (node->is_url()) { |
| 171 if (model->GetFavicon(node).width() != 0) { | 171 if (model->GetFavicon(node).width() != 0) { |
| 172 pixbuf = gfx::GdkPixbufFromSkBitmap(&model->GetFavicon(node)); | 172 pixbuf = gfx::GdkPixbufFromSkBitmap(&model->GetFavicon(node)); |
| 173 } else { | 173 } else { |
| 174 pixbuf = GtkThemeService::GetDefaultFavicon(native)->ToGdkPixbuf(); | 174 pixbuf = ThemeServiceGtk::GetDefaultFavicon(native)->ToGdkPixbuf(); |
| 175 g_object_ref(pixbuf); | 175 g_object_ref(pixbuf); |
| 176 } | 176 } |
| 177 } else { | 177 } else { |
| 178 pixbuf = GtkThemeService::GetFolderIcon(native)->ToGdkPixbuf(); | 178 pixbuf = ThemeServiceGtk::GetFolderIcon(native)->ToGdkPixbuf(); |
| 179 g_object_ref(pixbuf); | 179 g_object_ref(pixbuf); |
| 180 } | 180 } |
| 181 | 181 |
| 182 return pixbuf; | 182 return pixbuf; |
| 183 } | 183 } |
| 184 | 184 |
| 185 GtkWidget* GetDragRepresentation(GdkPixbuf* pixbuf, | 185 GtkWidget* GetDragRepresentation(GdkPixbuf* pixbuf, |
| 186 const string16& title, | 186 const string16& title, |
| 187 GtkThemeService* provider) { | 187 ThemeServiceGtk* provider) { |
| 188 GtkWidget* window = gtk_window_new(GTK_WINDOW_POPUP); | 188 GtkWidget* window = gtk_window_new(GTK_WINDOW_POPUP); |
| 189 | 189 |
| 190 if (ui::IsScreenComposited() && | 190 if (ui::IsScreenComposited() && |
| 191 gtk_util::AddWindowAlphaChannel(window)) { | 191 gtk_util::AddWindowAlphaChannel(window)) { |
| 192 DragRepresentationData* data = new DragRepresentationData( | 192 DragRepresentationData* data = new DragRepresentationData( |
| 193 pixbuf, title, | 193 pixbuf, title, |
| 194 provider->GetColor(ThemeService::COLOR_BOOKMARK_TEXT)); | 194 provider->GetColor(ThemeService::COLOR_BOOKMARK_TEXT)); |
| 195 g_signal_connect(window, "expose-event", G_CALLBACK(OnDragIconExpose), | 195 g_signal_connect(window, "expose-event", G_CALLBACK(OnDragIconExpose), |
| 196 data); | 196 data); |
| 197 g_object_ref(window); | 197 g_object_ref(window); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 217 PackButton(pixbuf, title, true, provider, floating_button); | 217 PackButton(pixbuf, title, true, provider, floating_button); |
| 218 gtk_container_add(GTK_CONTAINER(frame), floating_button); | 218 gtk_container_add(GTK_CONTAINER(frame), floating_button); |
| 219 gtk_widget_show_all(frame); | 219 gtk_widget_show_all(frame); |
| 220 } | 220 } |
| 221 | 221 |
| 222 return window; | 222 return window; |
| 223 } | 223 } |
| 224 | 224 |
| 225 GtkWidget* GetDragRepresentationForNode(const BookmarkNode* node, | 225 GtkWidget* GetDragRepresentationForNode(const BookmarkNode* node, |
| 226 BookmarkModel* model, | 226 BookmarkModel* model, |
| 227 GtkThemeService* provider) { | 227 ThemeServiceGtk* provider) { |
| 228 GdkPixbuf* pixbuf = GetPixbufForNode( | 228 GdkPixbuf* pixbuf = GetPixbufForNode( |
| 229 node, model, provider->UsingNativeTheme()); | 229 node, model, provider->UsingNativeTheme()); |
| 230 GtkWidget* widget = GetDragRepresentation(pixbuf, node->GetTitle(), provider); | 230 GtkWidget* widget = GetDragRepresentation(pixbuf, node->GetTitle(), provider); |
| 231 g_object_unref(pixbuf); | 231 g_object_unref(pixbuf); |
| 232 return widget; | 232 return widget; |
| 233 } | 233 } |
| 234 | 234 |
| 235 void ConfigureButtonForNode(const BookmarkNode* node, BookmarkModel* model, | 235 void ConfigureButtonForNode(const BookmarkNode* node, BookmarkModel* model, |
| 236 GtkWidget* button, GtkThemeService* provider) { | 236 GtkWidget* button, ThemeServiceGtk* provider) { |
| 237 GdkPixbuf* pixbuf = bookmark_utils::GetPixbufForNode( | 237 GdkPixbuf* pixbuf = bookmark_utils::GetPixbufForNode( |
| 238 node, model, provider->UsingNativeTheme()); | 238 node, model, provider->UsingNativeTheme()); |
| 239 PackButton(pixbuf, node->GetTitle(), node != model->other_node(), provider, | 239 PackButton(pixbuf, node->GetTitle(), node != model->other_node(), provider, |
| 240 button); | 240 button); |
| 241 g_object_unref(pixbuf); | 241 g_object_unref(pixbuf); |
| 242 | 242 |
| 243 std::string tooltip = BuildTooltipFor(node); | 243 std::string tooltip = BuildTooltipFor(node); |
| 244 if (!tooltip.empty()) | 244 if (!tooltip.empty()) |
| 245 gtk_widget_set_tooltip_markup(button, tooltip.c_str()); | 245 gtk_widget_set_tooltip_markup(button, tooltip.c_str()); |
| 246 | 246 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 268 } | 268 } |
| 269 | 269 |
| 270 return elided_name; | 270 return elided_name; |
| 271 } | 271 } |
| 272 | 272 |
| 273 const BookmarkNode* BookmarkNodeForWidget(GtkWidget* widget) { | 273 const BookmarkNode* BookmarkNodeForWidget(GtkWidget* widget) { |
| 274 return reinterpret_cast<const BookmarkNode*>( | 274 return reinterpret_cast<const BookmarkNode*>( |
| 275 g_object_get_data(G_OBJECT(widget), bookmark_utils::kBookmarkNode)); | 275 g_object_get_data(G_OBJECT(widget), bookmark_utils::kBookmarkNode)); |
| 276 } | 276 } |
| 277 | 277 |
| 278 void SetButtonTextColors(GtkWidget* label, GtkThemeService* provider) { | 278 void SetButtonTextColors(GtkWidget* label, ThemeServiceGtk* provider) { |
| 279 if (provider->UsingNativeTheme()) { | 279 if (provider->UsingNativeTheme()) { |
| 280 gtk_util::SetLabelColor(label, NULL); | 280 gtk_util::SetLabelColor(label, NULL); |
| 281 } else { | 281 } else { |
| 282 GdkColor color = provider->GetGdkColor( | 282 GdkColor color = provider->GetGdkColor( |
| 283 ThemeService::COLOR_BOOKMARK_TEXT); | 283 ThemeService::COLOR_BOOKMARK_TEXT); |
| 284 gtk_widget_modify_fg(label, GTK_STATE_NORMAL, &color); | 284 gtk_widget_modify_fg(label, GTK_STATE_NORMAL, &color); |
| 285 gtk_widget_modify_fg(label, GTK_STATE_INSENSITIVE, &color); | 285 gtk_widget_modify_fg(label, GTK_STATE_INSENSITIVE, &color); |
| 286 | 286 |
| 287 // Because the prelight state is a white image that doesn't change by the | 287 // Because the prelight state is a white image that doesn't change by the |
| 288 // theme, force the text color to black when it would be used. | 288 // theme, force the text color to black when it would be used. |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 GURL url; | 449 GURL url; |
| 450 string16 title; | 450 string16 title; |
| 451 if (!ui::ExtractNetscapeURL(selection_data, &url, &title)) | 451 if (!ui::ExtractNetscapeURL(selection_data, &url, &title)) |
| 452 return false; | 452 return false; |
| 453 | 453 |
| 454 model->AddURL(parent, idx, title, url); | 454 model->AddURL(parent, idx, title, url); |
| 455 return true; | 455 return true; |
| 456 } | 456 } |
| 457 | 457 |
| 458 } // namespace bookmark_utils | 458 } // namespace bookmark_utils |
| OLD | NEW |