Merge pull request #8676 from electron/focus-delegate
Prevent invisible windows from being activated
This commit is contained in:
commit
9a7ac5326c
6 changed files with 91 additions and 2 deletions
|
@ -48,6 +48,7 @@
|
|||
#include "ui/views/window/native_frame_view.h"
|
||||
#elif defined(OS_WIN)
|
||||
#include "atom/browser/ui/views/win_frame_view.h"
|
||||
#include "atom/browser/ui/win/atom_desktop_native_widget_aura.h"
|
||||
#include "atom/browser/ui/win/atom_desktop_window_tree_host_win.h"
|
||||
#include "skia/ext/skia_utils_win.h"
|
||||
#include "ui/base/win/shell.h"
|
||||
|
@ -204,8 +205,7 @@ NativeWindowViews::NativeWindowViews(
|
|||
if (parent)
|
||||
params.parent = parent->GetNativeWindow();
|
||||
|
||||
params.native_widget =
|
||||
new views::DesktopNativeWidgetAura(window_.get());
|
||||
params.native_widget = new AtomDesktopNativeWidgetAura(window_.get());
|
||||
atom_desktop_window_tree_host_win_ = new AtomDesktopWindowTreeHostWin(
|
||||
this,
|
||||
window_.get(),
|
||||
|
|
22
atom/browser/ui/win/atom_desktop_native_widget_aura.cc
Normal file
22
atom/browser/ui/win/atom_desktop_native_widget_aura.cc
Normal file
|
@ -0,0 +1,22 @@
|
|||
// Copyright (c) 2017 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "atom/browser/ui/win/atom_desktop_native_widget_aura.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
AtomDesktopNativeWidgetAura::AtomDesktopNativeWidgetAura(
|
||||
views::internal::NativeWidgetDelegate* delegate)
|
||||
: views::DesktopNativeWidgetAura(delegate) {
|
||||
}
|
||||
|
||||
void AtomDesktopNativeWidgetAura::Activate() {
|
||||
// Activate can cause the focused window to be blurred so only
|
||||
// call when the window being activated is visible. This prevents
|
||||
// hidden windows from blurring the focused window when created.
|
||||
if (IsVisible())
|
||||
views::DesktopNativeWidgetAura::Activate();
|
||||
}
|
||||
|
||||
} // namespace atom
|
27
atom/browser/ui/win/atom_desktop_native_widget_aura.h
Normal file
27
atom/browser/ui/win/atom_desktop_native_widget_aura.h
Normal file
|
@ -0,0 +1,27 @@
|
|||
// Copyright (c) 2017 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef ATOM_BROWSER_UI_WIN_ATOM_DESKTOP_NATIVE_WIDGET_AURA_H_
|
||||
#define ATOM_BROWSER_UI_WIN_ATOM_DESKTOP_NATIVE_WIDGET_AURA_H_
|
||||
|
||||
#include "atom/browser/native_window_views.h"
|
||||
#include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
class AtomDesktopNativeWidgetAura : public views::DesktopNativeWidgetAura {
|
||||
public:
|
||||
explicit AtomDesktopNativeWidgetAura(
|
||||
views::internal::NativeWidgetDelegate* delegate);
|
||||
|
||||
// internal::NativeWidgetPrivate:
|
||||
void Activate() override;
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(AtomDesktopNativeWidgetAura);
|
||||
};
|
||||
|
||||
} // namespace atom
|
||||
|
||||
#endif // ATOM_BROWSER_UI_WIN_ATOM_DESKTOP_NATIVE_WIDGET_AURA_H_
|
|
@ -317,6 +317,8 @@
|
|||
'atom/browser/ui/views/submenu_button.h',
|
||||
'atom/browser/ui/views/win_frame_view.cc',
|
||||
'atom/browser/ui/views/win_frame_view.h',
|
||||
'atom/browser/ui/win/atom_desktop_native_widget_aura.cc',
|
||||
'atom/browser/ui/win/atom_desktop_native_widget_aura.h',
|
||||
'atom/browser/ui/win/atom_desktop_window_tree_host_win.cc',
|
||||
'atom/browser/ui/win/atom_desktop_window_tree_host_win.h',
|
||||
'atom/browser/ui/win/jump_list.cc',
|
||||
|
|
|
@ -308,4 +308,18 @@ describe('webContents module', function () {
|
|||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('focus()', function () {
|
||||
describe('when the web contents is hidden', function () {
|
||||
it('does not blur the focused window', function (done) {
|
||||
ipcMain.once('answer', (event, parentFocused, childFocused) => {
|
||||
assert.equal(parentFocused, true)
|
||||
assert.equal(childFocused, false)
|
||||
done()
|
||||
})
|
||||
w.show()
|
||||
w.loadURL('file://' + path.join(__dirname, 'fixtures', 'pages', 'focus-web-contents.html'))
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
24
spec/fixtures/pages/focus-web-contents.html
vendored
Normal file
24
spec/fixtures/pages/focus-web-contents.html
vendored
Normal file
|
@ -0,0 +1,24 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title></title>
|
||||
<script>
|
||||
const {ipcRenderer, remote} = require('electron')
|
||||
|
||||
remote.getCurrentWindow().focus()
|
||||
|
||||
const child = new remote.BrowserWindow({show: false})
|
||||
child.loadURL('about:blank')
|
||||
child.webContents.focus()
|
||||
|
||||
const currentFocused = remote.getCurrentWindow().isFocused()
|
||||
const childFocused = child.isFocused()
|
||||
child.close()
|
||||
ipcRenderer.send('answer', currentFocused, childFocused)
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in a new issue