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

Side by Side Diff: app/l10n_util_win.cc

Issue 4139010: The UI language rather than the locale is now used to pick Chrome's language ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « app/l10n_util_win.h ('k') | base/base.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "app/l10n_util_win.h"
6
7 #include <windowsx.h>
8 #include <algorithm>
9 #include <iterator>
10
5 #include "app/l10n_util.h" 11 #include "app/l10n_util.h"
6
7 #include <algorithm>
8 #include <windowsx.h>
9
10 #include "app/l10n_util_win.h"
11 #include "base/i18n/rtl.h" 12 #include "base/i18n/rtl.h"
13 #include "base/lazy_instance.h"
12 #include "base/string_number_conversions.h" 14 #include "base/string_number_conversions.h"
15 #include "base/win/i18n.h"
13 #include "base/win/windows_version.h" 16 #include "base/win/windows_version.h"
14 #include "grit/app_locale_settings.h" 17 #include "grit/app_locale_settings.h"
15 18
16 namespace { 19 namespace {
17 20
18 void AdjustLogFont(const std::wstring& font_family, 21 void AdjustLogFont(const std::wstring& font_family,
19 double font_size_scaler, 22 double font_size_scaler,
20 LOGFONT* logfont) { 23 LOGFONT* logfont) {
21 DCHECK(font_size_scaler > 0); 24 DCHECK(font_size_scaler > 0);
22 font_size_scaler = std::max(std::min(font_size_scaler, 2.0), 0.7); 25 font_size_scaler = std::max(std::min(font_size_scaler, 2.0), 0.7);
(...skipping 22 matching lines...) Expand all
45 DWORD size_ret = GetTextFace(dc, LF_FACESIZE, actual_font_name); 48 DWORD size_ret = GetTextFace(dc, LF_FACESIZE, actual_font_name);
46 actual_font_name[LF_FACESIZE - 1] = 0; 49 actual_font_name[LF_FACESIZE - 1] = 0;
47 SelectObject(dc, oldFont); 50 SelectObject(dc, oldFont);
48 DeleteObject(hfont); 51 DeleteObject(hfont);
49 ReleaseDC(0, dc); 52 ReleaseDC(0, dc);
50 // We don't have to worry about East Asian fonts with locale-dependent 53 // We don't have to worry about East Asian fonts with locale-dependent
51 // names here. 54 // names here.
52 return wcscmp(font_name, actual_font_name) == 0; 55 return wcscmp(font_name, actual_font_name) == 0;
53 } 56 }
54 57
58 class OverrideLocaleHolder {
59 public:
60 OverrideLocaleHolder() {}
61 const std::vector<std::string>& value() const { return value_; }
62 void swap_value(std::vector<std::string>* override_value) {
63 value_.swap(*override_value);
64 }
65 private:
66 std::vector<std::string> value_;
67 DISALLOW_COPY_AND_ASSIGN(OverrideLocaleHolder);
68 };
69
70 base::LazyInstance<OverrideLocaleHolder>
71 override_locale_holder(base::LINKER_INITIALIZED);
72
55 } // namespace 73 } // namespace
56 74
57 namespace l10n_util { 75 namespace l10n_util {
58 76
59 int GetExtendedStyles() { 77 int GetExtendedStyles() {
60 return !base::i18n::IsRTL() ? 0 : WS_EX_LAYOUTRTL | WS_EX_RTLREADING; 78 return !base::i18n::IsRTL() ? 0 : WS_EX_LAYOUTRTL | WS_EX_RTLREADING;
61 } 79 }
62 80
63 int GetExtendedTooltipStyles() { 81 int GetExtendedTooltipStyles() {
64 return !base::i18n::IsRTL() ? 0 : WS_EX_LAYOUTRTL; 82 return !base::i18n::IsRTL() ? 0 : WS_EX_LAYOUTRTL;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 LOGFONT logfont; 158 LOGFONT logfont;
141 if (GetObject(GetWindowFont(hwnd), sizeof(logfont), &logfont)) { 159 if (GetObject(GetWindowFont(hwnd), sizeof(logfont), &logfont)) {
142 AdjustLogFont(ui_font_family, ui_font_size_scaler, &logfont); 160 AdjustLogFont(ui_font_family, ui_font_size_scaler, &logfont);
143 HFONT hfont = CreateFontIndirect(&logfont); 161 HFONT hfont = CreateFontIndirect(&logfont);
144 if (hfont) 162 if (hfont)
145 SetWindowFont(hwnd, hfont, FALSE); 163 SetWindowFont(hwnd, hfont, FALSE);
146 } 164 }
147 } 165 }
148 } 166 }
149 167
168 void OverrideLocaleWithUILanguageList() {
169 std::vector<std::wstring> ui_languages;
170 if (base::win::i18n::GetThreadPreferredUILanguageList(&ui_languages)) {
171 std::vector<std::string> ascii_languages;
172 ascii_languages.reserve(ui_languages.size());
173 std::transform(ui_languages.begin(), ui_languages.end(),
174 std::back_inserter(ascii_languages), &WideToASCII);
175 override_locale_holder.Get().swap_value(&ascii_languages);
176 } else {
177 NOTREACHED() << "Failed to determine the UI language for locale override.";
178 }
179 }
180
181 const std::vector<std::string>& GetLocaleOverrides() {
182 return override_locale_holder.Get().value();
183 }
184
150 } // namespace l10n_util 185 } // namespace l10n_util
OLDNEW
« no previous file with comments | « app/l10n_util_win.h ('k') | base/base.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698