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

Side by Side Diff: ui/gfx/font_smoothing_win.cc

Issue 9370026: Respect the system ClearType setting in RenderTextWin. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 8 years, 10 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 | Annotate | Revision Log
OLDNEW
(Empty)
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 "ui/gfx/font_smoothing_win.h"
6
7 #include "base/bind.h"
8 #include "base/callback.h"
9 #include "base/memory/singleton.h"
10 #include "ui/base/win/singleton_hwnd.h"
11
12 namespace {
13
14 // Helper class to cache font smoothing settings and listen for WM_SETTINGCHANGE
15 // notifications to re-query them from the system.
16 class CachedFontSmoothingSettings {
17 public:
18 // Singleton getter.
19 static CachedFontSmoothingSettings* GetInstance();
20
21 // Returns the cached screen compatible DC or creates one if needed.
22 void GetFontSmoothingSettings(bool* smoothing_enabled,
23 bool* cleartype_enabled);
24
25 // Listener for WM_SETTINGCHANGE notifications.
26 void OnWndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam);
27
28 private:
29 friend struct DefaultSingletonTraits<CachedFontSmoothingSettings>;
30
31 CachedFontSmoothingSettings();
32 ~CachedFontSmoothingSettings();
33
34 // Queries the font settings from the system.
35 void QueryFontSettings();
36
37 // Indicates whether the listener has been registered with the SingletonHwnd.
38 bool listener_registered_;
39
40 // Indicates that font smoothing is enabled.
41 bool smoothing_enabled_;
42
43 // Indicates that the ClearType font smoothing is enabled.
44 bool cleartype_enabled_;
45
46 DISALLOW_COPY_AND_ASSIGN(CachedFontSmoothingSettings);
47 };
48
49 CachedFontSmoothingSettings::CachedFontSmoothingSettings()
50 : listener_registered_(false),
51 smoothing_enabled_(false),
52 cleartype_enabled_(false) {
53 }
54
55 CachedFontSmoothingSettings::~CachedFontSmoothingSettings() {
56 }
57
58 // static
59 CachedFontSmoothingSettings* CachedFontSmoothingSettings::GetInstance() {
60 return Singleton<CachedFontSmoothingSettings>::get();
61 }
62
63 void CachedFontSmoothingSettings::OnWndProc(HWND hwnd,
64 UINT message,
65 WPARAM wparam,
66 LPARAM lparam) {
67 if (message == WM_SETTINGCHANGE)
68 QueryFontSettings();
69 }
70
71 // Returns the cached screen compatible DC or creates one if needed.
msw 2012/02/15 00:33:16 This comment just seems incorrect.
asvitkine_google 2012/02/15 15:10:44 Oops. Fixed.
72 void CachedFontSmoothingSettings::GetFontSmoothingSettings(
73 bool* smoothing_enabled,
74 bool* cleartype_enabled) {
75 if (!listener_registered_) {
76 ui::WndProcCallback callback =
77 base::Bind(&CachedFontSmoothingSettings::OnWndProc,
78 base::Unretained(this));
79 ui::SingletonHwnd::GetInstance()->RegisterListener(callback);
80 QueryFontSettings();
81 listener_registered_ = true;
msw 2012/02/15 00:33:16 Bad advice?: I don't expect re-entrance here, but
asvitkine_google 2012/02/15 15:10:44 If folks are calling this on different threads, th
82 }
83 *smoothing_enabled = smoothing_enabled_;
84 *cleartype_enabled = cleartype_enabled_;
85 }
86
87 void CachedFontSmoothingSettings::QueryFontSettings() {
88 smoothing_enabled_ = false;
89 cleartype_enabled_ = false;
90
91 BOOL enabled;
msw 2012/02/15 00:33:16 You should explicitly init this local.
asvitkine_google 2012/02/15 15:10:44 Done.
92 if (SystemParametersInfo(SPI_GETFONTSMOOTHING, 0, &enabled, 0) && enabled) {
msw 2012/02/15 00:33:16 Should we explicitly check for the BOOL to != 0?
asvitkine_google 2012/02/15 15:10:44 If we treat it like 'bool', we shouldn't..
93 smoothing_enabled_ = true;
94
95 UINT smooth_type;
msw 2012/02/15 00:33:16 You should explicitly init this local.
asvitkine_google 2012/02/15 15:10:44 Done.
96 if (SystemParametersInfo(SPI_GETFONTSMOOTHINGTYPE, 0, &smooth_type, 0))
97 cleartype_enabled_ = (smooth_type == FE_FONTSMOOTHINGCLEARTYPE);
98 }
99 }
100
101 } // namespace
102
103 namespace gfx {
104
105 void GetCachedFontSmoothingSettings(bool* smoothing_enabled,
106 bool* cleartype_enabled) {
107 CachedFontSmoothingSettings::GetInstance()->GetFontSmoothingSettings(
108 smoothing_enabled, cleartype_enabled);
msw 2012/02/15 00:33:16 These params should each be on their own lines.
asvitkine_google 2012/02/15 15:10:44 Done.
109 }
110
111 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698