OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/views/widget/native_widget_win.h" | 5 #include "ui/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 975 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
986 } | 986 } |
987 | 987 |
988 void NativeWidgetWin::Restore() { | 988 void NativeWidgetWin::Restore() { |
989 ExecuteSystemMenuCommand(SC_RESTORE); | 989 ExecuteSystemMenuCommand(SC_RESTORE); |
990 } | 990 } |
991 | 991 |
992 void NativeWidgetWin::SetFullscreen(bool fullscreen) { | 992 void NativeWidgetWin::SetFullscreen(bool fullscreen) { |
993 if (fullscreen_ == fullscreen) | 993 if (fullscreen_ == fullscreen) |
994 return; | 994 return; |
995 | 995 |
996 gfx::Rect window_rect; | 996 SetFullscreenInternal(fullscreen, false); |
997 if (fullscreen) { | |
998 MONITORINFO monitor_info; | |
999 monitor_info.cbSize = sizeof(monitor_info); | |
1000 GetMonitorInfo(MonitorFromWindow(GetNativeView(), MONITOR_DEFAULTTONEAREST), | |
1001 &monitor_info); | |
1002 window_rect = monitor_info.rcMonitor; | |
1003 } | |
1004 | |
1005 SetFullscreenInternal(fullscreen, window_rect); | |
1006 } | 997 } |
1007 | 998 |
1008 void NativeWidgetWin::SetMetroSnapFullscreen(bool metro_snap) { | 999 void NativeWidgetWin::SetMetroSnapFullscreen(bool metro_snap) { |
1009 if (metro_snap_ == metro_snap) | 1000 if (metro_snap_ == metro_snap) |
1010 return; | 1001 return; |
1011 | 1002 |
| 1003 SetFullscreenInternal(metro_snap, true); |
| 1004 |
1012 metro_snap_ = metro_snap; | 1005 metro_snap_ = metro_snap; |
1013 | |
1014 gfx::Rect window_rect; | |
1015 if (!metro_snap) { | |
1016 MONITORINFO monitor_info; | |
1017 monitor_info.cbSize = sizeof(monitor_info); | |
1018 GetMonitorInfo(MonitorFromWindow(GetNativeView(), MONITOR_DEFAULTTONEAREST), | |
1019 &monitor_info); | |
1020 window_rect = monitor_info.rcMonitor; | |
1021 } | |
1022 | |
1023 SetFullscreenInternal(metro_snap, window_rect); | |
1024 } | 1006 } |
1025 | 1007 |
1026 void NativeWidgetWin::SetFullscreenInternal(bool fullscreen, | 1008 void NativeWidgetWin::SetFullscreenInternal(bool fullscreen, |
1027 const gfx::Rect& window_rect) { | 1009 bool for_metro) { |
1028 | 1010 |
1029 // Reduce jankiness during the following position changes by hiding the window | 1011 // Reduce jankiness during the following position changes by hiding the window |
1030 // until it's in the final position. | 1012 // until it's in the final position. |
1031 PushForceHidden(); | 1013 PushForceHidden(); |
1032 | 1014 |
1033 // Size/position/style window appropriately. | 1015 // Save current window state if not already fullscreen. |
1034 if (!fullscreen_) { | 1016 if (!fullscreen_) { |
1035 // Save current window information. We force the window into restored mode | 1017 // Save current window information. We force the window into restored mode |
1036 // before going fullscreen because Windows doesn't seem to hide the | 1018 // before going fullscreen because Windows doesn't seem to hide the |
1037 // taskbar if the window is in the maximized state. | 1019 // taskbar if the window is in the maximized state. |
1038 saved_window_info_.maximized = IsMaximized(); | 1020 saved_window_info_.maximized = IsMaximized(); |
1039 if (saved_window_info_.maximized) | 1021 if (saved_window_info_.maximized) |
1040 Restore(); | 1022 Restore(); |
1041 saved_window_info_.style = GetWindowLong(GWL_STYLE); | 1023 saved_window_info_.style = GetWindowLong(GWL_STYLE); |
1042 saved_window_info_.ex_style = GetWindowLong(GWL_EXSTYLE); | 1024 saved_window_info_.ex_style = GetWindowLong(GWL_EXSTYLE); |
1043 GetWindowRect(&saved_window_info_.window_rect); | 1025 GetWindowRect(&saved_window_info_.window_rect); |
1044 } | 1026 } |
1045 | 1027 |
1046 fullscreen_ = fullscreen; | 1028 fullscreen_ = fullscreen; |
1047 | 1029 |
1048 if (fullscreen_) { | 1030 if (fullscreen_) { |
1049 // Set new window style and size. | 1031 // Set new window style and size. |
1050 SetWindowLong(GWL_STYLE, | 1032 SetWindowLong(GWL_STYLE, |
1051 saved_window_info_.style & ~(WS_CAPTION | WS_THICKFRAME)); | 1033 saved_window_info_.style & ~(WS_CAPTION | WS_THICKFRAME)); |
1052 SetWindowLong(GWL_EXSTYLE, | 1034 SetWindowLong(GWL_EXSTYLE, |
1053 saved_window_info_.ex_style & ~(WS_EX_DLGMODALFRAME | | 1035 saved_window_info_.ex_style & ~(WS_EX_DLGMODALFRAME | |
1054 WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE)); | 1036 WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE)); |
1055 | 1037 |
1056 // On expand, if we're given a window_rect, grow to it, otherwise do | 1038 // On expand, if we're given a window_rect, grow to it, otherwise do |
1057 // not resize. | 1039 // not resize. |
1058 if (window_rect.width() > 0) { | 1040 if (!for_metro) { |
| 1041 MONITORINFO monitor_info; |
| 1042 monitor_info.cbSize = sizeof(monitor_info); |
| 1043 GetMonitorInfo(MonitorFromWindow(GetNativeView(), |
| 1044 MONITOR_DEFAULTTONEAREST), |
| 1045 &monitor_info); |
| 1046 gfx::Rect window_rect(monitor_info.rcMonitor); |
1059 SetWindowPos(NULL, window_rect.x(), window_rect.y(), | 1047 SetWindowPos(NULL, window_rect.x(), window_rect.y(), |
1060 window_rect.width(), window_rect.height(), | 1048 window_rect.width(), window_rect.height(), |
1061 SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED); | 1049 SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED); |
1062 } | 1050 } |
1063 } else { | 1051 } else { |
1064 // Reset original window style and size. The multiple window size/moves | 1052 // Reset original window style and size. The multiple window size/moves |
1065 // here are ugly, but if SetWindowPos() doesn't redraw, the taskbar won't be | 1053 // here are ugly, but if SetWindowPos() doesn't redraw, the taskbar won't be |
1066 // repainted. Better-looking methods welcome. | 1054 // repainted. Better-looking methods welcome. |
1067 SetWindowLong(GWL_STYLE, saved_window_info_.style); | 1055 SetWindowLong(GWL_STYLE, saved_window_info_.style); |
1068 SetWindowLong(GWL_EXSTYLE, saved_window_info_.ex_style); | 1056 SetWindowLong(GWL_EXSTYLE, saved_window_info_.ex_style); |
1069 | 1057 |
1070 // On restore, if we're given a window_rect resize to that, otherwise | 1058 if (!for_metro) { |
1071 // resize to the previous saved rect size. | 1059 // On restore, resize to the previous saved rect size. |
1072 gfx::Rect new_rect; | 1060 gfx::Rect new_rect(saved_window_info_.window_rect); |
1073 if (window_rect.width() > 0) { | 1061 SetWindowPos(NULL, new_rect.x(), new_rect.y(), new_rect.width(), |
1074 new_rect = window_rect; | 1062 new_rect.height(), |
1075 } else { | 1063 SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED); |
1076 new_rect = saved_window_info_.window_rect; | |
1077 } | 1064 } |
1078 | |
1079 SetWindowPos(NULL, new_rect.x(), new_rect.y(), new_rect.width(), | |
1080 new_rect.height(), | |
1081 SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED); | |
1082 if (saved_window_info_.maximized) | 1065 if (saved_window_info_.maximized) |
1083 Maximize(); | 1066 Maximize(); |
1084 } | 1067 } |
1085 | 1068 |
1086 // Undo our anti-jankiness hacks. | 1069 // Undo our anti-jankiness hacks. |
1087 PopForceHidden(); | 1070 PopForceHidden(); |
1088 } | 1071 } |
1089 | 1072 |
1090 bool NativeWidgetWin::IsFullscreen() const { | 1073 bool NativeWidgetWin::IsFullscreen() const { |
1091 return fullscreen_; | 1074 return fullscreen_; |
(...skipping 1692 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2784 // static | 2767 // static |
2785 bool NativeWidgetPrivate::IsTouchDown() { | 2768 bool NativeWidgetPrivate::IsTouchDown() { |
2786 // This currently isn't necessary because we're not generating touch events on | 2769 // This currently isn't necessary because we're not generating touch events on |
2787 // windows. When we do, this will need to be updated. | 2770 // windows. When we do, this will need to be updated. |
2788 return false; | 2771 return false; |
2789 } | 2772 } |
2790 | 2773 |
2791 } // namespace internal | 2774 } // namespace internal |
2792 | 2775 |
2793 } // namespace views | 2776 } // namespace views |
OLD | NEW |