menu_delegate.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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_DELEGATE_H_
  5. #define ATOM_BROWSER_UI_VIEWS_MENU_DELEGATE_H_
  6. #include <memory>
  7. #include "atom/browser/ui/atom_menu_model.h"
  8. #include "ui/views/controls/menu/menu_delegate.h"
  9. namespace views {
  10. class MenuRunner;
  11. }
  12. namespace atom {
  13. class MenuBar;
  14. class MenuDelegate : public views::MenuDelegate {
  15. public:
  16. explicit MenuDelegate(MenuBar* menu_bar);
  17. virtual ~MenuDelegate();
  18. void RunMenu(AtomMenuModel* model, views::MenuButton* button);
  19. protected:
  20. // views::MenuDelegate:
  21. void ExecuteCommand(int id) override;
  22. void ExecuteCommand(int id, int mouse_event_flags) override;
  23. bool IsTriggerableEvent(views::MenuItemView* source,
  24. const ui::Event& e) override;
  25. bool GetAccelerator(int id, ui::Accelerator* accelerator) const override;
  26. base::string16 GetLabel(int id) const override;
  27. const gfx::FontList* GetLabelFontList(int id) const override;
  28. bool IsCommandEnabled(int id) const override;
  29. bool IsCommandVisible(int id) const override;
  30. bool IsItemChecked(int id) const override;
  31. void SelectionChanged(views::MenuItemView* menu) override;
  32. void WillShowMenu(views::MenuItemView* menu) override;
  33. void WillHideMenu(views::MenuItemView* menu) override;
  34. views::MenuItemView* GetSiblingMenu(
  35. views::MenuItemView* menu,
  36. const gfx::Point& screen_point,
  37. views::MenuAnchorPosition* anchor,
  38. bool* has_mnemonics,
  39. views::MenuButton** button) override;
  40. private:
  41. MenuBar* menu_bar_;
  42. int id_;
  43. std::unique_ptr<views::MenuDelegate> adapter_;
  44. std::unique_ptr<views::MenuRunner> menu_runner_;
  45. DISALLOW_COPY_AND_ASSIGN(MenuDelegate);
  46. };
  47. } // namespace atom
  48. #endif // ATOM_BROWSER_UI_VIEWS_MENU_DELEGATE_H_