mirror of
https://github.com/electron/electron.git
synced 2026-01-09 15:38:08 -05:00
feat: 'will-move' event for windows. (#14283)
* feat: 'will-resize' window event (Windows only) * documentation for 'will-move' event * comment and line break fix in docs
This commit is contained in:
committed by
Charles Kerr
parent
f1fe485768
commit
afdb6c5f90
@@ -205,6 +205,13 @@ void TopLevelWindow::OnWindowResize() {
|
||||
Emit("resize");
|
||||
}
|
||||
|
||||
void TopLevelWindow::OnWindowWillMove(const gfx::Rect& new_bounds,
|
||||
bool* prevent_default) {
|
||||
if (Emit("will-move", new_bounds)) {
|
||||
*prevent_default = true;
|
||||
}
|
||||
}
|
||||
|
||||
void TopLevelWindow::OnWindowMove() {
|
||||
Emit("move");
|
||||
}
|
||||
|
||||
@@ -63,6 +63,8 @@ class TopLevelWindow : public mate::TrackableObject<TopLevelWindow>,
|
||||
void OnWindowWillResize(const gfx::Rect& new_bounds,
|
||||
bool* prevent_default) override;
|
||||
void OnWindowResize() override;
|
||||
void OnWindowWillMove(const gfx::Rect& new_bounds,
|
||||
bool* prevent_default) override;
|
||||
void OnWindowMove() override;
|
||||
void OnWindowMoved() override;
|
||||
void OnWindowScrollTouchBegin() override;
|
||||
|
||||
@@ -468,6 +468,12 @@ void NativeWindow::NotifyWindowWillResize(const gfx::Rect& new_bounds,
|
||||
observer.OnWindowWillResize(new_bounds, prevent_default);
|
||||
}
|
||||
|
||||
void NativeWindow::NotifyWindowWillMove(const gfx::Rect& new_bounds,
|
||||
bool* prevent_default) {
|
||||
for (NativeWindowObserver& observer : observers_)
|
||||
observer.OnWindowWillMove(new_bounds, prevent_default);
|
||||
}
|
||||
|
||||
void NativeWindow::NotifyWindowResize() {
|
||||
for (NativeWindowObserver& observer : observers_)
|
||||
observer.OnWindowResize();
|
||||
|
||||
@@ -241,6 +241,7 @@ class NativeWindow : public base::SupportsUserData,
|
||||
void NotifyWindowWillResize(const gfx::Rect& new_bounds,
|
||||
bool* prevent_default);
|
||||
void NotifyWindowResize();
|
||||
void NotifyWindowWillMove(const gfx::Rect& new_bounds, bool* prevent_default);
|
||||
void NotifyWindowMoved();
|
||||
void NotifyWindowScrollTouchBegin();
|
||||
void NotifyWindowScrollTouchEnd();
|
||||
|
||||
@@ -70,6 +70,8 @@ class NativeWindowObserver {
|
||||
virtual void OnWindowWillResize(const gfx::Rect& new_bounds,
|
||||
bool* prevent_default) {}
|
||||
virtual void OnWindowResize() {}
|
||||
virtual void OnWindowWillMove(const gfx::Rect& new_bounds,
|
||||
bool* prevent_default) {}
|
||||
virtual void OnWindowMove() {}
|
||||
virtual void OnWindowMoved() {}
|
||||
virtual void OnWindowScrollTouchBegin() {}
|
||||
|
||||
@@ -207,9 +207,16 @@ bool NativeWindowViews::PreHandleMSG(UINT message,
|
||||
return false;
|
||||
}
|
||||
case WM_MOVING: {
|
||||
if (!movable_)
|
||||
bool prevent_default = false;
|
||||
NotifyWindowWillMove(gfx::Rect(*reinterpret_cast<RECT*>(l_param)),
|
||||
&prevent_default);
|
||||
if (!movable_ || prevent_default) {
|
||||
::GetWindowRect(GetAcceleratedWidget(),
|
||||
reinterpret_cast<RECT*>(l_param));
|
||||
return true; // Tells Windows that the Move is handled. If not true,
|
||||
// frameless windows can be moved using
|
||||
// -webkit-app-region: drag elements.
|
||||
}
|
||||
return false;
|
||||
}
|
||||
case WM_MOVE: {
|
||||
|
||||
@@ -505,6 +505,17 @@ 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_
|
||||
|
||||
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.
|
||||
|
||||
Note that this is only emitted when the window is being resized manually. Resizing the window with `setBounds`/`setSize` will not emit this event.
|
||||
|
||||
#### Event: 'move'
|
||||
|
||||
Emitted when the window is being moved to a new position.
|
||||
|
||||
Reference in New Issue
Block a user