Add BrowserWindow.focusOnWebView and blurWebView.
This commit is contained in:
parent
f3a8a0741c
commit
edf2e84895
7 changed files with 50 additions and 3 deletions
|
@ -401,6 +401,24 @@ v8::Handle<v8::Value> Window::CloseDevTools(const v8::Arguments &args) {
|
|||
return v8::Undefined();
|
||||
}
|
||||
|
||||
// static
|
||||
v8::Handle<v8::Value> Window::FocusOnWebView(const v8::Arguments &args) {
|
||||
UNWRAP_WINDOW_AND_CHECK;
|
||||
|
||||
self->window_->FocusOnWebView();
|
||||
|
||||
return v8::Undefined();
|
||||
}
|
||||
|
||||
// static
|
||||
v8::Handle<v8::Value> Window::BlurWebView(const v8::Arguments &args) {
|
||||
UNWRAP_WINDOW_AND_CHECK;
|
||||
|
||||
self->window_->BlurWebView();
|
||||
|
||||
return v8::Undefined();
|
||||
}
|
||||
|
||||
// static
|
||||
v8::Handle<v8::Value> Window::GetPageTitle(const v8::Arguments &args) {
|
||||
UNWRAP_WINDOW_AND_CHECK;
|
||||
|
@ -626,6 +644,8 @@ void Window::Initialize(v8::Handle<v8::Object> target) {
|
|||
NODE_SET_PROTOTYPE_METHOD(t, "isKiosk", IsKiosk);
|
||||
NODE_SET_PROTOTYPE_METHOD(t, "openDevTools", OpenDevTools);
|
||||
NODE_SET_PROTOTYPE_METHOD(t, "closeDevTools", CloseDevTools);
|
||||
NODE_SET_PROTOTYPE_METHOD(t, "focusOnWebView", FocusOnWebView);
|
||||
NODE_SET_PROTOTYPE_METHOD(t, "blurWebView", BlurWebView);
|
||||
|
||||
NODE_SET_PROTOTYPE_METHOD(t, "getPageTitle", GetPageTitle);
|
||||
NODE_SET_PROTOTYPE_METHOD(t, "isLoading", IsLoading);
|
||||
|
|
|
@ -74,6 +74,8 @@ class Window : public EventEmitter,
|
|||
static v8::Handle<v8::Value> IsKiosk(const v8::Arguments &args);
|
||||
static v8::Handle<v8::Value> OpenDevTools(const v8::Arguments &args);
|
||||
static v8::Handle<v8::Value> CloseDevTools(const v8::Arguments &args);
|
||||
static v8::Handle<v8::Value> FocusOnWebView(const v8::Arguments &args);
|
||||
static v8::Handle<v8::Value> BlurWebView(const v8::Arguments &args);
|
||||
|
||||
// APIs for WebContents.
|
||||
static v8::Handle<v8::Value> GetPageTitle(const v8::Arguments &args);
|
||||
|
|
|
@ -132,6 +132,14 @@ void NativeWindow::CloseDevTools() {
|
|||
inspectable_web_contents()->GetView()->CloseDevTools();
|
||||
}
|
||||
|
||||
void NativeWindow::FocusOnWebView() {
|
||||
GetWebContents()->GetRenderViewHost()->Focus();
|
||||
}
|
||||
|
||||
void NativeWindow::BlurWebView() {
|
||||
GetWebContents()->GetRenderViewHost()->Blur();
|
||||
}
|
||||
|
||||
void NativeWindow::CloseWebContents() {
|
||||
bool prevent_default = false;
|
||||
FOR_EACH_OBSERVER(NativeWindowObserver,
|
||||
|
@ -162,6 +170,10 @@ void NativeWindow::NotifyWindowClosed() {
|
|||
WindowList::RemoveWindow(this);
|
||||
}
|
||||
|
||||
void NativeWindow::NotifyWindowBlur() {
|
||||
FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnWindowBlur());
|
||||
}
|
||||
|
||||
// Window opened by window.open.
|
||||
void NativeWindow::WebContentsCreated(
|
||||
content::WebContents* source_contents,
|
||||
|
@ -207,11 +219,11 @@ bool NativeWindow::CanOverscrollContent() const {
|
|||
}
|
||||
|
||||
void NativeWindow::ActivateContents(content::WebContents* contents) {
|
||||
GetWebContents()->GetRenderViewHost()->Focus();
|
||||
FocusOnWebView();
|
||||
}
|
||||
|
||||
void NativeWindow::DeactivateContents(content::WebContents* contents) {
|
||||
GetWebContents()->GetRenderViewHost()->Blur();
|
||||
BlurWebView();
|
||||
}
|
||||
|
||||
void NativeWindow::MoveContents(content::WebContents* source,
|
||||
|
|
|
@ -95,6 +95,8 @@ class NativeWindow : public content::WebContentsDelegate,
|
|||
virtual bool IsClosed() const { return is_closed_; }
|
||||
virtual void OpenDevTools();
|
||||
virtual void CloseDevTools();
|
||||
virtual void FocusOnWebView();
|
||||
virtual void BlurWebView();
|
||||
|
||||
// The same with closing a tab in a real browser.
|
||||
//
|
||||
|
@ -120,6 +122,7 @@ class NativeWindow : public content::WebContentsDelegate,
|
|||
}
|
||||
|
||||
void NotifyWindowClosed();
|
||||
void NotifyWindowBlur();
|
||||
|
||||
// Implementations of content::WebContentsDelegate.
|
||||
virtual void WebContentsCreated(content::WebContents* source_contents,
|
||||
|
|
|
@ -54,6 +54,8 @@ class NativeWindowMac : public NativeWindow {
|
|||
|
||||
NSWindow*& window() { return window_; }
|
||||
|
||||
void NotifyWindowBlur() { NativeWindow::NotifyWindowBlur(); }
|
||||
|
||||
protected:
|
||||
void SetNonLionFullscreen(bool fullscreen);
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "content/public/browser/native_web_keyboard_event.h"
|
||||
#include "content/public/browser/web_contents.h"
|
||||
#include "content/public/browser/web_contents_view.h"
|
||||
#include "content/public/browser/render_view_host.h"
|
||||
|
||||
@interface AtomNSWindowDelegate : NSObject<NSWindowDelegate> {
|
||||
@private
|
||||
|
@ -36,6 +37,10 @@
|
|||
return self;
|
||||
}
|
||||
|
||||
- (void)windowDidResignKey:(NSNotification*)notification {
|
||||
shell_->NotifyWindowBlur();
|
||||
}
|
||||
|
||||
- (void)windowWillClose:(NSNotification*)notification {
|
||||
shell_->window() = nil;
|
||||
[self autorelease];
|
||||
|
|
|
@ -22,6 +22,9 @@ class NativeWindowObserver {
|
|||
|
||||
// Called when the window is closed.
|
||||
virtual void OnWindowClosed() {}
|
||||
|
||||
// Called when window loses focus.
|
||||
virtual void OnWindowBlur() {}
|
||||
};
|
||||
|
||||
} // namespace atom
|
||||
|
|
Loading…
Reference in a new issue