| 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/web_contents_view_win.h" | 5 #include "chrome/browser/web_contents_view_win.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 | 8 |
| 9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/download/download_request_manager.h" | 10 #include "chrome/browser/download/download_request_manager.h" |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 if (info_bar_view_.get() == NULL) { | 157 if (info_bar_view_.get() == NULL) { |
| 158 // TODO(brettw) currently the InfoBar thinks its owned by the WebContents, | 158 // TODO(brettw) currently the InfoBar thinks its owned by the WebContents, |
| 159 // but it should instead think it's owned by us. | 159 // but it should instead think it's owned by us. |
| 160 info_bar_view_.reset(new InfoBarView(web_contents_)); | 160 info_bar_view_.reset(new InfoBarView(web_contents_)); |
| 161 // We own the info-bar. | 161 // We own the info-bar. |
| 162 info_bar_view_->SetParentOwned(false); | 162 info_bar_view_->SetParentOwned(false); |
| 163 } | 163 } |
| 164 return info_bar_view_.get(); | 164 return info_bar_view_.get(); |
| 165 } | 165 } |
| 166 | 166 |
| 167 void WebContentsViewWin::SetPageTitle(const std::wstring& title) { |
| 168 if (GetContainerHWND()) { |
| 169 // It's possible to get this after the hwnd has been destroyed. |
| 170 ::SetWindowText(GetContainerHWND(), title.c_str()); |
| 171 // TODO(brettw) this call seems messy the way it reaches into the widget |
| 172 // view, and I'm not sure it's necessary. Maybe we should just remove it. |
| 173 ::SetWindowText(web_contents_->render_widget_host_view()->GetPluginHWND(), |
| 174 title.c_str()); |
| 175 } |
| 176 } |
| 177 |
| 178 void WebContentsViewWin::Invalidate() { |
| 179 // Note that it's possible to get this message after the window was destroyed. |
| 180 if (::IsWindow(GetContainerHWND())) |
| 181 InvalidateRect(GetContainerHWND(), NULL, FALSE); |
| 182 } |
| 183 |
| 167 void WebContentsViewWin::UpdateDragCursor(bool is_drop_target) { | 184 void WebContentsViewWin::UpdateDragCursor(bool is_drop_target) { |
| 168 drop_target_->set_is_drop_target(is_drop_target); | 185 drop_target_->set_is_drop_target(is_drop_target); |
| 169 } | 186 } |
| 170 | 187 |
| 171 void WebContentsViewWin::ShowContextMenu( | 188 void WebContentsViewWin::TakeFocus(bool reverse) { |
| 172 const ViewHostMsg_ContextMenu_Params& params) { | 189 views::FocusManager* focus_manager = |
| 173 RenderViewContextMenuController menu_controller(web_contents_, params); | 190 views::FocusManager::GetFocusManager(GetContainerHWND()); |
| 174 RenderViewContextMenu menu(&menu_controller, | |
| 175 GetHWND(), | |
| 176 params.type, | |
| 177 params.misspelled_word, | |
| 178 params.dictionary_suggestions, | |
| 179 web_contents_->profile()); | |
| 180 | 191 |
| 181 POINT screen_pt = { params.x, params.y }; | 192 // We may not have a focus manager if the tab has been switched before this |
| 182 MapWindowPoints(GetHWND(), HWND_DESKTOP, &screen_pt, 1); | 193 // message arrived. |
| 183 | 194 if (focus_manager) |
| 184 // Enable recursive tasks on the message loop so we can get updates while | 195 focus_manager->AdvanceFocus(reverse); |
| 185 // the context menu is being displayed. | |
| 186 bool old_state = MessageLoop::current()->NestableTasksAllowed(); | |
| 187 MessageLoop::current()->SetNestableTasksAllowed(true); | |
| 188 menu.RunMenuAt(screen_pt.x, screen_pt.y); | |
| 189 MessageLoop::current()->SetNestableTasksAllowed(old_state); | |
| 190 } | 196 } |
| 191 | 197 |
| 192 void WebContentsViewWin::HandleKeyboardEvent(const WebKeyboardEvent& event) { | 198 void WebContentsViewWin::HandleKeyboardEvent(const WebKeyboardEvent& event) { |
| 193 // The renderer returned a keyboard event it did not process. This may be | 199 // The renderer returned a keyboard event it did not process. This may be |
| 194 // a keyboard shortcut that we have to process. | 200 // a keyboard shortcut that we have to process. |
| 195 if (event.type == WebInputEvent::KEY_DOWN) { | 201 if (event.type == WebInputEvent::KEY_DOWN) { |
| 196 views::FocusManager* focus_manager = | 202 views::FocusManager* focus_manager = |
| 197 views::FocusManager::GetFocusManager(GetHWND()); | 203 views::FocusManager::GetFocusManager(GetHWND()); |
| 198 // We may not have a focus_manager at this point (if the tab has been | 204 // We may not have a focus_manager at this point (if the tab has been |
| 199 // switched by the time this message returned). | 205 // switched by the time this message returned). |
| (...skipping 11 matching lines...) Expand all Loading... |
| 211 } | 217 } |
| 212 | 218 |
| 213 // Any unhandled keyboard/character messages should be defproced. | 219 // Any unhandled keyboard/character messages should be defproced. |
| 214 // This allows stuff like Alt+F4, etc to work correctly. | 220 // This allows stuff like Alt+F4, etc to work correctly. |
| 215 DefWindowProc(event.actual_message.hwnd, | 221 DefWindowProc(event.actual_message.hwnd, |
| 216 event.actual_message.message, | 222 event.actual_message.message, |
| 217 event.actual_message.wParam, | 223 event.actual_message.wParam, |
| 218 event.actual_message.lParam); | 224 event.actual_message.lParam); |
| 219 } | 225 } |
| 220 | 226 |
| 227 void WebContentsViewWin::ShowContextMenu( |
| 228 const ViewHostMsg_ContextMenu_Params& params) { |
| 229 RenderViewContextMenuController menu_controller(web_contents_, params); |
| 230 RenderViewContextMenu menu(&menu_controller, |
| 231 GetHWND(), |
| 232 params.type, |
| 233 params.misspelled_word, |
| 234 params.dictionary_suggestions, |
| 235 web_contents_->profile()); |
| 236 |
| 237 POINT screen_pt = { params.x, params.y }; |
| 238 MapWindowPoints(GetHWND(), HWND_DESKTOP, &screen_pt, 1); |
| 239 |
| 240 // Enable recursive tasks on the message loop so we can get updates while |
| 241 // the context menu is being displayed. |
| 242 bool old_state = MessageLoop::current()->NestableTasksAllowed(); |
| 243 MessageLoop::current()->SetNestableTasksAllowed(true); |
| 244 menu.RunMenuAt(screen_pt.x, screen_pt.y); |
| 245 MessageLoop::current()->SetNestableTasksAllowed(old_state); |
| 246 } |
| 247 |
| 221 WebContents* WebContentsViewWin::CreateNewWindowInternal( | 248 WebContents* WebContentsViewWin::CreateNewWindowInternal( |
| 222 int route_id, | 249 int route_id, |
| 223 HANDLE modal_dialog_event) { | 250 HANDLE modal_dialog_event) { |
| 224 // Create the new web contents. This will automatically create the new | 251 // Create the new web contents. This will automatically create the new |
| 225 // WebContentsView. In the future, we may want to create the view separately. | 252 // WebContentsView. In the future, we may want to create the view separately. |
| 226 WebContents* new_contents = | 253 WebContents* new_contents = |
| 227 new WebContents(web_contents_->profile(), | 254 new WebContents(web_contents_->profile(), |
| 228 web_contents_->GetSiteInstance(), | 255 web_contents_->GetSiteInstance(), |
| 229 web_contents_->render_view_factory_, | 256 web_contents_->render_view_factory_, |
| 230 route_id, | 257 route_id, |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 default: | 377 default: |
| 351 break; | 378 break; |
| 352 } | 379 } |
| 353 | 380 |
| 354 return 0; | 381 return 0; |
| 355 } | 382 } |
| 356 | 383 |
| 357 void WebContentsViewWin::OnPaint(HDC junk_dc) { | 384 void WebContentsViewWin::OnPaint(HDC junk_dc) { |
| 358 if (web_contents_->render_view_host() && | 385 if (web_contents_->render_view_host() && |
| 359 !web_contents_->render_view_host()->IsRenderViewLive()) { | 386 !web_contents_->render_view_host()->IsRenderViewLive()) { |
| 360 if (!web_contents_->sad_tab_.get()) | 387 if (!sad_tab_.get()) |
| 361 web_contents_->sad_tab_.reset(new SadTabView); | 388 sad_tab_.reset(new SadTabView); |
| 362 CRect cr; | 389 CRect cr; |
| 363 GetClientRect(&cr); | 390 GetClientRect(&cr); |
| 364 web_contents_->sad_tab_->SetBounds(gfx::Rect(cr)); | 391 sad_tab_->SetBounds(gfx::Rect(cr)); |
| 365 ChromeCanvasPaint canvas(GetHWND(), true); | 392 ChromeCanvasPaint canvas(GetHWND(), true); |
| 366 web_contents_->sad_tab_->ProcessPaint(&canvas); | 393 sad_tab_->ProcessPaint(&canvas); |
| 367 return; | 394 return; |
| 368 } | 395 } |
| 369 | 396 |
| 370 // We need to do this to validate the dirty area so we don't end up in a | 397 // We need to do this to validate the dirty area so we don't end up in a |
| 371 // WM_PAINTstorm that causes other mysterious bugs (such as WM_TIMERs not | 398 // WM_PAINTstorm that causes other mysterious bugs (such as WM_TIMERs not |
| 372 // firing etc). It doesn't matter that we don't have any non-clipped area. | 399 // firing etc). It doesn't matter that we don't have any non-clipped area. |
| 373 CPaintDC dc(GetHWND()); | 400 CPaintDC dc(GetHWND()); |
| 374 SetMsgHandled(FALSE); | 401 SetMsgHandled(FALSE); |
| 375 } | 402 } |
| 376 | 403 |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 } | 541 } |
| 515 return false; | 542 return false; |
| 516 } | 543 } |
| 517 | 544 |
| 518 void WebContentsViewWin::WheelZoom(int distance) { | 545 void WebContentsViewWin::WheelZoom(int distance) { |
| 519 if (web_contents_->delegate()) { | 546 if (web_contents_->delegate()) { |
| 520 bool zoom_in = distance > 0; | 547 bool zoom_in = distance > 0; |
| 521 web_contents_->delegate()->ContentsZoomChange(zoom_in); | 548 web_contents_->delegate()->ContentsZoomChange(zoom_in); |
| 522 } | 549 } |
| 523 } | 550 } |
| OLD | NEW |