This source file includes following definitions.
- GetInstance
- GetFontSmoothingSettings
- cleartype_enabled_
- OnWndProc
- QueryFontSettings
- GetCachedFontSmoothingSettings
#include "ui/gfx/font_smoothing_win.h"
#include "base/memory/singleton.h"
#include "ui/gfx/win/singleton_hwnd.h"
namespace {
class CachedFontSmoothingSettings : public gfx::SingletonHwnd::Observer {
public:
static CachedFontSmoothingSettings* GetInstance();
void GetFontSmoothingSettings(bool* smoothing_enabled,
bool* cleartype_enabled);
private:
friend struct DefaultSingletonTraits<CachedFontSmoothingSettings>;
CachedFontSmoothingSettings();
virtual ~CachedFontSmoothingSettings();
virtual void OnWndProc(HWND hwnd,
UINT message,
WPARAM wparam,
LPARAM lparam) OVERRIDE;
void QueryFontSettings();
bool observer_added_;
bool need_to_query_settings_;
bool smoothing_enabled_;
bool cleartype_enabled_;
DISALLOW_COPY_AND_ASSIGN(CachedFontSmoothingSettings);
};
CachedFontSmoothingSettings* CachedFontSmoothingSettings::GetInstance() {
return Singleton<CachedFontSmoothingSettings>::get();
}
void CachedFontSmoothingSettings::GetFontSmoothingSettings(
bool* smoothing_enabled,
bool* cleartype_enabled) {
if (need_to_query_settings_) {
QueryFontSettings();
need_to_query_settings_ = false;
}
if (!observer_added_) {
gfx::SingletonHwnd::GetInstance()->AddObserver(this);
observer_added_ = true;
}
*smoothing_enabled = smoothing_enabled_;
*cleartype_enabled = cleartype_enabled_;
}
CachedFontSmoothingSettings::CachedFontSmoothingSettings()
: observer_added_(false),
need_to_query_settings_(true),
smoothing_enabled_(false),
cleartype_enabled_(false) {
}
CachedFontSmoothingSettings::~CachedFontSmoothingSettings() {
}
void CachedFontSmoothingSettings::OnWndProc(HWND hwnd,
UINT message,
WPARAM wparam,
LPARAM lparam) {
if (message == WM_SETTINGCHANGE)
need_to_query_settings_ = true;
}
void CachedFontSmoothingSettings::QueryFontSettings() {
smoothing_enabled_ = false;
cleartype_enabled_ = false;
BOOL enabled = false;
if (SystemParametersInfo(SPI_GETFONTSMOOTHING, 0, &enabled, 0) && enabled) {
smoothing_enabled_ = true;
UINT smooth_type = 0;
if (SystemParametersInfo(SPI_GETFONTSMOOTHINGTYPE, 0, &smooth_type, 0))
cleartype_enabled_ = (smooth_type == FE_FONTSMOOTHINGCLEARTYPE);
}
}
}
namespace gfx {
void GetCachedFontSmoothingSettings(bool* smoothing_enabled,
bool* cleartype_enabled) {
CachedFontSmoothingSettings::GetInstance()->GetFontSmoothingSettings(
smoothing_enabled,
cleartype_enabled);
}
}