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:
Charles Kerr 2018-04-05 21:53:08 -05:00 committed by GitHub
parent cad8eed6e4
commit f8b8dc1494
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 24 deletions

View file

@ -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);