| 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 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 //////////////////////////////////////////////////////////////////////////////// | 619 //////////////////////////////////////////////////////////////////////////////// |
| 620 // ConstrainedWindowWin, private: | 620 // ConstrainedWindowWin, private: |
| 621 | 621 |
| 622 ConstrainedWindowWin::ConstrainedWindowWin( | 622 ConstrainedWindowWin::ConstrainedWindowWin( |
| 623 TabContents* owner, | 623 TabContents* owner, |
| 624 views::WindowDelegate* window_delegate) | 624 views::WindowDelegate* window_delegate) |
| 625 : WindowWin(window_delegate), | 625 : WindowWin(window_delegate), |
| 626 owner_(owner) { | 626 owner_(owner) { |
| 627 GetNonClientView()->SetFrameView(CreateFrameViewForWindow()); | 627 GetNonClientView()->SetFrameView(CreateFrameViewForWindow()); |
| 628 | 628 |
| 629 focus_restoration_disabled_ = false; | |
| 630 set_window_style(WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_CAPTION | | 629 set_window_style(WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_CAPTION | |
| 631 WS_THICKFRAME | WS_SYSMENU); | 630 WS_THICKFRAME | WS_SYSMENU); |
| 632 set_focus_on_creation(false); | 631 set_focus_on_creation(false); |
| 633 | 632 |
| 634 WindowWin::Init(owner_->GetNativeView(), gfx::Rect()); | 633 WindowWin::Init(owner_->GetNativeView(), gfx::Rect()); |
| 635 ActivateConstrainedWindow(); | 634 ActivateConstrainedWindow(); |
| 636 } | 635 } |
| 637 | 636 |
| 638 void ConstrainedWindowWin::ActivateConstrainedWindow() { | 637 void ConstrainedWindowWin::ActivateConstrainedWindow() { |
| 639 // Other pop-ups are simply moved to the front of the z-order. | 638 // 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); | 639 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 } | |
| 658 } | 640 } |
| 659 | 641 |
| 660 //////////////////////////////////////////////////////////////////////////////// | 642 //////////////////////////////////////////////////////////////////////////////// |
| 661 // ConstrainedWindowWin, views::WidgetWin overrides: | 643 // ConstrainedWindowWin, views::WidgetWin overrides: |
| 662 | 644 |
| 663 void ConstrainedWindowWin::OnDestroy() { | 645 void ConstrainedWindowWin::OnDestroy() { |
| 664 // We do this here, rather than |Close|, since the window may be destroyed in | 646 // TODO(jcampan): figure out focus restoration |
| 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 } | |
| 683 | 647 |
| 684 // Make sure we call super so that it can do its cleanup. | 648 // Make sure we call super so that it can do its cleanup. |
| 685 WindowWin::OnDestroy(); | 649 WindowWin::OnDestroy(); |
| 686 } | 650 } |
| 687 | 651 |
| 688 void ConstrainedWindowWin::OnFinalMessage(HWND window) { | 652 void ConstrainedWindowWin::OnFinalMessage(HWND window) { |
| 689 // Tell our constraining TabContents that we've gone so it can update its | 653 // Tell our constraining TabContents that we've gone so it can update its |
| 690 // list. | 654 // list. |
| 691 owner_->WillClose(this); | 655 owner_->WillClose(this); |
| 692 | 656 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 716 | 680 |
| 717 | 681 |
| 718 // static | 682 // static |
| 719 ConstrainedWindow* ConstrainedWindow::CreateConstrainedDialog( | 683 ConstrainedWindow* ConstrainedWindow::CreateConstrainedDialog( |
| 720 TabContents* parent, | 684 TabContents* parent, |
| 721 views::WindowDelegate* window_delegate) { | 685 views::WindowDelegate* window_delegate) { |
| 722 ConstrainedWindowWin* window = new ConstrainedWindowWin(parent, | 686 ConstrainedWindowWin* window = new ConstrainedWindowWin(parent, |
| 723 window_delegate); | 687 window_delegate); |
| 724 return window; | 688 return window; |
| 725 } | 689 } |
| OLD | NEW |