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

Unified Diff: ui/base/win/singleton_hwnd.cc

Issue 9359019: Split the singleton hwnd from screen_compatible_dc_win.cc. (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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/base/win/singleton_hwnd.h ('k') | ui/gfx/screen_compatible_dc_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/base/win/singleton_hwnd.cc
===================================================================
--- ui/base/win/singleton_hwnd.cc (revision 0)
+++ ui/base/win/singleton_hwnd.cc (revision 0)
@@ -0,0 +1,84 @@
+// Copyright (c) 2012 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.
+
+#include "ui/base/win/singleton_hwnd.h"
+
+#include "base/bind.h"
+#include "base/callback.h"
+#include "base/logging.h"
+#include "base/win/wrapped_window_proc.h"
+#include "ui/base/win/hwnd_util.h"
+
+namespace {
+
+// Windows class name to use for the listener window.
+const wchar_t kWindowClassName[] = L"SingletonHwnd";
cpu_(ooo_6.6-7.5) 2012/02/09 21:58:37 too short. How about Chrome.SigletonHwnd or Chrome
+
+// Windows callback for listening for WM_* messages.
+LRESULT CALLBACK ListenerWindowProc(HWND hwnd,
+ UINT message,
+ WPARAM wparam,
+ LPARAM lparam) {
+ ui::SingletonHwnd::GetInstance()->OnWndProc(hwnd, message, wparam, lparam);
+ return ::DefWindowProc(hwnd, message, wparam, lparam);
cpu_(ooo_6.6-7.5) 2012/02/09 21:58:37 hmm, kind of weird that you can get to act on the
+}
+
+// Creates a listener window to receive WM_* messages.
+HWND CreateListenerWindow() {
+ HINSTANCE hinst = 0;
+ if (!::GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,
+ reinterpret_cast<char*>(&ListenerWindowProc),
+ &hinst)) {
+ NOTREACHED();
+ }
+
+ WNDCLASSEX wc = {0};
+ wc.cbSize = sizeof(wc);
+ wc.lpfnWndProc = base::win::WrappedWindowProc<ListenerWindowProc>;
+ wc.hInstance = hinst;
+ wc.lpszClassName = kWindowClassName;
+ ATOM clazz = ::RegisterClassEx(&wc);
cpu_(ooo_6.6-7.5) 2012/02/09 21:58:37 I can smell the copy and paste :) please use var n
+ DCHECK(clazz);
+
+ return ::CreateWindow(MAKEINTATOM(clazz), 0, 0, 0, 0, 0, 0, HWND_MESSAGE, 0,
+ hinst, 0);
cpu_(ooo_6.6-7.5) 2012/02/09 21:58:37 wait, this is also a message only window.. ?? you
+}
+
+} // namespace
+
+namespace ui {
+
+// static
+SingletonHwnd* SingletonHwnd::GetInstance() {
+ return Singleton<SingletonHwnd>::get();
+}
+
+void SingletonHwnd::RegisterListener(WndProcCallback& callback) {
+ if (!listener_window_) {
+ listener_window_ = CreateListenerWindow();
+ ui::CheckWindowCreated(listener_window_);
+ }
+ listeners_.push_back(callback);
+}
+
+void SingletonHwnd::OnWndProc(HWND hwnd,
+ UINT message,
+ WPARAM wparam,
+ LPARAM lparam) {
+ for (size_t i = 0; i < listeners_.size(); ++i)
+ listeners_[i].Run(hwnd, message, wparam, lparam);
+}
+
+SingletonHwnd::SingletonHwnd()
+ : listener_window_(NULL) {
+}
+
+SingletonHwnd::~SingletonHwnd() {
+ if (listener_window_) {
+ ::DestroyWindow(listener_window_);
+ ::UnregisterClass(kWindowClassName, GetModuleHandle(NULL));
+ }
+}
+
+} // namespace ui
« no previous file with comments | « ui/base/win/singleton_hwnd.h ('k') | ui/gfx/screen_compatible_dc_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698