diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-10 01:07:27 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-10 01:07:27 +0000 |
commit | 9b2ab5910c58603ec655bb613bec7596e732f87b (patch) | |
tree | 36ffb5af12e8f97cda70d58bc2806e11e88e3d5b /views/widget | |
parent | 5ea0531c8ca788207d7e5c2b5c95a9127916a73a (diff) | |
download | chromium_src-9b2ab5910c58603ec655bb613bec7596e732f87b.zip chromium_src-9b2ab5910c58603ec655bb613bec7596e732f87b.tar.gz chromium_src-9b2ab5910c58603ec655bb613bec7596e732f87b.tar.bz2 |
Adds the ability for classes other than native control to process
messages bounced to the parent and wires it up for autocompleteedit,
which I'm going to need shortly.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/4637002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@65612 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/widget')
-rw-r--r-- | views/widget/child_window_message_processor.cc | 27 | ||||
-rw-r--r-- | views/widget/child_window_message_processor.h | 50 | ||||
-rw-r--r-- | views/widget/widget_win.cc | 43 |
3 files changed, 98 insertions, 22 deletions
diff --git a/views/widget/child_window_message_processor.cc b/views/widget/child_window_message_processor.cc new file mode 100644 index 0000000..a3b578e --- /dev/null +++ b/views/widget/child_window_message_processor.cc @@ -0,0 +1,27 @@ +// Copyright (c) 2010 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 "views/widget/child_window_message_processor.h" + +#include "app/win/scoped_prop.h" + +namespace views { + +static const wchar_t* kChildWindowKey = L"__CHILD_WINDOW_MESSAGE_PROCESSOR__"; + +// static +app::win::ScopedProp* ChildWindowMessageProcessor::Register( + HWND hwnd, + ChildWindowMessageProcessor* processor) { + DCHECK(processor); + return new app::win::ScopedProp(hwnd, kChildWindowKey, processor); +} + +// static +ChildWindowMessageProcessor* ChildWindowMessageProcessor::Get(HWND hwnd) { + return reinterpret_cast<ChildWindowMessageProcessor*>( + ::GetProp(hwnd, kChildWindowKey)); +} + +} // namespace diff --git a/views/widget/child_window_message_processor.h b/views/widget/child_window_message_processor.h new file mode 100644 index 0000000..7d4e63e --- /dev/null +++ b/views/widget/child_window_message_processor.h @@ -0,0 +1,50 @@ +// Copyright (c) 2010 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 VIEWS_WIDGET_CHILD_WINDOW_MESSAGE_PROCESSOR_H_ +#define VIEWS_WIDGET_CHILD_WINDOW_MESSAGE_PROCESSOR_H_ +#pragma once + +#include <windows.h> + +namespace app { +namespace win { +class ScopedProp; +} +} + +namespace views { + +// Windows sends a handful of messages to the parent window rather than the +// window itself. For example, selection changes of a rich edit (EN_SELCHANGE) +// are sent to the parent, not the window. Typically such message are best +// dealt with by the window rather than the parent. WidgetWin allows for +// registering a ChildWindowMessageProcessor to handle such messages. +class ChildWindowMessageProcessor { + public: + // Registers |processor| for |hwnd|. The caller takes ownership of the + // returned object. + static app::win::ScopedProp* Register(HWND hwnd, + ChildWindowMessageProcessor* processor); + + // Returns the ChildWindowMessageProcessor for |hwnd|, NULL if there isn't + // one. + static ChildWindowMessageProcessor* Get(HWND hwnd); + + // Invoked for any messages that are sent to the parent and originated from + // the HWND this ChildWindowMessageProcessor was registered for. Returns true + // if the message was handled with a valid result in |result|. Returns false + // if the message was not handled. + virtual bool ProcessMessage(UINT message, + WPARAM w_param, + LPARAM l_param, + LRESULT* result) = 0; + + protected: + virtual ~ChildWindowMessageProcessor() {} +}; + +} // namespace views + +#endif // VIEWS_WIDGET_CHILD_WINDOW_MESSAGE_PROCESSOR_H_ diff --git a/views/widget/widget_win.cc b/views/widget/widget_win.cc index bb6ca8d..77cf8c1 100644 --- a/views/widget/widget_win.cc +++ b/views/widget/widget_win.cc @@ -19,6 +19,7 @@ #include "views/focus/focus_util_win.h" #include "views/views_delegate.h" #include "views/widget/aero_tooltip_manager.h" +#include "views/widget/child_window_message_processor.h" #include "views/widget/default_theme_provider.h" #include "views/widget/drop_target_win.h" #include "views/widget/root_view.h" @@ -41,11 +42,6 @@ RootView* GetRootViewForHWND(HWND hwnd) { return reinterpret_cast<RootView*>(::GetProp(hwnd, kRootViewWindowProperty)); } -NativeControlWin* GetNativeControlWinForHWND(HWND hwnd) { - return reinterpret_cast<NativeControlWin*>( - GetProp(hwnd, NativeControlWin::kNativeControlWinKey)); -} - /////////////////////////////////////////////////////////////////////////////// // WidgetWin, public @@ -1173,7 +1169,9 @@ RootView* WidgetWin::GetFocusedViewRootView() { // Get the source HWND of the specified message. Depending on the message, the // source HWND is encoded in either the WPARAM or the LPARAM value. -HWND GetControlHWNDForMessage(UINT message, WPARAM w_param, LPARAM l_param) { +static HWND GetControlHWNDForMessage(UINT message, + WPARAM w_param, + LPARAM l_param) { // Each of the following messages can be sent by a child HWND and must be // forwarded to its associated NativeControlWin for handling. switch (message) { @@ -1196,25 +1194,26 @@ HICON WidgetWin::GetDefaultWindowIcon() const { return NULL; } -// Some messages may be sent to us by a child HWND managed by -// NativeControlWin. If this is the case, this function will forward those -// messages on to the object associated with the source HWND and return true, -// in which case the window procedure must not do any further processing of -// the message. If there is no associated NativeControlWin, the return value -// will be false and the WndProc can continue processing the message normally. -// |l_result| contains the result of the message processing by the control and -// must be returned by the WndProc if the return value is true. -bool ProcessNativeControlMessage(UINT message, - WPARAM w_param, - LPARAM l_param, - LRESULT* l_result) { +// Some messages may be sent to us by a child HWND. If this is the case, this +// function will forward those messages on to the object associated with the +// source HWND and return true, in which case the window procedure must not do +// any further processing of the message. If there is no associated +// ChildWindowMessageProcessor, the return value will be false and the WndProc +// can continue processing the message normally. |l_result| contains the result +// of the message processing by the control and must be returned by the WndProc +// if the return value is true. +static bool ProcessChildWindowMessage(UINT message, + WPARAM w_param, + LPARAM l_param, + LRESULT* l_result) { *l_result = 0; HWND control_hwnd = GetControlHWNDForMessage(message, w_param, l_param); if (IsWindow(control_hwnd)) { - NativeControlWin* wrapper = GetNativeControlWinForHWND(control_hwnd); - if (wrapper) - return wrapper->ProcessMessage(message, w_param, l_param, l_result); + ChildWindowMessageProcessor* processor = + ChildWindowMessageProcessor::Get(control_hwnd); + if (processor) + return processor->ProcessMessage(message, w_param, l_param, l_result); } return false; @@ -1227,7 +1226,7 @@ LRESULT WidgetWin::OnWndProc(UINT message, WPARAM w_param, LPARAM l_param) { // First allow messages sent by child controls to be processed directly by // their associated views. If such a view is present, it will handle the // message *instead of* this WidgetWin. - if (ProcessNativeControlMessage(message, w_param, l_param, &result)) + if (ProcessChildWindowMessage(message, w_param, l_param, &result)) return result; // Otherwise we handle everything else. |