Merge pull request #1633 from deepak1556/window_event_patch

window: adding resize and move events
This commit is contained in:
Cheng Zhao 2015-05-27 14:54:36 +08:00
commit c244e83e10
10 changed files with 91 additions and 5 deletions

View file

@ -124,6 +124,18 @@ void Window::OnWindowRestore() {
Emit("restore");
}
void Window::OnWindowResize() {
Emit("resize");
}
void Window::OnWindowMove() {
Emit("move");
}
void Window::OnWindowMoved() {
Emit("moved");
}
void Window::OnWindowEnterFullScreen() {
Emit("enter-full-screen");
}

View file

@ -64,6 +64,9 @@ class Window : public mate::EventEmitter,
void OnWindowUnmaximize() override;
void OnWindowMinimize() override;
void OnWindowRestore() override;
void OnWindowResize() override;
void OnWindowMove() override;
void OnWindowMoved() override;
void OnWindowEnterFullScreen() override;
void OnWindowLeaveFullScreen() override;
void OnWindowEnterHtmlFullScreen() override;

View file

@ -535,6 +535,18 @@ void NativeWindow::NotifyWindowRestore() {
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::NotifyWindowMoved() {
FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnWindowMoved());
}
void NativeWindow::NotifyWindowEnterFullScreen() {
FOR_EACH_OBSERVER(NativeWindowObserver, observers_,
OnWindowEnterFullScreen());

View file

@ -207,6 +207,9 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
void NotifyWindowUnmaximize();
void NotifyWindowMinimize();
void NotifyWindowRestore();
void NotifyWindowMove();
void NotifyWindowResize();
void NotifyWindowMoved();
void NotifyWindowEnterFullScreen();
void NotifyWindowLeaveFullScreen();
void NotifyWindowEnterHtmlFullScreen();

View file

@ -98,6 +98,15 @@ static const CGFloat kAtomWindowCornerRadius = 4.0;
- (void)windowDidResize:(NSNotification*)notification {
if (!shell_->has_frame())
shell_->ClipWebView();
shell_->NotifyWindowResize();
}
- (void)windowDidMove:(NSNotification*)notification {
// TODO(zcbenz): Remove the alias after figuring out a proper
// way to disptach move.
shell_->NotifyWindowMove();
shell_->NotifyWindowMoved();
}
- (void)windowDidMiniaturize:(NSNotification*)notification {

View file

@ -47,6 +47,9 @@ class NativeWindowObserver {
virtual void OnWindowUnmaximize() {}
virtual void OnWindowMinimize() {}
virtual void OnWindowRestore() {}
virtual void OnWindowResize() {}
virtual void OnWindowMove() {}
virtual void OnWindowMoved() {}
virtual void OnWindowEnterFullScreen() {}
virtual void OnWindowLeaveFullScreen() {}
virtual void OnWindowEnterHtmlFullScreen() {}

View file

@ -176,6 +176,7 @@ NativeWindowViews::NativeWindowViews(content::WebContents* web_contents,
options.Get(switches::kWidth, &width);
options.Get(switches::kHeight, &height);
gfx::Rect bounds(0, 0, width, height);
widget_size_ = bounds.size();
window_->AddObserver(this);
@ -720,6 +721,17 @@ void NativeWindowViews::OnWidgetActivationChanged(
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();
}
}
void NativeWindowViews::DeleteDelegate() {
NotifyWindowClosed();
}
@ -807,6 +819,10 @@ views::NonClientFrameView* NativeWindowViews::CreateNonClientFrameView(
#endif
}
void NativeWindowViews::OnWidgetMove() {
NotifyWindowMove();
}
#if defined(OS_WIN)
bool NativeWindowViews::ExecuteWindowsCommand(int command_id) {
// Windows uses the 4 lower order bits of |command_id| for type-specific

View file

@ -93,6 +93,8 @@ class NativeWindowViews : public NativeWindow,
// views::WidgetObserver:
void OnWidgetActivationChanged(
views::Widget* widget, bool active) override;
void OnWidgetBoundsChanged(
views::Widget* widget, const gfx::Rect& bounds) override;
// views::WidgetDelegate:
void DeleteDelegate() override;
@ -113,6 +115,7 @@ class NativeWindowViews : public NativeWindow,
views::ClientView* CreateClientView(views::Widget* widget) override;
views::NonClientFrameView* CreateNonClientFrameView(
views::Widget* widget) override;
void OnWidgetMove() override;
#if defined(OS_WIN)
bool ExecuteWindowsCommand(int command_id) override;
#endif
@ -173,6 +176,7 @@ class NativeWindowViews : public NativeWindow,
std::string title_;
gfx::Size minimum_size_;
gfx::Size maximum_size_;
gfx::Size widget_size_;
scoped_ptr<SkRegion> draggable_region_;

View file

@ -171,6 +171,18 @@ Emitted when window is minimized.
Emitted when window is restored from minimized state.
### Event: 'resize'
Emitted when window is getting resized.
### Event: 'move'
Emitted when the window is getting moved to a new position.
### Event: 'moved'
Emitted once when the window is moved to a new position.
### Event: 'enter-full-screen'
Emitted when window enters full screen state.

View file

@ -90,12 +90,24 @@ describe 'browser-window module', ->
done()
describe 'BrowserWindow.setSize(width, height)', ->
it 'sets the window size', ->
size = [400, 400]
it 'sets the window size', (done) ->
size = [20, 400]
w.on 'resize', ->
newSize = w.getSize()
assert.equal newSize[0], size[0]
assert.equal newSize[1], size[1]
done()
w.setSize size[0], size[1]
after = w.getSize()
assert.equal after[0], size[0]
assert.equal after[1], size[1]
describe 'BrowserWindow.setPosition(x, y)', ->
it 'sets the window position', (done) ->
pos = [10, 10]
w.on 'move', ->
newPos = w.getPosition()
assert.equal newPos[0], pos[0]
assert.equal newPos[1], pos[1]
done()
w.setPosition pos[0], pos[1]
describe 'BrowserWindow.setContentSize(width, height)', ->
it 'sets the content size', ->