Chromium Code Reviews| Index: chrome/browser/ui/views/frame/global_menu_bar_x11.h |
| diff --git a/chrome/browser/ui/views/frame/global_menu_bar_x11.h b/chrome/browser/ui/views/frame/global_menu_bar_x11.h |
| index 46f8cf34de3d6d5ef406d116668b020e1c15ce6e..cc9aa554878ba31ac9c44252bb5f6cde5b339ce1 100644 |
| --- a/chrome/browser/ui/views/frame/global_menu_bar_x11.h |
| +++ b/chrome/browser/ui/views/frame/global_menu_bar_x11.h |
| @@ -11,18 +11,29 @@ |
| #include "base/compiler_specific.h" |
| #include "base/prefs/pref_change_registrar.h" |
| #include "chrome/browser/command_observer.h" |
| +#include "chrome/browser/common/cancelable_request.h" |
| +#include "chrome/browser/history/history_types.h" |
| +#include "chrome/browser/sessions/tab_restore_service.h" |
| +#include "chrome/browser/sessions/tab_restore_service_observer.h" |
| +#include "content/public/browser/notification_observer.h" |
| +#include "content/public/browser/notification_registrar.h" |
| #include "ui/base/glib/glib_signal.h" |
| #include "ui/views/widget/desktop_aura/desktop_root_window_host_observer_x11.h" |
| typedef struct _DbusmenuMenuitem DbusmenuMenuitem; |
| typedef struct _DbusmenuServer DbusmenuServer; |
| +namespace history { |
| +class TopSites; |
| +} |
| + |
| namespace ui { |
| class Accelerator; |
| } |
| class Browser; |
| class BrowserView; |
| +class Profile; |
| class BrowserDesktopRootWindowHostX11; |
| struct GlobalMenuBarCommand; |
| @@ -36,8 +47,16 @@ struct GlobalMenuBarCommand; |
| // interface directly with the lower level libdbusmenu-glib, which we |
| // opportunistically dlopen() since not everyone is running Ubuntu. |
| class GlobalMenuBarX11 : public CommandObserver, |
| + public content::NotificationObserver, |
| + public TabRestoreServiceObserver, |
| public views::DesktopRootWindowHostObserverX11 { |
| public: |
| + static const int TAG_NORMAL = 0; |
| + static const int TAG_MOST_VISITED = 1; |
| + static const int TAG_RECENTLY_CLOSED = 2; |
| + static const int TAG_MOST_VISITED_HEADER = 3; |
| + static const int TAG_RECENTLY_CLOSED_HEADER = 4; |
| + |
| GlobalMenuBarX11(BrowserView* browser_view, |
| BrowserDesktopRootWindowHostX11* host); |
| virtual ~GlobalMenuBarX11(); |
| @@ -45,7 +64,17 @@ class GlobalMenuBarX11 : public CommandObserver, |
| // Creates the object path for DbusemenuServer which is attached to |xid|. |
| static std::string GetPathForWindow(unsigned long xid); |
| + // Builds a separator. |
| + DbusmenuMenuitem* BuildSeparator(); |
| + |
| + // Creates an individual menu item from a title and command, and subscribes |
| + // to the activation signal. |
| + DbusmenuMenuitem* BuildMenuItem(const std::string& label, int tag_id); |
| + |
| private: |
| + class HistoryItem; |
| + struct ClearMenuClosure; |
| + typedef std::map<DbusmenuMenuitem*, HistoryItem*> MenuItemToHistoryMap; |
| typedef std::map<int, DbusmenuMenuitem*> CommandIDMenuItemMap; |
| // Creates a DbusmenuServer, and attaches all the menu items. |
| @@ -56,37 +85,73 @@ class GlobalMenuBarX11 : public CommandObserver, |
| // Creates a whole menu defined with |commands| and titled with the string |
| // |menu_str_id|. Then appends it to |parent|. |
| - void BuildMenuFrom(DbusmenuMenuitem* parent, |
| - int menu_str_id, |
| - CommandIDMenuItemMap* id_to_menu_item, |
| - GlobalMenuBarCommand* commands); |
| - |
| - // Creates an individual menu item from a title and command, and subscribes |
| - // to the activation signal. |
| - DbusmenuMenuitem* BuildMenuItem( |
| - int string_id, |
| - int command_id, |
| - int tag_id, |
| - CommandIDMenuItemMap* id_to_menu_item); |
| + DbusmenuMenuitem* BuildStaticMenu(DbusmenuMenuitem* parent, |
| + int menu_str_id, |
| + GlobalMenuBarCommand* commands); |
| // Sets the accelerator for |item|. |
| void RegisterAccelerator(DbusmenuMenuitem* item, |
| const ui::Accelerator& accelerator); |
| + // Returns the currently existing HistoryItem associated with |
| + // |menu_item|. Can return NULL. |
| + HistoryItem* HistoryItemForMenuItem(DbusmenuMenuitem* menu_item); |
| + |
| + // Creates a HistoryItem from the data in |entry|. |
| + HistoryItem* HistoryItemForTab(const TabRestoreService::Tab& entry); |
| + |
| + // Creates a menu item form |item| and inserts it in |menu| at |index|. |
| + void AddHistoryItemToMenu(HistoryItem* item, |
| + DbusmenuMenuitem* menu, |
| + int tag, |
| + int index); |
| + |
| + // Sends a message off to History for data. |
| + void GetTopSitesData(); |
| + |
| + // Callback to receive data requested from GetTopSitesData(). |
| + void OnTopSitesReceived(const history::MostVisitedURLList& visited_list); |
| + |
| // Updates the visibility of the bookmark bar on pref changes. |
| void OnBookmarkBarVisibilityChanged(); |
| + // Find the first index of the item in |menu| with the tag |tag_id|. |
| + int GetIndexOfMenuItemWithTag(DbusmenuMenuitem* menu, int tag_id); |
| + |
| + // This will remove all menu items in |menu| with |tag| as their tag. This |
| + // clears state about HistoryItems* that we keep to prevent that data from |
| + // going stale. That's why this method recurses into its child menus. |
| + void ClearMenuSection(DbusmenuMenuitem* menu, int tag_id); |
| + |
| + // Implementation detail of ClearMenuSection. |
| + static void ClearMenuCallback(DbusmenuMenuitem* menu_item, |
| + ClearMenuClosure* closure); |
| + |
| // Overridden from CommandObserver: |
| virtual void EnabledStateChangedForCommand(int id, bool enabled) OVERRIDE; |
| + // content::NotificationObserver: |
| + virtual void Observe(int type, |
| + const content::NotificationSource& source, |
| + const content::NotificationDetails& details) OVERRIDE; |
| + |
| + // For TabRestoreServiceObserver |
|
James Cook
2013/08/08 18:42:16
nit: either:
// TabRestoreServiceObserver:
or
/
|
| + virtual void TabRestoreServiceChanged(TabRestoreService* service) OVERRIDE; |
| + virtual void TabRestoreServiceDestroyed(TabRestoreService* service) OVERRIDE; |
| + |
| // Overridden from DesktopRootWindowHostObserverX11: |
| virtual void OnWindowMapped(unsigned long xid) OVERRIDE; |
| virtual void OnWindowUnmapped(unsigned long xid) OVERRIDE; |
| CHROMEG_CALLBACK_1(GlobalMenuBarX11, void, OnItemActivated, DbusmenuMenuitem*, |
| unsigned int); |
| + CHROMEG_CALLBACK_1(GlobalMenuBarX11, void, OnHistoryItemActivated, |
| + DbusmenuMenuitem*, unsigned int); |
| + CHROMEG_CALLBACK_0(GlobalMenuBarX11, void, OnHistoryMenuAboutToShow, |
| + DbusmenuMenuitem*); |
| Browser* browser_; |
| + Profile* profile_; |
| BrowserView* browser_view_; |
| BrowserDesktopRootWindowHostX11* host_; |
| @@ -96,10 +161,23 @@ class GlobalMenuBarX11 : public CommandObserver, |
| DbusmenuServer* server_; |
| DbusmenuMenuitem* root_item_; |
| + DbusmenuMenuitem* history_menu_; |
| // Tracks value of the kShowBookmarkBar preference. |
| PrefChangeRegistrar pref_change_registrar_; |
| + history::TopSites* top_sites_; |
| + |
| + // For callbacks may be run after destruction. |
| + 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
|
| + |
| + TabRestoreService* tab_restore_service_; // weak |
| + |
| + // A mapping from DbusmenuMenuitems to HistoryItems that maintain data. |
| + MenuItemToHistoryMap menu_item_history_map_; |
| + |
| + content::NotificationRegistrar registrar_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(GlobalMenuBarX11); |
| }; |