electron/atom/browser/ui/views/menu_delegate.h

80 lines
2.4 KiB
C
Raw Normal View History

// Copyright (c) 2014 GitHub, Inc.
2014-07-17 06:23:28 +00:00
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef ATOM_BROWSER_UI_VIEWS_MENU_DELEGATE_H_
#define ATOM_BROWSER_UI_VIEWS_MENU_DELEGATE_H_
2016-07-04 06:08:55 +00:00
#include <memory>
#include "atom/browser/ui/atom_menu_model.h"
#include "base/observer_list.h"
2014-07-17 06:23:28 +00:00
#include "ui/views/controls/menu/menu_delegate.h"
namespace views {
2016-01-05 03:57:58 +00:00
class MenuRunner;
2014-07-17 06:23:28 +00:00
}
namespace atom {
class MenuBar;
class MenuDelegate : public views::MenuDelegate {
public:
2014-07-18 01:17:17 +00:00
explicit MenuDelegate(MenuBar* menu_bar);
~MenuDelegate() override;
2014-07-17 06:23:28 +00:00
void RunMenu(AtomMenuModel* model,
views::MenuButton* button,
ui::MenuSourceType source_type);
class Observer {
public:
virtual void OnBeforeExecuteCommand() = 0;
virtual void OnMenuClosed() = 0;
};
void AddObserver(Observer* obs) { observers_.AddObserver(obs); }
void RemoveObserver(const Observer* obs) { observers_.RemoveObserver(obs); }
2014-07-17 06:23:28 +00:00
protected:
// views::MenuDelegate:
void ExecuteCommand(int id) override;
void ExecuteCommand(int id, int mouse_event_flags) override;
bool IsTriggerableEvent(views::MenuItemView* source,
const ui::Event& e) override;
bool GetAccelerator(int id, ui::Accelerator* accelerator) const override;
base::string16 GetLabel(int id) const override;
void GetLabelStyle(int id, LabelStyle* style) const override;
bool IsCommandEnabled(int id) const override;
bool IsCommandVisible(int id) const override;
bool IsItemChecked(int id) const override;
void WillShowMenu(views::MenuItemView* menu) override;
void WillHideMenu(views::MenuItemView* menu) override;
void OnMenuClosed(views::MenuItemView* menu) override;
2018-04-18 01:44:10 +00:00
views::MenuItemView* GetSiblingMenu(views::MenuItemView* menu,
const gfx::Point& screen_point,
views::MenuAnchorPosition* anchor,
bool* has_mnemonics,
views::MenuButton** button) override;
2014-07-17 06:23:28 +00:00
private:
MenuBar* menu_bar_;
int id_;
2016-05-23 01:59:39 +00:00
std::unique_ptr<views::MenuDelegate> adapter_;
std::unique_ptr<views::MenuRunner> menu_runner_;
2014-07-17 06:23:28 +00:00
// The menu button to switch to.
views::MenuButton* button_to_open_ = nullptr;
bool hold_first_switch_;
base::ObserverList<Observer>::Unchecked observers_;
2014-07-17 06:23:28 +00:00
DISALLOW_COPY_AND_ASSIGN(MenuDelegate);
};
} // namespace atom
#endif // ATOM_BROWSER_UI_VIEWS_MENU_DELEGATE_H_