window: adding resize and move events
This commit is contained in:
parent
d34800bb0a
commit
3a5977e09f
10 changed files with 81 additions and 5 deletions
|
@ -124,6 +124,14 @@ void Window::OnWindowRestore() {
|
||||||
Emit("restore");
|
Emit("restore");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Window::OnWindowResize() {
|
||||||
|
Emit("resize", GetBounds().size());
|
||||||
|
}
|
||||||
|
|
||||||
|
void Window::OnWindowMove() {
|
||||||
|
Emit("move", window_->GetPosition());
|
||||||
|
}
|
||||||
|
|
||||||
void Window::OnWindowEnterFullScreen() {
|
void Window::OnWindowEnterFullScreen() {
|
||||||
Emit("enter-full-screen");
|
Emit("enter-full-screen");
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,6 +64,8 @@ class Window : public mate::EventEmitter,
|
||||||
void OnWindowUnmaximize() override;
|
void OnWindowUnmaximize() override;
|
||||||
void OnWindowMinimize() override;
|
void OnWindowMinimize() override;
|
||||||
void OnWindowRestore() override;
|
void OnWindowRestore() override;
|
||||||
|
void OnWindowResize() override;
|
||||||
|
void OnWindowMove() override;
|
||||||
void OnWindowEnterFullScreen() override;
|
void OnWindowEnterFullScreen() override;
|
||||||
void OnWindowLeaveFullScreen() override;
|
void OnWindowLeaveFullScreen() override;
|
||||||
void OnWindowEnterHtmlFullScreen() override;
|
void OnWindowEnterHtmlFullScreen() override;
|
||||||
|
|
|
@ -535,6 +535,14 @@ void NativeWindow::NotifyWindowRestore() {
|
||||||
FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnWindowRestore());
|
FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnWindowRestore());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NativeWindow::NotifyWindowResize() {
|
||||||
|
FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnWindowResize());
|
||||||
|
}
|
||||||
|
|
||||||
|
void NativeWindow::NotifyWindowMove() {
|
||||||
|
FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnWindowMove());
|
||||||
|
}
|
||||||
|
|
||||||
void NativeWindow::NotifyWindowEnterFullScreen() {
|
void NativeWindow::NotifyWindowEnterFullScreen() {
|
||||||
FOR_EACH_OBSERVER(NativeWindowObserver, observers_,
|
FOR_EACH_OBSERVER(NativeWindowObserver, observers_,
|
||||||
OnWindowEnterFullScreen());
|
OnWindowEnterFullScreen());
|
||||||
|
|
|
@ -207,6 +207,8 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
|
||||||
void NotifyWindowUnmaximize();
|
void NotifyWindowUnmaximize();
|
||||||
void NotifyWindowMinimize();
|
void NotifyWindowMinimize();
|
||||||
void NotifyWindowRestore();
|
void NotifyWindowRestore();
|
||||||
|
void NotifyWindowMove();
|
||||||
|
void NotifyWindowResize();
|
||||||
void NotifyWindowEnterFullScreen();
|
void NotifyWindowEnterFullScreen();
|
||||||
void NotifyWindowLeaveFullScreen();
|
void NotifyWindowLeaveFullScreen();
|
||||||
void NotifyWindowEnterHtmlFullScreen();
|
void NotifyWindowEnterHtmlFullScreen();
|
||||||
|
|
|
@ -98,6 +98,12 @@ static const CGFloat kAtomWindowCornerRadius = 4.0;
|
||||||
- (void)windowDidResize:(NSNotification*)notification {
|
- (void)windowDidResize:(NSNotification*)notification {
|
||||||
if (!shell_->has_frame())
|
if (!shell_->has_frame())
|
||||||
shell_->ClipWebView();
|
shell_->ClipWebView();
|
||||||
|
|
||||||
|
shell_->NotifyWindowResize();
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)windowDidMove:(NSNotification*)notification {
|
||||||
|
shell_->NotifyWindowMove();
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)windowDidMiniaturize:(NSNotification*)notification {
|
- (void)windowDidMiniaturize:(NSNotification*)notification {
|
||||||
|
|
|
@ -47,6 +47,8 @@ class NativeWindowObserver {
|
||||||
virtual void OnWindowUnmaximize() {}
|
virtual void OnWindowUnmaximize() {}
|
||||||
virtual void OnWindowMinimize() {}
|
virtual void OnWindowMinimize() {}
|
||||||
virtual void OnWindowRestore() {}
|
virtual void OnWindowRestore() {}
|
||||||
|
virtual void OnWindowResize() {}
|
||||||
|
virtual void OnWindowMove() {}
|
||||||
virtual void OnWindowEnterFullScreen() {}
|
virtual void OnWindowEnterFullScreen() {}
|
||||||
virtual void OnWindowLeaveFullScreen() {}
|
virtual void OnWindowLeaveFullScreen() {}
|
||||||
virtual void OnWindowEnterHtmlFullScreen() {}
|
virtual void OnWindowEnterHtmlFullScreen() {}
|
||||||
|
|
|
@ -720,6 +720,22 @@ void NativeWindowViews::OnWidgetActivationChanged(
|
||||||
SetMenuBarVisibility(false);
|
SetMenuBarVisibility(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NativeWindowViews::OnWidgetBoundsChanged(
|
||||||
|
views::Widget* widget, const gfx::Rect& bounds) {
|
||||||
|
if (widget != window_.get())
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (widget_size_ != bounds.size()) {
|
||||||
|
NotifyWindowResize();
|
||||||
|
widget_size_ = bounds.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (widget_pos_ != bounds.origin()) {
|
||||||
|
NotifyWindowMove();
|
||||||
|
widget_pos_ = bounds.origin();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void NativeWindowViews::DeleteDelegate() {
|
void NativeWindowViews::DeleteDelegate() {
|
||||||
NotifyWindowClosed();
|
NotifyWindowClosed();
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,6 +93,8 @@ class NativeWindowViews : public NativeWindow,
|
||||||
// views::WidgetObserver:
|
// views::WidgetObserver:
|
||||||
void OnWidgetActivationChanged(
|
void OnWidgetActivationChanged(
|
||||||
views::Widget* widget, bool active) override;
|
views::Widget* widget, bool active) override;
|
||||||
|
void OnWidgetBoundsChanged(
|
||||||
|
views::Widget* widget, const gfx::Rect& bounds) override;
|
||||||
|
|
||||||
// views::WidgetDelegate:
|
// views::WidgetDelegate:
|
||||||
void DeleteDelegate() override;
|
void DeleteDelegate() override;
|
||||||
|
@ -173,6 +175,8 @@ class NativeWindowViews : public NativeWindow,
|
||||||
std::string title_;
|
std::string title_;
|
||||||
gfx::Size minimum_size_;
|
gfx::Size minimum_size_;
|
||||||
gfx::Size maximum_size_;
|
gfx::Size maximum_size_;
|
||||||
|
gfx::Size widget_size_;
|
||||||
|
gfx::Point widget_pos_;
|
||||||
|
|
||||||
scoped_ptr<SkRegion> draggable_region_;
|
scoped_ptr<SkRegion> draggable_region_;
|
||||||
|
|
||||||
|
|
|
@ -171,6 +171,24 @@ Emitted when window is minimized.
|
||||||
|
|
||||||
Emitted when window is restored from minimized state.
|
Emitted when window is restored from minimized state.
|
||||||
|
|
||||||
|
### Event: 'resize'
|
||||||
|
|
||||||
|
* `event` Event
|
||||||
|
* `value` Object
|
||||||
|
* `width` Integer
|
||||||
|
* `height` Integer
|
||||||
|
|
||||||
|
Emitted when window is resized.
|
||||||
|
|
||||||
|
### Event: 'move'
|
||||||
|
|
||||||
|
* `event` Event
|
||||||
|
* `value` Object
|
||||||
|
* `x` Integer
|
||||||
|
* `y` Integer
|
||||||
|
|
||||||
|
Emitted when window is moved.
|
||||||
|
|
||||||
### Event: 'enter-full-screen'
|
### Event: 'enter-full-screen'
|
||||||
|
|
||||||
Emitted when window enters full screen state.
|
Emitted when window enters full screen state.
|
||||||
|
|
|
@ -90,12 +90,22 @@ describe 'browser-window module', ->
|
||||||
done()
|
done()
|
||||||
|
|
||||||
describe 'BrowserWindow.setSize(width, height)', ->
|
describe 'BrowserWindow.setSize(width, height)', ->
|
||||||
it 'sets the window size', ->
|
it 'sets the window size', (done) ->
|
||||||
size = [400, 400]
|
size = [20, 400]
|
||||||
|
w.on 'resize', (e, value) ->
|
||||||
|
assert.equal value.width, size[0]
|
||||||
|
assert.equal value.height, size[1]
|
||||||
|
done()
|
||||||
w.setSize size[0], size[1]
|
w.setSize size[0], size[1]
|
||||||
after = w.getSize()
|
|
||||||
assert.equal after[0], size[0]
|
describe 'BrowserWindow.setPosition(x, y)', ->
|
||||||
assert.equal after[1], size[1]
|
it 'sets the window position', (done) ->
|
||||||
|
pos = [10, 10]
|
||||||
|
w.on 'move', (e, value) ->
|
||||||
|
assert.equal value.x, pos[0]
|
||||||
|
assert.equal value.y, pos[1]
|
||||||
|
done()
|
||||||
|
w.setPosition pos[0], pos[1]
|
||||||
|
|
||||||
describe 'BrowserWindow.setContentSize(width, height)', ->
|
describe 'BrowserWindow.setContentSize(width, height)', ->
|
||||||
it 'sets the content size', ->
|
it 'sets the content size', ->
|
||||||
|
|
Loading…
Reference in a new issue