2014-10-31 18:17:05 +00:00
|
|
|
// 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.
|
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#ifndef ELECTRON_SHELL_BROWSER_UI_VIEWS_MENU_DELEGATE_H_
|
|
|
|
#define ELECTRON_SHELL_BROWSER_UI_VIEWS_MENU_DELEGATE_H_
|
2014-07-17 06:23:28 +00:00
|
|
|
|
2016-07-04 06:08:55 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2023-05-11 20:07:39 +00:00
|
|
|
#include "base/memory/raw_ptr.h"
|
2018-10-29 18:08:47 +00:00
|
|
|
#include "base/observer_list.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/ui/electron_menu_model.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;
|
2019-04-20 17:20:37 +00:00
|
|
|
class Button;
|
|
|
|
} // namespace views
|
2014-07-17 06:23:28 +00:00
|
|
|
|
|
|
|
namespace electron {
|
|
|
|
|
|
|
|
class MenuBar;
|
|
|
|
|
|
|
|
class MenuDelegate : public views::MenuDelegate {
|
|
|
|
public:
|
2014-07-18 01:17:17 +00:00
|
|
|
explicit MenuDelegate(MenuBar* menu_bar);
|
2018-05-16 19:12:45 +00:00
|
|
|
~MenuDelegate() override;
|
2014-07-17 06:23:28 +00:00
|
|
|
|
2021-11-03 11:41:45 +00:00
|
|
|
// disable copy
|
|
|
|
MenuDelegate(const MenuDelegate&) = delete;
|
|
|
|
MenuDelegate& operator=(const MenuDelegate&) = delete;
|
|
|
|
|
2018-10-29 18:08:47 +00:00
|
|
|
void RunMenu(ElectronMenuModel* model,
|
2019-04-20 17:20:37 +00:00
|
|
|
views::Button* button,
|
2018-10-29 18:08:47 +00:00
|
|
|
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:
|
2014-11-16 07:54:40 +00:00
|
|
|
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;
|
2021-03-16 16:18:45 +00:00
|
|
|
std::u16string GetLabel(int id) const override;
|
2021-07-26 16:02:16 +00:00
|
|
|
const gfx::FontList* GetLabelFontList(int id) const override;
|
|
|
|
absl::optional<SkColor> GetLabelColor(int id) const override;
|
2014-11-16 07:54:40 +00:00
|
|
|
bool IsCommandEnabled(int id) const override;
|
2014-11-16 08:01:33 +00:00
|
|
|
bool IsCommandVisible(int id) const override;
|
2014-11-16 07:54:40 +00:00
|
|
|
bool IsItemChecked(int id) const override;
|
|
|
|
void WillShowMenu(views::MenuItemView* menu) override;
|
|
|
|
void WillHideMenu(views::MenuItemView* menu) override;
|
2017-09-13 21:06:43 +00:00
|
|
|
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:
|
2023-05-11 20:07:39 +00:00
|
|
|
raw_ptr<MenuBar> menu_bar_;
|
2021-01-26 18:16:21 +00:00
|
|
|
int id_ = -1;
|
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
|
|
|
|
2017-08-28 09:59:06 +00:00
|
|
|
// The menu button to switch to.
|
2023-05-11 20:07:39 +00:00
|
|
|
raw_ptr<views::MenuButton> button_to_open_ = nullptr;
|
2021-01-26 18:16:21 +00:00
|
|
|
bool hold_first_switch_ = false;
|
2018-10-29 18:08:47 +00:00
|
|
|
|
2018-10-25 06:43:50 +00:00
|
|
|
base::ObserverList<Observer>::Unchecked observers_;
|
2014-07-17 06:23:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace electron
|
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#endif // ELECTRON_SHELL_BROWSER_UI_VIEWS_MENU_DELEGATE_H_
|