Skip to content

Commit 48cc13d

Browse files
committed
Add BrowserWindow.getClientBounds API
1 parent cdfbeb1 commit 48cc13d

File tree

7 files changed

+21
-0
lines changed

7 files changed

+21
-0
lines changed

atom/browser/api/atom_api_window.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,10 @@ gfx::Rect Window::GetBounds() {
366366
return window_->GetBounds();
367367
}
368368

369+
gfx::Rect Window::GetContentBounds() {
370+
return window_->GetContentBounds();
371+
}
372+
369373
void Window::SetSize(int width, int height, mate::Arguments* args) {
370374
bool animate = false;
371375
args->GetNext(&animate);
@@ -785,6 +789,7 @@ void Window::BuildPrototype(v8::Isolate* isolate,
785789
.SetMethod("setBounds", &Window::SetBounds)
786790
.SetMethod("getSize", &Window::GetSize)
787791
.SetMethod("setSize", &Window::SetSize)
792+
.SetMethod("getContentBounds", &Window::GetContentBounds)
788793
.SetMethod("getContentSize", &Window::GetContentSize)
789794
.SetMethod("setContentSize", &Window::SetContentSize)
790795
.SetMethod("setMinimumSize", &Window::SetMinimumSize)

atom/browser/api/atom_api_window.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ class Window : public mate::TrackableObject<Window>,
112112
std::vector<int> GetSize();
113113
void SetContentSize(int width, int height, mate::Arguments* args);
114114
std::vector<int> GetContentSize();
115+
gfx::Rect GetContentBounds();
115116
void SetMinimumSize(int width, int height);
116117
std::vector<int> GetMinimumSize();
117118
void SetMaximumSize(int width, int height);

atom/browser/native_window.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ class NativeWindow : public base::SupportsUserData,
9191
virtual gfx::Point GetPosition();
9292
virtual void SetContentSize(const gfx::Size& size, bool animate = false);
9393
virtual gfx::Size GetContentSize();
94+
virtual gfx::Rect GetContentBounds() = 0;
9495
virtual void SetSizeConstraints(
9596
const extensions::SizeConstraints& size_constraints);
9697
virtual extensions::SizeConstraints GetSizeConstraints();

atom/browser/native_window_mac.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class NativeWindowMac : public NativeWindow {
4646
bool IsFullscreen() const override;
4747
void SetBounds(const gfx::Rect& bounds, bool animate = false) override;
4848
gfx::Rect GetBounds() override;
49+
gfx::Rect GetContentBounds() override;
4950
void SetContentSizeConstraints(
5051
const extensions::SizeConstraints& size_constraints) override;
5152
void SetResizable(bool resizable) override;

atom/browser/native_window_mac.mm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,14 @@ static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val,
753753
return bounds;
754754
}
755755

756+
gfx::Rect NativeWindowMac::GetContentBounds() {
757+
NSRect frame = [window_ convertRectToScreen:[[window_ contentView] frame]];
758+
gfx::Rect bounds(frame.origin.x, 0, NSWidth(frame), NSHeight(frame));
759+
NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
760+
bounds.set_y(NSHeight([screen frame]) - NSMaxY(frame));
761+
return bounds;
762+
}
763+
756764
void NativeWindowMac::SetContentSizeConstraints(
757765
const extensions::SizeConstraints& size_constraints) {
758766
auto convertSize = [this](const gfx::Size& size) {

atom/browser/native_window_views.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,10 @@ gfx::Rect NativeWindowViews::GetBounds() {
544544
return window_->GetWindowBoundsInScreen();
545545
}
546546

547+
gfx::Rect NativeWindowViews::GetContentBounds() {
548+
return window_->GetClientAreaBoundsInScreen();
549+
}
550+
547551
gfx::Size NativeWindowViews::GetContentSize() {
548552
#if defined(OS_WIN)
549553
if (IsMinimized())

atom/browser/native_window_views.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class NativeWindowViews : public NativeWindow,
6868
bool IsFullscreen() const override;
6969
void SetBounds(const gfx::Rect& bounds, bool animate) override;
7070
gfx::Rect GetBounds() override;
71+
gfx::Rect GetContentBounds() override;
7172
gfx::Size GetContentSize() override;
7273
void SetContentSizeConstraints(
7374
const extensions::SizeConstraints& size_constraints) override;

0 commit comments

Comments
 (0)