feat: BrowserWindow.getNormalBounds() (#13290)
* First commit * Add Mac support (1st attempt) * Add Mac support (2nd attempt) * Simplify tests * Restore window state ! * Looking at other tests, seems minimize, maximize, fullscreen are skipped when in CI * Fix Mac tests * Restore tests in CI * Fix typo * widget getRestoredBounds not working on Mac !! * widget getRestoredBounds not working on Mac !! * Add IsNormal function * Add IsNormal * IsNormal => isNormal * Deactivate fullscreen on Mac. Do not receive leave-fullscreen event * Set default original_frame_ * Set default original_frame_ * Fix Mac
This commit is contained in:
parent
872890ea5c
commit
5f6706ac33
10 changed files with 176 additions and 1 deletions
|
@ -469,6 +469,8 @@ NativeWindowMac::NativeWindowMac(const mate::Dictionary& options,
|
|||
// Default content view.
|
||||
SetContentView(new views::View());
|
||||
AddContentViewLayers();
|
||||
|
||||
original_frame_ = [window_ frame];
|
||||
}
|
||||
|
||||
NativeWindowMac::~NativeWindowMac() {
|
||||
|
@ -594,6 +596,9 @@ void NativeWindowMac::Maximize() {
|
|||
if (IsMaximized())
|
||||
return;
|
||||
|
||||
// Take note of the current window size
|
||||
if (IsNormal())
|
||||
original_frame_ = [window_ frame];
|
||||
[window_ zoom:nil];
|
||||
}
|
||||
|
||||
|
@ -618,6 +623,12 @@ bool NativeWindowMac::IsMaximized() {
|
|||
}
|
||||
|
||||
void NativeWindowMac::Minimize() {
|
||||
if (IsMinimized())
|
||||
return;
|
||||
|
||||
// Take note of the current window size
|
||||
if (IsNormal())
|
||||
original_frame_ = [window_ frame];
|
||||
[window_ miniaturize:nil];
|
||||
}
|
||||
|
||||
|
@ -633,6 +644,9 @@ void NativeWindowMac::SetFullScreen(bool fullscreen) {
|
|||
if (fullscreen == IsFullscreen())
|
||||
return;
|
||||
|
||||
// Take note of the current window size
|
||||
if (IsNormal())
|
||||
original_frame_ = [window_ frame];
|
||||
[window_ toggleFullScreenMode:nil];
|
||||
}
|
||||
|
||||
|
@ -668,6 +682,23 @@ gfx::Rect NativeWindowMac::GetBounds() {
|
|||
return bounds;
|
||||
}
|
||||
|
||||
bool NativeWindowMac::IsNormal() {
|
||||
return NativeWindow::IsNormal() && !IsSimpleFullScreen();
|
||||
}
|
||||
|
||||
gfx::Rect NativeWindowMac::GetNormalBounds() {
|
||||
if (IsNormal()) {
|
||||
return GetBounds();
|
||||
}
|
||||
NSRect frame = original_frame_;
|
||||
gfx::Rect bounds(frame.origin.x, 0, NSWidth(frame), NSHeight(frame));
|
||||
NSScreen* screen = [[NSScreen screens] firstObject];
|
||||
bounds.set_y(NSHeight([screen frame]) - NSMaxY(frame));
|
||||
return bounds;
|
||||
// Works on OS_WIN !
|
||||
// return widget()->GetRestoredBounds();
|
||||
}
|
||||
|
||||
void NativeWindowMac::SetContentSizeConstraints(
|
||||
const extensions::SizeConstraints& size_constraints) {
|
||||
auto convertSize = [this](const gfx::Size& size) {
|
||||
|
@ -860,7 +891,8 @@ void NativeWindowMac::SetSimpleFullScreen(bool simple_fullscreen) {
|
|||
is_simple_fullscreen_ = true;
|
||||
|
||||
// Take note of the current window size
|
||||
original_frame_ = [window frame];
|
||||
if (IsNormal())
|
||||
original_frame_ = [window_ frame];
|
||||
|
||||
simple_fullscreen_options_ = [NSApp currentSystemPresentationOptions];
|
||||
simple_fullscreen_mask_ = [window styleMask];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue