Add IsDevToolsViewFocused method
This commit is contained in:
parent
9d7fbdfd8e
commit
c30f458d4f
7 changed files with 54 additions and 0 deletions
|
@ -44,6 +44,7 @@ class InspectableWebContentsView {
|
|||
// Hide the DevTools view.
|
||||
virtual void CloseDevTools() = 0;
|
||||
virtual bool IsDevToolsViewShowing() = 0;
|
||||
virtual bool IsDevToolsViewFocused() = 0;
|
||||
virtual void SetIsDocked(bool docked) = 0;
|
||||
virtual void SetContentsResizingStrategy(
|
||||
const DevToolsContentsResizingStrategy& strategy) = 0;
|
||||
|
|
|
@ -21,6 +21,7 @@ class InspectableWebContentsViewMac : public InspectableWebContentsView {
|
|||
void ShowDevTools() override;
|
||||
void CloseDevTools() override;
|
||||
bool IsDevToolsViewShowing() override;
|
||||
bool IsDevToolsViewFocused() override;
|
||||
void SetIsDocked(bool docked) override;
|
||||
void SetContentsResizingStrategy(
|
||||
const DevToolsContentsResizingStrategy& strategy) override;
|
||||
|
|
|
@ -42,6 +42,10 @@ bool InspectableWebContentsViewMac::IsDevToolsViewShowing() {
|
|||
return [view_ isDevToolsVisible];
|
||||
}
|
||||
|
||||
bool InspectableWebContentsViewMac::IsDevToolsViewFocused() {
|
||||
return [view_ isDevToolsFocused];
|
||||
}
|
||||
|
||||
void InspectableWebContentsViewMac::SetIsDocked(bool docked) {
|
||||
[view_ setIsDocked:docked];
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ using brightray::InspectableWebContentsViewMac;
|
|||
base::scoped_nsobject<NSWindow> devtools_window_;
|
||||
BOOL devtools_visible_;
|
||||
BOOL devtools_docked_;
|
||||
BOOL devtools_is_first_responder_;
|
||||
|
||||
DevToolsContentsResizingStrategy strategy_;
|
||||
}
|
||||
|
@ -25,6 +26,7 @@ using brightray::InspectableWebContentsViewMac;
|
|||
- (instancetype)initWithInspectableWebContentsViewMac:(InspectableWebContentsViewMac*)view;
|
||||
- (void)setDevToolsVisible:(BOOL)visible;
|
||||
- (BOOL)isDevToolsVisible;
|
||||
- (BOOL)isDevToolsFocused;
|
||||
- (void)setIsDocked:(BOOL)docked;
|
||||
- (void)setContentsResizingStrategy:(const DevToolsContentsResizingStrategy&)strategy;
|
||||
- (void)setTitle:(NSString*)title;
|
||||
|
|
|
@ -19,6 +19,13 @@ using namespace brightray;
|
|||
inspectableWebContentsView_ = view;
|
||||
devtools_visible_ = NO;
|
||||
devtools_docked_ = NO;
|
||||
devtools_is_first_responder_ = NO;
|
||||
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
addObserver:self
|
||||
selector:@selector(viewDidBecomeFirstResponder:)
|
||||
name:kViewDidBecomeFirstResponder
|
||||
object:nil];
|
||||
|
||||
auto contents = inspectableWebContentsView_->inspectable_web_contents()->GetWebContents();
|
||||
auto contentsView = contents->GetNativeView();
|
||||
|
@ -86,6 +93,14 @@ using namespace brightray;
|
|||
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 {
|
||||
// Revert to no-devtools state.
|
||||
[self setDevToolsVisible:NO];
|
||||
|
@ -156,6 +171,29 @@ using namespace brightray;
|
|||
[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;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - NSWindowDelegate
|
||||
|
||||
- (void)windowWillClose:(NSNotification*)notification {
|
||||
|
|
|
@ -145,6 +145,13 @@ bool InspectableWebContentsViewViews::IsDevToolsViewShowing() {
|
|||
return devtools_visible_;
|
||||
}
|
||||
|
||||
bool InspectableWebContentsViewViews::IsDevToolsViewFocused() {
|
||||
if (devtools_web_view_)
|
||||
return devtools_web_view_->HasFocus();
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
void InspectableWebContentsViewViews::SetIsDocked(bool docked) {
|
||||
CloseDevTools();
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@ class InspectableWebContentsViewViews : public InspectableWebContentsView,
|
|||
void ShowDevTools() override;
|
||||
void CloseDevTools() override;
|
||||
bool IsDevToolsViewShowing() override;
|
||||
bool IsDevToolsViewFocused() override;
|
||||
void SetIsDocked(bool docked) override;
|
||||
void SetContentsResizingStrategy(
|
||||
const DevToolsContentsResizingStrategy& strategy) override;
|
||||
|
|
Loading…
Reference in a new issue