Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(212)

Side by Side Diff: chrome/browser/gtk/options/fonts_page_gtk.cc

Issue 159458: Gtk: Implement font selection options. (Closed)
Patch Set: move the NotifyPrefChanged call into SetFontsFromButton Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/gtk/options/fonts_page_gtk.h ('k') | chrome/chrome.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2009 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/gtk/options/fonts_page_gtk.h"
6
7 #include "app/l10n_util.h"
8 #include "chrome/browser/gtk/options/options_layout_gtk.h"
9 #include "chrome/common/gtk_util.h"
10 #include "chrome/common/pref_names.h"
11 #include "grit/generated_resources.h"
12
13 namespace {
14
15 // Make a Gtk font name string from a font family name and pixel size.
16 std::string MakeFontName(std::wstring family_name, int pixel_size) {
17 std::string fontname;
18 // TODO(mattm): We can pass in the size in pixels (px), and the font button
19 // actually honors it, but when you open the selector it interprets it as
20 // points. See crbug.com/17857
21 SStringPrintf(&fontname, "%s %dpx", WideToUTF8(family_name).c_str(),
22 pixel_size);
23 return fontname;
24 }
25
26 } // namespace
27
28 FontsPageGtk::FontsPageGtk(Profile* profile) : OptionsPageBase(profile) {
29 Init();
30 }
31
32 FontsPageGtk::~FontsPageGtk() {
33 }
34
35 void FontsPageGtk::Init() {
36 OptionsLayoutBuilderGtk options_builder;
37
38 serif_font_button_ = gtk_font_button_new();
39 gtk_font_button_set_use_font(GTK_FONT_BUTTON(serif_font_button_), TRUE);
40 gtk_font_button_set_use_size(GTK_FONT_BUTTON(serif_font_button_), TRUE);
41 g_signal_connect(serif_font_button_, "font-set", G_CALLBACK(OnSerifFontSet),
42 this);
43
44 sans_font_button_ = gtk_font_button_new();
45 gtk_font_button_set_use_font(GTK_FONT_BUTTON(sans_font_button_), TRUE);
46 gtk_font_button_set_use_size(GTK_FONT_BUTTON(sans_font_button_), TRUE);
47 g_signal_connect(sans_font_button_, "font-set", G_CALLBACK(OnSansFontSet),
48 this);
49
50 fixed_font_button_ = gtk_font_button_new();
51 gtk_font_button_set_use_font(GTK_FONT_BUTTON(fixed_font_button_), TRUE);
52 gtk_font_button_set_use_size(GTK_FONT_BUTTON(fixed_font_button_), TRUE);
53 g_signal_connect(fixed_font_button_, "font-set", G_CALLBACK(OnFixedFontSet),
54 this);
55
56 GtkWidget* font_controls = gtk_util::CreateLabeledControlsGroup(NULL,
57 l10n_util::GetStringUTF8(
58 IDS_FONT_LANGUAGE_SETTING_FONT_SELECTOR_SERIF_LABEL).c_str(),
59 serif_font_button_,
60 l10n_util::GetStringUTF8(
61 IDS_FONT_LANGUAGE_SETTING_FONT_SELECTOR_SANS_SERIF_LABEL).c_str(),
62 sans_font_button_,
63 l10n_util::GetStringUTF8(
64 IDS_FONT_LANGUAGE_SETTING_FONT_SELECTOR_FIXED_WIDTH_LABEL).c_str(),
65 fixed_font_button_,
66 NULL);
67
68 options_builder.AddOptionGroup(l10n_util::GetStringUTF8(
69 IDS_FONT_LANGUAGE_SETTING_FONT_SUB_DIALOG_FONT_TITLE),
70 font_controls, false);
71
72 // TODO(mattm): default encoding
73 options_builder.AddOptionGroup(l10n_util::GetStringUTF8(
74 IDS_FONT_LANGUAGE_SETTING_FONT_SUB_DIALOG_ENCODING_TITLE),
75 gtk_label_new("todo"), false);
76
77 page_ = options_builder.get_page_widget();
78
79 serif_name_.Init(prefs::kWebKitSerifFontFamily, profile()->GetPrefs(), this);
80 sans_serif_name_.Init(prefs::kWebKitSansSerifFontFamily,
81 profile()->GetPrefs(), this);
82 variable_width_size_.Init(prefs::kWebKitDefaultFontSize,
83 profile()->GetPrefs(), this);
84
85 fixed_width_name_.Init(prefs::kWebKitFixedFontFamily, profile()->GetPrefs(),
86 this);
87 fixed_width_size_.Init(prefs::kWebKitDefaultFixedFontSize,
88 profile()->GetPrefs(), this);
89
90 default_encoding_.Init(prefs::kDefaultCharset, profile()->GetPrefs(), this);
91
92 NotifyPrefChanged(NULL);
93 }
94
95 void FontsPageGtk::NotifyPrefChanged(const std::wstring* pref_name) {
96 if (!pref_name || *pref_name == prefs::kWebKitSerifFontFamily ||
97 *pref_name == prefs::kWebKitDefaultFontSize) {
98 gtk_font_button_set_font_name(GTK_FONT_BUTTON(serif_font_button_),
99 MakeFontName(serif_name_.GetValue(),
100 variable_width_size_.GetValue()).c_str());
101 }
102 if (!pref_name || *pref_name == prefs::kWebKitSansSerifFontFamily ||
103 *pref_name == prefs::kWebKitDefaultFontSize) {
104 gtk_font_button_set_font_name(GTK_FONT_BUTTON(sans_font_button_),
105 MakeFontName(sans_serif_name_.GetValue(),
106 variable_width_size_.GetValue()).c_str());
107 }
108 if (!pref_name || *pref_name == prefs::kWebKitFixedFontFamily ||
109 *pref_name == prefs::kWebKitDefaultFixedFontSize) {
110 gtk_font_button_set_font_name(GTK_FONT_BUTTON(fixed_font_button_),
111 MakeFontName(fixed_width_name_.GetValue(),
112 fixed_width_size_.GetValue()).c_str());
113 }
114 if (!pref_name || *pref_name == prefs::kDefaultCharset) {
115 // TODO
116 }
117 }
118
119 void FontsPageGtk::SetFontsFromButton(StringPrefMember* name_pref,
120 IntegerPrefMember* size_pref,
121 GtkFontButton* font_button) {
122 PangoFontDescription* desc = pango_font_description_from_string(
123 gtk_font_button_get_font_name(font_button));
124 int size = pango_font_description_get_size(desc);
125 name_pref->SetValue(UTF8ToWide(pango_font_description_get_family(desc)));
126 size_pref->SetValue(size / PANGO_SCALE);
127 pango_font_description_free(desc);
128 // Reset the button font in px, since the chooser will have set it in points.
129 // Also, both sans and serif share the same size so we need to update them
130 // both.
131 NotifyPrefChanged(NULL);
132 }
133
134
135 // static
136 void FontsPageGtk::OnSerifFontSet(GtkFontButton* font_button,
137 FontsPageGtk* fonts_page) {
138 fonts_page->SetFontsFromButton(&fonts_page->serif_name_,
139 &fonts_page->variable_width_size_,
140 font_button);
141 }
142
143 // static
144 void FontsPageGtk::OnSansFontSet(GtkFontButton* font_button,
145 FontsPageGtk* fonts_page) {
146 fonts_page->SetFontsFromButton(&fonts_page->sans_serif_name_,
147 &fonts_page->variable_width_size_,
148 font_button);
149 }
150
151 // static
152 void FontsPageGtk::OnFixedFontSet(GtkFontButton* font_button,
153 FontsPageGtk* fonts_page) {
154 fonts_page->SetFontsFromButton(&fonts_page->fixed_width_name_,
155 &fonts_page->fixed_width_size_,
156 font_button);
157 }
OLDNEW
« no previous file with comments | « chrome/browser/gtk/options/fonts_page_gtk.h ('k') | chrome/chrome.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698