| 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/constrained_window_win.h" | 5 #include "chrome/browser/views/constrained_window_win.h" |
| 6 | 6 |
| 7 #include "app/gfx/canvas.h" | 7 #include "app/gfx/canvas.h" |
| 8 #include "app/gfx/font.h" | 8 #include "app/gfx/font.h" |
| 9 #include "app/gfx/path.h" | 9 #include "app/gfx/path.h" |
| 10 #include "app/gfx/text_elider.h" | 10 #include "app/gfx/text_elider.h" |
| (...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 WS_THICKFRAME | WS_SYSMENU); | 631 WS_THICKFRAME | WS_SYSMENU); |
| 632 set_focus_on_creation(false); | 632 set_focus_on_creation(false); |
| 633 | 633 |
| 634 WindowWin::Init(owner_->GetNativeView(), gfx::Rect()); | 634 WindowWin::Init(owner_->GetNativeView(), gfx::Rect()); |
| 635 ActivateConstrainedWindow(); | 635 ActivateConstrainedWindow(); |
| 636 } | 636 } |
| 637 | 637 |
| 638 void ConstrainedWindowWin::ActivateConstrainedWindow() { | 638 void ConstrainedWindowWin::ActivateConstrainedWindow() { |
| 639 // Other pop-ups are simply moved to the front of the z-order. | 639 // Other pop-ups are simply moved to the front of the z-order. |
| 640 SetWindowPos(HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW); | 640 SetWindowPos(HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW); |
| 641 |
| 642 // Store the focus of our parent focus manager so we can restore it when we |
| 643 // close. |
| 644 views::FocusManager* focus_manager = |
| 645 views::FocusManager::GetFocusManager(GetNativeView()); |
| 646 DCHECK(focus_manager); |
| 647 focus_manager = focus_manager->GetParentFocusManager(); |
| 648 if (focus_manager) { |
| 649 // We could not have a parent focus manager if the ConstrainedWindow is |
| 650 // displayed in a tab that is not currently selected. |
| 651 // TODO(jcampan): we should store the ConstrainedWindow active events in |
| 652 // that case and replay them when the TabContents becomes selected. |
| 653 focus_manager->StoreFocusedView(); |
| 654 |
| 655 // Give our window the focus so we get keyboard messages. |
| 656 ::SetFocus(GetNativeView()); |
| 657 } |
| 641 } | 658 } |
| 642 | 659 |
| 643 //////////////////////////////////////////////////////////////////////////////// | 660 //////////////////////////////////////////////////////////////////////////////// |
| 644 // ConstrainedWindowWin, views::WidgetWin overrides: | 661 // ConstrainedWindowWin, views::WidgetWin overrides: |
| 645 | 662 |
| 646 void ConstrainedWindowWin::OnDestroy() { | 663 void ConstrainedWindowWin::OnDestroy() { |
| 647 // TODO(jcampan): figure out focus restoration | 664 // We do this here, rather than |Close|, since the window may be destroyed in |
| 665 // a way other than by some other component calling Close, e.g. by the native |
| 666 // window hierarchy closing. We are guaranteed to receive a WM_DESTROY |
| 667 // message regardless of how the window is closed. |
| 668 // Note that when we get this message, the focus manager of the |
| 669 // ConstrainedWindow has already been destroyed (by the processing of |
| 670 // WM_DESTROY in FocusManager). So the FocusManager we retrieve here is the |
| 671 // parent one (the one from the top window). |
| 672 views::FocusManager* focus_manager = |
| 673 views::FocusManager::GetFocusManager(GetNativeView()); |
| 674 if (focus_manager) { |
| 675 // We may not have a focus manager if: |
| 676 // - we are hidden when closed (the TabContent would be detached). |
| 677 // - the tab has been closed and we are closed as a result. |
| 678 // TODO(jcampan): when hidden, we should modify the stored focus of the tab |
| 679 // so when it becomes visible again we retrieve the focus appropriately. |
| 680 if (!focus_restoration_disabled_) |
| 681 focus_manager->RestoreFocusedView(); |
| 682 } |
| 648 | 683 |
| 649 // Make sure we call super so that it can do its cleanup. | 684 // Make sure we call super so that it can do its cleanup. |
| 650 WindowWin::OnDestroy(); | 685 WindowWin::OnDestroy(); |
| 651 } | 686 } |
| 652 | 687 |
| 653 void ConstrainedWindowWin::OnFinalMessage(HWND window) { | 688 void ConstrainedWindowWin::OnFinalMessage(HWND window) { |
| 654 // Tell our constraining TabContents that we've gone so it can update its | 689 // Tell our constraining TabContents that we've gone so it can update its |
| 655 // list. | 690 // list. |
| 656 owner_->WillClose(this); | 691 owner_->WillClose(this); |
| 657 | 692 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 681 | 716 |
| 682 | 717 |
| 683 // static | 718 // static |
| 684 ConstrainedWindow* ConstrainedWindow::CreateConstrainedDialog( | 719 ConstrainedWindow* ConstrainedWindow::CreateConstrainedDialog( |
| 685 TabContents* parent, | 720 TabContents* parent, |
| 686 views::WindowDelegate* window_delegate) { | 721 views::WindowDelegate* window_delegate) { |
| 687 ConstrainedWindowWin* window = new ConstrainedWindowWin(parent, | 722 ConstrainedWindowWin* window = new ConstrainedWindowWin(parent, |
| 688 window_delegate); | 723 window_delegate); |
| 689 return window; | 724 return window; |
| 690 } | 725 } |
| OLD | NEW |