global_menu_bar_x11.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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_GLOBAL_MENU_BAR_X11_H_
  5. #define ATOM_BROWSER_UI_VIEWS_GLOBAL_MENU_BAR_X11_H_
  6. #include <string>
  7. #include "atom/browser/ui/atom_menu_model.h"
  8. #include "base/compiler_specific.h"
  9. #include "base/macros.h"
  10. #include "ui/base/glib/glib_signal.h"
  11. #include "ui/gfx/native_widget_types.h"
  12. typedef struct _DbusmenuMenuitem DbusmenuMenuitem;
  13. typedef struct _DbusmenuServer DbusmenuServer;
  14. namespace ui {
  15. class Accelerator;
  16. }
  17. namespace atom {
  18. class NativeWindowViews;
  19. // Controls the Mac style menu bar on Unity.
  20. //
  21. // Unity has an Apple-like menu bar at the top of the screen that changes
  22. // depending on the active window. In the GTK port, we had a hidden GtkMenuBar
  23. // object in each GtkWindow which existed only to be scrapped by the
  24. // libdbusmenu-gtk code. Since we don't have GtkWindows anymore, we need to
  25. // interface directly with the lower level libdbusmenu-glib, which we
  26. // opportunistically dlopen() since not everyone is running Ubuntu.
  27. //
  28. // This class is like the chrome's corresponding one, but it generates the menu
  29. // from menu models instead, and it is also per-window specific.
  30. class GlobalMenuBarX11 {
  31. public:
  32. explicit GlobalMenuBarX11(NativeWindowViews* window);
  33. virtual ~GlobalMenuBarX11();
  34. // Creates the object path for DbusmenuServer which is attached to |xid|.
  35. static std::string GetPathForWindow(gfx::AcceleratedWidget xid);
  36. void SetMenu(AtomMenuModel* menu_model);
  37. bool IsServerStarted() const;
  38. // Called by NativeWindow when it show/hides.
  39. void OnWindowMapped();
  40. void OnWindowUnmapped();
  41. private:
  42. // Creates a DbusmenuServer.
  43. void InitServer(gfx::AcceleratedWidget xid);
  44. // Create a menu from menu model.
  45. void BuildMenuFromModel(AtomMenuModel* model, DbusmenuMenuitem* parent);
  46. // Sets the accelerator for |item|.
  47. void RegisterAccelerator(DbusmenuMenuitem* item,
  48. const ui::Accelerator& accelerator);
  49. CHROMEG_CALLBACK_1(GlobalMenuBarX11,
  50. void,
  51. OnItemActivated,
  52. DbusmenuMenuitem*,
  53. unsigned int);
  54. CHROMEG_CALLBACK_0(GlobalMenuBarX11, void, OnSubMenuShow, DbusmenuMenuitem*);
  55. NativeWindowViews* window_;
  56. gfx::AcceleratedWidget xid_;
  57. DbusmenuServer* server_ = nullptr;
  58. DISALLOW_COPY_AND_ASSIGN(GlobalMenuBarX11);
  59. };
  60. } // namespace atom
  61. #endif // ATOM_BROWSER_UI_VIEWS_GLOBAL_MENU_BAR_X11_H_