| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "chrome/views/native_control.h" | 5 #include "chrome/views/native_control.h" |
| 6 | 6 |
| 7 #include <atlbase.h> | 7 #include <atlbase.h> |
| 8 #include <atlapp.h> | 8 #include <atlapp.h> |
| 9 #include <atlcrack.h> | 9 #include <atlcrack.h> |
| 10 #include <atlframe.h> | 10 #include <atlframe.h> |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 } | 72 } |
| 73 | 73 |
| 74 void OnFinalMessage(HWND hwnd) { | 74 void OnFinalMessage(HWND hwnd) { |
| 75 if (parent_) | 75 if (parent_) |
| 76 parent_->NativeControlDestroyed(); | 76 parent_->NativeControlDestroyed(); |
| 77 delete this; | 77 delete this; |
| 78 } | 78 } |
| 79 private: | 79 private: |
| 80 | 80 |
| 81 LRESULT OnCreate(LPCREATESTRUCT create_struct) { | 81 LRESULT OnCreate(LPCREATESTRUCT create_struct) { |
| 82 TRACK_HWND_CREATION(m_hWnd); |
| 83 |
| 82 control_ = parent_->CreateNativeControl(m_hWnd); | 84 control_ = parent_->CreateNativeControl(m_hWnd); |
| 85 TRACK_HWND_CREATION(control_); |
| 86 |
| 83 FocusManager::InstallFocusSubclass(control_, parent_); | 87 FocusManager::InstallFocusSubclass(control_, parent_); |
| 84 if (parent_->NotifyOnKeyDown()) { | 88 |
| 85 // We subclass the control hwnd so we get the WM_KEYDOWN messages. | 89 // We subclass the control hwnd so we get the WM_KEYDOWN messages. |
| 86 WNDPROC original_handler = | 90 WNDPROC original_handler = |
| 87 win_util::SetWindowProc(control_, | 91 win_util::SetWindowProc(control_, |
| 88 &NativeControl::NativeControlWndProc); | 92 &NativeControl::NativeControlWndProc); |
| 89 SetProp(control_, kHandlerKey, original_handler); | 93 SetProp(control_, kHandlerKey, original_handler); |
| 90 SetProp(control_, kNativeControlKey , parent_); | 94 SetProp(control_, kNativeControlKey , parent_); |
| 91 } | 95 |
| 92 ::ShowWindow(control_, SW_SHOW); | 96 ::ShowWindow(control_, SW_SHOW); |
| 93 return 1; | 97 return 1; |
| 94 } | 98 } |
| 95 | 99 |
| 96 LRESULT OnEraseBkgnd(HDC dc) { | 100 LRESULT OnEraseBkgnd(HDC dc) { |
| 97 return 1; | 101 return 1; |
| 98 } | 102 } |
| 99 | 103 |
| 100 void OnPaint(HDC ignore) { | 104 void OnPaint(HDC ignore) { |
| 101 PAINTSTRUCT ps; | 105 PAINTSTRUCT ps; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 114 LRESULT OnNotify(int w_param, LPNMHDR l_param) { | 118 LRESULT OnNotify(int w_param, LPNMHDR l_param) { |
| 115 if (parent_) | 119 if (parent_) |
| 116 return parent_->OnNotify(w_param, l_param); | 120 return parent_->OnNotify(w_param, l_param); |
| 117 else | 121 else |
| 118 return 0; | 122 return 0; |
| 119 } | 123 } |
| 120 | 124 |
| 121 void OnDestroy() { | 125 void OnDestroy() { |
| 122 if (parent_) | 126 if (parent_) |
| 123 parent_->OnDestroy(); | 127 parent_->OnDestroy(); |
| 128 TRACK_HWND_DESTRUCTION(m_hWnd); |
| 124 } | 129 } |
| 125 | 130 |
| 126 void OnContextMenu(HWND window, const CPoint& location) { | 131 void OnContextMenu(HWND window, const CPoint& location) { |
| 127 if (parent_) | 132 if (parent_) |
| 128 parent_->OnContextMenu(location); | 133 parent_->OnContextMenu(location); |
| 129 } | 134 } |
| 130 | 135 |
| 131 // We need to find an ancestor with a non-null background, and | 136 // We need to find an ancestor with a non-null background, and |
| 132 // ask it for a (solid color) brush that approximates | 137 // ask it for a (solid color) brush that approximates |
| 133 // the background. The caller will use this when drawing | 138 // the background. The caller will use this when drawing |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 // static | 361 // static |
| 357 LRESULT CALLBACK NativeControl::NativeControlWndProc(HWND window, UINT message, | 362 LRESULT CALLBACK NativeControl::NativeControlWndProc(HWND window, UINT message, |
| 358 WPARAM w_param, | 363 WPARAM w_param, |
| 359 LPARAM l_param) { | 364 LPARAM l_param) { |
| 360 HANDLE original_handler = GetProp(window, kHandlerKey); | 365 HANDLE original_handler = GetProp(window, kHandlerKey); |
| 361 DCHECK(original_handler); | 366 DCHECK(original_handler); |
| 362 NativeControl* native_control = | 367 NativeControl* native_control = |
| 363 static_cast<NativeControl*>(GetProp(window, kNativeControlKey)); | 368 static_cast<NativeControl*>(GetProp(window, kNativeControlKey)); |
| 364 DCHECK(native_control); | 369 DCHECK(native_control); |
| 365 | 370 |
| 366 if (message == WM_KEYDOWN) { | 371 if (message == WM_KEYDOWN && native_control->NotifyOnKeyDown()) { |
| 367 if (native_control->OnKeyDown(static_cast<int>(w_param))) | 372 if (native_control->OnKeyDown(static_cast<int>(w_param))) |
| 368 return 0; | 373 return 0; |
| 369 } else if (message == WM_DESTROY) { | 374 } else if (message == WM_DESTROY) { |
| 370 win_util::SetWindowProc(window, | 375 win_util::SetWindowProc(window, |
| 371 reinterpret_cast<WNDPROC>(original_handler)); | 376 reinterpret_cast<WNDPROC>(original_handler)); |
| 372 RemoveProp(window, kHandlerKey); | 377 RemoveProp(window, kHandlerKey); |
| 373 RemoveProp(window, kNativeControlKey); | 378 RemoveProp(window, kNativeControlKey); |
| 379 TRACK_HWND_DESTRUCTION(window); |
| 374 } | 380 } |
| 375 | 381 |
| 376 return CallWindowProc(reinterpret_cast<WNDPROC>(original_handler), window, | 382 return CallWindowProc(reinterpret_cast<WNDPROC>(original_handler), window, |
| 377 message, w_param, l_param); | 383 message, w_param, l_param); |
| 378 } | 384 } |
| 379 | 385 |
| 380 } // namespace views | 386 } // namespace views |
| 381 | 387 |
| OLD | NEW |