summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfalken@chromium.org <falken@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-06 05:01:20 +0000
committerfalken@chromium.org <falken@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-06 05:01:20 +0000
commit28e466cf8282a13c22ff64eb762b7adef8f68f11 (patch)
treee6816e0ab6e5a4c6439fc6fb15c914fd118336b5
parentf24fd5c6ebb17b4b74e006c74bb2236218e88b1f (diff)
downloadchromium_src-28e466cf8282a13c22ff64eb762b7adef8f68f11.zip
chromium_src-28e466cf8282a13c22ff64eb762b7adef8f68f11.tar.gz
chromium_src-28e466cf8282a13c22ff64eb762b7adef8f68f11.tar.bz2
Switch fonts when Chrome OS locale changes.
This patch is just a start. When locale changes through the login screen UI, the fonts in ResourceBundle and PlatformFontGtk are updated, and the password fields and username labels are redrawn with the correct font. In the future, all widgets in the login screen would be redrawn with the correct font. When the locale changes upon login, the fonts are updated, though not all widgets are redrawn correctly yet. BUG=chromium-os:13450 TEST=manually Review URL: http://codereview.chromium.org/6788004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@80579 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/chromeos/login/existing_user_view.cc3
-rw-r--r--chrome/browser/chromeos/login/language_switch_menu.cc24
-rw-r--r--chrome/browser/chromeos/login/language_switch_menu.h2
-rw-r--r--chrome/browser/chromeos/login/user_controller.cc23
-rw-r--r--chrome/browser/chromeos/login/user_controller.h4
-rw-r--r--chrome/browser/chromeos/login/username_view.cc8
-rw-r--r--ui/base/resource/resource_bundle.cc13
-rw-r--r--ui/base/resource/resource_bundle.h4
-rw-r--r--ui/gfx/platform_font_gtk.cc8
-rw-r--r--ui/gfx/platform_font_gtk.h5
10 files changed, 81 insertions, 13 deletions
diff --git a/chrome/browser/chromeos/login/existing_user_view.cc b/chrome/browser/chromeos/login/existing_user_view.cc
index b91d639..ab5d3a4 100644
--- a/chrome/browser/chromeos/login/existing_user_view.cc
+++ b/chrome/browser/chromeos/login/existing_user_view.cc
@@ -10,6 +10,7 @@
#include "chrome/browser/chromeos/login/wizard_accessibility_helper.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
+#include "ui/base/resource/resource_bundle.h"
#include "views/background.h"
#include "views/controls/textfield/textfield.h"
#include "views/focus/focus_manager.h"
@@ -85,6 +86,8 @@ void ExistingUserView::RecreateFields() {
password_field_->SetController(this);
AddChildView(password_field_);
}
+ password_field_->SetFont(ResourceBundle::GetSharedInstance().GetFont(
+ ResourceBundle::BaseFont));
password_field_->set_text_to_display_when_empty(
l10n_util::GetStringUTF16(IDS_LOGIN_POD_EMPTY_PASSWORD_TEXT));
Layout();
diff --git a/chrome/browser/chromeos/login/language_switch_menu.cc b/chrome/browser/chromeos/login/language_switch_menu.cc
index 591d3f2..0e2f5d8 100644
--- a/chrome/browser/chromeos/login/language_switch_menu.cc
+++ b/chrome/browser/chromeos/login/language_switch_menu.cc
@@ -16,7 +16,10 @@
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/common/pref_names.h"
#include "grit/generated_resources.h"
+#include "grit/platform_locale_settings.h"
+#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
+#include "ui/gfx/platform_font_gtk.h"
#include "views/controls/button/menu_button.h"
#include "views/widget/widget_gtk.h"
@@ -97,6 +100,7 @@ bool LanguageSwitchMenu::SwitchLanguage(const std::string& locale) {
}
CHECK(!loaded_locale.empty()) << "Locale could not be found for " << locale;
+ LoadFontsForCurrentLocale();
// The following line does not seem to affect locale anyhow. Maybe in
// future..
g_browser_process->SetApplicationLocale(locale);
@@ -106,6 +110,26 @@ bool LanguageSwitchMenu::SwitchLanguage(const std::string& locale) {
}
// static
+void LanguageSwitchMenu::LoadFontsForCurrentLocale() {
+ std::string gtkrc = l10n_util::GetStringUTF8(IDS_LOCALE_GTKRC);
+
+ // Read locale-specific gtkrc. Ideally we'd discard all the previously read
+ // gtkrc information, but GTK doesn't support that. Reading the new locale's
+ // gtkrc overrides the styles from previous ones when there is a conflict, but
+ // styles that are added and not conflicted will not be overridden. So far
+ // there are no locales with such a thing; if there are then this solution
+ // will not work.
+ if (!gtkrc.empty())
+ gtk_rc_parse_string(gtkrc.c_str());
+ else
+ gtk_rc_parse("/etc/gtk-2.0/gtkrc");
+
+ // Switch the font.
+ gfx::PlatformFontGtk::ReloadDefaultFont();
+ ResourceBundle::GetSharedInstance().ReloadFonts();
+}
+
+// static
void LanguageSwitchMenu::SwitchLanguageAndEnableKeyboardLayouts(
const std::string& locale) {
if (SwitchLanguage(locale)) {
diff --git a/chrome/browser/chromeos/login/language_switch_menu.h b/chrome/browser/chromeos/login/language_switch_menu.h
index 14328bc3..aaa7f0c 100644
--- a/chrome/browser/chromeos/login/language_switch_menu.h
+++ b/chrome/browser/chromeos/login/language_switch_menu.h
@@ -51,6 +51,8 @@ class LanguageSwitchMenu : public views::ViewMenuDelegate,
const std::string& locale);
private:
+ static void LoadFontsForCurrentLocale();
+
// views::ViewMenuDelegate implementation.
virtual void RunMenu(views::View* source, const gfx::Point& pt);
diff --git a/chrome/browser/chromeos/login/user_controller.cc b/chrome/browser/chromeos/login/user_controller.cc
index 6189d6f..3af69ef9 100644
--- a/chrome/browser/chromeos/login/user_controller.cc
+++ b/chrome/browser/chromeos/login/user_controller.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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.
@@ -328,6 +328,8 @@ void UserController::OnLocaleChanged() {
if (name_tooltip_enabled_)
EnableNameTooltip(name_tooltip_enabled_);
}
+ label_view_->SetFont(GetLabelFont());
+ unselected_label_view_->SetFont(GetUnselectedLabelFont());
}
void UserController::OnRemoveUser() {
@@ -488,12 +490,8 @@ WidgetGtk* UserController::CreateLabelWindow(int index,
label = UsernameView::CreateShapedUsernameView(text, true);
}
- ResourceBundle& rb = ResourceBundle::GetSharedInstance();
const gfx::Font& font = (type == WM_IPC_WINDOW_LOGIN_LABEL) ?
- rb.GetFont(ResourceBundle::MediumBoldFont).DeriveFont(
- kSelectedUsernameFontDelta) :
- rb.GetFont(ResourceBundle::BaseFont).DeriveFont(
- kUnselectedUsernameFontDelta, gfx::Font::BOLD);
+ GetLabelFont() : GetUnselectedLabelFont();
label->SetFont(font);
label->SetColor(login::kTextColor);
@@ -519,6 +517,19 @@ WidgetGtk* UserController::CreateLabelWindow(int index,
return window;
}
+gfx::Font UserController::GetLabelFont() {
+ ResourceBundle& rb = ResourceBundle::GetSharedInstance();
+ return rb.GetFont(ResourceBundle::MediumBoldFont).DeriveFont(
+ kSelectedUsernameFontDelta);
+}
+
+gfx::Font UserController::GetUnselectedLabelFont() {
+ ResourceBundle& rb = ResourceBundle::GetSharedInstance();
+ return rb.GetFont(ResourceBundle::BaseFont).DeriveFont(
+ kUnselectedUsernameFontDelta, gfx::Font::BOLD);
+}
+
+
std::wstring UserController::GetNameTooltip() const {
if (is_new_user_)
return UTF16ToWide(l10n_util::GetStringUTF16(IDS_ADD_USER));
diff --git a/chrome/browser/chromeos/login/user_controller.h b/chrome/browser/chromeos/login/user_controller.h
index 738b214..57ff851 100644
--- a/chrome/browser/chromeos/login/user_controller.h
+++ b/chrome/browser/chromeos/login/user_controller.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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.
@@ -141,6 +141,8 @@ class UserController : public views::WidgetDelegate,
bool need_guest_link);
views::WidgetGtk* CreateImageWindow(int index);
views::WidgetGtk* CreateLabelWindow(int index, WmIpcWindowType type);
+ gfx::Font GetLabelFont();
+ gfx::Font GetUnselectedLabelFont();
void CreateBorderWindow(int index,
int total_user_count,
int controls_width, int controls_height);
diff --git a/chrome/browser/chromeos/login/username_view.cc b/chrome/browser/chromeos/login/username_view.cc
index e52c6f0..58b06a5 100644
--- a/chrome/browser/chromeos/login/username_view.cc
+++ b/chrome/browser/chromeos/login/username_view.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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.
@@ -12,6 +12,7 @@
#include "third_party/skia/include/core/SkComposeShader.h"
#include "third_party/skia/include/effects/SkGradientShader.h"
#include "ui/base/l10n/l10n_util.h"
+#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/canvas_skia.h"
#include "ui/gfx/gtk_util.h"
@@ -188,9 +189,10 @@ void UsernameView::PaintUsername(const gfx::Rect& bounds) {
void UsernameView::OnLocaleChanged() {
if (is_guest_) {
SetText(UTF16ToWide(l10n_util::GetStringUTF16(IDS_GUEST)));
- text_image_.reset();
- SchedulePaint();
}
+ // Repaint because the font may have changed.
+ text_image_.reset();
+ SchedulePaint();
}
} // namespace chromeos
diff --git a/ui/base/resource/resource_bundle.cc b/ui/base/resource/resource_bundle.cc
index af615c0..56b3761 100644
--- a/ui/base/resource/resource_bundle.cc
+++ b/ui/base/resource/resource_bundle.cc
@@ -161,7 +161,10 @@ RefCountedStaticMemory* ResourceBundle::LoadDataResourceBytes(
}
const gfx::Font& ResourceBundle::GetFont(FontStyle style) {
- LoadFontsIfNecessary();
+ {
+ base::AutoLock lock_scope(*lock_);
+ LoadFontsIfNecessary();
+ }
switch (style) {
case BoldFont:
return *bold_font_;
@@ -178,6 +181,12 @@ const gfx::Font& ResourceBundle::GetFont(FontStyle style) {
}
}
+void ResourceBundle::ReloadFonts() {
+ base::AutoLock lock_scope(*lock_);
+ base_font_.reset();
+ LoadFontsIfNecessary();
+}
+
ResourceBundle::ResourceBundle()
: lock_(new base::Lock),
resources_data_(NULL),
@@ -191,7 +200,7 @@ void ResourceBundle::FreeImages() {
}
void ResourceBundle::LoadFontsIfNecessary() {
- base::AutoLock lock_scope(*lock_);
+ lock_->AssertAcquired();
if (!base_font_.get()) {
base_font_.reset(new gfx::Font());
diff --git a/ui/base/resource/resource_bundle.h b/ui/base/resource/resource_bundle.h
index aa3d306..d973103 100644
--- a/ui/base/resource/resource_bundle.h
+++ b/ui/base/resource/resource_bundle.h
@@ -134,6 +134,10 @@ class ResourceBundle {
// Returns the font for the specified style.
const gfx::Font& GetFont(FontStyle style);
+ // Resets and reloads the cached fonts. This is useful when the fonts of the
+ // system have changed, for example, when the locale has changed.
+ void ReloadFonts();
+
#if defined(OS_WIN)
// Loads and returns an icon from the app module.
HICON LoadThemeIcon(int icon_id);
diff --git a/ui/gfx/platform_font_gtk.cc b/ui/gfx/platform_font_gtk.cc
index ac0831f..5ccc7c5 100644
--- a/ui/gfx/platform_font_gtk.cc
+++ b/ui/gfx/platform_font_gtk.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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.
@@ -200,6 +200,12 @@ double PlatformFontGtk::underline_thickness() const {
////////////////////////////////////////////////////////////////////////////////
// PlatformFontGtk, PlatformFont implementation:
+// static
+void PlatformFontGtk::ReloadDefaultFont() {
+ delete default_font_;
+ default_font_ = NULL;
+}
+
Font PlatformFontGtk::DeriveFont(int size_delta, int style) const {
// If the delta is negative, if must not push the size below 1
if (size_delta < 0)
diff --git a/ui/gfx/platform_font_gtk.h b/ui/gfx/platform_font_gtk.h
index 7f7a4ec..2159752 100644
--- a/ui/gfx/platform_font_gtk.h
+++ b/ui/gfx/platform_font_gtk.h
@@ -27,6 +27,11 @@ class PlatformFontGtk : public PlatformFont {
// pango_font_description_free().
static PangoFontDescription* PangoFontFromGfxFont(const gfx::Font& gfx_font);
+ // Resets and reloads the cached system font used by the default constructor.
+ // This function is useful when the system font has changed, for example, when
+ // the locale has changed.
+ static void ReloadDefaultFont();
+
// Position as an offset from the height of the drawn text, used to draw
// an underline. This is a negative number, so the underline would be
// drawn at y + height + underline_position;