1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_GTK_BOOKMARK_BAR_INSTRUCTIONS_GTK_CC_
#define CHROME_BROWSER_GTK_BOOKMARK_BAR_INSTRUCTIONS_GTK_CC_
#include "chrome/browser/gtk/bookmark_bar_instructions_gtk.h"
#include "app/l10n_util.h"
#include "base/observer_list.h"
#include "chrome/browser/gtk/gtk_chrome_link_button.h"
#include "chrome/browser/gtk/gtk_theme_provider.h"
#include "chrome/common/gtk_util.h"
#include "chrome/common/notification_service.h"
#include "grit/generated_resources.h"
BookmarkBarInstructionsGtk::BookmarkBarInstructionsGtk(Delegate* delegate,
Profile* profile)
: delegate_(delegate),
profile_(profile) {
instructions_hbox_ = gtk_hbox_new(FALSE, 0);
instructions_label_ =
gtk_label_new(l10n_util::GetStringUTF8(IDS_BOOKMARKS_NO_ITEMS).c_str());
instructions_label_ = gtk_label_new(
l10n_util::GetStringUTF8(IDS_BOOKMARKS_NO_ITEMS).c_str());
gtk_label_set_ellipsize(GTK_LABEL(instructions_label_), PANGO_ELLIPSIZE_END);
gtk_widget_set_size_request(instructions_label_, 0, -1);
gtk_misc_set_alignment(GTK_MISC(instructions_label_), 0, 0.5);
gtk_box_pack_start(GTK_BOX(instructions_hbox_), instructions_label_,
true, true, 1);
instructions_link_ = gtk_chrome_link_button_new(
l10n_util::GetStringUTF8(IDS_BOOKMARK_BAR_IMPORT_LINK).c_str());
g_signal_connect(instructions_link_, "clicked",
G_CALLBACK(OnButtonClick), this);
gtk_util::SetButtonTriggersNavigation(instructions_link_);
// Until we switch to vector graphics, force the font size.
// 13.4px == 10pt @ 96dpi
gtk_util::ForceFontSizePixels(
GTK_CHROME_LINK_BUTTON(instructions_link_)->label, 13.4);
gtk_util::CenterWidgetInHBox(instructions_hbox_, instructions_link_,
true, 1);
gtk_widget_show_all(instructions_hbox_);
registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED,
NotificationService::AllSources());
}
void BookmarkBarInstructionsGtk::Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details) {
if (type == NotificationType::BROWSER_THEME_CHANGED)
UpdateColors();
}
// static
void BookmarkBarInstructionsGtk::OnButtonClick(
GtkWidget* button, BookmarkBarInstructionsGtk* instructions) {
instructions->delegate_->ShowImportDialog();
}
void BookmarkBarInstructionsGtk::UpdateColors() {
const GtkThemeProvider* theme_provider = GtkThemeProvider::GetFrom(profile_);
if (!theme_provider)
return;
gtk_chrome_link_button_set_use_gtk_theme(
GTK_CHROME_LINK_BUTTON(instructions_link_),
theme_provider->UseGtkTheme());
// When using a non-standard, non-gtk theme, we make the link color match
// the bookmark text color. Otherwise, standard link blue can look very
// bad for some dark themes.
if (theme_provider->GetColor(BrowserThemeProvider::COLOR_BOOKMARK_TEXT) ==
BrowserThemeProvider::GetDefaultColor(
BrowserThemeProvider::COLOR_BOOKMARK_TEXT)) {
gtk_util::SetLabelColor(instructions_label_, NULL);
gtk_chrome_link_button_set_normal_color(
GTK_CHROME_LINK_BUTTON(instructions_link_), NULL);
} else {
GdkColor bookmark_color = theme_provider->GetGdkColor(
BrowserThemeProvider::COLOR_BOOKMARK_TEXT);
gtk_util::SetLabelColor(instructions_label_, &bookmark_color);
gtk_chrome_link_button_set_normal_color(
GTK_CHROME_LINK_BUTTON(instructions_link_), &bookmark_color);
}
}
#endif // CHROME_BROWSER_GTK_BOOKMARK_BAR_INSTRUCTIONS_GTK_CC_
|