| OLD | NEW |
| 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/view_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 using app::ViewProp; |
| 16 |
| 15 namespace views { | 17 namespace views { |
| 16 | 18 |
| 17 static const wchar_t* kNativeControlWinKey = L"__NATIVE_CONTROL_WIN__"; | 19 static const char* const kNativeControlWinKey = "__NATIVE_CONTROL_WIN__"; |
| 18 | 20 |
| 19 //////////////////////////////////////////////////////////////////////////////// | 21 //////////////////////////////////////////////////////////////////////////////// |
| 20 // NativeControlWin, public: | 22 // NativeControlWin, public: |
| 21 | 23 |
| 22 NativeControlWin::NativeControlWin() { | 24 NativeControlWin::NativeControlWin() { |
| 23 } | 25 } |
| 24 | 26 |
| 25 NativeControlWin::~NativeControlWin() { | 27 NativeControlWin::~NativeControlWin() { |
| 26 HWND hwnd = native_view(); | 28 HWND hwnd = native_view(); |
| 27 if (hwnd) { | 29 if (hwnd) { |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 | 125 |
| 124 if (location.x() == -1 && location.y() == -1) | 126 if (location.x() == -1 && location.y() == -1) |
| 125 View::ShowContextMenu(GetKeyboardContextMenuLocation(), false); | 127 View::ShowContextMenu(GetKeyboardContextMenuLocation(), false); |
| 126 else | 128 else |
| 127 View::ShowContextMenu(location, true); | 129 View::ShowContextMenu(location, true); |
| 128 } | 130 } |
| 129 | 131 |
| 130 void NativeControlWin::NativeControlCreated(HWND native_control) { | 132 void NativeControlWin::NativeControlCreated(HWND native_control) { |
| 131 // Associate this object with the control's HWND so that WidgetWin can find | 133 // Associate this object with the control's HWND so that WidgetWin can find |
| 132 // this object when it receives messages from it. | 134 // this object when it receives messages from it. |
| 133 props_.push_back( | 135 props_.push_back(new ViewProp(native_control, kNativeControlWinKey, this)); |
| 134 new app::win::ScopedProp(native_control, kNativeControlWinKey, this)); | |
| 135 props_.push_back(ChildWindowMessageProcessor::Register(native_control, this)); | 136 props_.push_back(ChildWindowMessageProcessor::Register(native_control, this)); |
| 136 | 137 |
| 137 // Subclass so we get WM_KEYDOWN and WM_SETFOCUS messages. | 138 // Subclass so we get WM_KEYDOWN and WM_SETFOCUS messages. |
| 138 original_wndproc_ = | 139 original_wndproc_ = |
| 139 win_util::SetWindowProc(native_control, | 140 win_util::SetWindowProc(native_control, |
| 140 &NativeControlWin::NativeControlWndProc); | 141 &NativeControlWin::NativeControlWndProc); |
| 141 | 142 |
| 142 Attach(native_control); | 143 Attach(native_control); |
| 143 // native_view() is now valid. | 144 // native_view() is now valid. |
| 144 | 145 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 | 190 |
| 190 // COLOR_BTNFACE is the default for dialog box backgrounds. | 191 // COLOR_BTNFACE is the default for dialog box backgrounds. |
| 191 return reinterpret_cast<LRESULT>(GetSysColorBrush(COLOR_BTNFACE)); | 192 return reinterpret_cast<LRESULT>(GetSysColorBrush(COLOR_BTNFACE)); |
| 192 } | 193 } |
| 193 | 194 |
| 194 // static | 195 // static |
| 195 LRESULT NativeControlWin::NativeControlWndProc(HWND window, | 196 LRESULT NativeControlWin::NativeControlWndProc(HWND window, |
| 196 UINT message, | 197 UINT message, |
| 197 WPARAM w_param, | 198 WPARAM w_param, |
| 198 LPARAM l_param) { | 199 LPARAM l_param) { |
| 199 NativeControlWin* native_control = | 200 NativeControlWin* native_control = reinterpret_cast<NativeControlWin*>( |
| 200 static_cast<NativeControlWin*>(GetProp(window, kNativeControlWinKey)); | 201 ViewProp::GetValue(window, kNativeControlWinKey)); |
| 201 DCHECK(native_control); | 202 DCHECK(native_control); |
| 202 | 203 |
| 203 if (message == WM_KEYDOWN && | 204 if (message == WM_KEYDOWN && |
| 204 native_control->OnKeyDown(static_cast<int>(w_param))) { | 205 native_control->OnKeyDown(static_cast<int>(w_param))) { |
| 205 return 0; | 206 return 0; |
| 206 } else if (message == WM_SETFOCUS) { | 207 } else if (message == WM_SETFOCUS) { |
| 207 // Let the focus manager know that the focus changed. | 208 // Let the focus manager know that the focus changed. |
| 208 FocusManager* focus_manager = native_control->GetFocusManager(); | 209 FocusManager* focus_manager = native_control->GetFocusManager(); |
| 209 if (focus_manager) { | 210 if (focus_manager) { |
| 210 focus_manager->SetFocusedView(native_control->focus_view()); | 211 focus_manager->SetFocusedView(native_control->focus_view()); |
| 211 } else { | 212 } else { |
| 212 NOTREACHED(); | 213 NOTREACHED(); |
| 213 } | 214 } |
| 214 } else if (message == WM_DESTROY) { | 215 } else if (message == WM_DESTROY) { |
| 215 native_control->props_.reset(); | 216 native_control->props_.reset(); |
| 216 win_util::SetWindowProc(window, native_control->original_wndproc_); | 217 win_util::SetWindowProc(window, native_control->original_wndproc_); |
| 217 } | 218 } |
| 218 | 219 |
| 219 return CallWindowProc(native_control->original_wndproc_, window, message, | 220 return CallWindowProc(native_control->original_wndproc_, window, message, |
| 220 w_param, l_param); | 221 w_param, l_param); |
| 221 } | 222 } |
| 222 | 223 |
| 223 } // namespace views | 224 } // namespace views |
| OLD | NEW |