From 48cc13d009a089804db46766d5b8eb475b268491 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 28 Jul 2016 18:19:17 -0700 Subject: [PATCH] Add BrowserWindow.getClientBounds API --- atom/browser/api/atom_api_window.cc | 5 +++++ atom/browser/api/atom_api_window.h | 1 + atom/browser/native_window.h | 1 + atom/browser/native_window_mac.h | 1 + atom/browser/native_window_mac.mm | 8 ++++++++ atom/browser/native_window_views.cc | 4 ++++ atom/browser/native_window_views.h | 1 + 7 files changed, 21 insertions(+) diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index 550372c577c6..7af5e6e2d7e4 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -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) diff --git a/atom/browser/api/atom_api_window.h b/atom/browser/api/atom_api_window.h index 5da7bd8d4bdc..056b4cae347d 100644 --- a/atom/browser/api/atom_api_window.h +++ b/atom/browser/api/atom_api_window.h @@ -112,6 +112,7 @@ class Window : public mate::TrackableObject, std::vector GetSize(); void SetContentSize(int width, int height, mate::Arguments* args); std::vector GetContentSize(); + gfx::Rect GetContentBounds(); void SetMinimumSize(int width, int height); std::vector GetMinimumSize(); void SetMaximumSize(int width, int height); diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index b932c6317b08..285a37a1bd9b 100644 --- a/atom/browser/native_window.h +++ b/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 gfx::Rect GetContentBounds() = 0; virtual void SetSizeConstraints( const extensions::SizeConstraints& size_constraints); virtual extensions::SizeConstraints GetSizeConstraints(); diff --git a/atom/browser/native_window_mac.h b/atom/browser/native_window_mac.h index d09faa18f6c6..e6ffceef8545 100644 --- a/atom/browser/native_window_mac.h +++ b/atom/browser/native_window_mac.h @@ -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; diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index e16682b33fc5..47b02525256a 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -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) { diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index b4dcf291714c..8d7ec3100c2b 100644 --- a/atom/browser/native_window_views.cc +++ b/atom/browser/native_window_views.cc @@ -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()) diff --git a/atom/browser/native_window_views.h b/atom/browser/native_window_views.h index 71504ceac355..f7619053812c 100644 --- a/atom/browser/native_window_views.h +++ b/atom/browser/native_window_views.h @@ -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;