From 5c3857790ca7d3aecb492791421e05d0f7d54f87 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 16 May 2013 22:56:52 +0800 Subject: [PATCH] Add BrowserWindow.isFocused() 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 ++++ 5 files changed, 14 insertions(+) diff --git a/browser/api/atom_api_window.cc b/browser/api/atom_api_window.cc index 755a8e7fad..7e131f29c8 100644 --- a/browser/api/atom_api_window.cc +++ b/browser/api/atom_api_window.cc @@ -116,6 +116,12 @@ v8::Handle Window::Focus(const v8::Arguments &args) { return v8::Undefined(); } +// static +v8::Handle Window::IsFocused(const v8::Arguments &args) { + UNWRAP_WINDOW_AND_CHECK; + return v8::Boolean::New(self->window_->IsFocused()); +} + // static v8::Handle Window::Show(const v8::Arguments &args) { UNWRAP_WINDOW_AND_CHECK; @@ -591,6 +597,7 @@ void Window::Initialize(v8::Handle target) { NODE_SET_PROTOTYPE_METHOD(t, "destroy", Destroy); NODE_SET_PROTOTYPE_METHOD(t, "close", Close); NODE_SET_PROTOTYPE_METHOD(t, "focus", Focus); + 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, "maximize", Maximize); diff --git a/browser/api/atom_api_window.h b/browser/api/atom_api_window.h index 79a97f9d9a..83fa056a62 100644 --- a/browser/api/atom_api_window.h +++ b/browser/api/atom_api_window.h @@ -45,6 +45,7 @@ class Window : public EventEmitter, // APIs for NativeWindow. static v8::Handle Close(const v8::Arguments &args); static v8::Handle Focus(const v8::Arguments &args); + 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 Maximize(const v8::Arguments &args); diff --git a/browser/native_window.h b/browser/native_window.h index d5ba8328f6..fafdda0b32 100644 --- a/browser/native_window.h +++ b/browser/native_window.h @@ -63,6 +63,7 @@ class NativeWindow : public content::WebContentsDelegate, 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; virtual void Hide() = 0; virtual void Maximize() = 0; diff --git a/browser/native_window_mac.h b/browser/native_window_mac.h index d5863d035a..ec34dde1ab 100644 --- a/browser/native_window_mac.h +++ b/browser/native_window_mac.h @@ -23,6 +23,7 @@ class NativeWindowMac : public NativeWindow { virtual void CloseImmediately() OVERRIDE; virtual void Move(const gfx::Rect& pos) OVERRIDE; virtual void Focus(bool focus) OVERRIDE; + virtual bool IsFocused() OVERRIDE; virtual void Show() OVERRIDE; virtual void Hide() OVERRIDE; virtual void Maximize() OVERRIDE; diff --git a/browser/native_window_mac.mm b/browser/native_window_mac.mm index 66c285b359..f4091d2238 100644 --- a/browser/native_window_mac.mm +++ b/browser/native_window_mac.mm @@ -151,6 +151,10 @@ void NativeWindowMac::Focus(bool focus) { [window() orderBack:nil]; } +bool NativeWindowMac::IsFocused() { + return [window() isKeyWindow]; +} + void NativeWindowMac::Show() { [window() makeKeyAndOrderFront:nil]; }