Chromium Code Reviews| Index: ui/base/win/hwnd_subclass.cc |
| =================================================================== |
| --- ui/base/win/hwnd_subclass.cc (revision 0) |
| +++ ui/base/win/hwnd_subclass.cc (revision 0) |
| @@ -0,0 +1,64 @@ |
| +// 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/hwnd_subclass.h" |
| + |
| +#include "base/logging.h" |
| +#include "ui/base/win/hwnd_util.h" |
| + |
| +namespace { |
| +const char* kHWNDSubclassKey = "__UI_BASE_WIN_HWND_SUBCLASS_PROC__"; |
|
tfarina
2012/04/27 21:06:02
nit: const char kFoo[] = "...";
|
| + |
| +LRESULT CALLBACK WndProc(HWND hwnd, |
| + UINT message, |
| + WPARAM w_param, |
| + LPARAM l_param) { |
| + ui::HWNDSubclass* wrapped_wnd_proc = |
| + reinterpret_cast<ui::HWNDSubclass*>( |
| + ui::ViewProp::GetValue(hwnd, kHWNDSubclassKey)); |
| + return wrapped_wnd_proc ? wrapped_wnd_proc->OnWndProc(hwnd, |
|
tfarina
2012/04/27 21:06:02
nit: if you move wrapped_wnd_proc->OnWndProc(...)
|
| + message, |
| + w_param, |
| + l_param) : 0; |
|
cpu_(ooo_6.6-7.5)
2012/04/27 21:07:12
so when the HWNDSubclass is destroyed, the message
|
| +} |
| + |
| +} |
|
tfarina
2012/04/27 21:06:02
nit: // namespace
|
| + |
| +namespace ui { |
| + |
| +HWNDSubclass::HWNDSubclass(HWND target) |
| + : target_(target), |
| + original_wnd_proc_(GetCurrentWndProc(target)), |
| + ALLOW_THIS_IN_INITIALIZER_LIST(prop_(target, kHWNDSubclassKey, this)) { |
| + ui::SetWindowProc(target_, &WndProc); |
| +} |
| + |
| +HWNDSubclass::~HWNDSubclass() { |
| +} |
| + |
| +void HWNDSubclass::SetFilter(HWNDMessageFilter* filter) { |
| + filter_.reset(filter); |
| +} |
| + |
| +LRESULT HWNDSubclass::OnWndProc(HWND hwnd, |
| + UINT message, |
| + WPARAM w_param, |
| + LPARAM l_param) { |
| + if (filter_.get()) { |
| + LRESULT l_result = 0; |
| + if (filter_->FilterMessage(hwnd, message, w_param, l_param, &l_result)) |
| + return l_result; |
| + } |
| + |
| + // In most cases, |original_wnd_proc_| will take care of calling |
| + // DefWindowProc. |
| + return CallWindowProc(original_wnd_proc_, hwnd, message, w_param, l_param); |
| +} |
| + |
| +// static |
| +WNDPROC HWNDSubclass::GetCurrentWndProc(HWND target) { |
|
tfarina
2012/04/27 21:06:02
nit: Worth moving this to unnamed namespace instea
|
| + return reinterpret_cast<WNDPROC>(GetWindowLong(target, GWL_WNDPROC)); |
| +} |
| + |
| +} // namespace ui |
| Property changes on: ui\base\win\hwnd_subclass.cc |
| ___________________________________________________________________ |
| Added: svn:eol-style |
| + LF |