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/browser/tab_contents/web_contents_view_win.h" | 5 #include "chrome/browser/tab_contents/web_contents_view_win.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 | 8 |
9 #include "chrome/browser/bookmarks/bookmark_drag_data.h" | 9 #include "chrome/browser/bookmarks/bookmark_drag_data.h" |
10 #include "chrome/browser/browser.h" // TODO(beng): this dependency is awful. | 10 #include "chrome/browser/browser.h" // TODO(beng): this dependency is awful. |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 RenderWidgetHostViewWin* WebContentsViewWin::CreateViewForWidget( | 66 RenderWidgetHostViewWin* WebContentsViewWin::CreateViewForWidget( |
67 RenderWidgetHost* render_widget_host) { | 67 RenderWidgetHost* render_widget_host) { |
68 DCHECK(!render_widget_host->view()); | 68 DCHECK(!render_widget_host->view()); |
69 RenderWidgetHostViewWin* view = | 69 RenderWidgetHostViewWin* view = |
70 new RenderWidgetHostViewWin(render_widget_host); | 70 new RenderWidgetHostViewWin(render_widget_host); |
71 view->Create(GetHWND()); | 71 view->Create(GetHWND()); |
72 view->ShowWindow(SW_SHOW); | 72 view->ShowWindow(SW_SHOW); |
73 return view; | 73 return view; |
74 } | 74 } |
75 | 75 |
76 HWND WebContentsViewWin::GetContainerHWND() const { | 76 gfx::NativeView WebContentsViewWin::GetNativeView() const { |
77 return GetHWND(); | 77 return GetHWND(); |
78 } | 78 } |
79 | 79 |
80 HWND WebContentsViewWin::GetContentHWND() const { | 80 gfx::NativeView WebContentsViewWin::GetContentNativeView() const { |
81 if (!web_contents_->render_widget_host_view()) | 81 if (!web_contents_->render_widget_host_view()) |
82 return NULL; | 82 return NULL; |
83 return web_contents_->render_widget_host_view()->GetPluginHWND(); | 83 return web_contents_->render_widget_host_view()->GetPluginHWND(); |
84 } | 84 } |
85 | 85 |
86 void WebContentsViewWin::GetContainerBounds(gfx::Rect* out) const { | 86 void WebContentsViewWin::GetContainerBounds(gfx::Rect* out) const { |
87 GetBounds(out, false); | 87 GetBounds(out, false); |
88 } | 88 } |
89 | 89 |
90 void WebContentsViewWin::StartDragging(const WebDropData& drop_data) { | 90 void WebContentsViewWin::StartDragging(const WebDropData& drop_data) { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 } | 165 } |
166 | 166 |
167 void WebContentsViewWin::OnDestroy() { | 167 void WebContentsViewWin::OnDestroy() { |
168 if (drop_target_.get()) { | 168 if (drop_target_.get()) { |
169 RevokeDragDrop(GetHWND()); | 169 RevokeDragDrop(GetHWND()); |
170 drop_target_ = NULL; | 170 drop_target_ = NULL; |
171 } | 171 } |
172 } | 172 } |
173 | 173 |
174 void WebContentsViewWin::SetPageTitle(const std::wstring& title) { | 174 void WebContentsViewWin::SetPageTitle(const std::wstring& title) { |
175 if (GetContainerHWND()) { | 175 if (GetNativeView()) { |
176 // It's possible to get this after the hwnd has been destroyed. | 176 // It's possible to get this after the hwnd has been destroyed. |
177 ::SetWindowText(GetContainerHWND(), title.c_str()); | 177 ::SetWindowText(GetNativeView(), title.c_str()); |
178 // TODO(brettw) this call seems messy the way it reaches into the widget | 178 // TODO(brettw) this call seems messy the way it reaches into the widget |
179 // view, and I'm not sure it's necessary. Maybe we should just remove it. | 179 // view, and I'm not sure it's necessary. Maybe we should just remove it. |
180 ::SetWindowText(web_contents_->render_widget_host_view()->GetPluginHWND(), | 180 ::SetWindowText(web_contents_->render_widget_host_view()->GetPluginHWND(), |
181 title.c_str()); | 181 title.c_str()); |
182 } | 182 } |
183 } | 183 } |
184 | 184 |
185 void WebContentsViewWin::Invalidate() { | 185 void WebContentsViewWin::Invalidate() { |
186 // Note that it's possible to get this message after the window was destroyed. | 186 // Note that it's possible to get this message after the window was destroyed. |
187 if (::IsWindow(GetContainerHWND())) | 187 if (::IsWindow(GetNativeView())) |
188 InvalidateRect(GetContainerHWND(), NULL, FALSE); | 188 InvalidateRect(GetNativeView(), NULL, FALSE); |
189 } | 189 } |
190 | 190 |
191 void WebContentsViewWin::SizeContents(const gfx::Size& size) { | 191 void WebContentsViewWin::SizeContents(const gfx::Size& size) { |
192 // TODO(brettw) this is a hack and should be removed. See web_contents_view.h. | 192 // TODO(brettw) this is a hack and should be removed. See web_contents_view.h. |
193 WasSized(size); | 193 WasSized(size); |
194 } | 194 } |
195 | 195 |
196 void WebContentsViewWin::FindInPage(const Browser& browser, | 196 void WebContentsViewWin::FindInPage(const Browser& browser, |
197 bool find_next, bool forward_direction) { | 197 bool find_next, bool forward_direction) { |
198 if (!find_bar_.get()) { | 198 if (!find_bar_.get()) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 *fully_visible = find_bar_->IsVisible() && !find_bar_->IsAnimating(); | 238 *fully_visible = find_bar_->IsVisible() && !find_bar_->IsAnimating(); |
239 return true; | 239 return true; |
240 } | 240 } |
241 | 241 |
242 void WebContentsViewWin::UpdateDragCursor(bool is_drop_target) { | 242 void WebContentsViewWin::UpdateDragCursor(bool is_drop_target) { |
243 drop_target_->set_is_drop_target(is_drop_target); | 243 drop_target_->set_is_drop_target(is_drop_target); |
244 } | 244 } |
245 | 245 |
246 void WebContentsViewWin::TakeFocus(bool reverse) { | 246 void WebContentsViewWin::TakeFocus(bool reverse) { |
247 views::FocusManager* focus_manager = | 247 views::FocusManager* focus_manager = |
248 views::FocusManager::GetFocusManager(GetContainerHWND()); | 248 views::FocusManager::GetFocusManager(GetNativeView()); |
249 | 249 |
250 // We may not have a focus manager if the tab has been switched before this | 250 // We may not have a focus manager if the tab has been switched before this |
251 // message arrived. | 251 // message arrived. |
252 if (focus_manager) | 252 if (focus_manager) |
253 focus_manager->AdvanceFocus(reverse); | 253 focus_manager->AdvanceFocus(reverse); |
254 } | 254 } |
255 | 255 |
256 void WebContentsViewWin::HandleKeyboardEvent(const WebKeyboardEvent& event) { | 256 void WebContentsViewWin::HandleKeyboardEvent(const WebKeyboardEvent& event) { |
257 // Previous calls to TranslateMessage can generate CHAR events as well as | 257 // Previous calls to TranslateMessage can generate CHAR events as well as |
258 // KEY_DOWN events, even if the latter triggered an accelerator. In these | 258 // KEY_DOWN events, even if the latter triggered an accelerator. In these |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 | 408 |
409 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost(); | 409 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost(); |
410 if (!widget_host->process()->channel()) { | 410 if (!widget_host->process()->channel()) { |
411 // The view has gone away or the renderer crashed. Nothing to do. | 411 // The view has gone away or the renderer crashed. Nothing to do. |
412 return; | 412 return; |
413 } | 413 } |
414 | 414 |
415 // This logic should be implemented by RenderWidgetHostHWND (as mentioned | 415 // This logic should be implemented by RenderWidgetHostHWND (as mentioned |
416 // above) in the ::Init function, which should take a parent and some initial | 416 // above) in the ::Init function, which should take a parent and some initial |
417 // bounds. | 417 // bounds. |
418 widget_host_view_win->Create(GetContainerHWND(), NULL, NULL, | 418 widget_host_view_win->Create(GetNativeView(), NULL, NULL, |
419 WS_POPUP, WS_EX_TOOLWINDOW); | 419 WS_POPUP, WS_EX_TOOLWINDOW); |
420 widget_host_view_win->MoveWindow(initial_pos.x(), initial_pos.y(), | 420 widget_host_view_win->MoveWindow(initial_pos.x(), initial_pos.y(), |
421 initial_pos.width(), initial_pos.height(), | 421 initial_pos.width(), initial_pos.height(), |
422 TRUE); | 422 TRUE); |
423 widget_host_view_win->ShowWindow(widget_host_view_win->activatable() ? | 423 widget_host_view_win->ShowWindow(widget_host_view_win->activatable() ? |
424 SW_SHOW : SW_SHOWNA); | 424 SW_SHOW : SW_SHOWNA); |
425 widget_host->Init(); | 425 widget_host->Init(); |
426 } | 426 } |
427 | 427 |
428 void WebContentsViewWin::OnHScroll(int scroll_type, short position, | 428 void WebContentsViewWin::OnHScroll(int scroll_type, short position, |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 // here since the view will draw everything correctly. | 582 // here since the view will draw everything correctly. |
583 } | 583 } |
584 | 584 |
585 void WebContentsViewWin::ScrollCommon(UINT message, int scroll_type, | 585 void WebContentsViewWin::ScrollCommon(UINT message, int scroll_type, |
586 short position, HWND scrollbar) { | 586 short position, HWND scrollbar) { |
587 // This window can receive scroll events as a result of the ThinkPad's | 587 // This window can receive scroll events as a result of the ThinkPad's |
588 // Trackpad scroll wheel emulation. | 588 // Trackpad scroll wheel emulation. |
589 if (!ScrollZoom(scroll_type)) { | 589 if (!ScrollZoom(scroll_type)) { |
590 // Reflect scroll message to the view() to give it a chance | 590 // Reflect scroll message to the view() to give it a chance |
591 // to process scrolling. | 591 // to process scrolling. |
592 SendMessage(GetContentHWND(), message, MAKELONG(scroll_type, position), | 592 SendMessage(GetContentNativeView(), message, |
593 (LPARAM) scrollbar); | 593 MAKELONG(scroll_type, position), |
| 594 reinterpret_cast<LPARAM>(scrollbar)); |
594 } | 595 } |
595 } | 596 } |
596 | 597 |
597 void WebContentsViewWin::WasHidden() { | 598 void WebContentsViewWin::WasHidden() { |
598 web_contents_->HideContents(); | 599 web_contents_->HideContents(); |
599 if (find_bar_.get()) | 600 if (find_bar_.get()) |
600 find_bar_->DidBecomeUnselected(); | 601 find_bar_->DidBecomeUnselected(); |
601 } | 602 } |
602 | 603 |
603 void WebContentsViewWin::WasShown() { | 604 void WebContentsViewWin::WasShown() { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
648 } | 649 } |
649 return false; | 650 return false; |
650 } | 651 } |
651 | 652 |
652 void WebContentsViewWin::WheelZoom(int distance) { | 653 void WebContentsViewWin::WheelZoom(int distance) { |
653 if (web_contents_->delegate()) { | 654 if (web_contents_->delegate()) { |
654 bool zoom_in = distance > 0; | 655 bool zoom_in = distance > 0; |
655 web_contents_->delegate()->ContentsZoomChange(zoom_in); | 656 web_contents_->delegate()->ContentsZoomChange(zoom_in); |
656 } | 657 } |
657 } | 658 } |
OLD | NEW |