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

Side by Side Diff: ui/base/win/singleton_hwnd.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/base/win/singleton_hwnd.h"
6
7 #include "base/bind.h"
8 #include "base/callback.h"
9 #include "base/logging.h"
10 #include "base/memory/singleton.h"
11 #include "base/process_util.h"
12 #include "base/win/wrapped_window_proc.h"
13 #include "ui/base/win/hwnd_util.h"
14
15 namespace {
16
17 // Windows class name to use for the listener window.
18 const wchar_t kWindowClassName[] = L"Chrome_SingletonHwnd";
19
20 // Windows callback for listening for WM_* messages.
21 LRESULT CALLBACK ListenerWindowProc(HWND hwnd,
22 UINT message,
23 WPARAM wparam,
24 LPARAM lparam) {
25 ui::SingletonHwnd::GetInstance()->OnWndProc(hwnd, message, wparam, lparam);
26 return ::DefWindowProc(hwnd, message, wparam, lparam);
27 }
28
29 // Creates a listener window to receive WM_* messages.
30 HWND CreateListenerWindow() {
31 HINSTANCE hinst = base::GetModuleFromAddress(&ListenerWindowProc);
32 WNDCLASSEX wc = {0};
33 wc.cbSize = sizeof(wc);
34 wc.lpfnWndProc = base::win::WrappedWindowProc<ListenerWindowProc>;
35 wc.hInstance = hinst;
36 wc.lpszClassName = kWindowClassName;
37 ATOM window_class = ::RegisterClassEx(&wc);
38 DCHECK(window_class);
39
40 return ::CreateWindow(MAKEINTATOM(window_class), 0, 0, 0, 0, 0, 0,
41 HWND_MESSAGE, 0, hinst, 0);
cpu_(ooo_6.6-7.5) 2012/02/14 20:53:30 same comment: I don't think message windows get th
42 }
43
44 } // namespace
45
46 namespace ui {
47
48 // static
49 SingletonHwnd* SingletonHwnd::GetInstance() {
50 return Singleton<SingletonHwnd>::get();
51 }
52
53 void SingletonHwnd::RegisterListener(const WndProcCallback& callback) {
54 if (!listener_window_) {
55 listener_window_ = CreateListenerWindow();
56 ui::CheckWindowCreated(listener_window_);
57 }
58 listeners_.push_back(callback);
59 }
60
61 void SingletonHwnd::OnWndProc(HWND hwnd,
62 UINT message,
63 WPARAM wparam,
64 LPARAM lparam) {
65 for (size_t i = 0; i < listeners_.size(); ++i)
66 listeners_[i].Run(hwnd, message, wparam, lparam);
67 }
68
69 SingletonHwnd::SingletonHwnd()
70 : listener_window_(NULL) {
71 }
72
73 SingletonHwnd::~SingletonHwnd() {
74 if (listener_window_) {
75 ::DestroyWindow(listener_window_);
76 ::UnregisterClass(kWindowClassName, GetModuleHandle(NULL));
77 }
78 }
79
80 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698