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

Unified 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, 8 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/clipboard/clipboard_unittest.cc ('k') | ui/base/win/hwnd_subclass.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/base/win/hwnd_subclass.h
===================================================================
--- ui/base/win/hwnd_subclass.h (revision 0)
+++ ui/base/win/hwnd_subclass.h (revision 0)
@@ -0,0 +1,58 @@
+// 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.
+
+#ifndef UI_BASE_WIN_HWND_SUBCLASS_H_
+#define UI_BASE_WIN_HWND_SUBCLASS_H_
+#pragma once
+
+#include <windows.h>
+
+#include "base/gtest_prod_util.h"
+#include "base/memory/scoped_ptr.h"
+#include "ui/base/ui_export.h"
+#include "ui/base/view_prop.h"
+
+namespace ui {
+
+// Classes implementing this interface get the opportunity to handle and consume
+// messages before they are sent to their target HWND.
+class UI_EXPORT HWNDMessageFilter {
+ public:
+ virtual ~HWNDMessageFilter() {}
+
+ // A derived class overrides this method to perform filtering of the messages
+ // before the |original_wnd_proc_| sees them. Return true to consume the
+ // message and prevent |original_wnd_proc_| from seeing them at all, false to
+ // allow it to process them.
+ virtual bool FilterMessage(HWND hwnd,
+ UINT message,
+ WPARAM w_param,
+ LPARAM l_param,
+ LRESULT* l_result) = 0;
+};
+
+// An object that instance-subclasses a window. If the window has already been
+// instance-subclassed, that subclassing is lost.
+class UI_EXPORT HWNDSubclass {
+ public:
+ explicit HWNDSubclass(HWND target);
+ ~HWNDSubclass();
+
+ // HWNDSubclass takes ownership of the filter.
+ void SetFilter(HWNDMessageFilter* filter);
+
+ LRESULT OnWndProc(HWND hwnd, UINT message, WPARAM w_param, LPARAM l_param);
+
+ private:
+ HWND target_;
+ scoped_ptr<HWNDMessageFilter> filter_;
+ WNDPROC original_wnd_proc_;
+ ui::ViewProp prop_;
+
+ DISALLOW_COPY_AND_ASSIGN(HWNDSubclass);
+};
+
+} // namespace ui
+
+#endif // UI_BASE_WIN_HWND_SUBCLASS_H_
Property changes on: ui\base\win\hwnd_subclass.h
___________________________________________________________________
Added: svn:eol-style
+ LF
« no previous file with comments | « ui/base/clipboard/clipboard_unittest.cc ('k') | ui/base/win/hwnd_subclass.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698