diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index 22f40be27e3..b71499d3699 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -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) diff --git a/atom/browser/api/atom_api_window.h b/atom/browser/api/atom_api_window.h index 2894f0e5037..d5c3ceedd2e 100644 --- a/atom/browser/api/atom_api_window.h +++ b/atom/browser/api/atom_api_window.h @@ -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 GetSize(); void SetContentSize(int width, int height); diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index b1f1a384b8b..d04769f171f 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -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; diff --git a/atom/browser/native_window_mac.h b/atom/browser/native_window_mac.h index 822594038a5..24d52664a05 100644 --- a/atom/browser/native_window_mac.h +++ b/atom/browser/native_window_mac.h @@ -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; diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index b7eccd2a6c7..d1cb82a2f4f 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -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; diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index 1ef0a63680c..d8eed64009c 100644 --- a/atom/browser/native_window_views.cc +++ b/atom/browser/native_window_views.cc @@ -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 diff --git a/atom/browser/native_window_views.h b/atom/browser/native_window_views.h index 6ec3f2aef43..020e349332b 100644 --- a/atom/browser/native_window_views.h +++ b/atom/browser/native_window_views.h @@ -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; diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index f16a629fccc..44021cabe93 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -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