2014-10-31 18:17:05 +00:00
|
|
|
// Copyright (c) 2014 GitHub, Inc.
|
2014-07-16 14:10:10 +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_BAR_H_
|
|
|
|
#define ELECTRON_SHELL_BROWSER_UI_VIEWS_MENU_BAR_H_
|
2014-07-16 14:10:10 +00:00
|
|
|
|
2023-05-11 20:07:39 +00:00
|
|
|
#include "base/memory/raw_ptr.h"
|
2021-05-21 17:00:47 +00:00
|
|
|
#include "shell/browser/native_window_observer.h"
|
2020-02-04 20:19:40 +00:00
|
|
|
#include "shell/browser/ui/electron_menu_model.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/ui/views/menu_delegate.h"
|
|
|
|
#include "shell/browser/ui/views/root_view.h"
|
2023-11-28 21:40:12 +00:00
|
|
|
#include "ui/base/metadata/metadata_header_macros.h"
|
|
|
|
#include "ui/base/metadata/metadata_impl_macros.h"
|
2018-10-29 18:08:47 +00:00
|
|
|
#include "ui/views/accessible_pane_view.h"
|
2014-07-16 14:10:10 +00:00
|
|
|
|
2014-07-17 06:23:28 +00:00
|
|
|
namespace views {
|
|
|
|
class MenuButton;
|
2021-05-21 17:00:47 +00:00
|
|
|
}
|
2014-07-17 06:23:28 +00:00
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
namespace electron {
|
2014-07-16 14:10:10 +00:00
|
|
|
|
2018-10-29 18:08:47 +00:00
|
|
|
class MenuBar : public views::AccessiblePaneView,
|
2021-05-21 17:00:47 +00:00
|
|
|
public MenuDelegate::Observer,
|
|
|
|
public NativeWindowObserver {
|
2023-11-28 21:40:12 +00:00
|
|
|
METADATA_HEADER(MenuBar, views::AccessiblePaneView)
|
2018-05-15 18:49:27 +00:00
|
|
|
|
2023-11-28 21:40:12 +00:00
|
|
|
public:
|
2021-05-21 17:00:47 +00:00
|
|
|
MenuBar(NativeWindow* window, RootView* root_view);
|
2018-05-16 19:12:45 +00:00
|
|
|
~MenuBar() override;
|
2014-07-16 14:10:10 +00:00
|
|
|
|
2021-11-03 11:41:45 +00:00
|
|
|
// disable copy
|
|
|
|
MenuBar(const MenuBar&) = delete;
|
|
|
|
MenuBar& operator=(const MenuBar&) = delete;
|
|
|
|
|
2014-07-17 06:23:28 +00:00
|
|
|
// Replaces current menu with a new one.
|
2020-02-04 20:19:40 +00:00
|
|
|
void SetMenu(ElectronMenuModel* menu_model);
|
2014-07-17 06:23:28 +00:00
|
|
|
|
2014-08-18 06:12:12 +00:00
|
|
|
// Shows underline under accelerators.
|
|
|
|
void SetAcceleratorVisibility(bool visible);
|
|
|
|
|
2018-03-16 21:37:36 +00:00
|
|
|
// Returns true if the submenu has accelerator |key|
|
2021-03-16 01:21:27 +00:00
|
|
|
bool HasAccelerator(char16_t key);
|
2014-08-18 06:52:44 +00:00
|
|
|
|
2014-08-18 06:42:21 +00:00
|
|
|
// Shows the submenu whose accelerator is |key|.
|
2021-03-16 01:21:27 +00:00
|
|
|
void ActivateAccelerator(char16_t key);
|
2014-08-18 06:42:21 +00:00
|
|
|
|
2014-07-17 06:23:28 +00:00
|
|
|
// Returns there are how many items in the root menu.
|
2022-08-17 18:35:53 +00:00
|
|
|
size_t GetItemCount() const;
|
2014-07-17 06:23:28 +00:00
|
|
|
|
|
|
|
// Get the menu under specified screen point.
|
|
|
|
bool GetMenuButtonFromScreenPoint(const gfx::Point& point,
|
2020-02-04 20:19:40 +00:00
|
|
|
ElectronMenuModel** menu_model,
|
2014-07-17 06:23:28 +00:00
|
|
|
views::MenuButton** button);
|
|
|
|
|
2023-03-31 16:06:09 +00:00
|
|
|
void ViewHierarchyChanged(
|
|
|
|
const views::ViewHierarchyChangedDetails& details) override;
|
|
|
|
|
2021-05-21 17:00:47 +00:00
|
|
|
private:
|
|
|
|
// MenuDelegate::Observer:
|
2018-10-29 18:08:47 +00:00
|
|
|
void OnBeforeExecuteCommand() override;
|
|
|
|
void OnMenuClosed() override;
|
|
|
|
|
2021-05-21 17:00:47 +00:00
|
|
|
// NativeWindowObserver:
|
|
|
|
void OnWindowBlur() override;
|
|
|
|
void OnWindowFocus() override;
|
|
|
|
|
2018-10-29 18:08:47 +00:00
|
|
|
// views::AccessiblePaneView:
|
|
|
|
bool AcceleratorPressed(const ui::Accelerator& accelerator) override;
|
2021-05-21 17:00:47 +00:00
|
|
|
bool SetPaneFocusAndFocusDefault() override;
|
2020-03-14 20:54:14 +00:00
|
|
|
void OnThemeChanged() override;
|
2018-10-29 18:08:47 +00:00
|
|
|
|
2021-05-21 17:00:47 +00:00
|
|
|
// views::FocusChangeListener:
|
|
|
|
void OnDidChangeFocus(View* focused_before, View* focused_now) override;
|
2020-11-14 00:16:56 +00:00
|
|
|
|
2014-07-16 14:10:10 +00:00
|
|
|
// views::View:
|
2021-10-21 18:51:36 +00:00
|
|
|
void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
|
2014-07-16 14:10:10 +00:00
|
|
|
|
2022-08-17 18:35:53 +00:00
|
|
|
void ButtonPressed(size_t id, const ui::Event& event);
|
2018-10-29 18:08:47 +00:00
|
|
|
|
2018-03-16 21:37:36 +00:00
|
|
|
void RebuildChildren();
|
|
|
|
void UpdateViewColors();
|
2021-08-11 21:04:56 +00:00
|
|
|
void RefreshColorCache(const ui::NativeTheme* theme);
|
2021-05-21 17:00:47 +00:00
|
|
|
View* FindAccelChild(char16_t key);
|
|
|
|
|
2014-08-05 01:41:29 +00:00
|
|
|
SkColor background_color_;
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_LINUX)
|
2014-08-05 01:41:29 +00:00
|
|
|
SkColor enabled_color_;
|
|
|
|
SkColor disabled_color_;
|
|
|
|
#endif
|
|
|
|
|
2023-05-11 20:07:39 +00:00
|
|
|
raw_ptr<NativeWindow> window_;
|
|
|
|
raw_ptr<RootView> root_view_;
|
|
|
|
raw_ptr<ElectronMenuModel> menu_model_ = nullptr;
|
2021-05-21 17:00:47 +00:00
|
|
|
bool accelerator_installed_ = false;
|
2014-07-16 14:10:10 +00:00
|
|
|
};
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
} // namespace electron
|
2014-07-16 14:10:10 +00:00
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#endif // ELECTRON_SHELL_BROWSER_UI_VIEWS_MENU_BAR_H_
|