Chromium Code Reviews
|
| OLD | NEW |
|---|---|
| (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/hwnd_subclass.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "ui/base/win/hwnd_util.h" | |
| 9 | |
| 10 namespace { | |
| 11 const char* kHWNDSubclassKey = "__UI_BASE_WIN_HWND_SUBCLASS_PROC__"; | |
|
tfarina
2012/04/27 21:06:02
nit: const char kFoo[] = "...";
| |
| 12 | |
| 13 LRESULT CALLBACK WndProc(HWND hwnd, | |
| 14 UINT message, | |
| 15 WPARAM w_param, | |
| 16 LPARAM l_param) { | |
| 17 ui::HWNDSubclass* wrapped_wnd_proc = | |
| 18 reinterpret_cast<ui::HWNDSubclass*>( | |
| 19 ui::ViewProp::GetValue(hwnd, kHWNDSubclassKey)); | |
| 20 return wrapped_wnd_proc ? wrapped_wnd_proc->OnWndProc(hwnd, | |
|
tfarina
2012/04/27 21:06:02
nit: if you move wrapped_wnd_proc->OnWndProc(...)
| |
| 21 message, | |
| 22 w_param, | |
| 23 l_param) : 0; | |
|
cpu_(ooo_6.6-7.5)
2012/04/27 21:07:12
so when the HWNDSubclass is destroyed, the message
| |
| 24 } | |
| 25 | |
| 26 } | |
|
tfarina
2012/04/27 21:06:02
nit: // namespace
| |
| 27 | |
| 28 namespace ui { | |
| 29 | |
| 30 HWNDSubclass::HWNDSubclass(HWND target) | |
| 31 : target_(target), | |
| 32 original_wnd_proc_(GetCurrentWndProc(target)), | |
| 33 ALLOW_THIS_IN_INITIALIZER_LIST(prop_(target, kHWNDSubclassKey, this)) { | |
| 34 ui::SetWindowProc(target_, &WndProc); | |
| 35 } | |
| 36 | |
| 37 HWNDSubclass::~HWNDSubclass() { | |
| 38 } | |
| 39 | |
| 40 void HWNDSubclass::SetFilter(HWNDMessageFilter* filter) { | |
| 41 filter_.reset(filter); | |
| 42 } | |
| 43 | |
| 44 LRESULT HWNDSubclass::OnWndProc(HWND hwnd, | |
| 45 UINT message, | |
| 46 WPARAM w_param, | |
| 47 LPARAM l_param) { | |
| 48 if (filter_.get()) { | |
| 49 LRESULT l_result = 0; | |
| 50 if (filter_->FilterMessage(hwnd, message, w_param, l_param, &l_result)) | |
| 51 return l_result; | |
| 52 } | |
| 53 | |
| 54 // In most cases, |original_wnd_proc_| will take care of calling | |
| 55 // DefWindowProc. | |
| 56 return CallWindowProc(original_wnd_proc_, hwnd, message, w_param, l_param); | |
| 57 } | |
| 58 | |
| 59 // static | |
| 60 WNDPROC HWNDSubclass::GetCurrentWndProc(HWND target) { | |
|
tfarina
2012/04/27 21:06:02
nit: Worth moving this to unnamed namespace instea
| |
| 61 return reinterpret_cast<WNDPROC>(GetWindowLong(target, GWL_WNDPROC)); | |
| 62 } | |
| 63 | |
| 64 } // namespace ui | |
| OLD | NEW |