Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(756)

Side by Side Diff: chrome/browser/ui/views/frame/global_menu_bar_x11.h

Issue 22562005: linux_aura: Implement the dynamic History menu in the dbusmenu. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Redo how HistoryItems are stored. Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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:
41 GlobalMenuBarX11(BrowserView* browser_view, 54 GlobalMenuBarX11(BrowserView* browser_view,
42 BrowserDesktopRootWindowHostX11* host); 55 BrowserDesktopRootWindowHostX11* host);
43 virtual ~GlobalMenuBarX11(); 56 virtual ~GlobalMenuBarX11();
44 57
45 // Creates the object path for DbusemenuServer which is attached to |xid|. 58 // Creates the object path for DbusemenuServer which is attached to |xid|.
46 static std::string GetPathForWindow(unsigned long xid); 59 static std::string GetPathForWindow(unsigned long xid);
47 60
48 private: 61 private:
62 struct HistoryItem;
49 typedef std::map<int, DbusmenuMenuitem*> CommandIDMenuItemMap; 63 typedef std::map<int, DbusmenuMenuitem*> CommandIDMenuItemMap;
50 64
65 // Builds a separator.
66 DbusmenuMenuitem* BuildSeparator();
67
68 // Creates an individual menu item from a title and command, and subscribes
69 // to the activation signal.
70 DbusmenuMenuitem* BuildMenuItem(const std::string& label, int tag_id);
71
51 // Creates a DbusmenuServer, and attaches all the menu items. 72 // Creates a DbusmenuServer, and attaches all the menu items.
52 void InitServer(unsigned long xid); 73 void InitServer(unsigned long xid);
53 74
54 // Stops listening to enable state changed events. 75 // Stops listening to enable state changed events.
55 void Disable(); 76 void Disable();
56 77
57 // Creates a whole menu defined with |commands| and titled with the string 78 // Creates a whole menu defined with |commands| and titled with the string
58 // |menu_str_id|. Then appends it to |parent|. 79 // |menu_str_id|. Then appends it to |parent|.
59 void BuildMenuFrom(DbusmenuMenuitem* parent, 80 DbusmenuMenuitem* BuildStaticMenu(DbusmenuMenuitem* parent,
60 int menu_str_id, 81 int menu_str_id,
61 CommandIDMenuItemMap* id_to_menu_item, 82 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 83
72 // Sets the accelerator for |item|. 84 // Sets the accelerator for |item|.
73 void RegisterAccelerator(DbusmenuMenuitem* item, 85 void RegisterAccelerator(DbusmenuMenuitem* item,
74 const ui::Accelerator& accelerator); 86 const ui::Accelerator& accelerator);
75 87
88 // Creates a HistoryItem from the data in |entry|.
89 HistoryItem* HistoryItemForTab(const TabRestoreService::Tab& entry);
90
91 // Creates a menu item form |item| and inserts it in |menu| at |index|.
92 void AddHistoryItemToMenu(HistoryItem* item,
93 DbusmenuMenuitem* menu,
94 int tag,
95 int index);
96
97 // Sends a message off to History for data.
98 void GetTopSitesData();
99
100 // Callback to receive data requested from GetTopSitesData().
101 void OnTopSitesReceived(const history::MostVisitedURLList& visited_list);
102
76 // Updates the visibility of the bookmark bar on pref changes. 103 // Updates the visibility of the bookmark bar on pref changes.
77 void OnBookmarkBarVisibilityChanged(); 104 void OnBookmarkBarVisibilityChanged();
78 105
106 // Find the first index of the item in |menu| with the tag |tag_id|.
107 int GetIndexOfMenuItemWithTag(DbusmenuMenuitem* menu, int tag_id);
108
109 // This will remove all menu items in |menu| with |tag| as their tag. This
110 // clears state about HistoryItems* that we keep to prevent that data from
111 // going stale. That's why this method recurses into its child menus.
112 void ClearMenuSection(DbusmenuMenuitem* menu, int tag_id);
113
114 // Deleter function for HistoryItem implementation detail.
115 static void DeleteHistoryItem(void* void_item);
116
79 // Overridden from CommandObserver: 117 // Overridden from CommandObserver:
80 virtual void EnabledStateChangedForCommand(int id, bool enabled) OVERRIDE; 118 virtual void EnabledStateChangedForCommand(int id, bool enabled) OVERRIDE;
81 119
82 // Overridden from DesktopRootWindowHostObserverX11: 120 // Overridden from content::NotificationObserver:
121 virtual void Observe(int type,
122 const content::NotificationSource& source,
123 const content::NotificationDetails& details) OVERRIDE;
124
125 // Overridden from TabRestoreServiceObserver:
126 virtual void TabRestoreServiceChanged(TabRestoreService* service) OVERRIDE;
127 virtual void TabRestoreServiceDestroyed(TabRestoreService* service) OVERRIDE;
128
129 // Overridden from views::DesktopRootWindowHostObserverX11:
83 virtual void OnWindowMapped(unsigned long xid) OVERRIDE; 130 virtual void OnWindowMapped(unsigned long xid) OVERRIDE;
84 virtual void OnWindowUnmapped(unsigned long xid) OVERRIDE; 131 virtual void OnWindowUnmapped(unsigned long xid) OVERRIDE;
85 132
86 CHROMEG_CALLBACK_1(GlobalMenuBarX11, void, OnItemActivated, DbusmenuMenuitem*, 133 CHROMEG_CALLBACK_1(GlobalMenuBarX11, void, OnItemActivated, DbusmenuMenuitem*,
87 unsigned int); 134 unsigned int);
135 CHROMEG_CALLBACK_1(GlobalMenuBarX11, void, OnHistoryItemActivated,
136 DbusmenuMenuitem*, unsigned int);
137 CHROMEG_CALLBACK_0(GlobalMenuBarX11, void, OnHistoryMenuAboutToShow,
138 DbusmenuMenuitem*);
88 139
89 Browser* browser_; 140 Browser* browser_;
141 Profile* profile_;
90 BrowserView* browser_view_; 142 BrowserView* browser_view_;
91 BrowserDesktopRootWindowHostX11* host_; 143 BrowserDesktopRootWindowHostX11* host_;
92 144
93 // Maps command ids to DbusmenuMenuitems so we can modify their 145 // Maps command ids to DbusmenuMenuitems so we can modify their
94 // enabled/checked state in response to state change notifications. 146 // enabled/checked state in response to state change notifications.
95 CommandIDMenuItemMap id_to_menu_item_; 147 CommandIDMenuItemMap id_to_menu_item_;
96 148
97 DbusmenuServer* server_; 149 DbusmenuServer* server_;
98 DbusmenuMenuitem* root_item_; 150 DbusmenuMenuitem* root_item_;
151 DbusmenuMenuitem* history_menu_;
99 152
100 // Tracks value of the kShowBookmarkBar preference. 153 // Tracks value of the kShowBookmarkBar preference.
101 PrefChangeRegistrar pref_change_registrar_; 154 PrefChangeRegistrar pref_change_registrar_;
102 155
156 history::TopSites* top_sites_;
157
158 TabRestoreService* tab_restore_service_; // weak
159
160 content::NotificationRegistrar registrar_;
161
162 // For callbacks may be run after destruction.
163 base::WeakPtrFactory<GlobalMenuBarX11> weak_ptr_factory_;
164
103 DISALLOW_COPY_AND_ASSIGN(GlobalMenuBarX11); 165 DISALLOW_COPY_AND_ASSIGN(GlobalMenuBarX11);
104 }; 166 };
105 167
106 #endif // CHROME_BROWSER_UI_VIEWS_FRAME_GLOBAL_MENU_BAR_X11_H_ 168 #endif // CHROME_BROWSER_UI_VIEWS_FRAME_GLOBAL_MENU_BAR_X11_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698