Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8442)

Unified Diff: chrome/browser/views/constrained_window_win.cc

Issue 140064: Revert :... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/views/browser_bubble_win.cc ('k') | chrome/browser/views/download_started_animation_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/views/constrained_window_win.cc
===================================================================
--- chrome/browser/views/constrained_window_win.cc (revision 18902)
+++ chrome/browser/views/constrained_window_win.cc (working copy)
@@ -638,13 +638,48 @@
void ConstrainedWindowWin::ActivateConstrainedWindow() {
// Other pop-ups are simply moved to the front of the z-order.
SetWindowPos(HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
+
+ // Store the focus of our parent focus manager so we can restore it when we
+ // close.
+ views::FocusManager* focus_manager =
+ views::FocusManager::GetFocusManager(GetNativeView());
+ DCHECK(focus_manager);
+ focus_manager = focus_manager->GetParentFocusManager();
+ if (focus_manager) {
+ // We could not have a parent focus manager if the ConstrainedWindow is
+ // displayed in a tab that is not currently selected.
+ // TODO(jcampan): we should store the ConstrainedWindow active events in
+ // that case and replay them when the TabContents becomes selected.
+ focus_manager->StoreFocusedView();
+
+ // Give our window the focus so we get keyboard messages.
+ ::SetFocus(GetNativeView());
+ }
}
////////////////////////////////////////////////////////////////////////////////
// ConstrainedWindowWin, views::WidgetWin overrides:
void ConstrainedWindowWin::OnDestroy() {
- // TODO(jcampan): figure out focus restoration
+ // We do this here, rather than |Close|, since the window may be destroyed in
+ // a way other than by some other component calling Close, e.g. by the native
+ // window hierarchy closing. We are guaranteed to receive a WM_DESTROY
+ // message regardless of how the window is closed.
+ // Note that when we get this message, the focus manager of the
+ // ConstrainedWindow has already been destroyed (by the processing of
+ // WM_DESTROY in FocusManager). So the FocusManager we retrieve here is the
+ // parent one (the one from the top window).
+ views::FocusManager* focus_manager =
+ views::FocusManager::GetFocusManager(GetNativeView());
+ if (focus_manager) {
+ // We may not have a focus manager if:
+ // - we are hidden when closed (the TabContent would be detached).
+ // - the tab has been closed and we are closed as a result.
+ // TODO(jcampan): when hidden, we should modify the stored focus of the tab
+ // so when it becomes visible again we retrieve the focus appropriately.
+ if (!focus_restoration_disabled_)
+ focus_manager->RestoreFocusedView();
+ }
// Make sure we call super so that it can do its cleanup.
WindowWin::OnDestroy();
« no previous file with comments | « chrome/browser/views/browser_bubble_win.cc ('k') | chrome/browser/views/download_started_animation_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698