window: adding setBounds and getBounds api

This commit is contained in:
deepak1556 2015-05-01 16:20:53 +05:30
parent 4608f5e9cd
commit ae6a1b409f
8 changed files with 54 additions and 0 deletions

View file

@ -15,6 +15,7 @@
#include "native_mate/callback.h"
#include "native_mate/constructor.h"
#include "native_mate/dictionary.h"
#include "ui/gfx/geometry/rect.h"
#include "atom/common/node_includes.h"
@ -222,6 +223,14 @@ bool Window::IsFullscreen() {
return window_->IsFullscreen();
}
void Window::SetBounds(const gfx::Rect& bounds) {
window_->SetBounds(bounds);
}
gfx::Rect Window::GetBounds() {
return window_->GetBounds();
}
void Window::SetSize(int width, int height) {
window_->SetSize(gfx::Size(width, height));
}
@ -464,6 +473,8 @@ void Window::BuildPrototype(v8::Isolate* isolate,
.SetMethod("isMinimized", &Window::IsMinimized)
.SetMethod("setFullScreen", &Window::SetFullScreen)
.SetMethod("isFullScreen", &Window::IsFullscreen)
.SetMethod("getBounds", &Window::GetBounds)
.SetMethod("setBounds", &Window::SetBounds)
.SetMethod("getSize", &Window::GetSize)
.SetMethod("setSize", &Window::SetSize)
.SetMethod("getContentSize", &Window::GetContentSize)

View file

@ -16,6 +16,10 @@
class GURL;
namespace gfx {
class Rect;
}
namespace mate {
class Arguments;
class Dictionary;
@ -85,6 +89,8 @@ class Window : public mate::EventEmitter,
bool IsMinimized();
void SetFullScreen(bool fullscreen);
bool IsFullscreen();
void SetBounds(const gfx::Rect& bounds);
gfx::Rect GetBounds();
void SetSize(int width, int height);
std::vector<int> GetSize();
void SetContentSize(int width, int height);

View file

@ -113,6 +113,8 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
virtual bool IsMinimized() = 0;
virtual void SetFullScreen(bool fullscreen) = 0;
virtual bool IsFullscreen() const = 0;
virtual void SetBounds(const gfx::Rect& bounds) = 0;
virtual gfx::Rect GetBounds() = 0;
virtual void SetSize(const gfx::Size& size) = 0;
virtual gfx::Size GetSize() = 0;
virtual void SetContentSize(const gfx::Size& size) = 0;

View file

@ -45,6 +45,8 @@ class NativeWindowMac : public NativeWindow {
bool IsMinimized() override;
void SetFullScreen(bool fullscreen) override;
bool IsFullscreen() const override;
void SetBounds(const gfx::Rect& bounds) override;
gfx::Rect GetBounds() override;
void SetSize(const gfx::Size& size) override;
gfx::Size GetSize() override;
void SetContentSize(const gfx::Size& size) override;

View file

@ -470,6 +470,15 @@ bool NativeWindowMac::IsFullscreen() const {
return [window_ styleMask] & NSFullScreenWindowMask;
}
void NativeWindowMac::SetBounds(const gfx::Rect& bounds) {
Move(bounds);
}
gfx::Rect NativeWindowMac::GetBounds() {
return gfx::Rect(GetPosition(),
GetSize());
}
void NativeWindowMac::SetSize(const gfx::Size& size) {
NSRect frame = [window_ frame];
frame.origin.y -= size.height() - frame.size.height;

View file

@ -373,6 +373,14 @@ bool NativeWindowViews::IsFullscreen() const {
return window_->IsFullscreen();
}
void NativeWindowViews::SetBounds(const gfx::Rect& bounds) {
window_->SetBoundsConstrained(bounds);
}
gfx::Rect NativeWindowViews::GetBounds() {
return window_->GetRestoredBounds();
}
void NativeWindowViews::SetSize(const gfx::Size& size) {
#if defined(USE_X11)
// On Linux the minimum and maximum size should be updated with window size

View file

@ -50,6 +50,8 @@ class NativeWindowViews : public NativeWindow,
bool IsMinimized() override;
void SetFullScreen(bool fullscreen) override;
bool IsFullscreen() const override;
void SetBounds(const gfx::Rect& bounds) override;
gfx::Rect GetBounds() override;
void SetSize(const gfx::Size& size) override;
gfx::Size GetSize() override;
void SetContentSize(const gfx::Size& size) override;

View file

@ -316,6 +316,20 @@ Sets whether the window should be in fullscreen mode.
Returns whether the window is in fullscreen mode.
### BrowserWindow.setBounds(options)
* `options` Object
* `x` Integer
* `y` Integer
* `width` Integer
* `height` Integer
Resizes and moves the window to `width`, `height`, `x`, `y`.
### BrowserWindow.getBounds()
Returns an object that contains window's width, height, x and y values.
### BrowserWindow.setSize(width, height)
* `width` Integer