| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this |
| 2 // source code is governed by a BSD-style license that can be found in the | 2 // source code is governed by a BSD-style license that can be found in the |
| 3 // LICENSE file. | 3 // LICENSE file. |
| 4 | 4 |
| 5 #include "views/controls/native_control_win.h" | 5 #include "views/controls/native_control_win.h" |
| 6 | 6 |
| 7 #include "app/l10n_util_win.h" | 7 #include "app/l10n_util_win.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/win_util.h" | 9 #include "base/win_util.h" |
| 10 | 10 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 x = point.x(); | 107 x = point.x(); |
| 108 y = point.y(); | 108 y = point.y(); |
| 109 is_mouse = false; | 109 is_mouse = false; |
| 110 } | 110 } |
| 111 View::ShowContextMenu(x, y, is_mouse); | 111 View::ShowContextMenu(x, y, is_mouse); |
| 112 } | 112 } |
| 113 | 113 |
| 114 void NativeControlWin::NativeControlCreated(HWND native_control) { | 114 void NativeControlWin::NativeControlCreated(HWND native_control) { |
| 115 // Associate this object with the control's HWND so that WidgetWin can find | 115 // Associate this object with the control's HWND so that WidgetWin can find |
| 116 // this object when it receives messages from it. | 116 // this object when it receives messages from it. |
| 117 // Note that we never unset this property. We don't have to. |
| 117 SetProp(native_control, kNativeControlWinKey, this); | 118 SetProp(native_control, kNativeControlWinKey, this); |
| 118 | 119 |
| 119 // Subclass the window so we can monitor for key presses. | 120 // Subclass the window so we can monitor for key presses. It's important that |
| 120 original_wndproc_ = | 121 // we *only* do this if the derived class wants to intercept keypresses, |
| 121 win_util::SetWindowProc(native_control, | 122 // because otherwise the subclass can mysteriously interfere with certain |
| 122 &NativeControlWin::NativeControlWndProc); | 123 // other controls, like the combobox, and cause weird effects. |
| 123 SetProp(native_control, kNativeControlOriginalWndProcKey, original_wndproc_); | 124 if (NotifyOnKeyDown()) { |
| 125 original_wndproc_ = |
| 126 win_util::SetWindowProc(native_control, |
| 127 &NativeControlWin::NativeControlWndProc); |
| 128 SetProp(native_control, kNativeControlOriginalWndProcKey, |
| 129 original_wndproc_); |
| 130 } |
| 124 | 131 |
| 125 Attach(native_control); | 132 Attach(native_control); |
| 126 // native_view() is now valid. | 133 // native_view() is now valid. |
| 127 | 134 |
| 128 // Update the newly created HWND with any resident enabled state. | 135 // Update the newly created HWND with any resident enabled state. |
| 129 EnableWindow(native_view(), IsEnabled()); | 136 EnableWindow(native_view(), IsEnabled()); |
| 130 | 137 |
| 131 // This message ensures that the focus border is shown. | 138 // This message ensures that the focus border is shown. |
| 132 SendMessage(native_view(), WM_CHANGEUISTATE, | 139 SendMessage(native_view(), WM_CHANGEUISTATE, |
| 133 MAKEWPARAM(UIS_CLEAR, UISF_HIDEFOCUS), 0); | 140 MAKEWPARAM(UIS_CLEAR, UISF_HIDEFOCUS), 0); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 LPARAM l_param) { | 188 LPARAM l_param) { |
| 182 NativeControlWin* native_control = | 189 NativeControlWin* native_control = |
| 183 static_cast<NativeControlWin*>(GetProp(window, kNativeControlWinKey)); | 190 static_cast<NativeControlWin*>(GetProp(window, kNativeControlWinKey)); |
| 184 DCHECK(native_control); | 191 DCHECK(native_control); |
| 185 | 192 |
| 186 if (message == WM_KEYDOWN && native_control->NotifyOnKeyDown()) { | 193 if (message == WM_KEYDOWN && native_control->NotifyOnKeyDown()) { |
| 187 if (native_control->OnKeyDown(static_cast<int>(w_param))) | 194 if (native_control->OnKeyDown(static_cast<int>(w_param))) |
| 188 return 0; | 195 return 0; |
| 189 } else if (message == WM_DESTROY) { | 196 } else if (message == WM_DESTROY) { |
| 190 win_util::SetWindowProc(window, native_control->original_wndproc_); | 197 win_util::SetWindowProc(window, native_control->original_wndproc_); |
| 191 RemoveProp(window, kNativeControlWinKey); | |
| 192 } | 198 } |
| 193 | 199 |
| 194 return CallWindowProc(native_control->original_wndproc_, window, message, | 200 return CallWindowProc(native_control->original_wndproc_, window, message, |
| 195 w_param, l_param); | 201 w_param, l_param); |
| 196 } | 202 } |
| 197 | 203 |
| 198 } // namespace views | 204 } // namespace views |
| OLD | NEW |