From 3f3212af4c18fdc7bee14cc3079f0c1e2f284446 Mon Sep 17 00:00:00 2001 From: Erick Zhao Date: Mon, 5 Aug 2019 16:32:17 -0700 Subject: [PATCH 1/6] wip... --- shell/browser/ui/cocoa/atom_ns_window_delegate.mm | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/shell/browser/ui/cocoa/atom_ns_window_delegate.mm b/shell/browser/ui/cocoa/atom_ns_window_delegate.mm index b67b10c7d3f6c..2db18509028ce 100644 --- a/shell/browser/ui/cocoa/atom_ns_window_delegate.mm +++ b/shell/browser/ui/cocoa/atom_ns_window_delegate.mm @@ -138,6 +138,18 @@ - (void)windowDidResize:(NSNotification*)notification { shell_->NotifyWindowResize(); } +- (void)windowWillMove:(NSNotification*)notification { + NSWindow* window = shell_->GetNativeWindow().GetNativeNSWindow(); + NSSize size = [[window contentView] frame].size; + gfx::Rect new_bounds(gfx::Point(window.frame.origin), gfx::Size(size)); + bool prevent_default = false; + + shell_->NotifyWindowWillMove(new_bounds, &prevent_default); + if (prevent_default) { + [window setMovable:false]; + } +} + - (void)windowDidMove:(NSNotification*)notification { [super windowDidMove:notification]; // TODO(zcbenz): Remove the alias after figuring out a proper From 97d1022e868ddbe12ce3fd4e46569430748a6528 Mon Sep 17 00:00:00 2001 From: Erick Zhao Date: Mon, 5 Aug 2019 17:25:09 -0700 Subject: [PATCH 2/6] more --- shell/browser/ui/cocoa/atom_ns_window_delegate.mm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shell/browser/ui/cocoa/atom_ns_window_delegate.mm b/shell/browser/ui/cocoa/atom_ns_window_delegate.mm index 2db18509028ce..714db45a0ae62 100644 --- a/shell/browser/ui/cocoa/atom_ns_window_delegate.mm +++ b/shell/browser/ui/cocoa/atom_ns_window_delegate.mm @@ -139,14 +139,14 @@ - (void)windowDidResize:(NSNotification*)notification { } - (void)windowWillMove:(NSNotification*)notification { - NSWindow* window = shell_->GetNativeWindow().GetNativeNSWindow(); + NSWindow* window = [notification object]; NSSize size = [[window contentView] frame].size; gfx::Rect new_bounds(gfx::Point(window.frame.origin), gfx::Size(size)); bool prevent_default = false; shell_->NotifyWindowWillMove(new_bounds, &prevent_default); if (prevent_default) { - [window setMovable:false]; + // prevent sefault somehow } } From 2f22e8823e9b9c7973d4c2153a415920d750f98a Mon Sep 17 00:00:00 2001 From: Erick Zhao Date: Mon, 5 Aug 2019 18:31:48 -0700 Subject: [PATCH 3/6] ggggg --- shell/browser/ui/cocoa/atom_ns_window_delegate.mm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/shell/browser/ui/cocoa/atom_ns_window_delegate.mm b/shell/browser/ui/cocoa/atom_ns_window_delegate.mm index 714db45a0ae62..1314799f45013 100644 --- a/shell/browser/ui/cocoa/atom_ns_window_delegate.mm +++ b/shell/browser/ui/cocoa/atom_ns_window_delegate.mm @@ -146,7 +146,8 @@ - (void)windowWillMove:(NSNotification*)notification { shell_->NotifyWindowWillMove(new_bounds, &prevent_default); if (prevent_default) { - // prevent sefault somehow + // doesn't work + [window setMovable:NO]; } } From 5a655c6e89305fd8ee9aaf2d4ad936cca8d9aed9 Mon Sep 17 00:00:00 2001 From: Erick Zhao Date: Tue, 13 Aug 2019 13:35:16 -0700 Subject: [PATCH 4/6] docs --- docs/api/browser-window.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index 8a069da09dbd2..c5501dc9514c1 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -516,14 +516,14 @@ Note that this is only emitted when the window is being resized manually. Resizi Emitted after the window has been resized. -#### Event: 'will-move' _Windows_ +#### Event: 'will-move' _macOS_ _Windows_ Returns: * `event` Event * `newBounds` [`Rectangle`](structures/rectangle.md) - Location the window is being moved to. -Emitted before the window is moved. Calling `event.preventDefault()` will prevent the window from being moved. +Emitted before the window is moved. On Windows, calling `event.preventDefault()` will prevent the window from being moved. Note that this is only emitted when the window is being resized manually. Resizing the window with `setBounds`/`setSize` will not emit this event. From f3909699517399c341f65e3d965d645381a57c8c Mon Sep 17 00:00:00 2001 From: Erick Zhao Date: Tue, 13 Aug 2019 13:37:05 -0700 Subject: [PATCH 5/6] prevent_default --- shell/browser/ui/cocoa/atom_ns_window_delegate.mm | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/shell/browser/ui/cocoa/atom_ns_window_delegate.mm b/shell/browser/ui/cocoa/atom_ns_window_delegate.mm index 1314799f45013..0101f3d7ced8d 100644 --- a/shell/browser/ui/cocoa/atom_ns_window_delegate.mm +++ b/shell/browser/ui/cocoa/atom_ns_window_delegate.mm @@ -144,11 +144,8 @@ - (void)windowWillMove:(NSNotification*)notification { gfx::Rect new_bounds(gfx::Point(window.frame.origin), gfx::Size(size)); bool prevent_default = false; + // prevent_default has no effect shell_->NotifyWindowWillMove(new_bounds, &prevent_default); - if (prevent_default) { - // doesn't work - [window setMovable:NO]; - } } - (void)windowDidMove:(NSNotification*)notification { From 67c30fe469e452a2e3783698f6ae8526a4435535 Mon Sep 17 00:00:00 2001 From: Erick Zhao Date: Thu, 15 Aug 2019 15:07:19 -0700 Subject: [PATCH 6/6] nsmakerect --- shell/browser/ui/cocoa/atom_ns_window_delegate.mm | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/shell/browser/ui/cocoa/atom_ns_window_delegate.mm b/shell/browser/ui/cocoa/atom_ns_window_delegate.mm index 0101f3d7ced8d..c1dea1b67d28d 100644 --- a/shell/browser/ui/cocoa/atom_ns_window_delegate.mm +++ b/shell/browser/ui/cocoa/atom_ns_window_delegate.mm @@ -141,11 +141,13 @@ - (void)windowDidResize:(NSNotification*)notification { - (void)windowWillMove:(NSNotification*)notification { NSWindow* window = [notification object]; NSSize size = [[window contentView] frame].size; - gfx::Rect new_bounds(gfx::Point(window.frame.origin), gfx::Size(size)); + NSRect new_bounds = NSMakeRect(window.frame.origin.x, window.frame.origin.y, + size.width, size.height); bool prevent_default = false; // prevent_default has no effect - shell_->NotifyWindowWillMove(new_bounds, &prevent_default); + shell_->NotifyWindowWillMove(gfx::ScreenRectFromNSRect(new_bounds), + &prevent_default); } - (void)windowDidMove:(NSNotification*)notification {