Simplify views/menu_bar focus management (#12536)
* Simplify views/menu_bar focus management * Make the linter happy * Remove NativeWindowView focus manager listener API * remove unnecessary change * MenuBar ctor now takes a views::View
This commit is contained in:
parent
cad8eed6e4
commit
f8b8dc1494
2 changed files with 8 additions and 24 deletions
|
@ -25,26 +25,16 @@ const SkColor kDefaultColor = SkColorSetARGB(255, 233, 233, 233);
|
|||
|
||||
} // namespace
|
||||
|
||||
MenuBar::MenuBar(NativeWindow* window)
|
||||
MenuBar::MenuBar(views::View* window)
|
||||
: background_color_(kDefaultColor), menu_model_(NULL), window_(window) {
|
||||
RefreshColorCache();
|
||||
UpdateViewColors();
|
||||
SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal));
|
||||
window_->GetFocusManager()->AddFocusChangeListener(this);
|
||||
}
|
||||
|
||||
MenuBar::~MenuBar() {}
|
||||
|
||||
void MenuBar::AddedToWidget() {
|
||||
auto fm = GetFocusManager();
|
||||
fm->AddFocusChangeListener(this);
|
||||
// Note that we don't own fm -- this manages the _connection_
|
||||
focus_manager_.reset(fm, [this](views::FocusManager* fm) {
|
||||
fm->RemoveFocusChangeListener(this);
|
||||
});
|
||||
}
|
||||
|
||||
void MenuBar::RemovedFromWidget() {
|
||||
focus_manager_.reset();
|
||||
MenuBar::~MenuBar() {
|
||||
window_->GetFocusManager()->RemoveFocusChangeListener(this);
|
||||
}
|
||||
|
||||
void MenuBar::SetMenu(AtomMenuModel* model) {
|
||||
|
@ -111,8 +101,8 @@ void MenuBar::OnMenuButtonClicked(views::MenuButton* source,
|
|||
if (!menu_model_)
|
||||
return;
|
||||
|
||||
if (!window_->IsFocused())
|
||||
window_->Focus(true);
|
||||
if (!window_->HasFocus())
|
||||
window_->RequestFocus();
|
||||
|
||||
int id = source->tag();
|
||||
AtomMenuModel::ItemType type = menu_model_->GetTypeAt(id);
|
||||
|
|
|
@ -5,9 +5,6 @@
|
|||
#ifndef ATOM_BROWSER_UI_VIEWS_MENU_BAR_H_
|
||||
#define ATOM_BROWSER_UI_VIEWS_MENU_BAR_H_
|
||||
|
||||
#include <memory>
|
||||
|
||||
#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/focus/focus_manager.h"
|
||||
|
@ -25,7 +22,7 @@ class MenuBar : public views::View,
|
|||
public views::MenuButtonListener,
|
||||
public views::FocusChangeListener {
|
||||
public:
|
||||
explicit MenuBar(NativeWindow* window);
|
||||
explicit MenuBar(views::View* window);
|
||||
virtual ~MenuBar();
|
||||
|
||||
// Replaces current menu with a new one.
|
||||
|
@ -50,9 +47,7 @@ class MenuBar : public views::View,
|
|||
|
||||
protected:
|
||||
// views::View:
|
||||
void AddedToWidget() override;
|
||||
const char* GetClassName() const override;
|
||||
void RemovedFromWidget() override;
|
||||
|
||||
// views::MenuButtonListener:
|
||||
void OnMenuButtonClicked(views::MenuButton* source,
|
||||
|
@ -75,12 +70,11 @@ class MenuBar : public views::View,
|
|||
SkColor disabled_color_;
|
||||
#endif
|
||||
|
||||
NativeWindow* window_;
|
||||
views::View* window_;
|
||||
AtomMenuModel* menu_model_;
|
||||
|
||||
View* FindAccelChild(base::char16 key);
|
||||
|
||||
std::shared_ptr<views::FocusManager> focus_manager_;
|
||||
bool has_focus_ = true;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(MenuBar);
|
||||
|
|
Loading…
Reference in a new issue