feat: implement will-move
event on macOS (#19641)
This commit is contained in:
parent
cd1b15a155
commit
145b4fae94
2 changed files with 14 additions and 2 deletions
|
@ -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.
|
Emitted after the window has been resized.
|
||||||
|
|
||||||
#### Event: 'will-move' _Windows_
|
#### Event: 'will-move' _macOS_ _Windows_
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
|
|
||||||
* `event` Event
|
* `event` Event
|
||||||
* `newBounds` [`Rectangle`](structures/rectangle.md) - Location the window is being moved to.
|
* `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.
|
Note that this is only emitted when the window is being resized manually. Resizing the window with `setBounds`/`setSize` will not emit this event.
|
||||||
|
|
||||||
|
|
|
@ -138,6 +138,18 @@ using TitleBarStyle = electron::NativeWindowMac::TitleBarStyle;
|
||||||
shell_->NotifyWindowResize();
|
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 {
|
- (void)windowDidMove:(NSNotification*)notification {
|
||||||
[super windowDidMove:notification];
|
[super windowDidMove:notification];
|
||||||
// TODO(zcbenz): Remove the alias after figuring out a proper
|
// TODO(zcbenz): Remove the alias after figuring out a proper
|
||||||
|
|
Loading…
Reference in a new issue