Add BrowserWindow.getClientBounds API

This commit is contained in:
Kevin Sawicki 2016-07-28 18:19:17 -07:00
parent cdfbeb1a0a
commit 48cc13d009
7 changed files with 21 additions and 0 deletions

View 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)

View 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);

View 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();

View 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;

View 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) {

View 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())

View 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;