| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "ui/views/controls/native_control_win.h" | 5 #include "ui/views/controls/native_control_win.h" |
| 6 | 6 |
| 7 #include <windowsx.h> | 7 #include <windowsx.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "ui/base/accessibility/accessibility_types.h" | 10 #include "ui/base/accessibility/accessibility_types.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 | 72 |
| 73 // Create the HWND when we're added to a valid Widget. Many controls need a | 73 // Create the HWND when we're added to a valid Widget. Many controls need a |
| 74 // parent HWND to function properly. | 74 // parent HWND to function properly. |
| 75 if (is_add && GetWidget() && !native_view()) | 75 if (is_add && GetWidget() && !native_view()) |
| 76 CreateNativeControl(); | 76 CreateNativeControl(); |
| 77 } | 77 } |
| 78 | 78 |
| 79 void NativeControlWin::VisibilityChanged(View* starting_from, bool is_visible) { | 79 void NativeControlWin::VisibilityChanged(View* starting_from, bool is_visible) { |
| 80 // We might get called due to visibility changes at any point in the | 80 // We might get called due to visibility changes at any point in the |
| 81 // hierarchy, lets check whether we are really visible or not. | 81 // hierarchy, lets check whether we are really visible or not. |
| 82 bool visible = IsVisibleInRootView(); | 82 bool is_drawn = IsDrawn(); |
| 83 if (!visible && native_view()) { | 83 if (!is_drawn && native_view()) { |
| 84 // We destroy the child control HWND when we become invisible because of the | 84 // We destroy the child control HWND when we become invisible because of the |
| 85 // performance cost of maintaining many HWNDs. | 85 // performance cost of maintaining many HWNDs. |
| 86 HWND hwnd = native_view(); | 86 HWND hwnd = native_view(); |
| 87 Detach(); | 87 Detach(); |
| 88 DestroyWindow(hwnd); | 88 DestroyWindow(hwnd); |
| 89 } else if (visible && !native_view()) { | 89 } else if (is_drawn && !native_view()) { |
| 90 if (GetWidget()) | 90 if (GetWidget()) |
| 91 CreateNativeControl(); | 91 CreateNativeControl(); |
| 92 } | 92 } |
| 93 if (visible) { | 93 if (is_drawn) { |
| 94 // The view becomes visible after native control is created. | 94 // The view becomes visible after native control is created. |
| 95 // Layout now. | 95 // Layout now. |
| 96 Layout(); | 96 Layout(); |
| 97 } | 97 } |
| 98 } | 98 } |
| 99 | 99 |
| 100 void NativeControlWin::OnFocus() { | 100 void NativeControlWin::OnFocus() { |
| 101 DCHECK(native_view()); | 101 DCHECK(native_view()); |
| 102 SetFocus(native_view()); | 102 SetFocus(native_view()); |
| 103 | 103 |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 } else if (message == WM_DESTROY) { | 217 } else if (message == WM_DESTROY) { |
| 218 native_control->props_.reset(); | 218 native_control->props_.reset(); |
| 219 ui::SetWindowProc(window, native_control->original_wndproc_); | 219 ui::SetWindowProc(window, native_control->original_wndproc_); |
| 220 } | 220 } |
| 221 | 221 |
| 222 return CallWindowProc(native_control->original_wndproc_, window, message, | 222 return CallWindowProc(native_control->original_wndproc_, window, message, |
| 223 w_param, l_param); | 223 w_param, l_param); |
| 224 } | 224 } |
| 225 | 225 |
| 226 } // namespace views | 226 } // namespace views |
| OLD | NEW |