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; | |
sadrul
2013/08/09 06:38:54
Can they be in the .cc instead?
| |
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); | |
sadrul
2013/08/09 06:38:54
Do these need to be public?
Elliot Glaysher
2013/08/09 20:19:25
no. done.
| |
73 | |
48 private: | 74 private: |
75 class HistoryItem; | |
76 typedef std::map<DbusmenuMenuitem*, HistoryItem*> MenuItemToHistoryMap; | |
49 typedef std::map<int, DbusmenuMenuitem*> CommandIDMenuItemMap; | 77 typedef std::map<int, DbusmenuMenuitem*> CommandIDMenuItemMap; |
50 | 78 |
51 // Creates a DbusmenuServer, and attaches all the menu items. | 79 // Creates a DbusmenuServer, and attaches all the menu items. |
52 void InitServer(unsigned long xid); | 80 void InitServer(unsigned long xid); |
53 | 81 |
54 // Stops listening to enable state changed events. | 82 // Stops listening to enable state changed events. |
55 void Disable(); | 83 void Disable(); |
56 | 84 |
57 // Creates a whole menu defined with |commands| and titled with the string | 85 // Creates a whole menu defined with |commands| and titled with the string |
58 // |menu_str_id|. Then appends it to |parent|. | 86 // |menu_str_id|. Then appends it to |parent|. |
59 void BuildMenuFrom(DbusmenuMenuitem* parent, | 87 DbusmenuMenuitem* BuildStaticMenu(DbusmenuMenuitem* parent, |
60 int menu_str_id, | 88 int menu_str_id, |
61 CommandIDMenuItemMap* id_to_menu_item, | 89 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 | 90 |
72 // Sets the accelerator for |item|. | 91 // Sets the accelerator for |item|. |
73 void RegisterAccelerator(DbusmenuMenuitem* item, | 92 void RegisterAccelerator(DbusmenuMenuitem* item, |
74 const ui::Accelerator& accelerator); | 93 const ui::Accelerator& accelerator); |
75 | 94 |
95 // Returns the currently existing HistoryItem associated with | |
96 // |menu_item|. Can return NULL. | |
97 HistoryItem* HistoryItemForMenuItem(DbusmenuMenuitem* menu_item); | |
98 | |
99 // Creates a HistoryItem from the data in |entry|. | |
100 HistoryItem* HistoryItemForTab(const TabRestoreService::Tab& entry); | |
101 | |
102 // Creates a menu item form |item| and inserts it in |menu| at |index|. | |
103 void AddHistoryItemToMenu(HistoryItem* item, | |
104 DbusmenuMenuitem* menu, | |
105 int tag, | |
106 int index); | |
107 | |
108 // Sends a message off to History for data. | |
109 void GetTopSitesData(); | |
110 | |
111 // Callback to receive data requested from GetTopSitesData(). | |
112 void OnTopSitesReceived(const history::MostVisitedURLList& visited_list); | |
113 | |
76 // Updates the visibility of the bookmark bar on pref changes. | 114 // Updates the visibility of the bookmark bar on pref changes. |
77 void OnBookmarkBarVisibilityChanged(); | 115 void OnBookmarkBarVisibilityChanged(); |
78 | 116 |
117 // Find the first index of the item in |menu| with the tag |tag_id|. | |
118 int GetIndexOfMenuItemWithTag(DbusmenuMenuitem* menu, int tag_id); | |
sadrul
2013/08/09 06:38:54
Please add a note that the invisible entries are a
Elliot Glaysher
2013/08/09 20:19:25
I'm not sure what you're saying here. All entries
sadrul
2013/08/09 20:31:34
Ah, I noticed that the visibility property was bei
| |
119 | |
120 // This will remove all menu items in |menu| with |tag| as their tag. This | |
121 // clears state about HistoryItems* that we keep to prevent that data from | |
122 // going stale. That's why this method recurses into its child menus. | |
123 void ClearMenuSection(DbusmenuMenuitem* menu, int tag_id); | |
124 | |
79 // Overridden from CommandObserver: | 125 // Overridden from CommandObserver: |
80 virtual void EnabledStateChangedForCommand(int id, bool enabled) OVERRIDE; | 126 virtual void EnabledStateChangedForCommand(int id, bool enabled) OVERRIDE; |
81 | 127 |
82 // Overridden from DesktopRootWindowHostObserverX11: | 128 // Overridden from content::NotificationObserver: |
129 virtual void Observe(int type, | |
130 const content::NotificationSource& source, | |
131 const content::NotificationDetails& details) OVERRIDE; | |
132 | |
133 // Overridden from TabRestoreServiceObserver: | |
134 virtual void TabRestoreServiceChanged(TabRestoreService* service) OVERRIDE; | |
135 virtual void TabRestoreServiceDestroyed(TabRestoreService* service) OVERRIDE; | |
136 | |
137 // Overridden from views::DesktopRootWindowHostObserverX11: | |
83 virtual void OnWindowMapped(unsigned long xid) OVERRIDE; | 138 virtual void OnWindowMapped(unsigned long xid) OVERRIDE; |
84 virtual void OnWindowUnmapped(unsigned long xid) OVERRIDE; | 139 virtual void OnWindowUnmapped(unsigned long xid) OVERRIDE; |
85 | 140 |
86 CHROMEG_CALLBACK_1(GlobalMenuBarX11, void, OnItemActivated, DbusmenuMenuitem*, | 141 CHROMEG_CALLBACK_1(GlobalMenuBarX11, void, OnItemActivated, DbusmenuMenuitem*, |
87 unsigned int); | 142 unsigned int); |
143 CHROMEG_CALLBACK_1(GlobalMenuBarX11, void, OnHistoryItemActivated, | |
144 DbusmenuMenuitem*, unsigned int); | |
145 CHROMEG_CALLBACK_0(GlobalMenuBarX11, void, OnHistoryMenuAboutToShow, | |
146 DbusmenuMenuitem*); | |
88 | 147 |
89 Browser* browser_; | 148 Browser* browser_; |
149 Profile* profile_; | |
90 BrowserView* browser_view_; | 150 BrowserView* browser_view_; |
91 BrowserDesktopRootWindowHostX11* host_; | 151 BrowserDesktopRootWindowHostX11* host_; |
92 | 152 |
93 // Maps command ids to DbusmenuMenuitems so we can modify their | 153 // Maps command ids to DbusmenuMenuitems so we can modify their |
94 // enabled/checked state in response to state change notifications. | 154 // enabled/checked state in response to state change notifications. |
95 CommandIDMenuItemMap id_to_menu_item_; | 155 CommandIDMenuItemMap id_to_menu_item_; |
96 | 156 |
97 DbusmenuServer* server_; | 157 DbusmenuServer* server_; |
98 DbusmenuMenuitem* root_item_; | 158 DbusmenuMenuitem* root_item_; |
159 DbusmenuMenuitem* history_menu_; | |
99 | 160 |
100 // Tracks value of the kShowBookmarkBar preference. | 161 // Tracks value of the kShowBookmarkBar preference. |
101 PrefChangeRegistrar pref_change_registrar_; | 162 PrefChangeRegistrar pref_change_registrar_; |
102 | 163 |
164 history::TopSites* top_sites_; | |
165 | |
166 TabRestoreService* tab_restore_service_; // weak | |
167 | |
168 // A mapping from DbusmenuMenuitems to HistoryItems that maintain data. | |
169 MenuItemToHistoryMap menu_item_history_map_; | |
170 | |
171 content::NotificationRegistrar registrar_; | |
172 | |
173 // For callbacks may be run after destruction. | |
174 base::WeakPtrFactory<GlobalMenuBarX11> weak_ptr_factory_; | |
175 | |
103 DISALLOW_COPY_AND_ASSIGN(GlobalMenuBarX11); | 176 DISALLOW_COPY_AND_ASSIGN(GlobalMenuBarX11); |
104 }; | 177 }; |
105 | 178 |
106 #endif // CHROME_BROWSER_UI_VIEWS_FRAME_GLOBAL_MENU_BAR_X11_H_ | 179 #endif // CHROME_BROWSER_UI_VIEWS_FRAME_GLOBAL_MENU_BAR_X11_H_ |
OLD | NEW |