OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "views/widget/native_widget_win.h" | 5 #include "views/widget/native_widget_win.h" |
6 | 6 |
7 #include <dwmapi.h> | 7 #include <dwmapi.h> |
8 #include <shellapi.h> | 8 #include <shellapi.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 815 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
826 SetWindowRgn(region, TRUE); | 826 SetWindowRgn(region, TRUE); |
827 } | 827 } |
828 | 828 |
829 void NativeWidgetWin::Close() { | 829 void NativeWidgetWin::Close() { |
830 if (!IsWindow()) | 830 if (!IsWindow()) |
831 return; // No need to do anything. | 831 return; // No need to do anything. |
832 | 832 |
833 // Let's hide ourselves right away. | 833 // Let's hide ourselves right away. |
834 Hide(); | 834 Hide(); |
835 | 835 |
| 836 // Modal dialog windows disable their owner windows; re-enable them now so |
| 837 // they can activate as foreground windows upon this window's destruction. |
| 838 RestoreEnabledIfNecessary(); |
| 839 |
836 if (!close_widget_factory_.HasWeakPtrs()) { | 840 if (!close_widget_factory_.HasWeakPtrs()) { |
837 // And we delay the close so that if we are called from an ATL callback, | 841 // And we delay the close so that if we are called from an ATL callback, |
838 // we don't destroy the window before the callback returned (as the caller | 842 // we don't destroy the window before the callback returned (as the caller |
839 // may delete ourselves on destroy and the ATL callback would still | 843 // may delete ourselves on destroy and the ATL callback would still |
840 // dereference us when the callback returns). | 844 // dereference us when the callback returns). |
841 MessageLoop::current()->PostTask( | 845 MessageLoop::current()->PostTask( |
842 FROM_HERE, | 846 FROM_HERE, |
843 base::Bind(&NativeWidgetWin::CloseNow, | 847 base::Bind(&NativeWidgetWin::CloseNow, |
844 close_widget_factory_.GetWeakPtr())); | 848 close_widget_factory_.GetWeakPtr())); |
845 } | 849 } |
846 | |
847 // If the user activates another app after opening us, then comes back and | |
848 // closes us, we want our owner to gain activation. But only if the owner | |
849 // is visible. If we don't manually force that here, the other app will | |
850 // regain activation instead. | |
851 // It's tempting to think that this could be done from OnDestroy, but by then | |
852 // it's too late - GetForegroundWindow() will return the window that Windows | |
853 // has decided to re-activate for us instead of this dialog. It's also | |
854 // tempting to think about removing the foreground window check entirely, but | |
855 // it's necessary to this code path from being triggered when an inactive | |
856 // window is closed. | |
857 HWND owner = ::GetWindow(GetNativeView(), GW_OWNER); | |
858 if (owner && GetNativeView() == GetForegroundWindow() && | |
859 IsWindowVisible(owner)) { | |
860 SetForegroundWindow(owner); | |
861 } | |
862 } | 850 } |
863 | 851 |
864 void NativeWidgetWin::CloseNow() { | 852 void NativeWidgetWin::CloseNow() { |
865 // We may already have been destroyed if the selection resulted in a tab | 853 // We may already have been destroyed if the selection resulted in a tab |
866 // switch which will have reactivated the browser window and closed us, so | 854 // switch which will have reactivated the browser window and closed us, so |
867 // we need to check to see if we're still a window before trying to destroy | 855 // we need to check to see if we're still a window before trying to destroy |
868 // ourself. | 856 // ourself. |
869 if (IsWindow()) | 857 if (IsWindow()) |
870 DestroyWindow(hwnd()); | 858 DestroyWindow(hwnd()); |
871 } | 859 } |
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1308 #endif | 1296 #endif |
1309 | 1297 |
1310 delegate_->OnNativeWidgetCreated(); | 1298 delegate_->OnNativeWidgetCreated(); |
1311 | 1299 |
1312 // Get access to a modifiable copy of the system menu. | 1300 // Get access to a modifiable copy of the system menu. |
1313 GetSystemMenu(hwnd(), false); | 1301 GetSystemMenu(hwnd(), false); |
1314 return 0; | 1302 return 0; |
1315 } | 1303 } |
1316 | 1304 |
1317 void NativeWidgetWin::OnDestroy() { | 1305 void NativeWidgetWin::OnDestroy() { |
1318 RestoreEnabledIfNecessary(); | |
1319 delegate_->OnNativeWidgetDestroying(); | 1306 delegate_->OnNativeWidgetDestroying(); |
1320 if (drop_target_.get()) { | 1307 if (drop_target_.get()) { |
1321 RevokeDragDrop(hwnd()); | 1308 RevokeDragDrop(hwnd()); |
1322 drop_target_ = NULL; | 1309 drop_target_ = NULL; |
1323 } | 1310 } |
1324 } | 1311 } |
1325 | 1312 |
1326 void NativeWidgetWin::OnDisplayChange(UINT bits_per_pixel, CSize screen_size) { | 1313 void NativeWidgetWin::OnDisplayChange(UINT bits_per_pixel, CSize screen_size) { |
1327 GetWidget()->widget_delegate()->OnDisplayChanged(); | 1314 GetWidget()->widget_delegate()->OnDisplayChanged(); |
1328 } | 1315 } |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1598 GetWidget()->widget_delegate()->OnWidgetMove(); | 1585 GetWidget()->widget_delegate()->OnWidgetMove(); |
1599 SetMsgHandled(FALSE); | 1586 SetMsgHandled(FALSE); |
1600 } | 1587 } |
1601 | 1588 |
1602 void NativeWidgetWin::OnMoving(UINT param, const LPRECT new_bounds) { | 1589 void NativeWidgetWin::OnMoving(UINT param, const LPRECT new_bounds) { |
1603 // TODO(beng): move to Widget. | 1590 // TODO(beng): move to Widget. |
1604 GetWidget()->widget_delegate()->OnWidgetMove(); | 1591 GetWidget()->widget_delegate()->OnWidgetMove(); |
1605 } | 1592 } |
1606 | 1593 |
1607 LRESULT NativeWidgetWin::OnNCActivate(BOOL active) { | 1594 LRESULT NativeWidgetWin::OnNCActivate(BOOL active) { |
| 1595 if (delegate_->CanActivate()) |
| 1596 delegate_->OnNativeWidgetActivationChanged(!!active); |
| 1597 |
1608 if (!GetWidget()->non_client_view()) { | 1598 if (!GetWidget()->non_client_view()) { |
1609 SetMsgHandled(FALSE); | 1599 SetMsgHandled(FALSE); |
1610 return 0; | 1600 return 0; |
1611 } | 1601 } |
1612 | 1602 |
1613 if (!delegate_->CanActivate()) | 1603 if (!delegate_->CanActivate()) |
1614 return TRUE; | 1604 return TRUE; |
1615 | 1605 |
1616 delegate_->OnNativeWidgetActivationChanged(!!active); | |
1617 | |
1618 // The frame may need to redraw as a result of the activation change. | 1606 // The frame may need to redraw as a result of the activation change. |
1619 // We can get WM_NCACTIVATE before we're actually visible. If we're not | 1607 // We can get WM_NCACTIVATE before we're actually visible. If we're not |
1620 // visible, no need to paint. | 1608 // visible, no need to paint. |
1621 if (IsVisible()) | 1609 if (IsVisible()) |
1622 GetWidget()->non_client_view()->SchedulePaint(); | 1610 GetWidget()->non_client_view()->SchedulePaint(); |
1623 | 1611 |
1624 if (!GetWidget()->ShouldUseNativeFrame()) { | 1612 if (!GetWidget()->ShouldUseNativeFrame()) { |
1625 // TODO(beng, et al): Hack to redraw this window and child windows | 1613 // TODO(beng, et al): Hack to redraw this window and child windows |
1626 // synchronously upon activation. Not all child windows are redrawing | 1614 // synchronously upon activation. Not all child windows are redrawing |
1627 // themselves leading to issues like http://crbug.com/74604 | 1615 // themselves leading to issues like http://crbug.com/74604 |
(...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2269 } else if (can_resize) { | 2257 } else if (can_resize) { |
2270 style |= WS_OVERLAPPED | WS_THICKFRAME; | 2258 style |= WS_OVERLAPPED | WS_THICKFRAME; |
2271 } | 2259 } |
2272 if (delegate_->IsDialogBox()) { | 2260 if (delegate_->IsDialogBox()) { |
2273 style |= DS_MODALFRAME; | 2261 style |= DS_MODALFRAME; |
2274 // NOTE: Turning this off means we lose the close button, which is bad. | 2262 // NOTE: Turning this off means we lose the close button, which is bad. |
2275 // Turning it on though means the user can maximize or size the window | 2263 // Turning it on though means the user can maximize or size the window |
2276 // from the system menu, which is worse. We may need to provide our own | 2264 // from the system menu, which is worse. We may need to provide our own |
2277 // menu to get the close button to appear properly. | 2265 // menu to get the close button to appear properly. |
2278 // style &= ~WS_SYSMENU; | 2266 // style &= ~WS_SYSMENU; |
| 2267 |
| 2268 // Set the WS_POPUP style for modal dialogs. This ensures that the owner |
| 2269 // window is activated on destruction. This style should not be set for |
| 2270 // non-modal non-top-level dialogs like constrained windows. |
| 2271 style |= delegate_->IsModal() ? WS_POPUP : 0; |
2279 } | 2272 } |
2280 ex_style |= delegate_->IsDialogBox() ? WS_EX_DLGMODALFRAME : 0; | 2273 ex_style |= delegate_->IsDialogBox() ? WS_EX_DLGMODALFRAME : 0; |
2281 break; | 2274 break; |
2282 } | 2275 } |
2283 case Widget::InitParams::TYPE_CONTROL: | 2276 case Widget::InitParams::TYPE_CONTROL: |
2284 style |= WS_VISIBLE; | 2277 style |= WS_VISIBLE; |
2285 break; | 2278 break; |
2286 case Widget::InitParams::TYPE_WINDOW_FRAMELESS: | 2279 case Widget::InitParams::TYPE_WINDOW_FRAMELESS: |
2287 style |= WS_POPUP; | 2280 style |= WS_POPUP; |
2288 break; | 2281 break; |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2624 return (GetKeyState(VK_LBUTTON) & 0x80) || | 2617 return (GetKeyState(VK_LBUTTON) & 0x80) || |
2625 (GetKeyState(VK_RBUTTON) & 0x80) || | 2618 (GetKeyState(VK_RBUTTON) & 0x80) || |
2626 (GetKeyState(VK_MBUTTON) & 0x80) || | 2619 (GetKeyState(VK_MBUTTON) & 0x80) || |
2627 (GetKeyState(VK_XBUTTON1) & 0x80) || | 2620 (GetKeyState(VK_XBUTTON1) & 0x80) || |
2628 (GetKeyState(VK_XBUTTON2) & 0x80); | 2621 (GetKeyState(VK_XBUTTON2) & 0x80); |
2629 } | 2622 } |
2630 | 2623 |
2631 } // namespace internal | 2624 } // namespace internal |
2632 | 2625 |
2633 } // namespace views | 2626 } // namespace views |
OLD | NEW |