Skip to content

Commit

Permalink
feat: implement will-move event on macOS (#19641)
Browse files Browse the repository at this point in the history
  • Loading branch information
erickzhao authored and codebytere committed Aug 20, 2019
1 parent cd1b15a commit 145b4fa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
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

0 comments on commit 145b4fa

Please sign in to comment.