From 88ce2a5390f8bdee4c477695d136aea322689055 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 3 Oct 2013 08:27:59 +0800 Subject: [PATCH] Add BrowserWindow.isVisible() API. --- browser/api/atom_api_window.cc | 7 +++++++ browser/api/atom_api_window.h | 1 + browser/native_window.h | 1 + browser/native_window_mac.h | 1 + browser/native_window_mac.mm | 4 ++++ browser/native_window_win.cc | 4 ++++ browser/native_window_win.h | 1 + docs/api/browser/browser-window.md | 4 ++++ 8 files changed, 23 insertions(+) diff --git a/browser/api/atom_api_window.cc b/browser/api/atom_api_window.cc index 8d1cd0a66749..95740bcdbc15 100644 --- a/browser/api/atom_api_window.cc +++ b/browser/api/atom_api_window.cc @@ -155,6 +155,12 @@ v8::Handle Window::Hide(const v8::Arguments &args) { return v8::Undefined(); } +// static +v8::Handle Window::IsVisible(const v8::Arguments& args) { + UNWRAP_WINDOW_AND_CHECK; + return ToV8Value(self->window_->IsVisible()); +} + // static v8::Handle Window::Maximize(const v8::Arguments &args) { UNWRAP_WINDOW_AND_CHECK; @@ -671,6 +677,7 @@ void Window::Initialize(v8::Handle target) { NODE_SET_PROTOTYPE_METHOD(t, "isFocused", IsFocused); NODE_SET_PROTOTYPE_METHOD(t, "show", Show); NODE_SET_PROTOTYPE_METHOD(t, "hide", Hide); + NODE_SET_PROTOTYPE_METHOD(t, "isVisible", IsVisible); NODE_SET_PROTOTYPE_METHOD(t, "maximize", Maximize); NODE_SET_PROTOTYPE_METHOD(t, "unmaximize", Unmaximize); NODE_SET_PROTOTYPE_METHOD(t, "minimize", Minimize); diff --git a/browser/api/atom_api_window.h b/browser/api/atom_api_window.h index 1de71781eb58..5318476e3542 100644 --- a/browser/api/atom_api_window.h +++ b/browser/api/atom_api_window.h @@ -53,6 +53,7 @@ class Window : public EventEmitter, static v8::Handle IsFocused(const v8::Arguments &args); static v8::Handle Show(const v8::Arguments &args); static v8::Handle Hide(const v8::Arguments &args); + static v8::Handle IsVisible(const v8::Arguments &args); static v8::Handle Maximize(const v8::Arguments &args); static v8::Handle Unmaximize(const v8::Arguments &args); static v8::Handle Minimize(const v8::Arguments &args); diff --git a/browser/native_window.h b/browser/native_window.h index b170c57af86d..f9c11e96fb51 100644 --- a/browser/native_window.h +++ b/browser/native_window.h @@ -69,6 +69,7 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate, virtual bool IsFocused() = 0; virtual void Show() = 0; virtual void Hide() = 0; + virtual bool IsVisible() = 0; virtual void Maximize() = 0; virtual void Unmaximize() = 0; virtual void Minimize() = 0; diff --git a/browser/native_window_mac.h b/browser/native_window_mac.h index ef3ed3a38399..d1729a0ef281 100644 --- a/browser/native_window_mac.h +++ b/browser/native_window_mac.h @@ -28,6 +28,7 @@ class NativeWindowMac : public NativeWindow { virtual bool IsFocused() OVERRIDE; virtual void Show() OVERRIDE; virtual void Hide() OVERRIDE; + virtual bool IsVisible() OVERRIDE; virtual void Maximize() OVERRIDE; virtual void Unmaximize() OVERRIDE; virtual void Minimize() OVERRIDE; diff --git a/browser/native_window_mac.mm b/browser/native_window_mac.mm index 65ff9e7d8a17..d538d983ceee 100644 --- a/browser/native_window_mac.mm +++ b/browser/native_window_mac.mm @@ -229,6 +229,10 @@ void NativeWindowMac::Hide() { [window() orderOut:nil]; } +bool NativeWindowMac::IsVisible() { + return [window() isVisible]; +} + void NativeWindowMac::Maximize() { [window() zoom:nil]; } diff --git a/browser/native_window_win.cc b/browser/native_window_win.cc index c8ac370e0c8d..46d693956831 100644 --- a/browser/native_window_win.cc +++ b/browser/native_window_win.cc @@ -231,6 +231,10 @@ void NativeWindowWin::Unmaximize() { window_->Restore(); } +bool NativeWindowWin::IsVisible() { + return window_->IsVisible(); +} + void NativeWindowWin::Minimize() { window_->Minimize(); } diff --git a/browser/native_window_win.h b/browser/native_window_win.h index 810b3eeb55ed..c44f31a229f9 100644 --- a/browser/native_window_win.h +++ b/browser/native_window_win.h @@ -34,6 +34,7 @@ class NativeWindowWin : public NativeWindow, virtual bool IsFocused() OVERRIDE; virtual void Show() OVERRIDE; virtual void Hide() OVERRIDE; + virtual bool IsVisible() OVERRIDE; virtual void Maximize() OVERRIDE; virtual void Unmaximize() OVERRIDE; virtual void Minimize() OVERRIDE; diff --git a/docs/api/browser/browser-window.md b/docs/api/browser/browser-window.md index fce37fb3d5fc..0977b077cfc4 100644 --- a/docs/api/browser/browser-window.md +++ b/docs/api/browser/browser-window.md @@ -141,6 +141,10 @@ Shows the window. Hides the window. +### BrowserWindow.isVisible() + +Returns whether the window is visible to the user. + ### BrowserWindow.maximize() Maximizes the window.