Browse Source

Add initial setContentBounds method

Kevin Sawicki 8 years ago
parent
commit
52199a008d

+ 7 - 0
atom/browser/api/atom_api_window.cc

@@ -366,6 +366,12 @@ gfx::Rect Window::GetBounds() {
   return window_->GetBounds();
 }
 
+void Window::SetContentBounds(const gfx::Rect& bounds, mate::Arguments* args) {
+  bool animate = false;
+  args->GetNext(&animate);
+  window_->SetContentBounds(bounds, animate);
+}
+
 gfx::Rect Window::GetContentBounds() {
   return window_->GetContentBounds();
 }
@@ -790,6 +796,7 @@ void Window::BuildPrototype(v8::Isolate* isolate,
       .SetMethod("getSize", &Window::GetSize)
       .SetMethod("setSize", &Window::SetSize)
       .SetMethod("getContentBounds", &Window::GetContentBounds)
+      .SetMethod("setContentBounds", &Window::SetContentBounds)
       .SetMethod("getContentSize", &Window::GetContentSize)
       .SetMethod("setContentSize", &Window::SetContentSize)
       .SetMethod("setMinimumSize", &Window::SetMinimumSize)

+ 1 - 0
atom/browser/api/atom_api_window.h

@@ -112,6 +112,7 @@ class Window : public mate::TrackableObject<Window>,
   std::vector<int> GetSize();
   void SetContentSize(int width, int height, mate::Arguments* args);
   std::vector<int> GetContentSize();
+  void SetContentBounds(const gfx::Rect& bounds, mate::Arguments* args);
   gfx::Rect GetContentBounds();
   void SetMinimumSize(int width, int height);
   std::vector<int> GetMinimumSize();

+ 4 - 0
atom/browser/native_window.cc

@@ -228,6 +228,10 @@ gfx::Size NativeWindow::GetContentSize() {
   return GetContentBounds().size();
 }
 
+void NativeWindow::SetContentBounds(const gfx::Rect& bounds, bool animate) {
+  SetBounds(ContentBoundsToWindowBounds(bounds), animate);
+}
+
 gfx::Rect NativeWindow::GetContentBounds() {
   return WindowBoundsToContentBounds(GetBounds());
 }

+ 1 - 0
atom/browser/native_window.h

@@ -91,6 +91,7 @@ class NativeWindow : public base::SupportsUserData,
   virtual gfx::Point GetPosition();
   virtual void SetContentSize(const gfx::Size& size, bool animate = false);
   virtual gfx::Size GetContentSize();
+  virtual void SetContentBounds(const gfx::Rect& bounds, bool animate = false);
   virtual gfx::Rect GetContentBounds();
   virtual void SetSizeConstraints(
       const extensions::SizeConstraints& size_constraints);

+ 8 - 3
atom/browser/native_window_mac.mm

@@ -1045,10 +1045,15 @@ std::vector<gfx::Rect> NativeWindowMac::CalculateNonDraggableRegions(
 
 gfx::Rect NativeWindowMac::ContentBoundsToWindowBounds(
     const gfx::Rect& bounds) {
-  if (has_frame())
-    return gfx::Rect([window_ frameRectForContentRect:bounds.ToCGRect()]);
-  else
+  if (has_frame()) {
+    gfx::Rect window_bounds(
+        [window_ frameRectForContentRect:bounds.ToCGRect()]);
+    int frame_height = window_bounds.height() - bounds.height();
+    window_bounds.set_y(window_bounds.y() - frame_height);
+    return window_bounds;
+  } else {
     return bounds;
+  }
 }
 
 gfx::Rect NativeWindowMac::WindowBoundsToContentBounds(