Move StoreFocus/RestoreFocus to BrowserWindow

This commit is contained in:
Cheng Zhao 2018-03-06 13:13:50 +09:00
parent cad3d694ab
commit 2eaa6d0874
2 changed files with 13 additions and 21 deletions

View file

@ -276,7 +276,6 @@ bool BrowserWindow::OnMessageReceived(const IPC::Message& message,
void BrowserWindow::OnCloseContents() { void BrowserWindow::OnCloseContents() {
if (!web_contents()) if (!web_contents())
return; return;
Observe(nullptr);
// Close all child windows before closing current window. // Close all child windows before closing current window.
v8::Locker locker(isolate()); v8::Locker locker(isolate());
@ -296,6 +295,9 @@ void BrowserWindow::OnCloseContents() {
// Do not sent "unresponsive" event after window is closed. // Do not sent "unresponsive" event after window is closed.
window_unresponsive_closure_.Cancel(); window_unresponsive_closure_.Cancel();
// Clear the web_contents() at last.
Observe(nullptr);
} }
void BrowserWindow::OnRendererResponsive() { void BrowserWindow::OnRendererResponsive() {
@ -360,10 +362,20 @@ void BrowserWindow::OnWindowEndSession() {
} }
void BrowserWindow::OnWindowBlur() { void BrowserWindow::OnWindowBlur() {
web_contents()->StoreFocus();
auto* rwhv = web_contents()->GetRenderWidgetHostView();
if (rwhv)
rwhv->SetActive(false);
Emit("blur"); Emit("blur");
} }
void BrowserWindow::OnWindowFocus() { void BrowserWindow::OnWindowFocus() {
web_contents()->RestoreFocus();
auto* rwhv = web_contents()->GetRenderWidgetHostView();
if (rwhv)
rwhv->SetActive(true);
Emit("focus"); Emit("focus");
} }

View file

@ -243,30 +243,10 @@ bool ScopedDisableResize::disable_resize_ = false;
} }
- (void)windowDidBecomeMain:(NSNotification*)notification { - (void)windowDidBecomeMain:(NSNotification*)notification {
content::WebContents* web_contents = shell_->web_contents();
if (!web_contents)
return;
web_contents->RestoreFocus();
content::RenderWidgetHostView* rwhv = web_contents->GetRenderWidgetHostView();
if (rwhv)
rwhv->SetActive(true);
shell_->NotifyWindowFocus(); shell_->NotifyWindowFocus();
} }
- (void)windowDidResignMain:(NSNotification*)notification { - (void)windowDidResignMain:(NSNotification*)notification {
content::WebContents* web_contents = shell_->web_contents();
if (!web_contents)
return;
web_contents->StoreFocus();
content::RenderWidgetHostView* rwhv = web_contents->GetRenderWidgetHostView();
if (rwhv)
rwhv->SetActive(false);
shell_->NotifyWindowBlur(); shell_->NotifyWindowBlur();
} }