Skip to content

Commit 070cec8

Browse files
committed
[WIN] move and resize event support
Fix nwjs#799
1 parent a7a684f commit 070cec8

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

src/browser/native_window_win.cc

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,8 @@ NativeWindowWin::NativeWindowWin(const base::WeakPtr<content::Shell>& shell,
247247
resizable_(true),
248248
minimum_size_(0, 0),
249249
maximum_size_(),
250-
initial_focus_(true) {
250+
initial_focus_(true),
251+
last_width_(-1), last_height_(-1) {
251252
manifest->GetBoolean("focus", &initial_focus_);
252253

253254
window_ = new views::Widget;
@@ -265,6 +266,9 @@ NativeWindowWin::NativeWindowWin(const base::WeakPtr<content::Shell>& shell,
265266
gfx::Rect window_bounds =
266267
window_->non_client_view()->GetWindowBoundsForClientBounds(
267268
gfx::Rect(width,height));
269+
last_width_ = width;
270+
last_height_ = height;
271+
window_->AddObserver(this);
268272
window_->SetSize(window_bounds.size());
269273
window_->CenterWindow(window_bounds.size());
270274

@@ -372,6 +376,19 @@ void NativeWindowWin::SetAlwaysOnTop(bool top) {
372376
window_->SetAlwaysOnTop(top);
373377
}
374378

379+
void NativeWindowWin::OnWidgetBoundsChanged(views::Widget* widget, const gfx::Rect& new_bounds) {
380+
int w = new_bounds.width();
381+
int h = new_bounds.height();
382+
if (shell() && (w != last_width_ || h != last_height_)) {
383+
base::ListValue args;
384+
args.AppendInteger(w);
385+
args.AppendInteger(h);
386+
shell()->SendEvent("resize", args);
387+
last_width_ = w;
388+
last_height_ = h;
389+
}
390+
}
391+
375392
void NativeWindowWin::SetPosition(const std::string& position) {
376393
if (position == "center") {
377394
gfx::Rect bounds = window_->GetWindowBoundsInScreen();
@@ -465,6 +482,16 @@ views::NonClientFrameView* NativeWindowWin::CreateNonClientFrameView(
465482
return frame_view;
466483
}
467484

485+
void NativeWindowWin::OnWidgetMove() {
486+
gfx::Point origin = GetPosition();
487+
if (shell()) {
488+
base::ListValue args;
489+
args.AppendInteger(origin.x());
490+
args.AppendInteger(origin.y());
491+
shell()->SendEvent("move", args);
492+
}
493+
}
494+
468495
bool NativeWindowWin::CanResize() const {
469496
return resizable_;
470497
}

src/browser/native_window_win.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "ui/gfx/rect.h"
2929
#include "ui/views/focus/widget_focus_manager.h"
3030
#include "ui/views/widget/widget_delegate.h"
31+
#include "ui/views/widget/widget_observer.h"
3132

3233
namespace views {
3334
class WebView;
@@ -39,7 +40,8 @@ class NativeWindowToolbarWin;
3940

4041
class NativeWindowWin : public NativeWindow,
4142
public views::WidgetFocusChangeListener,
42-
public views::WidgetDelegateView {
43+
public views::WidgetDelegateView ,
44+
public views::WidgetObserver {
4345
public:
4446
explicit NativeWindowWin(const base::WeakPtr<content::Shell>& shell,
4547
base::DictionaryValue* manifest);
@@ -83,6 +85,7 @@ class NativeWindowWin : public NativeWindow,
8385
virtual bool InitialFocus() OVERRIDE { return initial_focus_; }
8486

8587
// WidgetDelegate implementation.
88+
virtual void OnWidgetMove() OVERRIDE;
8689
virtual views::View* GetContentsView() OVERRIDE;
8790
virtual views::ClientView* CreateClientView(views::Widget*) OVERRIDE;
8891
virtual views::NonClientFrameView* CreateNonClientFrameView(
@@ -102,6 +105,9 @@ class NativeWindowWin : public NativeWindow,
102105
virtual void OnNativeFocusChange(gfx::NativeView focused_before,
103106
gfx::NativeView focused_now) OVERRIDE;
104107

108+
// WidgetObserver implementation
109+
virtual void OnWidgetBoundsChanged(views::Widget* widget, const gfx::Rect& new_bounds) OVERRIDE;
110+
105111
protected:
106112
// NativeWindow implementation.
107113
virtual void AddToolbar() OVERRIDE;
@@ -151,6 +157,9 @@ class NativeWindowWin : public NativeWindow,
151157

152158
bool initial_focus_;
153159

160+
int last_width_;
161+
int last_height_;
162+
154163
DISALLOW_COPY_AND_ASSIGN(NativeWindowWin);
155164
};
156165

0 commit comments

Comments
 (0)