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.
|
|
|
|
|
|
|
|
#ifndef ATOM_BROWSER_UI_VIEWS_MENU_BAR_H_
|
|
|
|
#define ATOM_BROWSER_UI_VIEWS_MENU_BAR_H_
|
|
|
|
|
2018-10-29 18:08:47 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2016-07-06 23:04:18 +00:00
|
|
|
#include "atom/browser/ui/atom_menu_model.h"
|
2018-10-29 18:08:47 +00:00
|
|
|
#include "atom/browser/ui/views/menu_delegate.h"
|
|
|
|
#include "atom/browser/ui/views/root_view.h"
|
|
|
|
#include "ui/views/accessible_pane_view.h"
|
2014-07-17 06:23:28 +00:00
|
|
|
#include "ui/views/controls/button/menu_button_listener.h"
|
2018-03-16 21:37:36 +00:00
|
|
|
#include "ui/views/focus/focus_manager.h"
|
2014-07-16 14:10:10 +00:00
|
|
|
#include "ui/views/view.h"
|
|
|
|
|
2014-07-17 06:23:28 +00:00
|
|
|
namespace views {
|
|
|
|
class MenuButton;
|
|
|
|
}
|
|
|
|
|
2014-07-16 14:10:10 +00:00
|
|
|
namespace atom {
|
|
|
|
|
2018-10-29 18:08:47 +00:00
|
|
|
class MenuBarColorUpdater : public views::FocusChangeListener {
|
|
|
|
public:
|
|
|
|
explicit MenuBarColorUpdater(MenuBar* menu_bar);
|
|
|
|
~MenuBarColorUpdater() override;
|
|
|
|
|
|
|
|
void OnDidChangeFocus(views::View* focused_before,
|
|
|
|
views::View* focused_now) override;
|
|
|
|
void OnWillChangeFocus(views::View* focused_before,
|
|
|
|
views::View* focused_now) override {}
|
|
|
|
|
|
|
|
private:
|
|
|
|
MenuBar* menu_bar_;
|
|
|
|
};
|
2014-07-17 06:23:28 +00:00
|
|
|
|
2018-10-29 18:08:47 +00:00
|
|
|
class MenuBar : public views::AccessiblePaneView,
|
2018-03-16 21:37:36 +00:00
|
|
|
public views::MenuButtonListener,
|
2018-10-29 18:08:47 +00:00
|
|
|
public atom::MenuDelegate::Observer {
|
2014-07-16 14:10:10 +00:00
|
|
|
public:
|
2018-05-15 18:49:27 +00:00
|
|
|
static const char kViewClassName[];
|
|
|
|
|
2018-10-29 18:08:47 +00:00
|
|
|
explicit MenuBar(RootView* window);
|
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.
|
2016-07-06 23:04:18 +00:00
|
|
|
void SetMenu(AtomMenuModel* 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|
|
|
|
|
bool HasAccelerator(base::char16 key);
|
2014-08-18 06:52:44 +00:00
|
|
|
|
2014-08-18 06:42:21 +00:00
|
|
|
// Shows the submenu whose accelerator is |key|.
|
|
|
|
void ActivateAccelerator(base::char16 key);
|
|
|
|
|
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,
|
2016-07-06 23:04:18 +00:00
|
|
|
AtomMenuModel** menu_model,
|
2014-07-17 06:23:28 +00:00
|
|
|
views::MenuButton** button);
|
|
|
|
|
2018-10-29 18:08:47 +00:00
|
|
|
// atom::MenuDelegate::Observer:
|
|
|
|
void OnBeforeExecuteCommand() override;
|
|
|
|
void OnMenuClosed() override;
|
|
|
|
|
|
|
|
// views::AccessiblePaneView:
|
|
|
|
bool AcceleratorPressed(const ui::Accelerator& accelerator) override;
|
|
|
|
bool SetPaneFocus(views::View* initial_focus) override;
|
|
|
|
void RemovePaneFocus() override;
|
|
|
|
|
2014-07-16 14:10:10 +00:00
|
|
|
protected:
|
|
|
|
// views::View:
|
2014-11-16 07:54:40 +00:00
|
|
|
const char* GetClassName() const override;
|
2014-07-16 14:10:10 +00:00
|
|
|
|
2014-07-17 06:23:28 +00:00
|
|
|
// views::MenuButtonListener:
|
2016-04-30 23:56:28 +00:00
|
|
|
void OnMenuButtonClicked(views::MenuButton* source,
|
|
|
|
const gfx::Point& point,
|
|
|
|
const ui::Event* event) override;
|
2016-06-21 09:05:01 +00:00
|
|
|
void OnNativeThemeChanged(const ui::NativeTheme* theme) override;
|
2014-07-17 06:23:28 +00:00
|
|
|
|
2014-07-16 14:10:10 +00:00
|
|
|
private:
|
2018-10-29 18:08:47 +00:00
|
|
|
friend class MenuBarColorUpdater;
|
|
|
|
|
2018-03-16 21:37:36 +00:00
|
|
|
void RebuildChildren();
|
|
|
|
void UpdateViewColors();
|
2016-06-21 09:05:01 +00:00
|
|
|
|
2018-03-16 21:37:36 +00:00
|
|
|
void RefreshColorCache(const ui::NativeTheme* theme = nullptr);
|
2014-08-05 01:41:29 +00:00
|
|
|
SkColor background_color_;
|
|
|
|
#if defined(USE_X11)
|
|
|
|
SkColor enabled_color_;
|
|
|
|
SkColor disabled_color_;
|
|
|
|
#endif
|
|
|
|
|
2018-10-29 18:08:47 +00:00
|
|
|
RootView* window_ = nullptr;
|
2018-05-21 22:18:38 +00:00
|
|
|
AtomMenuModel* menu_model_ = nullptr;
|
2014-07-17 06:23:28 +00:00
|
|
|
|
2018-03-16 21:37:36 +00:00
|
|
|
View* FindAccelChild(base::char16 key);
|
|
|
|
|
|
|
|
bool has_focus_ = true;
|
|
|
|
|
2018-10-29 18:08:47 +00:00
|
|
|
std::unique_ptr<MenuBarColorUpdater> color_updater_;
|
|
|
|
|
2014-07-16 14:10:10 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(MenuBar);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace atom
|
|
|
|
|
|
|
|
#endif // ATOM_BROWSER_UI_VIEWS_MENU_BAR_H_
|