| 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/win/fullscreen_handler.h" | 5 #include "ui/views/win/fullscreen_handler.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 // TODO(beng): Temporary dependancy until fullscreen moves to | 8 #include "ui/gfx/rect.h" |
| 9 // HWNDMessageHandler. | |
| 10 #include "ui/views/widget/widget.h" | |
| 11 #include "ui/views/win/scoped_fullscreen_visibility.h" | 9 #include "ui/views/win/scoped_fullscreen_visibility.h" |
| 12 | 10 |
| 13 namespace views { | 11 namespace views { |
| 14 | 12 |
| 15 //////////////////////////////////////////////////////////////////////////////// | 13 //////////////////////////////////////////////////////////////////////////////// |
| 16 // FullscreenHandler, public: | 14 // FullscreenHandler, public: |
| 17 | 15 |
| 18 FullscreenHandler::FullscreenHandler(Widget* widget) | 16 FullscreenHandler::FullscreenHandler() |
| 19 : widget_(widget), | 17 : hwnd_(NULL), |
| 20 fullscreen_(false), | 18 fullscreen_(false), |
| 21 metro_snap_(false) { | 19 metro_snap_(false) { |
| 22 } | 20 } |
| 23 | 21 |
| 24 FullscreenHandler::~FullscreenHandler() { | 22 FullscreenHandler::~FullscreenHandler() { |
| 25 } | 23 } |
| 26 | 24 |
| 27 void FullscreenHandler::SetFullscreen(bool fullscreen) { | 25 void FullscreenHandler::SetFullscreen(bool fullscreen) { |
| 28 if (fullscreen_ == fullscreen) | 26 if (fullscreen_ == fullscreen) |
| 29 return; | 27 return; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 40 } | 38 } |
| 41 | 39 |
| 42 gfx::Rect FullscreenHandler::GetRestoreBounds() const { | 40 gfx::Rect FullscreenHandler::GetRestoreBounds() const { |
| 43 return gfx::Rect(saved_window_info_.window_rect); | 41 return gfx::Rect(saved_window_info_.window_rect); |
| 44 } | 42 } |
| 45 | 43 |
| 46 //////////////////////////////////////////////////////////////////////////////// | 44 //////////////////////////////////////////////////////////////////////////////// |
| 47 // FullscreenHandler, private: | 45 // FullscreenHandler, private: |
| 48 | 46 |
| 49 void FullscreenHandler::SetFullscreenImpl(bool fullscreen, bool for_metro) { | 47 void FullscreenHandler::SetFullscreenImpl(bool fullscreen, bool for_metro) { |
| 50 ScopedFullscreenVisibility visibility(widget_->GetNativeView()); | 48 ScopedFullscreenVisibility visibility(hwnd_); |
| 51 | 49 |
| 52 // Save current window state if not already fullscreen. | 50 // Save current window state if not already fullscreen. |
| 53 if (!fullscreen_) { | 51 if (!fullscreen_) { |
| 54 // Save current window information. We force the window into restored mode | 52 // Save current window information. We force the window into restored mode |
| 55 // before going fullscreen because Windows doesn't seem to hide the | 53 // before going fullscreen because Windows doesn't seem to hide the |
| 56 // taskbar if the window is in the maximized state. | 54 // taskbar if the window is in the maximized state. |
| 57 saved_window_info_.maximized = widget_->IsMaximized(); | 55 saved_window_info_.maximized = !!::IsZoomed(hwnd_); |
| 58 if (saved_window_info_.maximized) | 56 if (saved_window_info_.maximized) |
| 59 widget_->Restore(); | 57 ::SendMessage(hwnd_, WM_SYSCOMMAND, SC_RESTORE, 0); |
| 60 saved_window_info_.style = | 58 saved_window_info_.style = GetWindowLong(hwnd_, GWL_STYLE); |
| 61 GetWindowLong(widget_->GetNativeView(), GWL_STYLE); | 59 saved_window_info_.ex_style = GetWindowLong(hwnd_, GWL_EXSTYLE); |
| 62 saved_window_info_.ex_style = | 60 GetWindowRect(hwnd_, &saved_window_info_.window_rect); |
| 63 GetWindowLong(widget_->GetNativeView(), GWL_EXSTYLE); | |
| 64 GetWindowRect(widget_->GetNativeView(), &saved_window_info_.window_rect); | |
| 65 } | 61 } |
| 66 | 62 |
| 67 fullscreen_ = fullscreen; | 63 fullscreen_ = fullscreen; |
| 68 | 64 |
| 69 if (fullscreen_) { | 65 if (fullscreen_) { |
| 70 // Set new window style and size. | 66 // Set new window style and size. |
| 71 SetWindowLong(widget_->GetNativeView(), GWL_STYLE, | 67 SetWindowLong(hwnd_, GWL_STYLE, |
| 72 saved_window_info_.style & ~(WS_CAPTION | WS_THICKFRAME)); | 68 saved_window_info_.style & ~(WS_CAPTION | WS_THICKFRAME)); |
| 73 SetWindowLong(widget_->GetNativeView(), GWL_EXSTYLE, | 69 SetWindowLong(hwnd_, GWL_EXSTYLE, |
| 74 saved_window_info_.ex_style & ~(WS_EX_DLGMODALFRAME | | 70 saved_window_info_.ex_style & ~(WS_EX_DLGMODALFRAME | |
| 75 WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE)); | 71 WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE)); |
| 76 | 72 |
| 77 // On expand, if we're given a window_rect, grow to it, otherwise do | 73 // On expand, if we're given a window_rect, grow to it, otherwise do |
| 78 // not resize. | 74 // not resize. |
| 79 if (!for_metro) { | 75 if (!for_metro) { |
| 80 MONITORINFO monitor_info; | 76 MONITORINFO monitor_info; |
| 81 monitor_info.cbSize = sizeof(monitor_info); | 77 monitor_info.cbSize = sizeof(monitor_info); |
| 82 GetMonitorInfo(MonitorFromWindow(widget_->GetNativeView(), | 78 GetMonitorInfo(MonitorFromWindow(hwnd_, MONITOR_DEFAULTTONEAREST), |
| 83 MONITOR_DEFAULTTONEAREST), | |
| 84 &monitor_info); | 79 &monitor_info); |
| 85 gfx::Rect window_rect(monitor_info.rcMonitor); | 80 gfx::Rect window_rect(monitor_info.rcMonitor); |
| 86 SetWindowPos(widget_->GetNativeView(), NULL, | 81 SetWindowPos(hwnd_, NULL, window_rect.x(), window_rect.y(), |
| 87 window_rect.x(), window_rect.y(), | |
| 88 window_rect.width(), window_rect.height(), | 82 window_rect.width(), window_rect.height(), |
| 89 SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED); | 83 SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED); |
| 90 } | 84 } |
| 91 } else { | 85 } else { |
| 92 // Reset original window style and size. The multiple window size/moves | 86 // Reset original window style and size. The multiple window size/moves |
| 93 // here are ugly, but if SetWindowPos() doesn't redraw, the taskbar won't be | 87 // here are ugly, but if SetWindowPos() doesn't redraw, the taskbar won't be |
| 94 // repainted. Better-looking methods welcome. | 88 // repainted. Better-looking methods welcome. |
| 95 SetWindowLong(widget_->GetNativeView(), GWL_STYLE, | 89 SetWindowLong(hwnd_, GWL_STYLE, saved_window_info_.style); |
| 96 saved_window_info_.style); | 90 SetWindowLong(hwnd_, GWL_EXSTYLE, saved_window_info_.ex_style); |
| 97 SetWindowLong(widget_->GetNativeView(), GWL_EXSTYLE, | |
| 98 saved_window_info_.ex_style); | |
| 99 | 91 |
| 100 if (!for_metro) { | 92 if (!for_metro) { |
| 101 // On restore, resize to the previous saved rect size. | 93 // On restore, resize to the previous saved rect size. |
| 102 gfx::Rect new_rect(saved_window_info_.window_rect); | 94 gfx::Rect new_rect(saved_window_info_.window_rect); |
| 103 SetWindowPos(widget_->GetNativeView(), NULL, | 95 SetWindowPos(hwnd_, NULL, new_rect.x(), new_rect.y(), |
| 104 new_rect.x(), new_rect.y(), | |
| 105 new_rect.width(), new_rect.height(), | 96 new_rect.width(), new_rect.height(), |
| 106 SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED); | 97 SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED); |
| 107 } | 98 } |
| 108 if (saved_window_info_.maximized) | 99 if (saved_window_info_.maximized) |
| 109 widget_->Maximize(); | 100 ::SendMessage(hwnd_, WM_SYSCOMMAND, SC_MAXIMIZE, 0); |
| 110 } | 101 } |
| 111 } | 102 } |
| 112 | 103 |
| 113 } // namespace views | 104 } // namespace views |
| OLD | NEW |