From f66a1879d8103e1c92e18b268b44152190cf5b98 Mon Sep 17 00:00:00 2001 From: "ben@chromium.org" Date: Wed, 16 Mar 2011 20:34:51 +0000 Subject: Fix window activation when closing a modal dialog box. It turns out GetForegroundWindow() returns a different value when it's called from WM_DESTROY vs. WM_CLOSE. We need to do activation restoration earlier than WM_DESTROY. http://crbug.com/75610 TEST=see bug TBR=sky Review URL: http://codereview.chromium.org/6670054 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@78420 0039d316-1c4b-4281-b951-d872f2087c98 --- views/window/window_win.cc | 32 ++++++++++++++++++++------------ views/window/window_win.h | 1 + 2 files changed, 21 insertions(+), 12 deletions(-) (limited to 'views/window') diff --git a/views/window/window_win.cc b/views/window/window_win.cc index 301b5099..9ba6056 100644 --- a/views/window/window_win.cc +++ b/views/window/window_win.cc @@ -404,19 +404,7 @@ void WindowWin::OnCommand(UINT notification_code, int command_id, HWND window) { void WindowWin::OnDestroy() { delegate_->OnNativeWindowDestroying(); - RestoreEnabledIfNecessary(); - - // If the user activates another app after opening us, then comes back and - // closes us, we want our owner to gain activation. But only if the owner - // is visible. If we don't manually force that here, the other app will - // regain activation instead. - HWND owner = GetOwner(GetNativeView()); - if (owner && GetNativeView() == GetForegroundWindow() && - IsWindowVisible(owner)) { - SetForegroundWindow(owner); - } - WidgetWin::OnDestroy(); } @@ -869,6 +857,26 @@ void WindowWin::OnWindowPosChanging(WINDOWPOS* window_pos) { WidgetWin::OnWindowPosChanging(window_pos); } +void WindowWin::Close() { + WidgetWin::Close(); + + // If the user activates another app after opening us, then comes back and + // closes us, we want our owner to gain activation. But only if the owner + // is visible. If we don't manually force that here, the other app will + // regain activation instead. + // It's tempting to think that this could be done from OnDestroy, but by then + // it's too late - GetForegroundWindow() will return the window that Windows + // has decided to re-activate for us instead of this dialog. It's also + // tempting to think about removing the foreground window check entirely, but + // it's necessary to this code path from being triggered when an inactive + // window is closed. + HWND owner = GetOwner(GetNativeView()); + if (owner && GetNativeView() == GetForegroundWindow() && + IsWindowVisible(owner)) { + SetForegroundWindow(owner); + } +} + //////////////////////////////////////////////////////////////////////////////// // WindowWin, NativeWindow implementation: diff --git a/views/window/window_win.h b/views/window/window_win.h index 114ea1e..e2ef0f6 100644 --- a/views/window/window_win.h +++ b/views/window/window_win.h @@ -135,6 +135,7 @@ class WindowWin : public WidgetWin, virtual void OnWindowPosChanging(WINDOWPOS* window_pos) OVERRIDE; virtual Window* GetWindow() OVERRIDE { return this; } virtual const Window* GetWindow() const OVERRIDE { return this; } + virtual void Close() OVERRIDE; // Overridden from NativeWindow: virtual NativeWidget* AsNativeWidget() OVERRIDE; -- cgit v1.1