]> khamidou — GitHub mirrors - electron.git/commitdiff
Animate window resizing on OS X
authorevgenyzinoviev <me@ch1p.com>
Fri, 15 Jan 2016 04:54:12 +0000 (05:54 +0100)
committerevgenyzinoviev <me@ch1p.com>
Fri, 15 Jan 2016 04:59:58 +0000 (05:59 +0100)
atom/browser/api/atom_api_window.cc
atom/browser/api/atom_api_window.h
atom/browser/native_window.cc
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
atom/browser/native_window_views_win.cc
docs/api/browser-window.md

index f32b6d19ccaf6cefab17b43fa4a768f1cdf02b45..f938fc7bf3b692f968b57765fb2b10dcd2b97797 100644 (file)
@@ -338,16 +338,30 @@ bool Window::IsFullscreen() {
   return window_->IsFullscreen();
 }
 
-void Window::SetBounds(const gfx::Rect& bounds) {
-  window_->SetBounds(bounds);
+void Window::SetBounds(mate::Arguments* args) {
+  gfx::Rect rect;
+  bool animate = false;
+  if (!args->GetNext(&rect) ||
+      (args->Length() == 2 && !args->GetNext(&animate))) {
+    args->ThrowError();
+    return;
+  }
+  window_->SetBounds(rect, animate);
 }
 
 gfx::Rect Window::GetBounds() {
   return window_->GetBounds();
 }
 
-void Window::SetSize(int width, int height) {
-  window_->SetSize(gfx::Size(width, height));
+void Window::SetSize(mate::Arguments* args) {
+  int width = 0, height = 0;
+  bool animate = false;
+  if (!args->GetNext(&width) || !args->GetNext(&height) ||
+      (args->Length() == 3 && !args->GetNext(&animate))) {
+    args->ThrowError();
+    return;
+  }
+  window_->SetSize(gfx::Size(width, height), animate);
 }
 
 std::vector<int> Window::GetSize() {
@@ -358,8 +372,15 @@ std::vector<int> Window::GetSize() {
   return result;
 }
 
-void Window::SetContentSize(int width, int height) {
-  window_->SetContentSize(gfx::Size(width, height));
+void Window::SetContentSize(mate::Arguments* args) {
+  int width = 0, height = 0;
+  bool animate = false;
+  if (!args->GetNext(&width) || !args->GetNext(&height) ||
+      (args->Length() == 3 && !args->GetNext(&animate))) {
+    args->ThrowError();
+    return;
+  }
+  window_->SetContentSize(gfx::Size(width, height), animate);
 }
 
 std::vector<int> Window::GetContentSize() {
@@ -414,8 +435,15 @@ void Window::Center() {
   window_->Center();
 }
 
-void Window::SetPosition(int x, int y) {
-  window_->SetPosition(gfx::Point(x, y));
+void Window::SetPosition(mate::Arguments* args) {
+  int x = 0, y = 0;
+  bool animate = false;
+  if (!args->GetNext(&x) || !args->GetNext(&y) ||
+      (args->Length() == 3 && !args->GetNext(&animate))) {
+    args->ThrowError();
+    return;
+  }
+  window_->SetPosition(gfx::Point(x, y), animate);
 }
 
 std::vector<int> Window::GetPosition() {
index fe9a7e828d39b9855a2f0d26e9f7e9c252d63350..1be7dc7844c655dc71437dcfa14ffc1b7eed48dc 100644 (file)
@@ -94,11 +94,11 @@ class Window : public mate::TrackableObject<Window>,
   bool IsMinimized();
   void SetFullScreen(bool fullscreen);
   bool IsFullscreen();
-  void SetBounds(const gfx::Rect& bounds);
+  void SetBounds(mate::Arguments* args);
   gfx::Rect GetBounds();
-  void SetSize(int width, int height);
+  void SetSize(mate::Arguments* args);
   std::vector<int> GetSize();
-  void SetContentSize(int width, int height);
+  void SetContentSize(mate::Arguments* args);
   std::vector<int> GetContentSize();
   void SetMinimumSize(int width, int height);
   std::vector<int> GetMinimumSize();
@@ -109,7 +109,7 @@ class Window : public mate::TrackableObject<Window>,
   void SetAlwaysOnTop(bool top);
   bool IsAlwaysOnTop();
   void Center();
-  void SetPosition(int x, int y);
+  void SetPosition(mate::Arguments* args);
   std::vector<int> GetPosition();
   void SetTitle(const std::string& title);
   std::string GetTitle();
index bed42b101906542972967b908c579128ef50c0b8..202fd3ba467bdd1701010ebf7f13ffcef255831e 100644 (file)
@@ -92,7 +92,7 @@ void NativeWindow::InitFromOptions(const mate::Dictionary& options) {
   int x = -1, y = -1;
   bool center;
   if (options.Get(options::kX, &x) && options.Get(options::kY, &y)) {
-    SetPosition(gfx::Point(x, y));
+    SetPosition(gfx::Point(x, y), false);
   } else if (options.Get(options::kCenter, &center) && center) {
     Center();
   }
@@ -154,24 +154,24 @@ void NativeWindow::InitFromOptions(const mate::Dictionary& options) {
     Show();
 }
 
-void NativeWindow::SetSize(const gfx::Size& size) {
-  SetBounds(gfx::Rect(GetPosition(), size));
+void NativeWindow::SetSize(const gfx::Size& size, bool animate) {
+  SetBounds(gfx::Rect(GetPosition(), size), animate);
 }
 
 gfx::Size NativeWindow::GetSize() {
   return GetBounds().size();
 }
 
-void NativeWindow::SetPosition(const gfx::Point& position) {
-  SetBounds(gfx::Rect(position, GetSize()));
+void NativeWindow::SetPosition(const gfx::Point& position, bool animate) {
+  SetBounds(gfx::Rect(position, GetSize()), animate);
 }
 
 gfx::Point NativeWindow::GetPosition() {
   return GetBounds().origin();
 }
 
-void NativeWindow::SetContentSize(const gfx::Size& size) {
-  SetSize(ContentSizeToWindowSize(size));
+void NativeWindow::SetContentSize(const gfx::Size& size, bool animate) {
+  SetSize(ContentSizeToWindowSize(size), animate);
 }
 
 gfx::Size NativeWindow::GetContentSize() {
index a11be26ff7d1ee0e07008a58a34792d855a3e8c8..5dd4a47985529811cc77a32236b1291e650b0126 100644 (file)
@@ -105,13 +105,13 @@ class NativeWindow : public base::SupportsUserData,
   virtual bool IsMinimized() = 0;
   virtual void SetFullScreen(bool fullscreen) = 0;
   virtual bool IsFullscreen() const = 0;
-  virtual void SetBounds(const gfx::Rect& bounds) = 0;
+  virtual void SetBounds(const gfx::Rect& bounds, bool animate) = 0;
   virtual gfx::Rect GetBounds() = 0;
-  virtual void SetSize(const gfx::Size& size);
+  virtual void SetSize(const gfx::Size& size, bool animate);
   virtual gfx::Size GetSize();
-  virtual void SetPosition(const gfx::Point& position);
+  virtual void SetPosition(const gfx::Point& position, bool animate);
   virtual gfx::Point GetPosition();
-  virtual void SetContentSize(const gfx::Size& size);
+  virtual void SetContentSize(const gfx::Size& size, bool animate);
   virtual gfx::Size GetContentSize();
   virtual void SetSizeConstraints(
       const extensions::SizeConstraints& size_constraints);
index d1703ac944dad610353740037068229bf6980c7a..bc71b7f26b8ca0df65b388c1bf1c593f63053378 100644 (file)
@@ -42,7 +42,7 @@ class NativeWindowMac : public NativeWindow {
   bool IsMinimized() override;
   void SetFullScreen(bool fullscreen) override;
   bool IsFullscreen() const override;
-  void SetBounds(const gfx::Rect& bounds) override;
+  void SetBounds(const gfx::Rect& bounds, bool animate) override;
   gfx::Rect GetBounds() override;
   void SetContentSizeConstraints(
       const extensions::SizeConstraints& size_constraints) override;
index 2d75a682c653990e52a985d576676d6c5edce9b9..1dac5960361371397b341ad07a99e2c75dc89028 100644 (file)
@@ -456,7 +456,7 @@ NativeWindowMac::NativeWindowMac(
   bool use_content_size = false;
   options.Get(options::kUseContentSize, &use_content_size);
   if (!has_frame() || !use_content_size)
-    SetSize(gfx::Size(width, height));
+    SetSize(gfx::Size(width, height), false);
 
   // Enable the NSView to accept first mouse event.
   bool acceptsFirstMouse = false;
@@ -576,7 +576,7 @@ bool NativeWindowMac::IsFullscreen() const {
   return [window_ styleMask] & NSFullScreenWindowMask;
 }
 
-void NativeWindowMac::SetBounds(const gfx::Rect& bounds) {
+void NativeWindowMac::SetBounds(const gfx::Rect& bounds, bool animate) {
   NSRect cocoa_bounds = NSMakeRect(bounds.x(), 0,
                                    bounds.width(),
                                    bounds.height());
@@ -585,7 +585,7 @@ void NativeWindowMac::SetBounds(const gfx::Rect& bounds) {
   cocoa_bounds.origin.y =
       NSHeight([screen frame]) - bounds.height() - bounds.y();
 
-  [window_ setFrame:cocoa_bounds display:YES];
+  [window_ setFrame:cocoa_bounds display:YES animate:animate];
 }
 
 gfx::Rect NativeWindowMac::GetBounds() {
index 35e12ad3c9b79eab88731643af22ffa30e9348f2..4f55973c1c68c9af6e1e955a5969282689c52d90 100644 (file)
@@ -375,7 +375,7 @@ bool NativeWindowViews::IsFullscreen() const {
   return window_->IsFullscreen();
 }
 
-void NativeWindowViews::SetBounds(const gfx::Rect& bounds) {
+void NativeWindowViews::SetBounds(const gfx::Rect& bounds, bool animate) {
 #if defined(USE_X11)
   // On Linux the minimum and maximum size should be updated with window size
   // when window is not resizable.
@@ -586,7 +586,7 @@ void NativeWindowViews::SetMenu(ui::MenuModel* menu_model) {
         SetContentSizeConstraints(constraints);
 
         // Resize the window to make sure content size is not changed.
-        SetContentSize(content_size);
+        SetContentSize(content_size, false);
       }
     }
   }
index 125cd47408314d08db9f60dc203c7646dadbb5d3..6592242210ff3228b99c0b39d6c541b9e41dac4a 100644 (file)
@@ -61,7 +61,7 @@ class NativeWindowViews : public NativeWindow,
   bool IsMinimized() override;
   void SetFullScreen(bool fullscreen) override;
   bool IsFullscreen() const override;
-  void SetBounds(const gfx::Rect& bounds) override;
+  void SetBounds(const gfx::Rect& bounds, bool animate) override;
   gfx::Rect GetBounds() override;
   gfx::Size GetContentSize() override;
   void SetContentSizeConstraints(
index 513b33bcb858963c9733a34b79e621cfdb411162..975ce2ad60162e279168ce2bf034e9150eb2335f 100644 (file)
@@ -121,7 +121,7 @@ void NativeWindowViews::HandleSizeEvent(WPARAM w_param, LPARAM l_param) {
 
             // When the window is restored we resize it to the previous known
             // normal size.
-            NativeWindow::SetSize(last_normal_size_);
+            NativeWindow::SetSize(last_normal_size_, false);
 
             NotifyWindowUnmaximize();
             break;
@@ -134,7 +134,7 @@ void NativeWindowViews::HandleSizeEvent(WPARAM w_param, LPARAM l_param) {
 
               // When the window is restored we resize it to the previous known
               // normal size.
-              NativeWindow::SetSize(last_normal_size_);
+              NativeWindow::SetSize(last_normal_size_, false);
 
               NotifyWindowRestore();
             }
index 61180d5b89a9e6d4f510c320ceab4a2447116013..a9b1f894cdecb2ffecb71d3bc418244c41171ff6 100644 (file)
@@ -448,7 +448,7 @@ the player itself we would call this function with arguments of 16/9 and
 are within the content view--only that they exist. Just sum any extra width and
 height areas you have within the overall content view.
 
-### `win.setBounds(options)`
+### `win.setBounds(options[, animate])`
 
 `options` Object, properties:
 
@@ -456,6 +456,7 @@ height areas you have within the overall content view.
 * `y` Integer
 * `width` Integer
 * `height` Integer
+* `animate` Boolean (optional) _OS X_
 
 Resizes and moves the window to `width`, `height`, `x`, `y`.
 
@@ -463,10 +464,11 @@ Resizes and moves the window to `width`, `height`, `x`, `y`.
 
 Returns an object that contains window's width, height, x and y values.
 
-### `win.setSize(width, height)`
+### `win.setSize(width, height[, animate])`
 
 * `width` Integer
 * `height` Integer
+* `animate` Boolean (optional) _OS X_
 
 Resizes the window to `width` and `height`.
 
@@ -474,10 +476,11 @@ Resizes the window to `width` and `height`.
 
 Returns an array that contains window's width and height.
 
-### `win.setContentSize(width, height)`
+### `win.setContentSize(width, height[, animate])`
 
 * `width` Integer
 * `height` Integer
+* `animate` Boolean (optional) _OS X_
 
 Resizes the window's client area (e.g. the web page) to `width` and `height`.
 
@@ -533,10 +536,11 @@ Returns whether the window is always on top of other windows.
 
 Moves window to the center of the screen.
 
-### `win.setPosition(x, y)`
+### `win.setPosition(x, y[, animate])`
 
 * `x` Integer
 * `y` Integer
+* `animate` Boolean (optional) _OS X_
 
 Moves window to `x` and `y`.