]> khamidou — GitHub mirrors - electron.git/commitdiff
window: adding setBounds and getBounds api
authordeepak1556 <hop2deep@gmail.com>
Fri, 1 May 2015 10:50:53 +0000 (16:20 +0530)
committerdeepak1556 <hop2deep@gmail.com>
Fri, 1 May 2015 10:50:53 +0000 (16:20 +0530)
atom/browser/api/atom_api_window.cc
atom/browser/api/atom_api_window.h
atom/browser/native_window.h
atom/browser/native_window_mac.h
atom/browser/native_window_mac.mm
atom/browser/native_window_views.cc
atom/browser/native_window_views.h
docs/api/browser-window.md

index 22f40be27e30b037abaac184bae49e2e86a7f871..b71499d3699c32237a85facf92e6767b16ffbf28 100644 (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)
index 2894f0e50379c2c7d0bc875eb29064e94d01ecb3..d5c3ceedd2eb7501d0893529e0506634c70914e9 100644 (file)
 
 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);
index b1f1a384b8bb731a32d86bc5be702dbd6310d5bd..d04769f171f8c47a254076d5f5e6a358c1b00307 100644 (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;
index 822594038a5ae5bc047ad1bcdc758b63e1a78716..24d52664a0507d232648311fe710ccbcf8326b31 100644 (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;
index b7eccd2a6c7c58e6d9bdb487821e1203c3289876..d1cb82a2f4f19fa50bb24a89c526f12bab86426e 100644 (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;
index 1ef0a63680c9780da8ef1179de581c5d10e6a3fc..d8eed64009c13678eff4affb9d20b398feb0753e 100644 (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
index 6ec3f2aef438f1aed888ea81cb9e03470aa8ba6c..020e349332bfbea70ecd9af6d60692a30fde3b57 100644 (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;
index f16a629fccc679c1f95c07ca63cff3055c21e601..44021cabe9391f1e71a2bfaea80c24d7984c7430 100644 (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