Merge pull request #1545 from deepak1556/windows_patch
window: adding setBounds and getBounds api
This commit is contained in:
commit
5f27bb597f
9 changed files with 88 additions and 36 deletions
|
@ -15,6 +15,7 @@
|
|||
#include "native_mate/callback.h"
|
||||
#include "native_mate/constructor.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
#include "ui/gfx/geometry/rect.h"
|
||||
|
||||
#include "atom/common/node_includes.h"
|
||||
|
||||
|
@ -222,6 +223,14 @@ bool Window::IsFullscreen() {
|
|||
return window_->IsFullscreen();
|
||||
}
|
||||
|
||||
void Window::SetBounds(const gfx::Rect& bounds) {
|
||||
window_->SetBounds(bounds);
|
||||
}
|
||||
|
||||
gfx::Rect Window::GetBounds() {
|
||||
return window_->GetBounds();
|
||||
}
|
||||
|
||||
void Window::SetSize(int width, int height) {
|
||||
window_->SetSize(gfx::Size(width, height));
|
||||
}
|
||||
|
@ -464,6 +473,8 @@ void Window::BuildPrototype(v8::Isolate* isolate,
|
|||
.SetMethod("isMinimized", &Window::IsMinimized)
|
||||
.SetMethod("setFullScreen", &Window::SetFullScreen)
|
||||
.SetMethod("isFullScreen", &Window::IsFullscreen)
|
||||
.SetMethod("getBounds", &Window::GetBounds)
|
||||
.SetMethod("setBounds", &Window::SetBounds)
|
||||
.SetMethod("getSize", &Window::GetSize)
|
||||
.SetMethod("setSize", &Window::SetSize)
|
||||
.SetMethod("getContentSize", &Window::GetContentSize)
|
||||
|
|
|
@ -16,6 +16,10 @@
|
|||
|
||||
class GURL;
|
||||
|
||||
namespace gfx {
|
||||
class Rect;
|
||||
}
|
||||
|
||||
namespace mate {
|
||||
class Arguments;
|
||||
class Dictionary;
|
||||
|
@ -85,6 +89,8 @@ class Window : public mate::EventEmitter,
|
|||
bool IsMinimized();
|
||||
void SetFullScreen(bool fullscreen);
|
||||
bool IsFullscreen();
|
||||
void SetBounds(const gfx::Rect& bounds);
|
||||
gfx::Rect GetBounds();
|
||||
void SetSize(int width, int height);
|
||||
std::vector<int> GetSize();
|
||||
void SetContentSize(int width, int height);
|
||||
|
|
|
@ -192,7 +192,7 @@ void NativeWindow::InitFromOptions(const mate::Dictionary& options) {
|
|||
int width = -1, height = -1;
|
||||
options.Get(switches::kWidth, &width);
|
||||
options.Get(switches::kHeight, &height);
|
||||
Move(gfx::Rect(x, y, width, height));
|
||||
SetBounds(gfx::Rect(x, y, width, height));
|
||||
} else if (options.Get(switches::kCenter, ¢er) && center) {
|
||||
Center();
|
||||
}
|
||||
|
@ -646,8 +646,7 @@ void NativeWindow::DeactivateContents(content::WebContents* contents) {
|
|||
|
||||
void NativeWindow::MoveContents(content::WebContents* source,
|
||||
const gfx::Rect& pos) {
|
||||
SetPosition(pos.origin());
|
||||
SetSize(pos.size());
|
||||
SetBounds(pos);
|
||||
}
|
||||
|
||||
void NativeWindow::CloseContents(content::WebContents* source) {
|
||||
|
|
|
@ -98,7 +98,6 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
|
|||
|
||||
virtual void Close() = 0;
|
||||
virtual void CloseImmediately() = 0;
|
||||
virtual void Move(const gfx::Rect& pos) = 0;
|
||||
virtual void Focus(bool focus) = 0;
|
||||
virtual bool IsFocused() = 0;
|
||||
virtual void Show() = 0;
|
||||
|
@ -113,6 +112,8 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
|
|||
virtual bool IsMinimized() = 0;
|
||||
virtual void SetFullScreen(bool fullscreen) = 0;
|
||||
virtual bool IsFullscreen() const = 0;
|
||||
virtual void SetBounds(const gfx::Rect& bounds) = 0;
|
||||
virtual gfx::Rect GetBounds() = 0;
|
||||
virtual void SetSize(const gfx::Size& size) = 0;
|
||||
virtual gfx::Size GetSize() = 0;
|
||||
virtual void SetContentSize(const gfx::Size& size) = 0;
|
||||
|
|
|
@ -30,7 +30,6 @@ class NativeWindowMac : public NativeWindow {
|
|||
// NativeWindow implementation.
|
||||
void Close() override;
|
||||
void CloseImmediately() override;
|
||||
void Move(const gfx::Rect& pos) override;
|
||||
void Focus(bool focus) override;
|
||||
bool IsFocused() override;
|
||||
void Show() override;
|
||||
|
@ -45,6 +44,8 @@ class NativeWindowMac : public NativeWindow {
|
|||
bool IsMinimized() override;
|
||||
void SetFullScreen(bool fullscreen) override;
|
||||
bool IsFullscreen() const override;
|
||||
void SetBounds(const gfx::Rect& bounds) override;
|
||||
gfx::Rect GetBounds() override;
|
||||
void SetSize(const gfx::Size& size) override;
|
||||
gfx::Size GetSize() override;
|
||||
void SetContentSize(const gfx::Size& size) override;
|
||||
|
|
|
@ -382,18 +382,6 @@ void NativeWindowMac::CloseImmediately() {
|
|||
[window_ close];
|
||||
}
|
||||
|
||||
void NativeWindowMac::Move(const gfx::Rect& pos) {
|
||||
NSRect cocoa_bounds = NSMakeRect(pos.x(), 0,
|
||||
pos.width(),
|
||||
pos.height());
|
||||
// Flip coordinates based on the primary screen.
|
||||
NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
|
||||
cocoa_bounds.origin.y =
|
||||
NSHeight([screen frame]) - pos.height() - pos.y();
|
||||
|
||||
[window_ setFrame:cocoa_bounds display:YES];
|
||||
}
|
||||
|
||||
void NativeWindowMac::Focus(bool focus) {
|
||||
if (!IsVisible())
|
||||
return;
|
||||
|
@ -470,6 +458,29 @@ bool NativeWindowMac::IsFullscreen() const {
|
|||
return [window_ styleMask] & NSFullScreenWindowMask;
|
||||
}
|
||||
|
||||
void NativeWindowMac::SetBounds(const gfx::Rect& bounds) {
|
||||
NSRect cocoa_bounds = NSMakeRect(bounds.x(), 0,
|
||||
bounds.width(),
|
||||
bounds.height());
|
||||
// Flip coordinates based on the primary screen.
|
||||
NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
|
||||
cocoa_bounds.origin.y =
|
||||
NSHeight([screen frame]) - bounds.height() - bounds.y();
|
||||
|
||||
[window_ setFrame:cocoa_bounds display:YES];
|
||||
}
|
||||
|
||||
gfx::Rect NativeWindowMac::GetBounds() {
|
||||
NSRect frame = [window_ frame];
|
||||
NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
|
||||
|
||||
gfx::Point pos(frame.origin.x,
|
||||
NSHeight([screen frame]) - frame.origin.y - frame.size.height);
|
||||
gfx::Size size(frame.size.width, frame.size.height);
|
||||
|
||||
return gfx::Rect(pos, size);
|
||||
}
|
||||
|
||||
void NativeWindowMac::SetSize(const gfx::Size& size) {
|
||||
NSRect frame = [window_ frame];
|
||||
frame.origin.y -= size.height() - frame.size.height;
|
||||
|
@ -480,8 +491,7 @@ void NativeWindowMac::SetSize(const gfx::Size& size) {
|
|||
}
|
||||
|
||||
gfx::Size NativeWindowMac::GetSize() {
|
||||
NSRect frame = [window_ frame];
|
||||
return gfx::Size(frame.size.width, frame.size.height);
|
||||
return GetBounds().size();
|
||||
}
|
||||
|
||||
void NativeWindowMac::SetContentSize(const gfx::Size& size) {
|
||||
|
@ -555,15 +565,11 @@ void NativeWindowMac::Center() {
|
|||
}
|
||||
|
||||
void NativeWindowMac::SetPosition(const gfx::Point& position) {
|
||||
Move(gfx::Rect(position, GetSize()));
|
||||
SetBounds(gfx::Rect(position, GetSize()));
|
||||
}
|
||||
|
||||
gfx::Point NativeWindowMac::GetPosition() {
|
||||
NSRect frame = [window_ frame];
|
||||
NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
|
||||
|
||||
return gfx::Point(frame.origin.x,
|
||||
NSHeight([screen frame]) - frame.origin.y - frame.size.height);
|
||||
return GetBounds().origin();
|
||||
}
|
||||
|
||||
void NativeWindowMac::SetTitle(const std::string& title) {
|
||||
|
|
|
@ -291,10 +291,6 @@ void NativeWindowViews::CloseImmediately() {
|
|||
window_->CloseNow();
|
||||
}
|
||||
|
||||
void NativeWindowViews::Move(const gfx::Rect& bounds) {
|
||||
window_->SetBounds(bounds);
|
||||
}
|
||||
|
||||
void NativeWindowViews::Focus(bool focus) {
|
||||
if (focus)
|
||||
window_->Activate();
|
||||
|
@ -373,6 +369,28 @@ bool NativeWindowViews::IsFullscreen() const {
|
|||
return window_->IsFullscreen();
|
||||
}
|
||||
|
||||
void NativeWindowViews::SetBounds(const gfx::Rect& bounds) {
|
||||
#if defined(USE_X11)
|
||||
// On Linux the minimum and maximum size should be updated with window size
|
||||
// when window is not resizable.
|
||||
if (!resizable_) {
|
||||
SetMaximumSize(bounds.size());
|
||||
SetMinimumSize(bounds.size());
|
||||
}
|
||||
#endif
|
||||
|
||||
window_->SetBounds(bounds);
|
||||
}
|
||||
|
||||
gfx::Rect NativeWindowViews::GetBounds() {
|
||||
#if defined(OS_WIN)
|
||||
if (IsMinimized())
|
||||
return window_->GetRestoredBounds();
|
||||
#endif
|
||||
|
||||
return window_->GetWindowBoundsInScreen();
|
||||
}
|
||||
|
||||
void NativeWindowViews::SetSize(const gfx::Size& size) {
|
||||
#if defined(USE_X11)
|
||||
// On Linux the minimum and maximum size should be updated with window size
|
||||
|
@ -387,12 +405,7 @@ void NativeWindowViews::SetSize(const gfx::Size& size) {
|
|||
}
|
||||
|
||||
gfx::Size NativeWindowViews::GetSize() {
|
||||
#if defined(OS_WIN)
|
||||
if (IsMinimized())
|
||||
return window_->GetRestoredBounds().size();
|
||||
#endif
|
||||
|
||||
return window_->GetWindowBoundsInScreen().size();
|
||||
return GetBounds().size();
|
||||
}
|
||||
|
||||
void NativeWindowViews::SetContentSize(const gfx::Size& size) {
|
||||
|
|
|
@ -35,7 +35,6 @@ class NativeWindowViews : public NativeWindow,
|
|||
// NativeWindow:
|
||||
void Close() override;
|
||||
void CloseImmediately() override;
|
||||
void Move(const gfx::Rect& pos) override;
|
||||
void Focus(bool focus) override;
|
||||
bool IsFocused() override;
|
||||
void Show() override;
|
||||
|
@ -50,6 +49,8 @@ class NativeWindowViews : public NativeWindow,
|
|||
bool IsMinimized() override;
|
||||
void SetFullScreen(bool fullscreen) override;
|
||||
bool IsFullscreen() const override;
|
||||
void SetBounds(const gfx::Rect& bounds) override;
|
||||
gfx::Rect GetBounds() override;
|
||||
void SetSize(const gfx::Size& size) override;
|
||||
gfx::Size GetSize() override;
|
||||
void SetContentSize(const gfx::Size& size) override;
|
||||
|
|
|
@ -316,6 +316,20 @@ Sets whether the window should be in fullscreen mode.
|
|||
|
||||
Returns whether the window is in fullscreen mode.
|
||||
|
||||
### BrowserWindow.setBounds(options)
|
||||
|
||||
* `options` Object
|
||||
* `x` Integer
|
||||
* `y` Integer
|
||||
* `width` Integer
|
||||
* `height` Integer
|
||||
|
||||
Resizes and moves the window to `width`, `height`, `x`, `y`.
|
||||
|
||||
### BrowserWindow.getBounds()
|
||||
|
||||
Returns an object that contains window's width, height, x and y values.
|
||||
|
||||
### BrowserWindow.setSize(width, height)
|
||||
|
||||
* `width` Integer
|
||||
|
|
Loading…
Reference in a new issue