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 2 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
7 changes: 6 additions & 1 deletion atom/browser/native_window_views_win.cc
Expand Up @@ -207,9 +207,14 @@ 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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does the changed return value do here?

For the most part this patch seems symmetrical with the WM_SIZING handler except that it always returns false.

Copy link
Contributor Author

@sgd2z sgd2z Aug 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without the change in value, frameless windows can still be moved with -webkit-app-region drag and neither !movable nor preventdefault work

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. Could you add a short comment in the code to this effect?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ckerr done

}
return false;
}
case WM_MOVE: {
Expand Down
3,075 changes: 1,543 additions & 1,532 deletions docs/api/browser-window.md

Large diffs are not rendered by default.