From 352f758cd1ceeddb50298930a378b3092a154bc8 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 15 Sep 2015 11:24:35 +0800 Subject: [PATCH] Make DevToolsFocused in OS X --- .../browser/inspectable_web_contents_impl.cc | 2 ++ .../mac/bry_inspectable_web_contents_view.h | 1 + .../mac/bry_inspectable_web_contents_view.mm | 26 +++++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index c7d93a7aca..f6532e4ed0 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -608,8 +608,10 @@ void InspectableWebContentsImpl::CloseContents(content::WebContents* source) { } void InspectableWebContentsImpl::OnWebContentsFocused() { +#if defined(TOOLKIT_VIEWS) if (view_->GetDelegate()) view_->GetDelegate()->DevToolsFocused(); +#endif } void InspectableWebContentsImpl::OnURLFetchComplete(const net::URLFetcher* source) { diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.h b/brightray/browser/mac/bry_inspectable_web_contents_view.h index 7d8556973a..b67baa6385 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.h +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.h @@ -24,6 +24,7 @@ using brightray::InspectableWebContentsViewMac; } - (instancetype)initWithInspectableWebContentsViewMac:(InspectableWebContentsViewMac*)view; +- (void)notifyDevToolsFocused; - (void)setDevToolsVisible:(BOOL)visible; - (BOOL)isDevToolsVisible; - (BOOL)isDevToolsFocused; diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.mm b/brightray/browser/mac/bry_inspectable_web_contents_view.mm index dd40f1e259..1123f7e0cd 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.mm +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.mm @@ -1,6 +1,7 @@ #include "browser/mac/bry_inspectable_web_contents_view.h" #include "browser/inspectable_web_contents_impl.h" +#include "browser/inspectable_web_contents_view_delegate.h" #include "browser/inspectable_web_contents_view_mac.h" #include "content/public/browser/render_widget_host_view.h" @@ -27,6 +28,12 @@ using namespace brightray; name:kViewDidBecomeFirstResponder object:nil]; + [[NSNotificationCenter defaultCenter] + addObserver:self + selector:@selector(parentWindowBecameMain:) + name:NSWindowDidBecomeMainNotification + object:nil]; + auto contents = inspectableWebContentsView_->inspectable_web_contents()->GetWebContents(); auto contentsView = contents->GetNativeView(); [contentsView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; @@ -38,6 +45,11 @@ using namespace brightray; return self; } +- (void)dealloc { + [[NSNotificationCenter defaultCenter] removeObserver:self]; + [super dealloc]; +} + - (void)resizeSubviewsWithOldSize:(NSSize)oldBoundsSize { [self adjustSubviews]; } @@ -46,6 +58,11 @@ using namespace brightray; inspectableWebContentsView_->inspectable_web_contents()->ShowDevTools(); } +- (void)notifyDevToolsFocused { + if (inspectableWebContentsView_->GetDelegate()) + inspectableWebContentsView_->GetDelegate()->DevToolsFocused(); +} + - (void)setDevToolsVisible:(BOOL)visible { if (visible == devtools_visible_) return; @@ -191,9 +208,16 @@ using namespace brightray; if ([[devToolsView subviews] containsObject:view]) { devtools_is_first_responder_ = YES; + [self notifyDevToolsFocused]; } } +- (void)parentWindowBecameMain:(NSNotification*)notification { + NSWindow* parentWindow = [notification object]; + if ([self window] == parentWindow && devtools_docked_ && devtools_is_first_responder_) + [self notifyDevToolsFocused]; +} + #pragma mark - NSWindowDelegate - (void)windowWillClose:(NSNotification*)notification { @@ -211,6 +235,8 @@ using namespace brightray; content::RenderWidgetHostView* rwhv = web_contents->GetRenderWidgetHostView(); if (rwhv) rwhv->SetActive(true); + + [self notifyDevToolsFocused]; } - (void)windowDidResignMain:(NSNotification*)notification {