Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement will-move event on macOS #19641

Merged
merged 6 commits into from Aug 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/api/browser-window.md
Expand Up @@ -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.

Expand Down
12 changes: 12 additions & 0 deletions shell/browser/ui/cocoa/atom_ns_window_delegate.mm
Expand Up @@ -138,6 +138,18 @@ - (void)windowDidResize:(NSNotification*)notification {
shell_->NotifyWindowResize();
}

- (void)windowWillMove:(NSNotification*)notification {
NSWindow* window = [notification object];
NSSize size = [[window contentView] frame].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(gfx::ScreenRectFromNSRect(new_bounds),
&prevent_default);
}

- (void)windowDidMove:(NSNotification*)notification {
[super windowDidMove:notification];
// TODO(zcbenz): Remove the alias after figuring out a proper
Expand Down