Add BrowserWindow.getClientBounds API
authorKevin Sawicki <kevinsawicki@gmail.com>
Fri, 29 Jul 2016 01:19:17 +0000 (18:19 -0700)
committerKevin Sawicki <kevinsawicki@gmail.com>
Thu, 4 Aug 2016 16:58:35 +0000 (09:58 -0700)
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

index 550372c..7af5e6e 100644 (file)
@@ -366,6 +366,10 @@ gfx::Rect Window::GetBounds() {
   return window_->GetBounds();
 }
 
+gfx::Rect Window::GetContentBounds() {
+  return window_->GetContentBounds();
+}
+
 void Window::SetSize(int width, int height, mate::Arguments* args) {
   bool animate = false;
   args->GetNext(&animate);
@@ -785,6 +789,7 @@ void Window::BuildPrototype(v8::Isolate* isolate,
       .SetMethod("setBounds", &Window::SetBounds)
       .SetMethod("getSize", &Window::GetSize)
       .SetMethod("setSize", &Window::SetSize)
+      .SetMethod("getContentBounds", &Window::GetContentBounds)
       .SetMethod("getContentSize", &Window::GetContentSize)
       .SetMethod("setContentSize", &Window::SetContentSize)
       .SetMethod("setMinimumSize", &Window::SetMinimumSize)
index 5da7bd8..056b4ca 100644 (file)
@@ -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();
+  gfx::Rect GetContentBounds();
   void SetMinimumSize(int width, int height);
   std::vector<int> GetMinimumSize();
   void SetMaximumSize(int width, int height);
index b932c63..285a37a 100644 (file)
@@ -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 gfx::Rect GetContentBounds() = 0;
   virtual void SetSizeConstraints(
       const extensions::SizeConstraints& size_constraints);
   virtual extensions::SizeConstraints GetSizeConstraints();
index d09faa1..e6ffcee 100644 (file)
@@ -46,6 +46,7 @@ class NativeWindowMac : public NativeWindow {
   bool IsFullscreen() const override;
   void SetBounds(const gfx::Rect& bounds, bool animate = false) override;
   gfx::Rect GetBounds() override;
+  gfx::Rect GetContentBounds() override;
   void SetContentSizeConstraints(
       const extensions::SizeConstraints& size_constraints) override;
   void SetResizable(bool resizable) override;
index e16682b..47b0252 100644 (file)
@@ -753,6 +753,14 @@ gfx::Rect NativeWindowMac::GetBounds() {
   return bounds;
 }
 
+gfx::Rect NativeWindowMac::GetContentBounds() {
+  NSRect frame = [window_ convertRectToScreen:[[window_ contentView] frame]];
+  gfx::Rect bounds(frame.origin.x, 0, NSWidth(frame), NSHeight(frame));
+  NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
+  bounds.set_y(NSHeight([screen frame]) - NSMaxY(frame));
+  return bounds;
+}
+
 void NativeWindowMac::SetContentSizeConstraints(
     const extensions::SizeConstraints& size_constraints) {
   auto convertSize = [this](const gfx::Size& size) {
index b4dcf29..8d7ec31 100644 (file)
@@ -544,6 +544,10 @@ gfx::Rect NativeWindowViews::GetBounds() {
   return window_->GetWindowBoundsInScreen();
 }
 
+gfx::Rect NativeWindowViews::GetContentBounds() {
+  return window_->GetClientAreaBoundsInScreen();
+}
+
 gfx::Size NativeWindowViews::GetContentSize() {
 #if defined(OS_WIN)
   if (IsMinimized())
index 71504ce..f761905 100644 (file)
@@ -68,6 +68,7 @@ class NativeWindowViews : public NativeWindow,
   bool IsFullscreen() const override;
   void SetBounds(const gfx::Rect& bounds, bool animate) override;
   gfx::Rect GetBounds() override;
+  gfx::Rect GetContentBounds() override;
   gfx::Size GetContentSize() override;
   void SetContentSizeConstraints(
       const extensions::SizeConstraints& size_constraints) override;