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: 'will-move' event for windows. #14283

Merged
merged 3 commits into from Aug 28, 2018
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
7 changes: 7 additions & 0 deletions atom/browser/api/atom_api_top_level_window.cc
Expand Up @@ -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");
}
Expand Down
2 changes: 2 additions & 0 deletions atom/browser/api/atom_api_top_level_window.h
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions atom/browser/native_window.cc
Expand Up @@ -464,6 +464,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();
Expand Down
1 change: 1 addition & 0 deletions atom/browser/native_window.h
Expand Up @@ -239,6 +239,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();
Expand Down
2 changes: 2 additions & 0 deletions atom/browser/native_window_observer.h
Expand Up @@ -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() {}
Expand Down
9 changes: 8 additions & 1 deletion atom/browser/native_window_views_win.cc
Expand Up @@ -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: {
Expand Down
11 changes: 11 additions & 0 deletions docs/api/browser-window.md
Expand Up @@ -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.
Expand Down