menu_bar.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // Copyright (c) 2014 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #ifndef ATOM_BROWSER_UI_VIEWS_MENU_BAR_H_
  5. #define ATOM_BROWSER_UI_VIEWS_MENU_BAR_H_
  6. #include "atom/browser/native_window.h"
  7. #include "atom/browser/ui/atom_menu_model.h"
  8. #include "ui/views/controls/button/menu_button_listener.h"
  9. #include "ui/views/view.h"
  10. namespace views {
  11. class MenuButton;
  12. }
  13. namespace atom {
  14. class MenuDelegate;
  15. class MenuBar : public views::View,
  16. public views::MenuButtonListener {
  17. public:
  18. explicit MenuBar(NativeWindow* window);
  19. virtual ~MenuBar();
  20. // Replaces current menu with a new one.
  21. void SetMenu(AtomMenuModel* menu_model);
  22. // Shows underline under accelerators.
  23. void SetAcceleratorVisibility(bool visible);
  24. // Returns which submenu has accelerator |key|, -1 would be returned when
  25. // there is no matching submenu.
  26. int GetAcceleratorIndex(base::char16 key);
  27. // Shows the submenu whose accelerator is |key|.
  28. void ActivateAccelerator(base::char16 key);
  29. // Returns there are how many items in the root menu.
  30. int GetItemCount() const;
  31. // Get the menu under specified screen point.
  32. bool GetMenuButtonFromScreenPoint(const gfx::Point& point,
  33. AtomMenuModel** menu_model,
  34. views::MenuButton** button);
  35. protected:
  36. // views::View:
  37. const char* GetClassName() const override;
  38. // views::MenuButtonListener:
  39. void OnMenuButtonClicked(views::MenuButton* source,
  40. const gfx::Point& point,
  41. const ui::Event* event) override;
  42. void OnNativeThemeChanged(const ui::NativeTheme* theme) override;
  43. private:
  44. void UpdateMenuBarColor();
  45. SkColor background_color_;
  46. #if defined(USE_X11)
  47. SkColor enabled_color_;
  48. SkColor disabled_color_;
  49. SkColor highlight_color_;
  50. SkColor hover_color_;
  51. #endif
  52. NativeWindow* window_;
  53. AtomMenuModel* menu_model_;
  54. DISALLOW_COPY_AND_ASSIGN(MenuBar);
  55. };
  56. } // namespace atom
  57. #endif // ATOM_BROWSER_UI_VIEWS_MENU_BAR_H_