From baff7446019daa6323921d235ae8a29eadf7556b Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sat, 9 Jul 2016 22:49:55 +0900 Subject: [PATCH 1/4] Use setBounds to implement maximize for window without thickFrame --- atom/browser/native_window_views.cc | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index 58d7a352fc..20e43a1b77 100644 --- a/atom/browser/native_window_views.cc +++ b/atom/browser/native_window_views.cc @@ -23,6 +23,7 @@ #include "ui/aura/window_tree_host.h" #include "ui/base/hit_test.h" #include "ui/gfx/image/image.h" +#include "ui/gfx/screen.h" #include "ui/views/background.h" #include "ui/views/controls/webview/unhandled_keyboard_event_handler.h" #include "ui/views/controls/webview/webview.h" @@ -415,6 +416,16 @@ bool NativeWindowViews::IsEnabled() { } void NativeWindowViews::Maximize() { +#if defined(OS_WIN) + // For window without WS_THICKFRAME style, we can not call Maximize(). + if (!thick_frame_) { + auto display = + gfx::Screen::GetScreen()->GetDisplayNearestPoint(GetPosition()); + SetBounds(display.work_area(), false); + return; + } +#endif + if (IsVisible()) window_->Maximize(); else @@ -459,6 +470,15 @@ void NativeWindowViews::SetFullScreen(bool fullscreen) { last_window_state_ = ui::SHOW_STATE_NORMAL; NotifyWindowLeaveFullScreen(); } + + // For window without WS_THICKFRAME style, we can not call Maximize(). + if (!thick_frame_) { + auto display = + gfx::Screen::GetScreen()->GetDisplayNearestPoint(GetPosition()); + SetBounds(display.bounds(), false); + return; + } + // We set the new value after notifying, so we can handle the size event // correctly. window_->SetFullscreen(fullscreen); @@ -475,8 +495,7 @@ bool NativeWindowViews::IsFullscreen() const { return window_->IsFullscreen(); } -void NativeWindowViews::SetBounds(const gfx::Rect& bounds, - bool animate = false) { +void NativeWindowViews::SetBounds(const gfx::Rect& bounds, bool animate) { #if defined(USE_X11) // On Linux the minimum and maximum size should be updated with window size // when window is not resizable. From c4de246bfbdc4f2ec6611b922fdf1723fab1c02f Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sat, 9 Jul 2016 23:04:42 +0900 Subject: [PATCH 2/4] Correctly handle unmaximize --- atom/browser/native_window_views.cc | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index 20e43a1b77..7b65dfc8be 100644 --- a/atom/browser/native_window_views.cc +++ b/atom/browser/native_window_views.cc @@ -284,7 +284,7 @@ NativeWindowViews::NativeWindowViews( last_window_state_ = ui::SHOW_STATE_FULLSCREEN; else last_window_state_ = ui::SHOW_STATE_NORMAL; - last_normal_size_ = gfx::Size(widget_size_); + last_normal_size_ = widget_size_; if (!has_frame()) { // Set Window style so that we get a minimize and maximize animation when @@ -419,6 +419,7 @@ void NativeWindowViews::Maximize() { #if defined(OS_WIN) // For window without WS_THICKFRAME style, we can not call Maximize(). if (!thick_frame_) { + last_normal_size_ = GetSize(); auto display = gfx::Screen::GetScreen()->GetDisplayNearestPoint(GetPosition()); SetBounds(display.work_area(), false); @@ -434,6 +435,13 @@ void NativeWindowViews::Maximize() { } void NativeWindowViews::Unmaximize() { +#if defined(OS_WIN) + if (!thick_frame_) { + NativeWindow::SetSize(last_normal_size_); + return; + } +#endif + window_->Restore(); } @@ -471,11 +479,16 @@ void NativeWindowViews::SetFullScreen(bool fullscreen) { NotifyWindowLeaveFullScreen(); } - // For window without WS_THICKFRAME style, we can not call Maximize(). + // For window without WS_THICKFRAME style, we can not call SetFullscreen(). if (!thick_frame_) { - auto display = - gfx::Screen::GetScreen()->GetDisplayNearestPoint(GetPosition()); - SetBounds(display.bounds(), false); + if (fullscreen) { + last_normal_size_ = GetSize(); + auto display = + gfx::Screen::GetScreen()->GetDisplayNearestPoint(GetPosition()); + SetBounds(display.bounds(), false); + } else { + NativeWindow::SetSize(last_normal_size_); + } return; } From 5979c1464f501459bd6785e2c3df2de237105748 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sat, 9 Jul 2016 23:10:36 +0900 Subject: [PATCH 3/4] Remember bounds instead of size --- atom/browser/native_window_views.cc | 24 +++++++++++++----------- atom/browser/native_window_views.h | 2 +- atom/browser/native_window_views_win.cc | 6 +++--- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index 7b65dfc8be..0bb16d364b 100644 --- a/atom/browser/native_window_views.cc +++ b/atom/browser/native_window_views.cc @@ -279,13 +279,6 @@ NativeWindowViews::NativeWindowViews( AddChildView(web_view_); #if defined(OS_WIN) - // Save initial window state. - if (fullscreen) - last_window_state_ = ui::SHOW_STATE_FULLSCREEN; - else - last_window_state_ = ui::SHOW_STATE_NORMAL; - last_normal_size_ = widget_size_; - if (!has_frame()) { // Set Window style so that we get a minimize and maximize animation when // frameless. @@ -325,6 +318,15 @@ NativeWindowViews::NativeWindowViews( window_->CenterWindow(size); Layout(); + +#if defined(OS_WIN) + // Save initial window state. + if (fullscreen) + last_window_state_ = ui::SHOW_STATE_FULLSCREEN; + else + last_window_state_ = ui::SHOW_STATE_NORMAL; + last_normal_bounds_ = GetBounds(); +#endif } NativeWindowViews::~NativeWindowViews() { @@ -419,7 +421,7 @@ void NativeWindowViews::Maximize() { #if defined(OS_WIN) // For window without WS_THICKFRAME style, we can not call Maximize(). if (!thick_frame_) { - last_normal_size_ = GetSize(); + last_normal_bounds_ = GetBounds(); auto display = gfx::Screen::GetScreen()->GetDisplayNearestPoint(GetPosition()); SetBounds(display.work_area(), false); @@ -437,7 +439,7 @@ void NativeWindowViews::Maximize() { void NativeWindowViews::Unmaximize() { #if defined(OS_WIN) if (!thick_frame_) { - NativeWindow::SetSize(last_normal_size_); + SetBounds(last_normal_bounds_, false); return; } #endif @@ -482,12 +484,12 @@ void NativeWindowViews::SetFullScreen(bool fullscreen) { // For window without WS_THICKFRAME style, we can not call SetFullscreen(). if (!thick_frame_) { if (fullscreen) { - last_normal_size_ = GetSize(); + last_normal_bounds_ = GetBounds(); auto display = gfx::Screen::GetScreen()->GetDisplayNearestPoint(GetPosition()); SetBounds(display.bounds(), false); } else { - NativeWindow::SetSize(last_normal_size_); + SetBounds(last_normal_bounds_, false); } return; } diff --git a/atom/browser/native_window_views.h b/atom/browser/native_window_views.h index f3ca27077f..4c7d0efca1 100644 --- a/atom/browser/native_window_views.h +++ b/atom/browser/native_window_views.h @@ -212,7 +212,7 @@ class NativeWindowViews : public NativeWindow, // to receive the wrong size (#2498). To circumvent that, we keep tabs on the // size of the window while in the normal state (not maximized, minimized or // fullscreen), so we restore it correctly. - gfx::Size last_normal_size_; + gfx::Rect last_normal_bounds_; // In charge of running taskbar related APIs. TaskbarHost taskbar_host_; diff --git a/atom/browser/native_window_views_win.cc b/atom/browser/native_window_views_win.cc index 038ab10522..c49533033c 100644 --- a/atom/browser/native_window_views_win.cc +++ b/atom/browser/native_window_views_win.cc @@ -140,7 +140,7 @@ void NativeWindowViews::HandleSizeEvent(WPARAM w_param, LPARAM l_param) { case SIZE_RESTORED: if (last_window_state_ == ui::SHOW_STATE_NORMAL) { // Window was resized so we save it's new size. - last_normal_size_ = GetSize(); + last_normal_bounds_ = GetBounds(); } else { switch (last_window_state_) { case ui::SHOW_STATE_MAXIMIZED: @@ -148,7 +148,7 @@ void NativeWindowViews::HandleSizeEvent(WPARAM w_param, LPARAM l_param) { // When the window is restored we resize it to the previous known // normal size. - NativeWindow::SetSize(last_normal_size_); + SetBounds(last_normal_bounds_, false); NotifyWindowUnmaximize(); break; @@ -161,7 +161,7 @@ void NativeWindowViews::HandleSizeEvent(WPARAM w_param, LPARAM l_param) { // When the window is restored we resize it to the previous known // normal size. - NativeWindow::SetSize(last_normal_size_); + SetBounds(last_normal_bounds_, false); NotifyWindowRestore(); } From f77b9db0696b86994b36542e48207a210668d32e Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sat, 9 Jul 2016 23:16:57 +0900 Subject: [PATCH 4/4] Fix unmaximize() not working --- atom/browser/native_window_views.cc | 8 ++++---- atom/browser/native_window_views.h | 3 +++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index 0bb16d364b..339feb52c1 100644 --- a/atom/browser/native_window_views.cc +++ b/atom/browser/native_window_views.cc @@ -421,7 +421,7 @@ void NativeWindowViews::Maximize() { #if defined(OS_WIN) // For window without WS_THICKFRAME style, we can not call Maximize(). if (!thick_frame_) { - last_normal_bounds_ = GetBounds(); + restore_bounds_ = GetBounds(); auto display = gfx::Screen::GetScreen()->GetDisplayNearestPoint(GetPosition()); SetBounds(display.work_area(), false); @@ -439,7 +439,7 @@ void NativeWindowViews::Maximize() { void NativeWindowViews::Unmaximize() { #if defined(OS_WIN) if (!thick_frame_) { - SetBounds(last_normal_bounds_, false); + SetBounds(restore_bounds_, false); return; } #endif @@ -484,12 +484,12 @@ void NativeWindowViews::SetFullScreen(bool fullscreen) { // For window without WS_THICKFRAME style, we can not call SetFullscreen(). if (!thick_frame_) { if (fullscreen) { - last_normal_bounds_ = GetBounds(); + restore_bounds_ = GetBounds(); auto display = gfx::Screen::GetScreen()->GetDisplayNearestPoint(GetPosition()); SetBounds(display.bounds(), false); } else { - SetBounds(last_normal_bounds_, false); + SetBounds(restore_bounds_, false); } return; } diff --git a/atom/browser/native_window_views.h b/atom/browser/native_window_views.h index 4c7d0efca1..7ad5e8ec29 100644 --- a/atom/browser/native_window_views.h +++ b/atom/browser/native_window_views.h @@ -223,6 +223,9 @@ class NativeWindowViews : public NativeWindow, // Whether to show the WS_THICKFRAME style. bool thick_frame_; + // The bounds of window before maximize/fullscreen. + gfx::Rect restore_bounds_; + // The icons of window and taskbar. base::win::ScopedHICON window_icon_; base::win::ScopedHICON app_icon_;