| OLD | NEW |
| (Empty) |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_UI_VIEWS_FRAME_GLOBAL_MENU_BAR_X11_H_ | |
| 6 #define CHROME_BROWSER_UI_VIEWS_FRAME_GLOBAL_MENU_BAR_X11_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/compiler_specific.h" | |
| 12 #include "base/prefs/pref_change_registrar.h" | |
| 13 #include "chrome/browser/command_observer.h" | |
| 14 #include "ui/base/glib/glib_signal.h" | |
| 15 #include "ui/views/widget/desktop_aura/desktop_root_window_host_observer_x11.h" | |
| 16 | |
| 17 typedef struct _DbusmenuMenuitem DbusmenuMenuitem; | |
| 18 typedef struct _DbusmenuServer DbusmenuServer; | |
| 19 | |
| 20 namespace ui { | |
| 21 class Accelerator; | |
| 22 } | |
| 23 | |
| 24 class Browser; | |
| 25 class BrowserView; | |
| 26 | |
| 27 class BrowserDesktopRootWindowHostX11; | |
| 28 struct GlobalMenuBarCommand; | |
| 29 | |
| 30 // Controls the Mac style menu bar on Unity. | |
| 31 // | |
| 32 // Unity has an Apple-like menu bar at the top of the screen that changes | |
| 33 // depending on the active window. In the GTK port, we had a hidden GtkMenuBar | |
| 34 // object in each GtkWindow which existed only to be scrapped by the | |
| 35 // libdbusmenu-gtk code. Since we don't have GtkWindows anymore, we need to | |
| 36 // interface directly with the lower level libdbusmenu-glib, which we | |
| 37 // opportunistically dlopen() since not everyone is running Ubuntu. | |
| 38 class GlobalMenuBarX11 : public CommandObserver, | |
| 39 public views::DesktopRootWindowHostObserverX11 { | |
| 40 public: | |
| 41 GlobalMenuBarX11(BrowserView* browser_view, | |
| 42 BrowserDesktopRootWindowHostX11* host); | |
| 43 virtual ~GlobalMenuBarX11(); | |
| 44 | |
| 45 // Creates the object path for DbusemenuServer which is attached to |xid|. | |
| 46 static std::string GetPathForWindow(unsigned long xid); | |
| 47 | |
| 48 private: | |
| 49 typedef std::map<int, DbusmenuMenuitem*> CommandIDMenuItemMap; | |
| 50 | |
| 51 // Creates a DbusmenuServer, and attaches all the menu items. | |
| 52 void InitServer(unsigned long xid); | |
| 53 | |
| 54 // Stops listening to enable state changed events. | |
| 55 void Disable(); | |
| 56 | |
| 57 // Creates a whole menu defined with |commands| and titled with the string | |
| 58 // |menu_str_id|. Then appends it to |parent|. | |
| 59 void BuildMenuFrom(DbusmenuMenuitem* parent, | |
| 60 int menu_str_id, | |
| 61 CommandIDMenuItemMap* id_to_menu_item, | |
| 62 GlobalMenuBarCommand* commands); | |
| 63 | |
| 64 // Creates an individual menu item from a title and command, and subscribes | |
| 65 // to the activation signal. | |
| 66 DbusmenuMenuitem* BuildMenuItem( | |
| 67 int string_id, | |
| 68 int command_id, | |
| 69 int tag_id, | |
| 70 CommandIDMenuItemMap* id_to_menu_item); | |
| 71 | |
| 72 // Sets the accelerator for |item|. | |
| 73 void RegisterAccelerator(DbusmenuMenuitem* item, | |
| 74 const ui::Accelerator& accelerator); | |
| 75 | |
| 76 // Updates the visibility of the bookmark bar on pref changes. | |
| 77 void OnBookmarkBarVisibilityChanged(); | |
| 78 | |
| 79 // Overridden from CommandObserver: | |
| 80 virtual void EnabledStateChangedForCommand(int id, bool enabled) OVERRIDE; | |
| 81 | |
| 82 // Overridden from DesktopRootWindowHostObserverX11: | |
| 83 virtual void OnWindowMapped(unsigned long xid) OVERRIDE; | |
| 84 virtual void OnWindowUnmapped(unsigned long xid) OVERRIDE; | |
| 85 | |
| 86 CHROMEG_CALLBACK_1(GlobalMenuBarX11, void, OnItemActivated, DbusmenuMenuitem*, | |
| 87 unsigned int); | |
| 88 | |
| 89 Browser* browser_; | |
| 90 BrowserView* browser_view_; | |
| 91 BrowserDesktopRootWindowHostX11* host_; | |
| 92 | |
| 93 // Maps command ids to DbusmenuMenuitems so we can modify their | |
| 94 // enabled/checked state in response to state change notifications. | |
| 95 CommandIDMenuItemMap id_to_menu_item_; | |
| 96 | |
| 97 DbusmenuServer* server_; | |
| 98 DbusmenuMenuitem* root_item_; | |
| 99 | |
| 100 // Tracks value of the kShowBookmarkBar preference. | |
| 101 PrefChangeRegistrar pref_change_registrar_; | |
| 102 | |
| 103 DISALLOW_COPY_AND_ASSIGN(GlobalMenuBarX11); | |
| 104 }; | |
| 105 | |
| 106 #endif // CHROME_BROWSER_UI_VIEWS_FRAME_GLOBAL_MENU_BAR_X11_H_ | |
| OLD | NEW |