| 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/views/tab_contents/tab_contents_view_win.h" | 5 #include "chrome/browser/views/tab_contents/tab_contents_view_win.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 | 8 |
| 9 #include "app/gfx/canvas_paint.h" | 9 #include "app/gfx/canvas_paint.h" |
| 10 #include "app/os_exchange_data.h" | 10 #include "app/os_exchange_data.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 | 46 |
| 47 } // namespace | 47 } // namespace |
| 48 | 48 |
| 49 // static | 49 // static |
| 50 TabContentsView* TabContentsView::Create(TabContents* tab_contents) { | 50 TabContentsView* TabContentsView::Create(TabContents* tab_contents) { |
| 51 return new TabContentsViewWin(tab_contents); | 51 return new TabContentsViewWin(tab_contents); |
| 52 } | 52 } |
| 53 | 53 |
| 54 TabContentsViewWin::TabContentsViewWin(TabContents* tab_contents) | 54 TabContentsViewWin::TabContentsViewWin(TabContents* tab_contents) |
| 55 : TabContentsView(tab_contents), | 55 : TabContentsView(tab_contents), |
| 56 ignore_next_char_event_(false) { | 56 ignore_next_char_event_(false), |
| 57 focus_manager_(NULL) { |
| 57 last_focused_view_storage_id_ = | 58 last_focused_view_storage_id_ = |
| 58 views::ViewStorage::GetSharedInstance()->CreateStorageID(); | 59 views::ViewStorage::GetSharedInstance()->CreateStorageID(); |
| 59 } | 60 } |
| 60 | 61 |
| 61 TabContentsViewWin::~TabContentsViewWin() { | 62 TabContentsViewWin::~TabContentsViewWin() { |
| 62 // Makes sure to remove any stored view we may still have in the ViewStorage. | 63 // Makes sure to remove any stored view we may still have in the ViewStorage. |
| 63 // | 64 // |
| 64 // It is possible the view went away before us, so we only do this if the | 65 // It is possible the view went away before us, so we only do this if the |
| 65 // view is registered. | 66 // view is registered. |
| 66 views::ViewStorage* view_storage = views::ViewStorage::GetSharedInstance(); | 67 views::ViewStorage* view_storage = views::ViewStorage::GetSharedInstance(); |
| 67 if (view_storage->RetrieveView(last_focused_view_storage_id_) != NULL) | 68 if (view_storage->RetrieveView(last_focused_view_storage_id_) != NULL) |
| 68 view_storage->RemoveView(last_focused_view_storage_id_); | 69 view_storage->RemoveView(last_focused_view_storage_id_); |
| 69 } | 70 } |
| 70 | 71 |
| 72 void TabContentsViewWin::Unparent() { |
| 73 // Remember who our FocusManager is, we won't be able to access it once |
| 74 // unparented. |
| 75 focus_manager_ = views::WidgetWin::GetFocusManager(); |
| 76 // Note that we do not DCHECK on focus_manager_ as it may be NULL when used |
| 77 // with an external tab container. |
| 78 ::SetParent(GetNativeView(), NULL); |
| 79 } |
| 80 |
| 71 void TabContentsViewWin::CreateView() { | 81 void TabContentsViewWin::CreateView() { |
| 72 set_delete_on_destroy(false); | 82 set_delete_on_destroy(false); |
| 73 // Since we create these windows parented to the desktop window initially, we | 83 // Since we create these windows parented to the desktop window initially, we |
| 74 // don't want to create them initially visible. | 84 // don't want to create them initially visible. |
| 75 set_window_style(WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS); | 85 set_window_style(WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS); |
| 76 WidgetWin::Init(GetDesktopWindow(), gfx::Rect(), false); | 86 WidgetWin::Init(GetDesktopWindow(), gfx::Rect()); |
| 77 | 87 |
| 78 // Remove the root view drop target so we can register our own. | 88 // Remove the root view drop target so we can register our own. |
| 79 RevokeDragDrop(GetNativeView()); | 89 RevokeDragDrop(GetNativeView()); |
| 80 drop_target_ = new WebDropTarget(GetNativeView(), tab_contents()); | 90 drop_target_ = new WebDropTarget(GetNativeView(), tab_contents()); |
| 81 } | 91 } |
| 82 | 92 |
| 83 RenderWidgetHostView* TabContentsViewWin::CreateViewForWidget( | 93 RenderWidgetHostView* TabContentsViewWin::CreateViewForWidget( |
| 84 RenderWidgetHost* render_widget_host) { | 94 RenderWidgetHost* render_widget_host) { |
| 85 if (render_widget_host->view()) { | 95 if (render_widget_host->view()) { |
| 86 // During testing, the view will already be set up in most cases to the | 96 // During testing, the view will already be set up in most cases to the |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 InvalidateRect(GetNativeView(), NULL, FALSE); | 236 InvalidateRect(GetNativeView(), NULL, FALSE); |
| 227 } | 237 } |
| 228 | 238 |
| 229 void TabContentsViewWin::SizeContents(const gfx::Size& size) { | 239 void TabContentsViewWin::SizeContents(const gfx::Size& size) { |
| 230 // TODO(brettw) this is a hack and should be removed. See tab_contents_view.h. | 240 // TODO(brettw) this is a hack and should be removed. See tab_contents_view.h. |
| 231 WasSized(size); | 241 WasSized(size); |
| 232 } | 242 } |
| 233 | 243 |
| 234 void TabContentsViewWin::Focus() { | 244 void TabContentsViewWin::Focus() { |
| 235 views::FocusManager* focus_manager = | 245 views::FocusManager* focus_manager = |
| 236 views::FocusManager::GetFocusManager(GetNativeView()); | 246 views::FocusManager::GetFocusManagerForNativeView(GetNativeView()); |
| 237 | 247 |
| 238 if (tab_contents()->interstitial_page()) { | 248 if (tab_contents()->interstitial_page()) { |
| 239 tab_contents()->interstitial_page()->Focus(); | 249 tab_contents()->interstitial_page()->Focus(); |
| 240 return; | 250 return; |
| 241 } | 251 } |
| 242 | 252 |
| 243 if (sad_tab_.get()) { | 253 if (sad_tab_.get()) { |
| 244 sad_tab_->RequestFocus(); | 254 sad_tab_->RequestFocus(); |
| 245 return; | 255 return; |
| 246 } | 256 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 262 Focus(); | 272 Focus(); |
| 263 } | 273 } |
| 264 | 274 |
| 265 void TabContentsViewWin::StoreFocus() { | 275 void TabContentsViewWin::StoreFocus() { |
| 266 views::ViewStorage* view_storage = views::ViewStorage::GetSharedInstance(); | 276 views::ViewStorage* view_storage = views::ViewStorage::GetSharedInstance(); |
| 267 | 277 |
| 268 if (view_storage->RetrieveView(last_focused_view_storage_id_) != NULL) | 278 if (view_storage->RetrieveView(last_focused_view_storage_id_) != NULL) |
| 269 view_storage->RemoveView(last_focused_view_storage_id_); | 279 view_storage->RemoveView(last_focused_view_storage_id_); |
| 270 | 280 |
| 271 views::FocusManager* focus_manager = | 281 views::FocusManager* focus_manager = |
| 272 views::FocusManager::GetFocusManager(GetNativeView()); | 282 views::FocusManager::GetFocusManagerForNativeView(GetNativeView()); |
| 273 if (focus_manager) { | 283 if (focus_manager) { |
| 274 // |focus_manager| can be NULL if the tab has been detached but still | 284 // |focus_manager| can be NULL if the tab has been detached but still |
| 275 // exists. | 285 // exists. |
| 276 views::View* focused_view = focus_manager->GetFocusedView(); | 286 views::View* focused_view = focus_manager->GetFocusedView(); |
| 277 if (focused_view) | 287 if (focused_view) |
| 278 view_storage->StoreView(last_focused_view_storage_id_, focused_view); | 288 view_storage->StoreView(last_focused_view_storage_id_, focused_view); |
| 279 | 289 |
| 280 // If the focus was on the page, explicitly clear the focus so that we | 290 // If the focus was on the page, explicitly clear the focus so that we |
| 281 // don't end up with the focused HWND not part of the window hierarchy. | 291 // don't end up with the focused HWND not part of the window hierarchy. |
| 282 // TODO(brettw) this should move to the view somehow. | 292 // TODO(brettw) this should move to the view somehow. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 294 | 304 |
| 295 void TabContentsViewWin::RestoreFocus() { | 305 void TabContentsViewWin::RestoreFocus() { |
| 296 views::ViewStorage* view_storage = views::ViewStorage::GetSharedInstance(); | 306 views::ViewStorage* view_storage = views::ViewStorage::GetSharedInstance(); |
| 297 views::View* last_focused_view = | 307 views::View* last_focused_view = |
| 298 view_storage->RetrieveView(last_focused_view_storage_id_); | 308 view_storage->RetrieveView(last_focused_view_storage_id_); |
| 299 | 309 |
| 300 if (!last_focused_view) { | 310 if (!last_focused_view) { |
| 301 SetInitialFocus(); | 311 SetInitialFocus(); |
| 302 } else { | 312 } else { |
| 303 views::FocusManager* focus_manager = | 313 views::FocusManager* focus_manager = |
| 304 views::FocusManager::GetFocusManager(GetNativeView()); | 314 views::FocusManager::GetFocusManagerForNativeView(GetNativeView()); |
| 305 | 315 |
| 306 // If you hit this DCHECK, please report it to Jay (jcampan). | 316 // If you hit this DCHECK, please report it to Jay (jcampan). |
| 307 DCHECK(focus_manager != NULL) << "No focus manager when restoring focus."; | 317 DCHECK(focus_manager != NULL) << "No focus manager when restoring focus."; |
| 308 | 318 |
| 309 if (last_focused_view->IsFocusable() && focus_manager && | 319 if (last_focused_view->IsFocusable() && focus_manager && |
| 310 focus_manager->ContainsView(last_focused_view)) { | 320 focus_manager->ContainsView(last_focused_view)) { |
| 311 last_focused_view->RequestFocus(); | 321 last_focused_view->RequestFocus(); |
| 312 } else { | 322 } else { |
| 313 // The focused view may not belong to the same window hierarchy (e.g. | 323 // The focused view may not belong to the same window hierarchy (e.g. |
| 314 // if the location bar was focused and the tab is dragged out), or it may | 324 // if the location bar was focused and the tab is dragged out), or it may |
| (...skipping 11 matching lines...) Expand all Loading... |
| 326 } | 336 } |
| 327 | 337 |
| 328 void TabContentsViewWin::GotFocus() { | 338 void TabContentsViewWin::GotFocus() { |
| 329 if (tab_contents()->delegate()) | 339 if (tab_contents()->delegate()) |
| 330 tab_contents()->delegate()->TabContentsFocused(tab_contents()); | 340 tab_contents()->delegate()->TabContentsFocused(tab_contents()); |
| 331 } | 341 } |
| 332 | 342 |
| 333 void TabContentsViewWin::TakeFocus(bool reverse) { | 343 void TabContentsViewWin::TakeFocus(bool reverse) { |
| 334 if (!tab_contents()->delegate()->TakeFocus(reverse)) { | 344 if (!tab_contents()->delegate()->TakeFocus(reverse)) { |
| 335 views::FocusManager* focus_manager = | 345 views::FocusManager* focus_manager = |
| 336 views::FocusManager::GetFocusManager(GetNativeView()); | 346 views::FocusManager::GetFocusManagerForNativeView(GetNativeView()); |
| 337 | 347 |
| 338 // We may not have a focus manager if the tab has been switched before this | 348 // We may not have a focus manager if the tab has been switched before this |
| 339 // message arrived. | 349 // message arrived. |
| 340 if (focus_manager) | 350 if (focus_manager) |
| 341 focus_manager->AdvanceFocus(reverse); | 351 focus_manager->AdvanceFocus(reverse); |
| 342 } | 352 } |
| 343 } | 353 } |
| 344 | 354 |
| 345 void TabContentsViewWin::HandleKeyboardEvent( | 355 void TabContentsViewWin::HandleKeyboardEvent( |
| 346 const NativeWebKeyboardEvent& event) { | 356 const NativeWebKeyboardEvent& event) { |
| 347 // Previous calls to TranslateMessage can generate CHAR events as well as | 357 // Previous calls to TranslateMessage can generate CHAR events as well as |
| 348 // RAW_KEY_DOWN events, even if the latter triggered an accelerator. In these | 358 // RAW_KEY_DOWN events, even if the latter triggered an accelerator. In these |
| 349 // cases, we discard the CHAR events. | 359 // cases, we discard the CHAR events. |
| 350 if (event.type == WebInputEvent::Char && ignore_next_char_event_) { | 360 if (event.type == WebInputEvent::Char && ignore_next_char_event_) { |
| 351 ignore_next_char_event_ = false; | 361 ignore_next_char_event_ = false; |
| 352 return; | 362 return; |
| 353 } | 363 } |
| 354 ignore_next_char_event_ = false; | 364 ignore_next_char_event_ = false; |
| 355 | 365 |
| 356 // The renderer returned a keyboard event it did not process. This may be | 366 // The renderer returned a keyboard event it did not process. This may be |
| 357 // a keyboard shortcut that we have to process. | 367 // a keyboard shortcut that we have to process. |
| 358 if (event.type == WebInputEvent::RawKeyDown) { | 368 if (event.type == WebInputEvent::RawKeyDown) { |
| 359 views::FocusManager* focus_manager = | 369 views::FocusManager* focus_manager = |
| 360 views::FocusManager::GetFocusManager(GetNativeView()); | 370 views::FocusManager::GetFocusManagerForNativeView(GetNativeView()); |
| 361 // We may not have a focus_manager at this point (if the tab has been | 371 // We may not have a focus_manager at this point (if the tab has been |
| 362 // switched by the time this message returned). | 372 // switched by the time this message returned). |
| 363 if (focus_manager) { | 373 if (focus_manager) { |
| 364 views::Accelerator accelerator(event.windowsKeyCode, | 374 views::Accelerator accelerator(event.windowsKeyCode, |
| 365 (event.modifiers & WebInputEvent::ShiftKey) == | 375 (event.modifiers & WebInputEvent::ShiftKey) == |
| 366 WebInputEvent::ShiftKey, | 376 WebInputEvent::ShiftKey, |
| 367 (event.modifiers & WebInputEvent::ControlKey) == | 377 (event.modifiers & WebInputEvent::ControlKey) == |
| 368 WebInputEvent::ControlKey, | 378 WebInputEvent::ControlKey, |
| 369 (event.modifiers & WebInputEvent::AltKey) == | 379 (event.modifiers & WebInputEvent::AltKey) == |
| 370 WebInputEvent::AltKey); | 380 WebInputEvent::AltKey); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 386 } | 396 } |
| 387 | 397 |
| 388 // Any unhandled keyboard/character messages should be defproced. | 398 // Any unhandled keyboard/character messages should be defproced. |
| 389 // This allows stuff like Alt+F4, etc to work correctly. | 399 // This allows stuff like Alt+F4, etc to work correctly. |
| 390 DefWindowProc(event.os_event.hwnd, | 400 DefWindowProc(event.os_event.hwnd, |
| 391 event.os_event.message, | 401 event.os_event.message, |
| 392 event.os_event.wParam, | 402 event.os_event.wParam, |
| 393 event.os_event.lParam); | 403 event.os_event.lParam); |
| 394 } | 404 } |
| 395 | 405 |
| 406 views::FocusManager* TabContentsViewWin::GetFocusManager() { |
| 407 views::FocusManager* focus_manager = WidgetWin::GetFocusManager(); |
| 408 if (focus_manager) { |
| 409 // If focus_manager_ is non NULL, it means we have been reparented, in which |
| 410 // case its value may not be valid anymore. |
| 411 focus_manager_ = NULL; |
| 412 return focus_manager; |
| 413 } |
| 414 |
| 415 DCHECK(focus_manager_); |
| 416 return focus_manager_; |
| 417 } |
| 418 |
| 396 void TabContentsViewWin::ShowContextMenu(const ContextMenuParams& params) { | 419 void TabContentsViewWin::ShowContextMenu(const ContextMenuParams& params) { |
| 397 // Allow delegates to handle the context menu operation first. | 420 // Allow delegates to handle the context menu operation first. |
| 398 if (tab_contents()->delegate()->HandleContextMenu(params)) | 421 if (tab_contents()->delegate()->HandleContextMenu(params)) |
| 399 return; | 422 return; |
| 400 | 423 |
| 401 context_menu_.reset(new RenderViewContextMenuWin(tab_contents(), params)); | 424 context_menu_.reset(new RenderViewContextMenuWin(tab_contents(), params)); |
| 402 context_menu_->Init(); | 425 context_menu_->Init(); |
| 403 | 426 |
| 404 POINT screen_pt = { params.x, params.y }; | 427 POINT screen_pt = { params.x, params.y }; |
| 405 MapWindowPoints(GetNativeView(), HWND_DESKTOP, &screen_pt, 1); | 428 MapWindowPoints(GetNativeView(), HWND_DESKTOP, &screen_pt, 1); |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 609 } | 632 } |
| 610 return false; | 633 return false; |
| 611 } | 634 } |
| 612 | 635 |
| 613 void TabContentsViewWin::WheelZoom(int distance) { | 636 void TabContentsViewWin::WheelZoom(int distance) { |
| 614 if (tab_contents()->delegate()) { | 637 if (tab_contents()->delegate()) { |
| 615 bool zoom_in = distance > 0; | 638 bool zoom_in = distance > 0; |
| 616 tab_contents()->delegate()->ContentsZoomChange(zoom_in); | 639 tab_contents()->delegate()->ContentsZoomChange(zoom_in); |
| 617 } | 640 } |
| 618 } | 641 } |
| OLD | NEW |