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