diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index 771caf583d..b0722cbc4a 100644 --- a/atom/browser/native_window_views.cc +++ b/atom/browser/native_window_views.cc @@ -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(), diff --git a/atom/browser/ui/win/atom_desktop_native_widget_aura.cc b/atom/browser/ui/win/atom_desktop_native_widget_aura.cc new file mode 100644 index 0000000000..e0cd68608a --- /dev/null +++ b/atom/browser/ui/win/atom_desktop_native_widget_aura.cc @@ -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 diff --git a/atom/browser/ui/win/atom_desktop_native_widget_aura.h b/atom/browser/ui/win/atom_desktop_native_widget_aura.h new file mode 100644 index 0000000000..b5a6c0933d --- /dev/null +++ b/atom/browser/ui/win/atom_desktop_native_widget_aura.h @@ -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_ diff --git a/filenames.gypi b/filenames.gypi index d3dc7ed22c..00297becef 100644 --- a/filenames.gypi +++ b/filenames.gypi @@ -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', diff --git a/spec/api-web-contents-spec.js b/spec/api-web-contents-spec.js index f80e04ac7c..0faaafbcda 100644 --- a/spec/api-web-contents-spec.js +++ b/spec/api-web-contents-spec.js @@ -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')) + }) + }) + }) }) diff --git a/spec/fixtures/pages/focus-web-contents.html b/spec/fixtures/pages/focus-web-contents.html new file mode 100644 index 0000000000..83675bc1d3 --- /dev/null +++ b/spec/fixtures/pages/focus-web-contents.html @@ -0,0 +1,24 @@ + + +
+ +