| 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 "views/controls/native/native_view_host_win.h" | 5 #include "views/controls/native/native_view_host_win.h" |
| 6 | 6 |
| 7 #include "app/gfx/canvas.h" | 7 #include "app/gfx/canvas.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/win_util.h" | |
| 10 #include "views/controls/native/native_view_host.h" | 9 #include "views/controls/native/native_view_host.h" |
| 11 #include "views/focus/focus_manager.h" | 10 #include "views/focus/focus_manager.h" |
| 12 #include "views/widget/widget.h" | 11 #include "views/widget/widget.h" |
| 13 | 12 |
| 14 const wchar_t* kNativeViewHostWinKey = L"__NATIVE_VIEW_HOST_WIN__"; | |
| 15 | |
| 16 namespace views { | 13 namespace views { |
| 17 | 14 |
| 18 //////////////////////////////////////////////////////////////////////////////// | 15 //////////////////////////////////////////////////////////////////////////////// |
| 19 // NativeViewHostWin, public: | 16 // NativeViewHostWin, public: |
| 20 | 17 |
| 21 NativeViewHostWin::NativeViewHostWin(NativeViewHost* host) | 18 NativeViewHostWin::NativeViewHostWin(NativeViewHost* host) |
| 22 : host_(host), | 19 : host_(host), |
| 23 installed_clip_(false), | 20 installed_clip_(false) { |
| 24 original_wndproc_(NULL) { | |
| 25 } | 21 } |
| 26 | 22 |
| 27 NativeViewHostWin::~NativeViewHostWin() { | 23 NativeViewHostWin::~NativeViewHostWin() { |
| 28 } | 24 } |
| 29 | 25 |
| 30 //////////////////////////////////////////////////////////////////////////////// | 26 //////////////////////////////////////////////////////////////////////////////// |
| 31 // NativeViewHostWin, NativeViewHostWrapper implementation: | 27 // NativeViewHostWin, NativeViewHostWrapper implementation: |
| 32 | 28 |
| 33 void NativeViewHostWin::NativeViewAttached() { | 29 void NativeViewHostWin::NativeViewAttached() { |
| 34 DCHECK(host_->native_view()) | 30 DCHECK(host_->native_view()) |
| 35 << "Impossible detatched tab case; See crbug.com/6316"; | 31 << "Impossible detatched tab case; See crbug.com/6316"; |
| 36 | 32 |
| 37 // First hide the new window. We don't want anything to draw (like sub-hwnd | 33 // First hide the new window. We don't want anything to draw (like sub-hwnd |
| 38 // borders), when we change the parent below. | 34 // borders), when we change the parent below. |
| 39 ShowWindow(host_->native_view(), SW_HIDE); | 35 ShowWindow(host_->native_view(), SW_HIDE); |
| 40 | 36 |
| 41 // Need to set the HWND's parent before changing its size to avoid flashing. | 37 // Need to set the HWND's parent before changing its size to avoid flashing. |
| 42 SetParent(host_->native_view(), host_->GetWidget()->GetNativeView()); | 38 SetParent(host_->native_view(), host_->GetWidget()->GetNativeView()); |
| 43 host_->Layout(); | 39 host_->Layout(); |
| 44 | |
| 45 // Subclass the appropriate HWND to get focus notifications. | |
| 46 HWND focus_hwnd = host_->focus_native_view(); | |
| 47 DCHECK(focus_hwnd == host_->native_view() || | |
| 48 ::IsChild(host_->native_view(), focus_hwnd)); | |
| 49 original_wndproc_ = | |
| 50 win_util::SetWindowProc(focus_hwnd, | |
| 51 &NativeViewHostWin::NativeViewHostWndProc); | |
| 52 | |
| 53 // We use a property to retrieve the NativeViewHostWin from the window | |
| 54 // procedure. | |
| 55 ::SetProp(focus_hwnd, kNativeViewHostWinKey, this); | |
| 56 } | 40 } |
| 57 | 41 |
| 58 void NativeViewHostWin::NativeViewDetaching() { | 42 void NativeViewHostWin::NativeViewDetaching() { |
| 59 installed_clip_ = false; | 43 installed_clip_ = false; |
| 60 | |
| 61 // Restore the original Windows procedure. | |
| 62 DCHECK(original_wndproc_); | |
| 63 WNDPROC wndproc = win_util::SetWindowProc(host_->focus_native_view(), | |
| 64 original_wndproc_); | |
| 65 DCHECK(wndproc == &NativeViewHostWin::NativeViewHostWndProc); | |
| 66 | |
| 67 // Also remove the property, it's not needed anymore. | |
| 68 HANDLE h = ::RemoveProp(host_->focus_native_view(), kNativeViewHostWinKey); | |
| 69 DCHECK(h == this); | |
| 70 } | 44 } |
| 71 | 45 |
| 72 void NativeViewHostWin::AddedToWidget() { | 46 void NativeViewHostWin::AddedToWidget() { |
| 73 if (!IsWindow(host_->native_view())) | 47 if (!IsWindow(host_->native_view())) |
| 74 return; | 48 return; |
| 75 HWND parent_hwnd = GetParent(host_->native_view()); | 49 HWND parent_hwnd = GetParent(host_->native_view()); |
| 76 HWND widget_hwnd = host_->GetWidget()->GetNativeView(); | 50 HWND widget_hwnd = host_->GetWidget()->GetNativeView(); |
| 77 if (parent_hwnd != widget_hwnd) | 51 if (parent_hwnd != widget_hwnd) |
| 78 SetParent(host_->native_view(), widget_hwnd); | 52 SetParent(host_->native_view(), widget_hwnd); |
| 79 if (host_->IsVisibleInRootView()) | 53 if (host_->IsVisibleInRootView()) |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 if (!IsWindowVisible(host_->native_view())) | 109 if (!IsWindowVisible(host_->native_view())) |
| 136 return; // Currently not visible, nothing to do. | 110 return; // Currently not visible, nothing to do. |
| 137 | 111 |
| 138 // The window is currently visible, but its clipped by another view. Hide | 112 // The window is currently visible, but its clipped by another view. Hide |
| 139 // it. | 113 // it. |
| 140 SetWindowPos(host_->native_view(), 0, 0, 0, 0, 0, | 114 SetWindowPos(host_->native_view(), 0, 0, 0, 0, 0, |
| 141 SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | | 115 SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | |
| 142 SWP_NOREDRAW | SWP_NOOWNERZORDER); | 116 SWP_NOREDRAW | SWP_NOOWNERZORDER); |
| 143 } | 117 } |
| 144 | 118 |
| 145 // static | 119 void NativeViewHostWin::SetFocus() { |
| 146 LRESULT CALLBACK NativeViewHostWin::NativeViewHostWndProc(HWND window, | 120 ::SetFocus(host_->native_view()); |
| 147 UINT message, | |
| 148 WPARAM w_param, | |
| 149 LPARAM l_param) { | |
| 150 NativeViewHostWin* native_view_host = | |
| 151 static_cast<NativeViewHostWin*>(::GetProp(window, kNativeViewHostWinKey)); | |
| 152 DCHECK(native_view_host); | |
| 153 | |
| 154 if (message == WM_SETFOCUS) | |
| 155 native_view_host->host_->GotNativeFocus(); | |
| 156 if (message == WM_DESTROY) | |
| 157 native_view_host->host_->Detach(); | |
| 158 | |
| 159 return CallWindowProc(native_view_host->original_wndproc_, | |
| 160 window, message, w_param, l_param); | |
| 161 } | 121 } |
| 162 | 122 |
| 163 //////////////////////////////////////////////////////////////////////////////// | 123 //////////////////////////////////////////////////////////////////////////////// |
| 164 // NativeViewHostWrapper, public: | 124 // NativeViewHostWrapper, public: |
| 165 | 125 |
| 166 // static | 126 // static |
| 167 NativeViewHostWrapper* NativeViewHostWrapper::CreateWrapper( | 127 NativeViewHostWrapper* NativeViewHostWrapper::CreateWrapper( |
| 168 NativeViewHost* host) { | 128 NativeViewHost* host) { |
| 169 return new NativeViewHostWin(host); | 129 return new NativeViewHostWin(host); |
| 170 } | 130 } |
| 171 | 131 |
| 172 } // namespace views | 132 } // namespace views |
| OLD | NEW |