diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index 771caf583dec..a883a66cbb64 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" @@ -148,7 +149,8 @@ NativeWindowViews::NativeWindowViews( resizable_(true), maximizable_(true), minimizable_(true), - fullscreenable_(true) { + fullscreenable_(true), + focusable_(true) { options.Get(options::kTitle, &title_); options.Get(options::kAutoHideMenuBar, &menu_bar_autohide_); @@ -196,16 +198,14 @@ NativeWindowViews::NativeWindowViews( if (transparent() && !has_frame()) params.shadow_type = views::Widget::InitParams::SHADOW_TYPE_NONE; - bool focusable; - if (options.Get(options::kFocusable, &focusable) && !focusable) + if (options.Get(options::kFocusable, &focusable_) && !focusable_) params.activatable = views::Widget::InitParams::ACTIVATABLE_NO; #if defined(OS_WIN) if (parent) params.parent = parent->GetNativeWindow(); - params.native_widget = - new views::DesktopNativeWidgetAura(window_.get()); + params.native_widget = new AtomDeskopNativeWidgetAura(window_.get(), this); atom_desktop_window_tree_host_win_ = new AtomDesktopWindowTreeHostWin( this, window_.get(), @@ -806,6 +806,7 @@ void NativeWindowViews::SetContentProtection(bool enable) { } void NativeWindowViews::SetFocusable(bool focusable) { + focusable_ = focusable; #if defined(OS_WIN) LONG ex_style = ::GetWindowLong(GetAcceleratedWidget(), GWL_EXSTYLE); if (focusable) diff --git a/atom/browser/native_window_views.h b/atom/browser/native_window_views.h index a7f02fb2727d..032c78f1d18d 100644 --- a/atom/browser/native_window_views.h +++ b/atom/browser/native_window_views.h @@ -130,6 +130,7 @@ class NativeWindowViews : public NativeWindow, #if defined(OS_WIN) TaskbarHost& taskbar_host() { return taskbar_host_; } + bool CanFocus(); #endif private: @@ -262,6 +263,7 @@ class NativeWindowViews : public NativeWindow, bool maximizable_; bool minimizable_; bool fullscreenable_; + bool focusable_; std::string title_; gfx::Size widget_size_; diff --git a/atom/browser/native_window_views_win.cc b/atom/browser/native_window_views_win.cc index 1b523e90b804..ea6fc8004a97 100644 --- a/atom/browser/native_window_views_win.cc +++ b/atom/browser/native_window_views_win.cc @@ -202,4 +202,8 @@ void NativeWindowViews::HandleSizeEvent(WPARAM w_param, LPARAM l_param) { } } +bool NativeWindowViews::CanFocus() { + return focusable_ && IsVisible(); +} + } // namespace atom 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 000000000000..812e2636bf5b --- /dev/null +++ b/atom/browser/ui/win/atom_desktop_native_widget_aura.cc @@ -0,0 +1,20 @@ +// 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 { + +AtomDeskopNativeWidgetAura::AtomDeskopNativeWidgetAura( + views::internal::NativeWidgetDelegate* delegate, + NativeWindowViews* window) + : views::DesktopNativeWidgetAura(delegate), + window_(window) { +} + +bool AtomDeskopNativeWidgetAura::CanFocus() { + return window_->CanFocus(); +} + +} // 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 000000000000..7048a47c19c7 --- /dev/null +++ b/atom/browser/ui/win/atom_desktop_native_widget_aura.h @@ -0,0 +1,29 @@ +// 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 AtomDeskopNativeWidgetAura : public views::DesktopNativeWidgetAura { + public: + AtomDeskopNativeWidgetAura(views::internal::NativeWidgetDelegate* delegate, + NativeWindowViews* window); + + // aura::WindowDelegate + bool CanFocus() override; + + private: + NativeWindowViews* window_; + + DISALLOW_COPY_AND_ASSIGN(AtomDeskopNativeWidgetAura); +}; + +} // namespace atom + +#endif // ATOM_BROWSER_UI_WIN_ATOM_DESKTOP_NATIVE_WIDGET_AURA_H_ diff --git a/filenames.gypi b/filenames.gypi index d3dc7ed22cef..00297becef28 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',