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

Side by Side Diff: ui/base/win/hwnd_subclass.h

Issue 10256008: Adds a class that makes it easy to subclass a HWND and filter messages sent to it. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 7 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
Property Changes:
Added: svn:eol-style
+ LF
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 #ifndef UI_BASE_WIN_HWND_SUBCLASS_H_
6 #define UI_BASE_WIN_HWND_SUBCLASS_H_
7 #pragma once
8
9 #include <windows.h>
10
11 #include "base/gtest_prod_util.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "ui/base/ui_export.h"
14 #include "ui/base/view_prop.h"
15 #include "ui/gfx/native_widget_types.h"
tfarina 2012/04/27 21:06:02 nit: do you really need this include?
16
17 namespace ui {
18
19 // Classes implementing this interface get the opportunity to handle and consume
20 // messages before they are sent to their target HWND.
21 class UI_EXPORT HWNDMessageFilter {
22 public:
23 virtual ~HWNDMessageFilter() {}
24
25 // A derived class overrides this method to perform filtering of the messages
26 // before the |original_wnd_proc_| sees them. Return true to consume the
27 // message and prevent |original_wnd_proc_| from seeing them at all, false to
28 // allow it to process them.
29 virtual bool FilterMessage(HWND hwnd,
30 UINT message,
31 WPARAM w_param,
32 LPARAM l_param,
33 LRESULT* l_result) = 0;
34 };
35
36 // An object that instance-subclasses a window. If the window has already been
37 // instance-subclassed, that subclassing is lost.
38 class UI_EXPORT HWNDSubclass {
39 public:
40 explicit HWNDSubclass(HWND target);
41 ~HWNDSubclass();
42
43 // HWNDSubclass takes ownership of the filter.
44 void SetFilter(HWNDMessageFilter* filter);
45
46 LRESULT OnWndProc(HWND hwnd, UINT message, WPARAM w_param, LPARAM l_param);
47
48 private:
49 FRIEND_TEST_ALL_PREFIXES(HWNDSubclassTest, Filtering);
50
51 static WNDPROC GetCurrentWndProc(HWND target);
52
53 HWND target_;
54 scoped_ptr<HWNDMessageFilter> filter_;
55 WNDPROC original_wnd_proc_;
56 ui::ViewProp prop_;
57
58 DISALLOW_COPY_AND_ASSIGN(HWNDSubclass);
59 };
60
61 } // namespace ui
62
63 #endif // UI_BASE_WIN_HWND_SUBCLASS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698