This source file includes following definitions.
- metro_snap_
- SetFullscreen
- SetMetroSnap
- GetRestoreBounds
- SetFullscreenImpl
#include "ui/views/win/fullscreen_handler.h"
#include "base/logging.h"
#include "base/win/win_util.h"
#include "ui/gfx/rect.h"
#include "ui/views/win/scoped_fullscreen_visibility.h"
namespace views {
FullscreenHandler::FullscreenHandler()
: hwnd_(NULL),
fullscreen_(false),
metro_snap_(false) {
}
FullscreenHandler::~FullscreenHandler() {
}
void FullscreenHandler::SetFullscreen(bool fullscreen) {
if (fullscreen_ == fullscreen)
return;
SetFullscreenImpl(fullscreen, false);
}
void FullscreenHandler::SetMetroSnap(bool metro_snap) {
if (metro_snap_ == metro_snap)
return;
SetFullscreenImpl(metro_snap, true);
metro_snap_ = metro_snap;
}
gfx::Rect FullscreenHandler::GetRestoreBounds() const {
return gfx::Rect(saved_window_info_.window_rect);
}
void FullscreenHandler::SetFullscreenImpl(bool fullscreen, bool for_metro) {
ScopedFullscreenVisibility visibility(hwnd_);
if (!fullscreen_) {
saved_window_info_.maximized = !!::IsZoomed(hwnd_);
if (saved_window_info_.maximized)
::SendMessage(hwnd_, WM_SYSCOMMAND, SC_RESTORE, 0);
saved_window_info_.style = GetWindowLong(hwnd_, GWL_STYLE);
saved_window_info_.ex_style = GetWindowLong(hwnd_, GWL_EXSTYLE);
GetWindowRect(hwnd_, &saved_window_info_.window_rect);
}
fullscreen_ = fullscreen;
if (fullscreen_) {
SetWindowLong(hwnd_, GWL_STYLE,
saved_window_info_.style & ~(WS_CAPTION | WS_THICKFRAME));
SetWindowLong(hwnd_, GWL_EXSTYLE,
saved_window_info_.ex_style & ~(WS_EX_DLGMODALFRAME |
WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE));
if (!for_metro) {
MONITORINFO monitor_info;
monitor_info.cbSize = sizeof(monitor_info);
GetMonitorInfo(MonitorFromWindow(hwnd_, MONITOR_DEFAULTTONEAREST),
&monitor_info);
gfx::Rect window_rect(monitor_info.rcMonitor);
SetWindowPos(hwnd_, NULL, window_rect.x(), window_rect.y(),
window_rect.width(), window_rect.height(),
SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED);
}
} else {
SetWindowLong(hwnd_, GWL_STYLE, saved_window_info_.style);
SetWindowLong(hwnd_, GWL_EXSTYLE, saved_window_info_.ex_style);
if (!for_metro) {
gfx::Rect new_rect(saved_window_info_.window_rect);
SetWindowPos(hwnd_, NULL, new_rect.x(), new_rect.y(),
new_rect.width(), new_rect.height(),
SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED);
}
if (saved_window_info_.maximized)
::SendMessage(hwnd_, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
}
}
}