Browse Source

Focus window on menu bar click

Kevin Sawicki 8 years ago
parent
commit
98387e50cc

+ 1 - 1
atom/browser/native_window_views.cc

@@ -846,7 +846,7 @@ void NativeWindowViews::SetMenu(AtomMenuModel* menu_model) {
 
   if (!menu_bar_) {
     gfx::Size content_size = GetContentSize();
-    menu_bar_.reset(new MenuBar);
+    menu_bar_.reset(new MenuBar(this));
     menu_bar_->set_owned_by_client();
 
     if (!menu_bar_autohide_) {

+ 6 - 2
atom/browser/ui/views/menu_bar.cc

@@ -47,9 +47,10 @@ void GetMenuBarColor(SkColor* enabled, SkColor* disabled, SkColor* highlight,
 
 }  // namespace
 
-MenuBar::MenuBar()
+MenuBar::MenuBar(NativeWindow* window)
     : background_color_(kDefaultColor),
-      menu_model_(NULL) {
+      menu_model_(NULL),
+      window_(window) {
   UpdateMenuBarColor();
   SetLayoutManager(new views::BoxLayout(
       views::BoxLayout::kHorizontal, 0, 0, 0));
@@ -142,6 +143,9 @@ void MenuBar::OnMenuButtonClicked(views::MenuButton* source,
   if (!menu_model_)
     return;
 
+  if (!window_->IsFocused())
+    window_->Focus(true);
+
   int id = source->tag();
   AtomMenuModel::ItemType type = menu_model_->GetTypeAt(id);
   if (type != AtomMenuModel::TYPE_SUBMENU) {

+ 3 - 1
atom/browser/ui/views/menu_bar.h

@@ -5,6 +5,7 @@
 #ifndef ATOM_BROWSER_UI_VIEWS_MENU_BAR_H_
 #define ATOM_BROWSER_UI_VIEWS_MENU_BAR_H_
 
+#include "atom/browser/native_window.h"
 #include "atom/browser/ui/atom_menu_model.h"
 #include "ui/views/controls/button/menu_button_listener.h"
 #include "ui/views/view.h"
@@ -20,7 +21,7 @@ class MenuDelegate;
 class MenuBar : public views::View,
                 public views::MenuButtonListener {
  public:
-  MenuBar();
+  explicit MenuBar(NativeWindow* window);
   virtual ~MenuBar();
 
   // Replaces current menu with a new one.
@@ -66,6 +67,7 @@ class MenuBar : public views::View,
   SkColor hover_color_;
 #endif
 
+  NativeWindow* window_;
   AtomMenuModel* menu_model_;
 
   DISALLOW_COPY_AND_ASSIGN(MenuBar);

+ 0 - 4
atom/browser/ui/views/submenu_button.cc

@@ -52,10 +52,6 @@ SubmenuButton::SubmenuButton(const base::string16& title,
   SetHasInkDrop(true);
   set_ink_drop_base_color(
       color_utils::BlendTowardOppositeLuma(background_color_, 0x61));
-
-  set_request_focus_on_press(true);
-  SetFocusForPlatform();
-  SetFocusPainter(nullptr);
 }
 
 SubmenuButton::~SubmenuButton() {