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

Side by Side Diff: views/controls/native_control_win.cc

Issue 4637002: Adds the ability for classes other than native control to process (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/chrome
Patch Set: Tweaks Created 10 years, 1 month 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
« no previous file with comments | « views/controls/native_control_win.h ('k') | views/views.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "views/controls/native_control_win.h" 5 #include "views/controls/native_control_win.h"
6 6
7 #include <windowsx.h> 7 #include <windowsx.h>
8 8
9 #include "app/l10n_util_win.h" 9 #include "app/l10n_util_win.h"
10 #include "app/win/scoped_prop.h" 10 #include "app/win/scoped_prop.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/win_util.h" 12 #include "base/win_util.h"
13 #include "views/focus/focus_manager.h" 13 #include "views/focus/focus_manager.h"
14 14
15 namespace views { 15 namespace views {
16 16
17 // static 17 static const wchar_t* kNativeControlWinKey = L"__NATIVE_CONTROL_WIN__";
18 const wchar_t* NativeControlWin::kNativeControlWinKey =
19 L"__NATIVE_CONTROL_WIN__";
20 18
21 //////////////////////////////////////////////////////////////////////////////// 19 ////////////////////////////////////////////////////////////////////////////////
22 // NativeControlWin, public: 20 // NativeControlWin, public:
23 21
24 NativeControlWin::NativeControlWin() { 22 NativeControlWin::NativeControlWin() {
25 } 23 }
26 24
27 NativeControlWin::~NativeControlWin() { 25 NativeControlWin::~NativeControlWin() {
28 HWND hwnd = native_view(); 26 HWND hwnd = native_view();
29 if (hwnd) { 27 if (hwnd) {
30 // Destroy the hwnd if it still exists. Otherwise we won't have shut things 28 // Destroy the hwnd if it still exists. Otherwise we won't have shut things
31 // down correctly, leading to leaking and crashing if another message 29 // down correctly, leading to leaking and crashing if another message
32 // comes in for the hwnd. 30 // comes in for the hwnd.
33 Detach(); 31 Detach();
34 DestroyWindow(hwnd); 32 DestroyWindow(hwnd);
35 } 33 }
36 } 34 }
37 35
38 bool NativeControlWin::ProcessMessage(UINT message, WPARAM w_param, 36 bool NativeControlWin::ProcessMessage(UINT message,
39 LPARAM l_param, LRESULT* result) { 37 WPARAM w_param,
38 LPARAM l_param,
39 LRESULT* result) {
40 switch (message) { 40 switch (message) {
41 case WM_CONTEXTMENU: 41 case WM_CONTEXTMENU:
42 ShowContextMenu(gfx::Point(GET_X_LPARAM(l_param), GET_Y_LPARAM(l_param))); 42 ShowContextMenu(gfx::Point(GET_X_LPARAM(l_param), GET_Y_LPARAM(l_param)));
43 *result = 0; 43 *result = 0;
44 return true; 44 return true;
45 case WM_CTLCOLORBTN: 45 case WM_CTLCOLORBTN:
46 case WM_CTLCOLORSTATIC: 46 case WM_CTLCOLORSTATIC:
47 *result = GetControlColor(message, reinterpret_cast<HDC>(w_param), 47 *result = GetControlColor(message, reinterpret_cast<HDC>(w_param),
48 native_view()); 48 native_view());
49 return true; 49 return true;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 123
124 if (location.x() == -1 && location.y() == -1) 124 if (location.x() == -1 && location.y() == -1)
125 View::ShowContextMenu(GetKeyboardContextMenuLocation(), false); 125 View::ShowContextMenu(GetKeyboardContextMenuLocation(), false);
126 else 126 else
127 View::ShowContextMenu(location, true); 127 View::ShowContextMenu(location, true);
128 } 128 }
129 129
130 void NativeControlWin::NativeControlCreated(HWND native_control) { 130 void NativeControlWin::NativeControlCreated(HWND native_control) {
131 // Associate this object with the control's HWND so that WidgetWin can find 131 // Associate this object with the control's HWND so that WidgetWin can find
132 // this object when it receives messages from it. 132 // this object when it receives messages from it.
133 prop_.reset( 133 props_.push_back(
134 new app::win::ScopedProp(native_control, kNativeControlWinKey, this)); 134 new app::win::ScopedProp(native_control, kNativeControlWinKey, this));
135 props_.push_back(ChildWindowMessageProcessor::Register(native_control, this));
135 136
136 // Subclass so we get WM_KEYDOWN and WM_SETFOCUS messages. 137 // Subclass so we get WM_KEYDOWN and WM_SETFOCUS messages.
137 original_wndproc_ = 138 original_wndproc_ =
138 win_util::SetWindowProc(native_control, 139 win_util::SetWindowProc(native_control,
139 &NativeControlWin::NativeControlWndProc); 140 &NativeControlWin::NativeControlWndProc);
140 141
141 Attach(native_control); 142 Attach(native_control);
142 // native_view() is now valid. 143 // native_view() is now valid.
143 144
144 // Update the newly created HWND with any resident enabled state. 145 // Update the newly created HWND with any resident enabled state.
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 return 0; 205 return 0;
205 } else if (message == WM_SETFOCUS) { 206 } else if (message == WM_SETFOCUS) {
206 // Let the focus manager know that the focus changed. 207 // Let the focus manager know that the focus changed.
207 FocusManager* focus_manager = native_control->GetFocusManager(); 208 FocusManager* focus_manager = native_control->GetFocusManager();
208 if (focus_manager) { 209 if (focus_manager) {
209 focus_manager->SetFocusedView(native_control->focus_view()); 210 focus_manager->SetFocusedView(native_control->focus_view());
210 } else { 211 } else {
211 NOTREACHED(); 212 NOTREACHED();
212 } 213 }
213 } else if (message == WM_DESTROY) { 214 } else if (message == WM_DESTROY) {
214 native_control->prop_.reset(); 215 native_control->props_.reset();
215 win_util::SetWindowProc(window, native_control->original_wndproc_); 216 win_util::SetWindowProc(window, native_control->original_wndproc_);
216 } 217 }
217 218
218 return CallWindowProc(native_control->original_wndproc_, window, message, 219 return CallWindowProc(native_control->original_wndproc_, window, message,
219 w_param, l_param); 220 w_param, l_param);
220 } 221 }
221 222
222 } // namespace views 223 } // namespace views
OLDNEW
« no previous file with comments | « views/controls/native_control_win.h ('k') | views/views.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698