Merge pull request #6944 from electron/check-window-from-native-view
Access native window through native view
This commit is contained in:
commit
7bdce52290
3 changed files with 28 additions and 10 deletions
|
@ -1004,7 +1004,8 @@ void WebContents::InspectElement(int x, int y) {
|
|||
if (type_ == REMOTE)
|
||||
return;
|
||||
|
||||
OpenDevTools(nullptr);
|
||||
if (!managed_web_contents()->GetDevToolsWebContents())
|
||||
OpenDevTools(nullptr);
|
||||
scoped_refptr<content::DevToolsAgentHost> agent(
|
||||
content::DevToolsAgentHost::GetOrCreateFor(web_contents()));
|
||||
agent->InspectElement(x, y);
|
||||
|
@ -1175,7 +1176,7 @@ bool WebContents::IsFocused() const {
|
|||
if (!view) return false;
|
||||
|
||||
if (GetType() != BACKGROUND_PAGE) {
|
||||
auto window = web_contents()->GetTopLevelNativeWindow();
|
||||
auto window = web_contents()->GetNativeView()->GetToplevelWindow();
|
||||
if (window && !window->IsVisible())
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -4,9 +4,7 @@
|
|||
|
||||
#include "atom/browser/api/atom_api_web_contents.h"
|
||||
|
||||
@interface NSWindow
|
||||
- (BOOL)isKeyWindow;
|
||||
@end
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
namespace atom {
|
||||
|
||||
|
@ -17,7 +15,7 @@ bool WebContents::IsFocused() const {
|
|||
if (!view) return false;
|
||||
|
||||
if (GetType() != BACKGROUND_PAGE) {
|
||||
auto window = web_contents()->GetTopLevelNativeWindow();
|
||||
auto window = [web_contents()->GetNativeView() window];
|
||||
// On Mac the render widget host view does not lose focus when the window
|
||||
// loses focus so check if the top level window is the key window.
|
||||
if (window && ![window isKeyWindow])
|
||||
|
|
|
@ -49,11 +49,9 @@ describe('webContents module', function () {
|
|||
})
|
||||
|
||||
describe('getFocusedWebContents() API', function () {
|
||||
if (isCi) {
|
||||
return
|
||||
}
|
||||
|
||||
it('returns the focused web contents', function (done) {
|
||||
if (isCi) return done()
|
||||
|
||||
const specWebContents = remote.getCurrentWebContents()
|
||||
assert.equal(specWebContents.getId(), webContents.getFocusedWebContents().getId())
|
||||
|
||||
|
@ -69,6 +67,27 @@ describe('webContents module', function () {
|
|||
|
||||
specWebContents.openDevTools()
|
||||
})
|
||||
|
||||
it('does not crash when called on a detached dev tools window', function (done) {
|
||||
const specWebContents = w.webContents
|
||||
|
||||
specWebContents.once('devtools-opened', function () {
|
||||
assert.doesNotThrow(function () {
|
||||
webContents.getFocusedWebContents()
|
||||
})
|
||||
specWebContents.closeDevTools()
|
||||
})
|
||||
|
||||
specWebContents.once('devtools-closed', function () {
|
||||
assert.doesNotThrow(function () {
|
||||
webContents.getFocusedWebContents()
|
||||
})
|
||||
done()
|
||||
})
|
||||
|
||||
specWebContents.openDevTools({mode: 'detach'})
|
||||
w.inspectElement(100, 100)
|
||||
})
|
||||
})
|
||||
|
||||
describe('isFocused() API', function () {
|
||||
|
|
Loading…
Add table
Reference in a new issue