electron/atom/browser/ui/views/menu_bar.h

88 lines
2.4 KiB
C
Raw Normal View History

// 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_
#include "atom/browser/ui/atom_menu_model.h"
2014-07-17 06:23:28 +00:00
#include "ui/views/controls/button/menu_button_listener.h"
#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 {
2014-07-17 06:23:28 +00:00
class MenuDelegate;
class MenuBar : public views::View,
public views::MenuButtonListener,
public views::FocusChangeListener {
2014-07-16 14:10:10 +00:00
public:
static const char kViewClassName[];
explicit MenuBar(views::View* window);
~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.
void SetMenu(AtomMenuModel* menu_model);
2014-07-17 06:23:28 +00:00
// Shows underline under accelerators.
void SetAcceleratorVisibility(bool visible);
// Returns true if the submenu has accelerator |key|
bool HasAccelerator(base::char16 key);
// 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,
AtomMenuModel** menu_model,
2014-07-17 06:23:28 +00:00
views::MenuButton** button);
2014-07-16 14:10:10 +00:00
protected:
// views::View:
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;
void OnNativeThemeChanged(const ui::NativeTheme* theme) override;
2014-07-17 06:23:28 +00:00
// views::FocusChangeListener:
void OnDidChangeFocus(View* focused_before, View* focused_now) override;
void OnWillChangeFocus(View* focused_before, View* focused_now) override {}
2014-07-16 14:10:10 +00:00
private:
void RebuildChildren();
void UpdateViewColors();
void RefreshColorCache(const ui::NativeTheme* theme = nullptr);
SkColor background_color_;
#if defined(USE_X11)
SkColor enabled_color_;
SkColor disabled_color_;
#endif
views::View* window_ = nullptr;
AtomMenuModel* menu_model_ = nullptr;
2014-07-17 06:23:28 +00:00
View* FindAccelChild(base::char16 key);
bool has_focus_ = true;
2014-07-16 14:10:10 +00:00
DISALLOW_COPY_AND_ASSIGN(MenuBar);
};
} // namespace atom
#endif // ATOM_BROWSER_UI_VIEWS_MENU_BAR_H_