| 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 "chrome/browser/ui/views/tab_contents/native_tab_contents_view_win.h" | 5 #include "chrome/browser/ui/views/tab_contents/native_tab_contents_view_win.h" |
| 6 | 6 |
| 7 #include "chrome/browser/renderer_host/render_widget_host_view_win.h" | 7 #include "chrome/browser/renderer_host/render_widget_host_view_win.h" |
| 8 #include "chrome/browser/tab_contents/web_drop_target_win.h" | 8 #include "chrome/browser/tab_contents/web_drop_target_win.h" |
| 9 #include "chrome/browser/ui/views/tab_contents/tab_contents_drag_win.h" | 9 #include "chrome/browser/ui/views/tab_contents/tab_contents_drag_win.h" |
| 10 #include "chrome/browser/ui/views/tab_contents/native_tab_contents_view_delegate
.h" | 10 #include "chrome/browser/ui/views/tab_contents/native_tab_contents_view_delegate
.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 // | 23 // |
| 24 // It may be tempting to use GetDesktopWindow() instead, but this is | 24 // It may be tempting to use GetDesktopWindow() instead, but this is |
| 25 // problematic as the shell sends messages to children of the desktop | 25 // problematic as the shell sends messages to children of the desktop |
| 26 // window that interact poorly with us. | 26 // window that interact poorly with us. |
| 27 // | 27 // |
| 28 // See: http://crbug.com/16476 | 28 // See: http://crbug.com/16476 |
| 29 HWND GetHiddenTabHostWindow() { | 29 HWND GetHiddenTabHostWindow() { |
| 30 static views::Widget* widget = NULL; | 30 static views::Widget* widget = NULL; |
| 31 | 31 |
| 32 if (!widget) { | 32 if (!widget) { |
| 33 widget = views::Widget::CreateWidget(); | 33 widget = new views::Widget; |
| 34 // We don't want this widget to be closed automatically, this causes |
| 35 // problems in tests that close the last non-secondary window. |
| 36 widget->set_is_secondary_widget(false); |
| 34 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); | 37 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); |
| 35 widget->Init(params); | 38 widget->Init(params); |
| 36 // If a background window requests focus, the hidden tab host will | 39 // If a background window requests focus, the hidden tab host will |
| 37 // be activated to focus the tab. Use WS_DISABLED to prevent | 40 // be activated to focus the tab. Use WS_DISABLED to prevent |
| 38 // this. | 41 // this. |
| 39 EnableWindow(widget->GetNativeView(), FALSE); | 42 EnableWindow(widget->GetNativeView(), FALSE); |
| 40 } | 43 } |
| 41 | 44 |
| 42 return widget->GetNativeView(); | 45 return widget->GetNativeView(); |
| 43 } | 46 } |
| 44 | 47 |
| 45 } // namespace | 48 } // namespace |
| 46 | 49 |
| 47 //////////////////////////////////////////////////////////////////////////////// | 50 //////////////////////////////////////////////////////////////////////////////// |
| 48 // NativeTabContentsViewWin, public: | 51 // NativeTabContentsViewWin, public: |
| 49 | 52 |
| 50 NativeTabContentsViewWin::NativeTabContentsViewWin( | 53 NativeTabContentsViewWin::NativeTabContentsViewWin( |
| 51 internal::NativeTabContentsViewDelegate* delegate) | 54 internal::NativeTabContentsViewDelegate* delegate) |
| 52 : delegate_(delegate), | 55 : views::WidgetWin(delegate->AsNativeWidgetDelegate()), |
| 53 focus_manager_(NULL) { | 56 delegate_(delegate) { |
| 54 } | 57 } |
| 55 | 58 |
| 56 NativeTabContentsViewWin::~NativeTabContentsViewWin() { | 59 NativeTabContentsViewWin::~NativeTabContentsViewWin() { |
| 57 CloseNow(); | 60 CloseNow(); |
| 58 } | 61 } |
| 59 | 62 |
| 60 TabContents* NativeTabContentsViewWin::GetTabContents() const { | 63 TabContents* NativeTabContentsViewWin::GetTabContents() const { |
| 61 return delegate_->GetTabContents(); | 64 return delegate_->GetTabContents(); |
| 62 } | 65 } |
| 63 | 66 |
| 64 void NativeTabContentsViewWin::EndDragging() { | 67 void NativeTabContentsViewWin::EndDragging() { |
| 65 delegate_->OnNativeTabContentsViewDraggingEnded(); | 68 delegate_->OnNativeTabContentsViewDraggingEnded(); |
| 66 drag_handler_ = NULL; | 69 drag_handler_ = NULL; |
| 67 } | 70 } |
| 68 | 71 |
| 69 //////////////////////////////////////////////////////////////////////////////// | 72 //////////////////////////////////////////////////////////////////////////////// |
| 70 // NativeTabContentsViewWin, NativeTabContentsView implementation: | 73 // NativeTabContentsViewWin, NativeTabContentsView implementation: |
| 71 | 74 |
| 72 void NativeTabContentsViewWin::InitNativeTabContentsView() { | 75 void NativeTabContentsViewWin::InitNativeTabContentsView() { |
| 73 views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL); | 76 views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL); |
| 77 params.native_widget = this; |
| 74 params.delete_on_destroy = false; | 78 params.delete_on_destroy = false; |
| 75 params.parent = GetHiddenTabHostWindow(); | 79 params.parent = GetHiddenTabHostWindow(); |
| 76 GetWidget()->Init(params); | 80 GetWidget()->Init(params); |
| 77 | 81 |
| 78 // Remove the root view drop target so we can register our own. | 82 // Remove the root view drop target so we can register our own. |
| 79 RevokeDragDrop(GetNativeView()); | 83 RevokeDragDrop(GetNativeView()); |
| 80 drop_target_ = new WebDropTarget(GetNativeView(), | 84 drop_target_ = new WebDropTarget(GetNativeView(), |
| 81 delegate_->GetTabContents()); | 85 delegate_->GetTabContents()); |
| 82 } | 86 } |
| 83 | 87 |
| 84 void NativeTabContentsViewWin::Unparent() { | 88 void NativeTabContentsViewWin::Unparent() { |
| 85 // Remember who our FocusManager is, we won't be able to access it once | |
| 86 // unparented. | |
| 87 focus_manager_ = views::WidgetWin::GetFocusManager(); | |
| 88 // Note that we do not DCHECK on focus_manager_ as it may be NULL when used | 89 // Note that we do not DCHECK on focus_manager_ as it may be NULL when used |
| 89 // with an external tab container. | 90 // with an external tab container. |
| 90 NativeWidget::ReparentNativeView(GetNativeView(), GetHiddenTabHostWindow()); | 91 NativeWidget::ReparentNativeView(GetNativeView(), GetHiddenTabHostWindow()); |
| 91 } | 92 } |
| 92 | 93 |
| 93 RenderWidgetHostView* NativeTabContentsViewWin::CreateRenderWidgetHostView( | 94 RenderWidgetHostView* NativeTabContentsViewWin::CreateRenderWidgetHostView( |
| 94 RenderWidgetHost* render_widget_host) { | 95 RenderWidgetHost* render_widget_host) { |
| 95 RenderWidgetHostViewWin* view = | 96 RenderWidgetHostViewWin* view = |
| 96 new RenderWidgetHostViewWin(render_widget_host); | 97 new RenderWidgetHostViewWin(render_widget_host); |
| 97 view->CreateWnd(GetNativeView()); | 98 view->CreateWnd(GetNativeView()); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 return WidgetWin::OnMouseRange(msg, w_param, l_param); | 160 return WidgetWin::OnMouseRange(msg, w_param, l_param); |
| 160 | 161 |
| 161 switch (msg) { | 162 switch (msg) { |
| 162 case WM_LBUTTONDOWN: | 163 case WM_LBUTTONDOWN: |
| 163 case WM_MBUTTONDOWN: | 164 case WM_MBUTTONDOWN: |
| 164 case WM_RBUTTONDOWN: { | 165 case WM_RBUTTONDOWN: { |
| 165 delegate_->OnNativeTabContentsViewMouseDown(); | 166 delegate_->OnNativeTabContentsViewMouseDown(); |
| 166 break; | 167 break; |
| 167 } | 168 } |
| 168 case WM_MOUSEMOVE: | 169 case WM_MOUSEMOVE: |
| 169 delegate_->OnNativeTabContentsViewMouseMove(); | 170 delegate_->OnNativeTabContentsViewMouseMove(true); |
| 170 break; | 171 break; |
| 171 default: | 172 default: |
| 172 break; | 173 break; |
| 173 } | 174 } |
| 174 return 0; | 175 return 0; |
| 175 } | 176 } |
| 176 | 177 |
| 177 // A message is reflected here from view(). | 178 // A message is reflected here from view(). |
| 178 // Return non-zero to indicate that it is handled here. | 179 // Return non-zero to indicate that it is handled here. |
| 179 // Return 0 to allow view() to further process it. | 180 // Return 0 to allow view() to further process it. |
| 180 LRESULT NativeTabContentsViewWin::OnReflectedMessage(UINT msg, | 181 LRESULT NativeTabContentsViewWin::OnReflectedMessage(UINT msg, |
| 181 WPARAM w_param, | 182 WPARAM w_param, |
| 182 LPARAM l_param) { | 183 LPARAM l_param) { |
| 183 MSG* message = reinterpret_cast<MSG*>(l_param); | 184 MSG* message = reinterpret_cast<MSG*>(l_param); |
| 184 switch (message->message) { | 185 switch (message->message) { |
| 185 case WM_MOUSEWHEEL: | 186 case WM_MOUSEWHEEL: |
| 186 // This message is reflected from the view() to this window. | 187 // This message is reflected from the view() to this window. |
| 187 if (GET_KEYSTATE_WPARAM(message->wParam) & MK_CONTROL) { | 188 if (GET_KEYSTATE_WPARAM(message->wParam) & MK_CONTROL) { |
| 188 delegate_->OnNativeTabContentsViewWheelZoom( | 189 delegate_->OnNativeTabContentsViewWheelZoom( |
| 189 GET_WHEEL_DELTA_WPARAM(message->wParam)); | 190 GET_WHEEL_DELTA_WPARAM(message->wParam) > 0); |
| 190 return 1; | 191 return 1; |
| 191 } | 192 } |
| 192 break; | 193 break; |
| 193 case WM_HSCROLL: | 194 case WM_HSCROLL: |
| 194 case WM_VSCROLL: | 195 case WM_VSCROLL: |
| 195 if (ScrollZoom(LOWORD(message->wParam))) | 196 if (ScrollZoom(LOWORD(message->wParam))) |
| 196 return 1; | 197 return 1; |
| 197 default: | 198 default: |
| 198 break; | 199 break; |
| 199 } | 200 } |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 // to receive scroll messages from ThinkPad touch-pad driver. Suppress | 257 // to receive scroll messages from ThinkPad touch-pad driver. Suppress |
| 257 // painting of scrollbars by returning 0 size for them. | 258 // painting of scrollbars by returning 0 size for them. |
| 258 return 0; | 259 return 0; |
| 259 } | 260 } |
| 260 | 261 |
| 261 void NativeTabContentsViewWin::OnNCPaint(HRGN rgn) { | 262 void NativeTabContentsViewWin::OnNCPaint(HRGN rgn) { |
| 262 // Suppress default WM_NCPAINT handling. We don't need to do anything | 263 // Suppress default WM_NCPAINT handling. We don't need to do anything |
| 263 // here since the view will draw everything correctly. | 264 // here since the view will draw everything correctly. |
| 264 } | 265 } |
| 265 | 266 |
| 266 views::FocusManager* NativeTabContentsViewWin::GetFocusManager() { | |
| 267 views::FocusManager* focus_manager = WidgetWin::GetFocusManager(); | |
| 268 if (focus_manager) { | |
| 269 // If focus_manager_ is non NULL, it means we have been reparented, in which | |
| 270 // case its value may not be valid anymore. | |
| 271 focus_manager_ = NULL; | |
| 272 return focus_manager; | |
| 273 } | |
| 274 // TODO(jcampan): we should DCHECK on focus_manager_, as it should not be | |
| 275 // NULL. We are not doing it as it breaks some unit-tests. We should | |
| 276 // probably have an empty TabContentView implementation for the unit-tests, | |
| 277 // that would prevent that code being executed in the unit-test case. | |
| 278 // DCHECK(focus_manager_); | |
| 279 return focus_manager_; | |
| 280 } | |
| 281 | |
| 282 //////////////////////////////////////////////////////////////////////////////// | 267 //////////////////////////////////////////////////////////////////////////////// |
| 283 // NativeTabContentsViewWin, private: | 268 // NativeTabContentsViewWin, private: |
| 284 | 269 |
| 285 void NativeTabContentsViewWin::ScrollCommon(UINT message, int scroll_type, | 270 void NativeTabContentsViewWin::ScrollCommon(UINT message, int scroll_type, |
| 286 short position, HWND scrollbar) { | 271 short position, HWND scrollbar) { |
| 287 // This window can receive scroll events as a result of the ThinkPad's | 272 // This window can receive scroll events as a result of the ThinkPad's |
| 288 // touch-pad scroll wheel emulation. | 273 // touch-pad scroll wheel emulation. |
| 289 if (!ScrollZoom(scroll_type)) { | 274 if (!ScrollZoom(scroll_type)) { |
| 290 // Reflect scroll message to the view() to give it a chance | 275 // Reflect scroll message to the view() to give it a chance |
| 291 // to process scrolling. | 276 // to process scrolling. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 313 break; | 298 break; |
| 314 case SB_LINEDOWN: | 299 case SB_LINEDOWN: |
| 315 distance = -WHEEL_DELTA; | 300 distance = -WHEEL_DELTA; |
| 316 break; | 301 break; |
| 317 // TODO(joshia): Handle SB_PAGEUP, SB_PAGEDOWN, SB_THUMBPOSITION, | 302 // TODO(joshia): Handle SB_PAGEUP, SB_PAGEDOWN, SB_THUMBPOSITION, |
| 318 // and SB_THUMBTRACK for completeness | 303 // and SB_THUMBTRACK for completeness |
| 319 default: | 304 default: |
| 320 break; | 305 break; |
| 321 } | 306 } |
| 322 | 307 |
| 323 delegate_->OnNativeTabContentsViewWheelZoom(distance); | 308 delegate_->OnNativeTabContentsViewWheelZoom(distance > 0); |
| 324 return true; | 309 return true; |
| 325 } | 310 } |
| 326 return false; | 311 return false; |
| 327 } | 312 } |
| 328 | 313 |
| 329 //////////////////////////////////////////////////////////////////////////////// | 314 //////////////////////////////////////////////////////////////////////////////// |
| 330 // NativeTabContentsView, public: | 315 // NativeTabContentsView, public: |
| 331 | 316 |
| 332 // static | 317 // static |
| 333 NativeTabContentsView* NativeTabContentsView::CreateNativeTabContentsView( | 318 NativeTabContentsView* NativeTabContentsView::CreateNativeTabContentsView( |
| 334 internal::NativeTabContentsViewDelegate* delegate) { | 319 internal::NativeTabContentsViewDelegate* delegate) { |
| 335 return new NativeTabContentsViewWin(delegate); | 320 return new NativeTabContentsViewWin(delegate); |
| 336 } | 321 } |
| OLD | NEW |