Merge pull request #142 from atom/devtools-focus
Add IsDevToolsViewFocused method and make DevToolsFocused work in OS X
This commit is contained in:
commit
43c4efb4c7
8 changed files with 83 additions and 0 deletions
|
@ -608,8 +608,10 @@ void InspectableWebContentsImpl::CloseContents(content::WebContents* source) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void InspectableWebContentsImpl::OnWebContentsFocused() {
|
void InspectableWebContentsImpl::OnWebContentsFocused() {
|
||||||
|
#if defined(TOOLKIT_VIEWS)
|
||||||
if (view_->GetDelegate())
|
if (view_->GetDelegate())
|
||||||
view_->GetDelegate()->DevToolsFocused();
|
view_->GetDelegate()->DevToolsFocused();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void InspectableWebContentsImpl::OnURLFetchComplete(const net::URLFetcher* source) {
|
void InspectableWebContentsImpl::OnURLFetchComplete(const net::URLFetcher* source) {
|
||||||
|
|
|
@ -44,6 +44,7 @@ class InspectableWebContentsView {
|
||||||
// Hide the DevTools view.
|
// Hide the DevTools view.
|
||||||
virtual void CloseDevTools() = 0;
|
virtual void CloseDevTools() = 0;
|
||||||
virtual bool IsDevToolsViewShowing() = 0;
|
virtual bool IsDevToolsViewShowing() = 0;
|
||||||
|
virtual bool IsDevToolsViewFocused() = 0;
|
||||||
virtual void SetIsDocked(bool docked) = 0;
|
virtual void SetIsDocked(bool docked) = 0;
|
||||||
virtual void SetContentsResizingStrategy(
|
virtual void SetContentsResizingStrategy(
|
||||||
const DevToolsContentsResizingStrategy& strategy) = 0;
|
const DevToolsContentsResizingStrategy& strategy) = 0;
|
||||||
|
|
|
@ -21,6 +21,7 @@ class InspectableWebContentsViewMac : public InspectableWebContentsView {
|
||||||
void ShowDevTools() override;
|
void ShowDevTools() override;
|
||||||
void CloseDevTools() override;
|
void CloseDevTools() override;
|
||||||
bool IsDevToolsViewShowing() override;
|
bool IsDevToolsViewShowing() override;
|
||||||
|
bool IsDevToolsViewFocused() override;
|
||||||
void SetIsDocked(bool docked) override;
|
void SetIsDocked(bool docked) override;
|
||||||
void SetContentsResizingStrategy(
|
void SetContentsResizingStrategy(
|
||||||
const DevToolsContentsResizingStrategy& strategy) override;
|
const DevToolsContentsResizingStrategy& strategy) override;
|
||||||
|
|
|
@ -42,6 +42,10 @@ bool InspectableWebContentsViewMac::IsDevToolsViewShowing() {
|
||||||
return [view_ isDevToolsVisible];
|
return [view_ isDevToolsVisible];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool InspectableWebContentsViewMac::IsDevToolsViewFocused() {
|
||||||
|
return [view_ isDevToolsFocused];
|
||||||
|
}
|
||||||
|
|
||||||
void InspectableWebContentsViewMac::SetIsDocked(bool docked) {
|
void InspectableWebContentsViewMac::SetIsDocked(bool docked) {
|
||||||
[view_ setIsDocked:docked];
|
[view_ setIsDocked:docked];
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,13 +18,16 @@ using brightray::InspectableWebContentsViewMac;
|
||||||
base::scoped_nsobject<NSWindow> devtools_window_;
|
base::scoped_nsobject<NSWindow> devtools_window_;
|
||||||
BOOL devtools_visible_;
|
BOOL devtools_visible_;
|
||||||
BOOL devtools_docked_;
|
BOOL devtools_docked_;
|
||||||
|
BOOL devtools_is_first_responder_;
|
||||||
|
|
||||||
DevToolsContentsResizingStrategy strategy_;
|
DevToolsContentsResizingStrategy strategy_;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (instancetype)initWithInspectableWebContentsViewMac:(InspectableWebContentsViewMac*)view;
|
- (instancetype)initWithInspectableWebContentsViewMac:(InspectableWebContentsViewMac*)view;
|
||||||
|
- (void)notifyDevToolsFocused;
|
||||||
- (void)setDevToolsVisible:(BOOL)visible;
|
- (void)setDevToolsVisible:(BOOL)visible;
|
||||||
- (BOOL)isDevToolsVisible;
|
- (BOOL)isDevToolsVisible;
|
||||||
|
- (BOOL)isDevToolsFocused;
|
||||||
- (void)setIsDocked:(BOOL)docked;
|
- (void)setIsDocked:(BOOL)docked;
|
||||||
- (void)setContentsResizingStrategy:(const DevToolsContentsResizingStrategy&)strategy;
|
- (void)setContentsResizingStrategy:(const DevToolsContentsResizingStrategy&)strategy;
|
||||||
- (void)setTitle:(NSString*)title;
|
- (void)setTitle:(NSString*)title;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include "browser/mac/bry_inspectable_web_contents_view.h"
|
#include "browser/mac/bry_inspectable_web_contents_view.h"
|
||||||
|
|
||||||
#include "browser/inspectable_web_contents_impl.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 "browser/inspectable_web_contents_view_mac.h"
|
||||||
|
|
||||||
#include "content/public/browser/render_widget_host_view.h"
|
#include "content/public/browser/render_widget_host_view.h"
|
||||||
|
@ -19,6 +20,19 @@ using namespace brightray;
|
||||||
inspectableWebContentsView_ = view;
|
inspectableWebContentsView_ = view;
|
||||||
devtools_visible_ = NO;
|
devtools_visible_ = NO;
|
||||||
devtools_docked_ = NO;
|
devtools_docked_ = NO;
|
||||||
|
devtools_is_first_responder_ = NO;
|
||||||
|
|
||||||
|
[[NSNotificationCenter defaultCenter]
|
||||||
|
addObserver:self
|
||||||
|
selector:@selector(viewDidBecomeFirstResponder:)
|
||||||
|
name:kViewDidBecomeFirstResponder
|
||||||
|
object:nil];
|
||||||
|
|
||||||
|
[[NSNotificationCenter defaultCenter]
|
||||||
|
addObserver:self
|
||||||
|
selector:@selector(parentWindowBecameMain:)
|
||||||
|
name:NSWindowDidBecomeMainNotification
|
||||||
|
object:nil];
|
||||||
|
|
||||||
auto contents = inspectableWebContentsView_->inspectable_web_contents()->GetWebContents();
|
auto contents = inspectableWebContentsView_->inspectable_web_contents()->GetWebContents();
|
||||||
auto contentsView = contents->GetNativeView();
|
auto contentsView = contents->GetNativeView();
|
||||||
|
@ -31,6 +45,11 @@ using namespace brightray;
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)dealloc {
|
||||||
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||||
|
[super dealloc];
|
||||||
|
}
|
||||||
|
|
||||||
- (void)resizeSubviewsWithOldSize:(NSSize)oldBoundsSize {
|
- (void)resizeSubviewsWithOldSize:(NSSize)oldBoundsSize {
|
||||||
[self adjustSubviews];
|
[self adjustSubviews];
|
||||||
}
|
}
|
||||||
|
@ -39,6 +58,11 @@ using namespace brightray;
|
||||||
inspectableWebContentsView_->inspectable_web_contents()->ShowDevTools();
|
inspectableWebContentsView_->inspectable_web_contents()->ShowDevTools();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)notifyDevToolsFocused {
|
||||||
|
if (inspectableWebContentsView_->GetDelegate())
|
||||||
|
inspectableWebContentsView_->GetDelegate()->DevToolsFocused();
|
||||||
|
}
|
||||||
|
|
||||||
- (void)setDevToolsVisible:(BOOL)visible {
|
- (void)setDevToolsVisible:(BOOL)visible {
|
||||||
if (visible == devtools_visible_)
|
if (visible == devtools_visible_)
|
||||||
return;
|
return;
|
||||||
|
@ -86,6 +110,14 @@ using namespace brightray;
|
||||||
return devtools_visible_;
|
return devtools_visible_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (BOOL)isDevToolsFocused {
|
||||||
|
if (devtools_docked_) {
|
||||||
|
return [[self window] isKeyWindow] && devtools_is_first_responder_;
|
||||||
|
} else {
|
||||||
|
return [devtools_window_ isKeyWindow];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
- (void)setIsDocked:(BOOL)docked {
|
- (void)setIsDocked:(BOOL)docked {
|
||||||
// Revert to no-devtools state.
|
// Revert to no-devtools state.
|
||||||
[self setDevToolsVisible:NO];
|
[self setDevToolsVisible:NO];
|
||||||
|
@ -156,6 +188,36 @@ using namespace brightray;
|
||||||
[devtools_window_ setTitle:title];
|
[devtools_window_ setTitle:title];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)viewDidBecomeFirstResponder:(NSNotification*)notification {
|
||||||
|
auto inspectable_web_contents = inspectableWebContentsView_->inspectable_web_contents();
|
||||||
|
if (!inspectable_web_contents)
|
||||||
|
return;
|
||||||
|
auto webContents = inspectable_web_contents->GetWebContents();
|
||||||
|
auto webContentsView = webContents->GetNativeView();
|
||||||
|
|
||||||
|
NSView* view = [notification object];
|
||||||
|
if ([[webContentsView subviews] containsObject:view]) {
|
||||||
|
devtools_is_first_responder_ = NO;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto devToolsWebContents = inspectable_web_contents->GetDevToolsWebContents();
|
||||||
|
if (!devToolsWebContents)
|
||||||
|
return;
|
||||||
|
auto devToolsView = devToolsWebContents->GetNativeView();
|
||||||
|
|
||||||
|
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
|
#pragma mark - NSWindowDelegate
|
||||||
|
|
||||||
- (void)windowWillClose:(NSNotification*)notification {
|
- (void)windowWillClose:(NSNotification*)notification {
|
||||||
|
@ -173,6 +235,8 @@ using namespace brightray;
|
||||||
content::RenderWidgetHostView* rwhv = web_contents->GetRenderWidgetHostView();
|
content::RenderWidgetHostView* rwhv = web_contents->GetRenderWidgetHostView();
|
||||||
if (rwhv)
|
if (rwhv)
|
||||||
rwhv->SetActive(true);
|
rwhv->SetActive(true);
|
||||||
|
|
||||||
|
[self notifyDevToolsFocused];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)windowDidResignMain:(NSNotification*)notification {
|
- (void)windowDidResignMain:(NSNotification*)notification {
|
||||||
|
|
|
@ -145,6 +145,13 @@ bool InspectableWebContentsViewViews::IsDevToolsViewShowing() {
|
||||||
return devtools_visible_;
|
return devtools_visible_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool InspectableWebContentsViewViews::IsDevToolsViewFocused() {
|
||||||
|
if (devtools_web_view_)
|
||||||
|
return devtools_web_view_->HasFocus();
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void InspectableWebContentsViewViews::SetIsDocked(bool docked) {
|
void InspectableWebContentsViewViews::SetIsDocked(bool docked) {
|
||||||
CloseDevTools();
|
CloseDevTools();
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,7 @@ class InspectableWebContentsViewViews : public InspectableWebContentsView,
|
||||||
void ShowDevTools() override;
|
void ShowDevTools() override;
|
||||||
void CloseDevTools() override;
|
void CloseDevTools() override;
|
||||||
bool IsDevToolsViewShowing() override;
|
bool IsDevToolsViewShowing() override;
|
||||||
|
bool IsDevToolsViewFocused() override;
|
||||||
void SetIsDocked(bool docked) override;
|
void SetIsDocked(bool docked) override;
|
||||||
void SetContentsResizingStrategy(
|
void SetContentsResizingStrategy(
|
||||||
const DevToolsContentsResizingStrategy& strategy) override;
|
const DevToolsContentsResizingStrategy& strategy) override;
|
||||||
|
|
Loading…
Reference in a new issue