| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2010 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_GTK_BOOKMARK_BAR_INSTRUCTIONS_GTK_CC_ | |
| 6 #define CHROME_BROWSER_GTK_BOOKMARK_BAR_INSTRUCTIONS_GTK_CC_ | |
| 7 | |
| 8 #include "chrome/browser/gtk/bookmark_bar_instructions_gtk.h" | |
| 9 | |
| 10 #include "app/l10n_util.h" | |
| 11 #include "base/observer_list.h" | |
| 12 #include "chrome/browser/gtk/gtk_chrome_link_button.h" | |
| 13 #include "chrome/browser/gtk/gtk_chrome_shrinkable_hbox.h" | |
| 14 #include "chrome/browser/gtk/gtk_theme_provider.h" | |
| 15 #include "chrome/browser/gtk/gtk_util.h" | |
| 16 #include "chrome/common/notification_service.h" | |
| 17 #include "grit/generated_resources.h" | |
| 18 | |
| 19 BookmarkBarInstructionsGtk::BookmarkBarInstructionsGtk(Delegate* delegate, | |
| 20 Profile* profile) | |
| 21 : delegate_(delegate), | |
| 22 profile_(profile), | |
| 23 theme_provider_(GtkThemeProvider::GetFrom(profile_)) { | |
| 24 instructions_hbox_ = gtk_chrome_shrinkable_hbox_new(FALSE, FALSE, 0); | |
| 25 gtk_widget_set_size_request(instructions_hbox_, 0, -1); | |
| 26 | |
| 27 instructions_label_ = gtk_label_new( | |
| 28 l10n_util::GetStringUTF8(IDS_BOOKMARKS_NO_ITEMS).c_str()); | |
| 29 gtk_misc_set_alignment(GTK_MISC(instructions_label_), 0, 0.5); | |
| 30 gtk_util::CenterWidgetInHBox(instructions_hbox_, instructions_label_, | |
| 31 false, 1); | |
| 32 g_signal_connect(instructions_label_, "map", | |
| 33 G_CALLBACK(gtk_util::InitLabelSizeRequestAndEllipsizeMode), | |
| 34 NULL); | |
| 35 | |
| 36 instructions_link_ = gtk_chrome_link_button_new( | |
| 37 l10n_util::GetStringUTF8(IDS_BOOKMARK_BAR_IMPORT_LINK).c_str()); | |
| 38 gtk_misc_set_alignment( | |
| 39 GTK_MISC(GTK_CHROME_LINK_BUTTON(instructions_link_)->label), 0, 0.5); | |
| 40 g_signal_connect(instructions_link_, "clicked", | |
| 41 G_CALLBACK(OnButtonClickThunk), this); | |
| 42 gtk_util::SetButtonTriggersNavigation(instructions_link_); | |
| 43 // Until we switch to vector graphics, force the font size. | |
| 44 // 13.4px == 10pt @ 96dpi | |
| 45 gtk_util::ForceFontSizePixels( | |
| 46 GTK_CHROME_LINK_BUTTON(instructions_link_)->label, 13.4); | |
| 47 gtk_util::CenterWidgetInHBox(instructions_hbox_, instructions_link_, | |
| 48 false, 6); | |
| 49 g_signal_connect(GTK_CHROME_LINK_BUTTON(instructions_link_)->label, "map", | |
| 50 G_CALLBACK(gtk_util::InitLabelSizeRequestAndEllipsizeMode), | |
| 51 NULL); | |
| 52 | |
| 53 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, | |
| 54 NotificationService::AllSources()); | |
| 55 theme_provider_->InitThemesFor(this); | |
| 56 } | |
| 57 | |
| 58 void BookmarkBarInstructionsGtk::Observe(NotificationType type, | |
| 59 const NotificationSource& source, | |
| 60 const NotificationDetails& details) { | |
| 61 if (type == NotificationType::BROWSER_THEME_CHANGED) | |
| 62 UpdateColors(); | |
| 63 } | |
| 64 | |
| 65 void BookmarkBarInstructionsGtk::OnButtonClick(GtkWidget* button) { | |
| 66 delegate_->ShowImportDialog(); | |
| 67 } | |
| 68 | |
| 69 void BookmarkBarInstructionsGtk::UpdateColors() { | |
| 70 gtk_chrome_link_button_set_use_gtk_theme( | |
| 71 GTK_CHROME_LINK_BUTTON(instructions_link_), | |
| 72 theme_provider_->UseGtkTheme()); | |
| 73 | |
| 74 GdkColor bookmark_color = theme_provider_->GetGdkColor( | |
| 75 BrowserThemeProvider::COLOR_BOOKMARK_TEXT); | |
| 76 if (theme_provider_->UseGtkTheme()) { | |
| 77 gtk_util::SetLabelColor(instructions_label_, NULL); | |
| 78 gtk_chrome_link_button_set_normal_color( | |
| 79 GTK_CHROME_LINK_BUTTON(instructions_link_), NULL); | |
| 80 } else { | |
| 81 gtk_util::SetLabelColor(instructions_label_, &bookmark_color); | |
| 82 | |
| 83 // When using a non-standard, non-gtk theme, we make the link color match | |
| 84 // the bookmark text color. Otherwise, standard link blue can look very | |
| 85 // bad for some dark themes. | |
| 86 if (theme_provider_->GetColor(BrowserThemeProvider::COLOR_BOOKMARK_TEXT) == | |
| 87 BrowserThemeProvider::GetDefaultColor( | |
| 88 BrowserThemeProvider::COLOR_BOOKMARK_TEXT)) { | |
| 89 gtk_chrome_link_button_set_normal_color( | |
| 90 GTK_CHROME_LINK_BUTTON(instructions_link_), NULL); | |
| 91 } else { | |
| 92 gtk_chrome_link_button_set_normal_color( | |
| 93 GTK_CHROME_LINK_BUTTON(instructions_link_), &bookmark_color); | |
| 94 } | |
| 95 } | |
| 96 } | |
| 97 | |
| 98 #endif // CHROME_BROWSER_GTK_BOOKMARK_BAR_INSTRUCTIONS_GTK_CC_ | |
| OLD | NEW |