Merge pull request #6417 from electron/thick-frame-maximze
Correctly handle maximize/fullscreen in window without thickFrame
This commit is contained in:
commit
c5dd345b98
3 changed files with 50 additions and 13 deletions
|
@ -23,6 +23,7 @@
|
||||||
#include "ui/aura/window_tree_host.h"
|
#include "ui/aura/window_tree_host.h"
|
||||||
#include "ui/base/hit_test.h"
|
#include "ui/base/hit_test.h"
|
||||||
#include "ui/gfx/image/image.h"
|
#include "ui/gfx/image/image.h"
|
||||||
|
#include "ui/gfx/screen.h"
|
||||||
#include "ui/views/background.h"
|
#include "ui/views/background.h"
|
||||||
#include "ui/views/controls/webview/unhandled_keyboard_event_handler.h"
|
#include "ui/views/controls/webview/unhandled_keyboard_event_handler.h"
|
||||||
#include "ui/views/controls/webview/webview.h"
|
#include "ui/views/controls/webview/webview.h"
|
||||||
|
@ -278,13 +279,6 @@ NativeWindowViews::NativeWindowViews(
|
||||||
AddChildView(web_view_);
|
AddChildView(web_view_);
|
||||||
|
|
||||||
#if defined(OS_WIN)
|
#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_ = gfx::Size(widget_size_);
|
|
||||||
|
|
||||||
if (!has_frame()) {
|
if (!has_frame()) {
|
||||||
// Set Window style so that we get a minimize and maximize animation when
|
// Set Window style so that we get a minimize and maximize animation when
|
||||||
// frameless.
|
// frameless.
|
||||||
|
@ -324,6 +318,15 @@ NativeWindowViews::NativeWindowViews(
|
||||||
|
|
||||||
window_->CenterWindow(size);
|
window_->CenterWindow(size);
|
||||||
Layout();
|
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() {
|
NativeWindowViews::~NativeWindowViews() {
|
||||||
|
@ -415,6 +418,17 @@ bool NativeWindowViews::IsEnabled() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindowViews::Maximize() {
|
void NativeWindowViews::Maximize() {
|
||||||
|
#if defined(OS_WIN)
|
||||||
|
// For window without WS_THICKFRAME style, we can not call Maximize().
|
||||||
|
if (!thick_frame_) {
|
||||||
|
restore_bounds_ = GetBounds();
|
||||||
|
auto display =
|
||||||
|
gfx::Screen::GetScreen()->GetDisplayNearestPoint(GetPosition());
|
||||||
|
SetBounds(display.work_area(), false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (IsVisible())
|
if (IsVisible())
|
||||||
window_->Maximize();
|
window_->Maximize();
|
||||||
else
|
else
|
||||||
|
@ -423,6 +437,13 @@ void NativeWindowViews::Maximize() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindowViews::Unmaximize() {
|
void NativeWindowViews::Unmaximize() {
|
||||||
|
#if defined(OS_WIN)
|
||||||
|
if (!thick_frame_) {
|
||||||
|
SetBounds(restore_bounds_, false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
window_->Restore();
|
window_->Restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -459,6 +480,20 @@ void NativeWindowViews::SetFullScreen(bool fullscreen) {
|
||||||
last_window_state_ = ui::SHOW_STATE_NORMAL;
|
last_window_state_ = ui::SHOW_STATE_NORMAL;
|
||||||
NotifyWindowLeaveFullScreen();
|
NotifyWindowLeaveFullScreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// For window without WS_THICKFRAME style, we can not call SetFullscreen().
|
||||||
|
if (!thick_frame_) {
|
||||||
|
if (fullscreen) {
|
||||||
|
restore_bounds_ = GetBounds();
|
||||||
|
auto display =
|
||||||
|
gfx::Screen::GetScreen()->GetDisplayNearestPoint(GetPosition());
|
||||||
|
SetBounds(display.bounds(), false);
|
||||||
|
} else {
|
||||||
|
SetBounds(restore_bounds_, false);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// We set the new value after notifying, so we can handle the size event
|
// We set the new value after notifying, so we can handle the size event
|
||||||
// correctly.
|
// correctly.
|
||||||
window_->SetFullscreen(fullscreen);
|
window_->SetFullscreen(fullscreen);
|
||||||
|
@ -475,8 +510,7 @@ bool NativeWindowViews::IsFullscreen() const {
|
||||||
return window_->IsFullscreen();
|
return window_->IsFullscreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindowViews::SetBounds(const gfx::Rect& bounds,
|
void NativeWindowViews::SetBounds(const gfx::Rect& bounds, bool animate) {
|
||||||
bool animate = false) {
|
|
||||||
#if defined(USE_X11)
|
#if defined(USE_X11)
|
||||||
// On Linux the minimum and maximum size should be updated with window size
|
// On Linux the minimum and maximum size should be updated with window size
|
||||||
// when window is not resizable.
|
// when window is not resizable.
|
||||||
|
|
|
@ -212,7 +212,7 @@ class NativeWindowViews : public NativeWindow,
|
||||||
// to receive the wrong size (#2498). To circumvent that, we keep tabs on the
|
// 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
|
// size of the window while in the normal state (not maximized, minimized or
|
||||||
// fullscreen), so we restore it correctly.
|
// fullscreen), so we restore it correctly.
|
||||||
gfx::Size last_normal_size_;
|
gfx::Rect last_normal_bounds_;
|
||||||
|
|
||||||
// In charge of running taskbar related APIs.
|
// In charge of running taskbar related APIs.
|
||||||
TaskbarHost taskbar_host_;
|
TaskbarHost taskbar_host_;
|
||||||
|
@ -223,6 +223,9 @@ class NativeWindowViews : public NativeWindow,
|
||||||
// Whether to show the WS_THICKFRAME style.
|
// Whether to show the WS_THICKFRAME style.
|
||||||
bool thick_frame_;
|
bool thick_frame_;
|
||||||
|
|
||||||
|
// The bounds of window before maximize/fullscreen.
|
||||||
|
gfx::Rect restore_bounds_;
|
||||||
|
|
||||||
// The icons of window and taskbar.
|
// The icons of window and taskbar.
|
||||||
base::win::ScopedHICON window_icon_;
|
base::win::ScopedHICON window_icon_;
|
||||||
base::win::ScopedHICON app_icon_;
|
base::win::ScopedHICON app_icon_;
|
||||||
|
|
|
@ -140,7 +140,7 @@ void NativeWindowViews::HandleSizeEvent(WPARAM w_param, LPARAM l_param) {
|
||||||
case SIZE_RESTORED:
|
case SIZE_RESTORED:
|
||||||
if (last_window_state_ == ui::SHOW_STATE_NORMAL) {
|
if (last_window_state_ == ui::SHOW_STATE_NORMAL) {
|
||||||
// Window was resized so we save it's new size.
|
// Window was resized so we save it's new size.
|
||||||
last_normal_size_ = GetSize();
|
last_normal_bounds_ = GetBounds();
|
||||||
} else {
|
} else {
|
||||||
switch (last_window_state_) {
|
switch (last_window_state_) {
|
||||||
case ui::SHOW_STATE_MAXIMIZED:
|
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
|
// When the window is restored we resize it to the previous known
|
||||||
// normal size.
|
// normal size.
|
||||||
NativeWindow::SetSize(last_normal_size_);
|
SetBounds(last_normal_bounds_, false);
|
||||||
|
|
||||||
NotifyWindowUnmaximize();
|
NotifyWindowUnmaximize();
|
||||||
break;
|
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
|
// When the window is restored we resize it to the previous known
|
||||||
// normal size.
|
// normal size.
|
||||||
NativeWindow::SetSize(last_normal_size_);
|
SetBounds(last_normal_bounds_, false);
|
||||||
|
|
||||||
NotifyWindowRestore();
|
NotifyWindowRestore();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue