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.
|
|
|
|
|
2019-06-19 20:56:58 +00:00
|
|
|
#ifndef SHELL_BROWSER_UI_VIEWS_MENU_BAR_H_
|
|
|
|
#define SHELL_BROWSER_UI_VIEWS_MENU_BAR_H_
|
2014-07-16 14:10:10 +00:00
|
|
|
|
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"
|
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 {
|
2014-07-16 14:10:10 +00:00
|
|
|
public:
|
2018-05-15 18:49:27 +00:00
|
|
|
static const char kViewClassName[];
|
|
|
|
|
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
|
|
|
|
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.
|
|
|
|
int GetItemCount() const;
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
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:
|
2014-11-16 07:54:40 +00:00
|
|
|
const char* GetClassName() const override;
|
2014-07-16 14:10:10 +00:00
|
|
|
|
2021-01-29 20:43:51 +00:00
|
|
|
void ButtonPressed(int 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();
|
2019-05-13 23:52:31 +00:00
|
|
|
void RefreshColorCache();
|
2021-05-21 17:00:47 +00:00
|
|
|
View* FindAccelChild(char16_t key);
|
|
|
|
|
2014-08-05 01:41:29 +00:00
|
|
|
SkColor background_color_;
|
2020-10-20 18:24:52 +00:00
|
|
|
#if defined(OS_LINUX)
|
2014-08-05 01:41:29 +00:00
|
|
|
SkColor enabled_color_;
|
|
|
|
SkColor disabled_color_;
|
|
|
|
#endif
|
|
|
|
|
2021-05-21 17:00:47 +00:00
|
|
|
NativeWindow* window_;
|
|
|
|
RootView* root_view_;
|
2020-02-04 20:19:40 +00:00
|
|
|
ElectronMenuModel* menu_model_ = nullptr;
|
2021-05-21 17:00:47 +00:00
|
|
|
bool accelerator_installed_ = false;
|
2018-10-29 18:08:47 +00:00
|
|
|
|
2014-07-16 14:10:10 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(MenuBar);
|
|
|
|
};
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
} // namespace electron
|
2014-07-16 14:10:10 +00:00
|
|
|
|
2019-06-19 20:56:58 +00:00
|
|
|
#endif // SHELL_BROWSER_UI_VIEWS_MENU_BAR_H_
|