Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_UI_VIEWS_FRAME_GLOBAL_MENU_BAR_X11_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_FRAME_GLOBAL_MENU_BAR_X11_H_ |
| 6 #define CHROME_BROWSER_UI_VIEWS_FRAME_GLOBAL_MENU_BAR_X11_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_FRAME_GLOBAL_MENU_BAR_X11_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/prefs/pref_change_registrar.h" | 12 #include "base/prefs/pref_change_registrar.h" |
| 13 #include "chrome/browser/command_observer.h" | 13 #include "chrome/browser/command_observer.h" |
| 14 #include "chrome/browser/common/cancelable_request.h" | |
| 15 #include "chrome/browser/history/history_types.h" | |
| 16 #include "chrome/browser/sessions/tab_restore_service.h" | |
| 17 #include "chrome/browser/sessions/tab_restore_service_observer.h" | |
| 18 #include "content/public/browser/notification_observer.h" | |
| 19 #include "content/public/browser/notification_registrar.h" | |
| 14 #include "ui/base/glib/glib_signal.h" | 20 #include "ui/base/glib/glib_signal.h" |
| 15 #include "ui/views/widget/desktop_aura/desktop_root_window_host_observer_x11.h" | 21 #include "ui/views/widget/desktop_aura/desktop_root_window_host_observer_x11.h" |
| 16 | 22 |
| 17 typedef struct _DbusmenuMenuitem DbusmenuMenuitem; | 23 typedef struct _DbusmenuMenuitem DbusmenuMenuitem; |
| 18 typedef struct _DbusmenuServer DbusmenuServer; | 24 typedef struct _DbusmenuServer DbusmenuServer; |
| 19 | 25 |
| 26 namespace history { | |
| 27 class TopSites; | |
| 28 } | |
| 29 | |
| 20 namespace ui { | 30 namespace ui { |
| 21 class Accelerator; | 31 class Accelerator; |
| 22 } | 32 } |
| 23 | 33 |
| 24 class Browser; | 34 class Browser; |
| 25 class BrowserView; | 35 class BrowserView; |
| 36 class Profile; | |
| 26 | 37 |
| 27 class BrowserDesktopRootWindowHostX11; | 38 class BrowserDesktopRootWindowHostX11; |
| 28 struct GlobalMenuBarCommand; | 39 struct GlobalMenuBarCommand; |
| 29 | 40 |
| 30 // Controls the Mac style menu bar on Unity. | 41 // Controls the Mac style menu bar on Unity. |
| 31 // | 42 // |
| 32 // Unity has an Apple-like menu bar at the top of the screen that changes | 43 // 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 | 44 // 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 | 45 // 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 | 46 // libdbusmenu-gtk code. Since we don't have GtkWindows anymore, we need to |
| 36 // interface directly with the lower level libdbusmenu-glib, which we | 47 // interface directly with the lower level libdbusmenu-glib, which we |
| 37 // opportunistically dlopen() since not everyone is running Ubuntu. | 48 // opportunistically dlopen() since not everyone is running Ubuntu. |
| 38 class GlobalMenuBarX11 : public CommandObserver, | 49 class GlobalMenuBarX11 : public CommandObserver, |
| 50 public content::NotificationObserver, | |
| 51 public TabRestoreServiceObserver, | |
| 39 public views::DesktopRootWindowHostObserverX11 { | 52 public views::DesktopRootWindowHostObserverX11 { |
| 40 public: | 53 public: |
| 54 static const int TAG_NORMAL = 0; | |
| 55 static const int TAG_MOST_VISITED = 1; | |
| 56 static const int TAG_RECENTLY_CLOSED = 2; | |
| 57 static const int TAG_MOST_VISITED_HEADER = 3; | |
| 58 static const int TAG_RECENTLY_CLOSED_HEADER = 4; | |
| 59 | |
| 41 GlobalMenuBarX11(BrowserView* browser_view, | 60 GlobalMenuBarX11(BrowserView* browser_view, |
| 42 BrowserDesktopRootWindowHostX11* host); | 61 BrowserDesktopRootWindowHostX11* host); |
| 43 virtual ~GlobalMenuBarX11(); | 62 virtual ~GlobalMenuBarX11(); |
| 44 | 63 |
| 45 // Creates the object path for DbusemenuServer which is attached to |xid|. | 64 // Creates the object path for DbusemenuServer which is attached to |xid|. |
| 46 static std::string GetPathForWindow(unsigned long xid); | 65 static std::string GetPathForWindow(unsigned long xid); |
| 47 | 66 |
| 67 // Builds a separator. | |
| 68 DbusmenuMenuitem* BuildSeparator(); | |
| 69 | |
| 70 // Creates an individual menu item from a title and command, and subscribes | |
| 71 // to the activation signal. | |
| 72 DbusmenuMenuitem* BuildMenuItem(const std::string& label, int tag_id); | |
| 73 | |
| 48 private: | 74 private: |
| 75 class HistoryItem; | |
| 76 struct ClearMenuClosure; | |
| 77 typedef std::map<DbusmenuMenuitem*, HistoryItem*> MenuItemToHistoryMap; | |
| 49 typedef std::map<int, DbusmenuMenuitem*> CommandIDMenuItemMap; | 78 typedef std::map<int, DbusmenuMenuitem*> CommandIDMenuItemMap; |
| 50 | 79 |
| 51 // Creates a DbusmenuServer, and attaches all the menu items. | 80 // Creates a DbusmenuServer, and attaches all the menu items. |
| 52 void InitServer(unsigned long xid); | 81 void InitServer(unsigned long xid); |
| 53 | 82 |
| 54 // Stops listening to enable state changed events. | 83 // Stops listening to enable state changed events. |
| 55 void Disable(); | 84 void Disable(); |
| 56 | 85 |
| 57 // Creates a whole menu defined with |commands| and titled with the string | 86 // Creates a whole menu defined with |commands| and titled with the string |
| 58 // |menu_str_id|. Then appends it to |parent|. | 87 // |menu_str_id|. Then appends it to |parent|. |
| 59 void BuildMenuFrom(DbusmenuMenuitem* parent, | 88 DbusmenuMenuitem* BuildStaticMenu(DbusmenuMenuitem* parent, |
| 60 int menu_str_id, | 89 int menu_str_id, |
| 61 CommandIDMenuItemMap* id_to_menu_item, | 90 GlobalMenuBarCommand* commands); |
| 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 | 91 |
| 72 // Sets the accelerator for |item|. | 92 // Sets the accelerator for |item|. |
| 73 void RegisterAccelerator(DbusmenuMenuitem* item, | 93 void RegisterAccelerator(DbusmenuMenuitem* item, |
| 74 const ui::Accelerator& accelerator); | 94 const ui::Accelerator& accelerator); |
| 75 | 95 |
| 96 // Returns the currently existing HistoryItem associated with | |
| 97 // |menu_item|. Can return NULL. | |
| 98 HistoryItem* HistoryItemForMenuItem(DbusmenuMenuitem* menu_item); | |
| 99 | |
| 100 // Creates a HistoryItem from the data in |entry|. | |
| 101 HistoryItem* HistoryItemForTab(const TabRestoreService::Tab& entry); | |
| 102 | |
| 103 // Creates a menu item form |item| and inserts it in |menu| at |index|. | |
| 104 void AddHistoryItemToMenu(HistoryItem* item, | |
| 105 DbusmenuMenuitem* menu, | |
| 106 int tag, | |
| 107 int index); | |
| 108 | |
| 109 // Sends a message off to History for data. | |
| 110 void GetTopSitesData(); | |
| 111 | |
| 112 // Callback to receive data requested from GetTopSitesData(). | |
| 113 void OnTopSitesReceived(const history::MostVisitedURLList& visited_list); | |
| 114 | |
| 76 // Updates the visibility of the bookmark bar on pref changes. | 115 // Updates the visibility of the bookmark bar on pref changes. |
| 77 void OnBookmarkBarVisibilityChanged(); | 116 void OnBookmarkBarVisibilityChanged(); |
| 78 | 117 |
| 118 // Find the first index of the item in |menu| with the tag |tag_id|. | |
| 119 int GetIndexOfMenuItemWithTag(DbusmenuMenuitem* menu, int tag_id); | |
| 120 | |
| 121 // This will remove all menu items in |menu| with |tag| as their tag. This | |
| 122 // clears state about HistoryItems* that we keep to prevent that data from | |
| 123 // going stale. That's why this method recurses into its child menus. | |
| 124 void ClearMenuSection(DbusmenuMenuitem* menu, int tag_id); | |
| 125 | |
| 126 // Implementation detail of ClearMenuSection. | |
| 127 static void ClearMenuCallback(DbusmenuMenuitem* menu_item, | |
| 128 ClearMenuClosure* closure); | |
| 129 | |
| 79 // Overridden from CommandObserver: | 130 // Overridden from CommandObserver: |
| 80 virtual void EnabledStateChangedForCommand(int id, bool enabled) OVERRIDE; | 131 virtual void EnabledStateChangedForCommand(int id, bool enabled) OVERRIDE; |
| 81 | 132 |
| 133 // content::NotificationObserver: | |
| 134 virtual void Observe(int type, | |
| 135 const content::NotificationSource& source, | |
| 136 const content::NotificationDetails& details) OVERRIDE; | |
| 137 | |
| 138 // For TabRestoreServiceObserver | |
|
James Cook
2013/08/08 18:42:16
nit: either:
// TabRestoreServiceObserver:
or
/
| |
| 139 virtual void TabRestoreServiceChanged(TabRestoreService* service) OVERRIDE; | |
| 140 virtual void TabRestoreServiceDestroyed(TabRestoreService* service) OVERRIDE; | |
| 141 | |
| 82 // Overridden from DesktopRootWindowHostObserverX11: | 142 // Overridden from DesktopRootWindowHostObserverX11: |
| 83 virtual void OnWindowMapped(unsigned long xid) OVERRIDE; | 143 virtual void OnWindowMapped(unsigned long xid) OVERRIDE; |
| 84 virtual void OnWindowUnmapped(unsigned long xid) OVERRIDE; | 144 virtual void OnWindowUnmapped(unsigned long xid) OVERRIDE; |
| 85 | 145 |
| 86 CHROMEG_CALLBACK_1(GlobalMenuBarX11, void, OnItemActivated, DbusmenuMenuitem*, | 146 CHROMEG_CALLBACK_1(GlobalMenuBarX11, void, OnItemActivated, DbusmenuMenuitem*, |
| 87 unsigned int); | 147 unsigned int); |
| 148 CHROMEG_CALLBACK_1(GlobalMenuBarX11, void, OnHistoryItemActivated, | |
| 149 DbusmenuMenuitem*, unsigned int); | |
| 150 CHROMEG_CALLBACK_0(GlobalMenuBarX11, void, OnHistoryMenuAboutToShow, | |
| 151 DbusmenuMenuitem*); | |
| 88 | 152 |
| 89 Browser* browser_; | 153 Browser* browser_; |
| 154 Profile* profile_; | |
| 90 BrowserView* browser_view_; | 155 BrowserView* browser_view_; |
| 91 BrowserDesktopRootWindowHostX11* host_; | 156 BrowserDesktopRootWindowHostX11* host_; |
| 92 | 157 |
| 93 // Maps command ids to DbusmenuMenuitems so we can modify their | 158 // Maps command ids to DbusmenuMenuitems so we can modify their |
| 94 // enabled/checked state in response to state change notifications. | 159 // enabled/checked state in response to state change notifications. |
| 95 CommandIDMenuItemMap id_to_menu_item_; | 160 CommandIDMenuItemMap id_to_menu_item_; |
| 96 | 161 |
| 97 DbusmenuServer* server_; | 162 DbusmenuServer* server_; |
| 98 DbusmenuMenuitem* root_item_; | 163 DbusmenuMenuitem* root_item_; |
| 164 DbusmenuMenuitem* history_menu_; | |
| 99 | 165 |
| 100 // Tracks value of the kShowBookmarkBar preference. | 166 // Tracks value of the kShowBookmarkBar preference. |
| 101 PrefChangeRegistrar pref_change_registrar_; | 167 PrefChangeRegistrar pref_change_registrar_; |
| 102 | 168 |
| 169 history::TopSites* top_sites_; | |
| 170 | |
| 171 // For callbacks may be run after destruction. | |
| 172 base::WeakPtrFactory<GlobalMenuBarX11> weak_ptr_factory_; | |
|
James Cook
2013/08/08 18:42:16
I think this should be the last item in the member
| |
| 173 | |
| 174 TabRestoreService* tab_restore_service_; // weak | |
| 175 | |
| 176 // A mapping from DbusmenuMenuitems to HistoryItems that maintain data. | |
| 177 MenuItemToHistoryMap menu_item_history_map_; | |
| 178 | |
| 179 content::NotificationRegistrar registrar_; | |
| 180 | |
| 103 DISALLOW_COPY_AND_ASSIGN(GlobalMenuBarX11); | 181 DISALLOW_COPY_AND_ASSIGN(GlobalMenuBarX11); |
| 104 }; | 182 }; |
| 105 | 183 |
| 106 #endif // CHROME_BROWSER_UI_VIEWS_FRAME_GLOBAL_MENU_BAR_X11_H_ | 184 #endif // CHROME_BROWSER_UI_VIEWS_FRAME_GLOBAL_MENU_BAR_X11_H_ |
| OLD | NEW |