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