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