From 100c4a426bdbc4a290db0867c58eb0066007f1fd Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 18 Apr 2013 15:38:04 +0800 Subject: [PATCH] Complete a few APIs for getters. --- browser/api/atom_api_window.cc | 42 ++++++++++++++++++++++++++++++++++ browser/api/atom_api_window.h | 4 ++++ browser/native_window.h | 4 ++++ browser/native_window_mac.h | 4 ++++ browser/native_window_mac.mm | 22 ++++++++++++++++++ 5 files changed, 76 insertions(+) diff --git a/browser/api/atom_api_window.cc b/browser/api/atom_api_window.cc index 3a90d76db02..51f1ec29069 100644 --- a/browser/api/atom_api_window.cc +++ b/browser/api/atom_api_window.cc @@ -193,6 +193,18 @@ v8::Handle Window::SetMinimumSize(const v8::Arguments &args) { return v8::Undefined(); } +// static +v8::Handle Window::GetMinimumSize(const v8::Arguments &args) { + Window* self = ObjectWrap::Unwrap(args.This()); + + gfx::Size size = self->window_->GetMinimumSize(); + v8::Handle ret = v8::Array::New(2); + ret->Set(0, v8::Integer::New(size.width())); + ret->Set(1, v8::Integer::New(size.height())); + + return ret; +} + // static v8::Handle Window::SetMaximumSize(const v8::Arguments &args) { Window* self = ObjectWrap::Unwrap(args.This()); @@ -205,6 +217,18 @@ v8::Handle Window::SetMaximumSize(const v8::Arguments &args) { return v8::Undefined(); } +// static +v8::Handle Window::GetMaximumSize(const v8::Arguments &args) { + Window* self = ObjectWrap::Unwrap(args.This()); + + gfx::Size size = self->window_->GetMaximumSize(); + v8::Handle ret = v8::Array::New(2); + ret->Set(0, v8::Integer::New(size.width())); + ret->Set(1, v8::Integer::New(size.height())); + + return ret; +} + // static v8::Handle Window::SetResizable(const v8::Arguments &args) { Window* self = ObjectWrap::Unwrap(args.This()); @@ -216,6 +240,13 @@ v8::Handle Window::SetResizable(const v8::Arguments &args) { return v8::Undefined(); } +// static +v8::Handle Window::IsResizable(const v8::Arguments &args) { + Window* self = ObjectWrap::Unwrap(args.This()); + + return v8::Boolean::New(self->window_->IsResizable()); +} + // static v8::Handle Window::SetAlwaysOnTop(const v8::Arguments &args) { Window* self = ObjectWrap::Unwrap(args.This()); @@ -227,6 +258,13 @@ v8::Handle Window::SetAlwaysOnTop(const v8::Arguments &args) { return v8::Undefined(); } +// static +v8::Handle Window::IsAlwaysOnTop(const v8::Arguments &args) { + Window* self = ObjectWrap::Unwrap(args.This()); + + return v8::Boolean::New(self->window_->IsAlwaysOnTop()); +} + // static v8::Handle Window::SetPosition(const v8::Arguments &args) { Window* self = ObjectWrap::Unwrap(args.This()); @@ -496,9 +534,13 @@ void Window::Initialize(v8::Handle target) { NODE_SET_PROTOTYPE_METHOD(t, "setSize", SetSize); NODE_SET_PROTOTYPE_METHOD(t, "getSize", GetSize); NODE_SET_PROTOTYPE_METHOD(t, "setMinimumSize", SetMinimumSize); + NODE_SET_PROTOTYPE_METHOD(t, "getMinimumSize", GetMinimumSize); NODE_SET_PROTOTYPE_METHOD(t, "setMaximumSize", SetMaximumSize); + NODE_SET_PROTOTYPE_METHOD(t, "getMaximumSize", GetMaximumSize); NODE_SET_PROTOTYPE_METHOD(t, "setResizable", SetResizable); + NODE_SET_PROTOTYPE_METHOD(t, "isResizable", IsResizable); NODE_SET_PROTOTYPE_METHOD(t, "setAlwaysOnTop", SetAlwaysOnTop); + NODE_SET_PROTOTYPE_METHOD(t, "isAlwaysOnTop", IsAlwaysOnTop); NODE_SET_PROTOTYPE_METHOD(t, "setPosition", SetPosition); NODE_SET_PROTOTYPE_METHOD(t, "getPosition", GetPosition); NODE_SET_PROTOTYPE_METHOD(t, "setTitle", SetTitle); diff --git a/browser/api/atom_api_window.h b/browser/api/atom_api_window.h index ab9f6ebd706..a109bf55e6f 100644 --- a/browser/api/atom_api_window.h +++ b/browser/api/atom_api_window.h @@ -47,9 +47,13 @@ class Window : public EventEmitter { static v8::Handle SetSize(const v8::Arguments &args); static v8::Handle GetSize(const v8::Arguments &args); static v8::Handle SetMinimumSize(const v8::Arguments &args); + static v8::Handle GetMinimumSize(const v8::Arguments &args); static v8::Handle SetMaximumSize(const v8::Arguments &args); + static v8::Handle GetMaximumSize(const v8::Arguments &args); static v8::Handle SetResizable(const v8::Arguments &args); + static v8::Handle IsResizable(const v8::Arguments &args); static v8::Handle SetAlwaysOnTop(const v8::Arguments &args); + static v8::Handle IsAlwaysOnTop(const v8::Arguments &args); static v8::Handle SetPosition(const v8::Arguments &args); static v8::Handle GetPosition(const v8::Arguments &args); static v8::Handle SetTitle(const v8::Arguments &args); diff --git a/browser/native_window.h b/browser/native_window.h index 25aec9d2b16..bda6026f55a 100644 --- a/browser/native_window.h +++ b/browser/native_window.h @@ -56,9 +56,13 @@ class NativeWindow : public content::WebContentsDelegate { virtual void SetSize(const gfx::Size& size) = 0; virtual gfx::Size GetSize() = 0; virtual void SetMinimumSize(const gfx::Size& size) = 0; + virtual gfx::Size GetMinimumSize() = 0; virtual void SetMaximumSize(const gfx::Size& size) = 0; + virtual gfx::Size GetMaximumSize() = 0; virtual void SetResizable(bool resizable) = 0; + virtual bool IsResizable() = 0; virtual void SetAlwaysOnTop(bool top) = 0; + virtual bool IsAlwaysOnTop() = 0; virtual void SetPosition(const std::string& position) = 0; virtual void SetPosition(const gfx::Point& position) = 0; virtual gfx::Point GetPosition() = 0; diff --git a/browser/native_window_mac.h b/browser/native_window_mac.h index f9cb788729b..2f9190f203a 100644 --- a/browser/native_window_mac.h +++ b/browser/native_window_mac.h @@ -33,9 +33,13 @@ class NativeWindowMac : public NativeWindow { virtual void SetSize(const gfx::Size& size) OVERRIDE; virtual gfx::Size GetSize() OVERRIDE; virtual void SetMinimumSize(const gfx::Size& size) OVERRIDE; + virtual gfx::Size GetMinimumSize() OVERRIDE; virtual void SetMaximumSize(const gfx::Size& size) OVERRIDE; + virtual gfx::Size GetMaximumSize() OVERRIDE; virtual void SetResizable(bool resizable) OVERRIDE; + virtual bool IsResizable() OVERRIDE; virtual void SetAlwaysOnTop(bool top) OVERRIDE; + virtual bool IsAlwaysOnTop() OVERRIDE; virtual void SetPosition(const std::string& position) OVERRIDE; virtual void SetPosition(const gfx::Point& position) OVERRIDE; virtual gfx::Point GetPosition() OVERRIDE; diff --git a/browser/native_window_mac.mm b/browser/native_window_mac.mm index 9adb7be4e23..a6a334df9d1 100644 --- a/browser/native_window_mac.mm +++ b/browser/native_window_mac.mm @@ -224,12 +224,26 @@ void NativeWindowMac::SetMinimumSize(const gfx::Size& size) { [window() setContentMinSize:[content convertSize:min_size toView:nil]]; } +gfx::Size NativeWindowMac::GetMinimumSize() { + NSView* content = [window() contentView]; + NSSize min_size = [content convertSize:[window() contentMinSize] + fromView:nil]; + return gfx::Size(min_size.width, min_size.height); +} + void NativeWindowMac::SetMaximumSize(const gfx::Size& size) { NSSize max_size = NSMakeSize(size.width(), size.height()); NSView* content = [window() contentView]; [window() setContentMaxSize:[content convertSize:max_size toView:nil]]; } +gfx::Size NativeWindowMac::GetMaximumSize() { + NSView* content = [window() contentView]; + NSSize max_size = [content convertSize:[window() contentMaxSize] + fromView:nil]; + return gfx::Size(max_size.width, max_size.height); +} + void NativeWindowMac::SetResizable(bool resizable) { if (resizable) { [[window() standardWindowButton:NSWindowZoomButton] setEnabled:YES]; @@ -240,10 +254,18 @@ void NativeWindowMac::SetResizable(bool resizable) { } } +bool NativeWindowMac::IsResizable() { + return [window() styleMask] & NSResizableWindowMask; +} + void NativeWindowMac::SetAlwaysOnTop(bool top) { [window() setLevel:(top ? NSFloatingWindowLevel : NSNormalWindowLevel)]; } +bool NativeWindowMac::IsAlwaysOnTop() { + return [window() level] == NSFloatingWindowLevel; +} + void NativeWindowMac::SetPosition(const std::string& position) { if (position == "center") [window() center];