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

Side by Side Diff: chrome/browser/ui/gtk/global_menu_bar.h

Issue 6840068: GTK: Add Recently Closed tabs to the History menu in the global menu bar. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix for the Hardy trybots Created 9 years, 8 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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_GTK_GLOBAL_MENU_BAR_H_ 5 #ifndef CHROME_BROWSER_UI_GTK_GLOBAL_MENU_BAR_H_
6 #define CHROME_BROWSER_UI_GTK_GLOBAL_MENU_BAR_H_ 6 #define CHROME_BROWSER_UI_GTK_GLOBAL_MENU_BAR_H_
7 7
8 #include <map> 8 #include <map>
9 9
10 #include "content/browser/cancelable_request.h"
10 #include "chrome/browser/command_updater.h" 11 #include "chrome/browser/command_updater.h"
12 #include "chrome/browser/favicon_service.h"
13 #include "chrome/browser/sessions/tab_restore_service.h"
14 #include "chrome/browser/sessions/tab_restore_service_observer.h"
15 #include "chrome/browser/ui/gtk/owned_widget_gtk.h"
11 #include "content/common/notification_observer.h" 16 #include "content/common/notification_observer.h"
12 #include "content/common/notification_registrar.h" 17 #include "content/common/notification_registrar.h"
13 #include "ui/base/gtk/gtk_signal.h" 18 #include "ui/base/gtk/gtk_signal.h"
14 19
15 class Browser; 20 class Browser;
16 class BrowserWindowGtk;
17 struct GlobalMenuBarCommand; 21 struct GlobalMenuBarCommand;
18 22
23 typedef struct _GdkPixbuf GdkPixbuf;
19 typedef struct _GtkAccelGroup GtkAccelGroup; 24 typedef struct _GtkAccelGroup GtkAccelGroup;
20 typedef struct _GtkWidget GtkWidget; 25 typedef struct _GtkWidget GtkWidget;
21 26
22 // Controls the Mac style menu bar on Linux. 27 // Controls the Mac style menu bar on Linux.
23 // 28 //
24 // Unity and some configurations of GNOME have a Apple-like menu bar at the top 29 // Unity and some configurations of GNOME have a Apple-like menu bar at the top
25 // of the screen that changes depending on the active window. These mainly work 30 // of the screen that changes depending on the active window. These mainly work
26 // by inspecting the application's widget hierarchy, and intercepting any 31 // by inspecting the application's widget hierarchy, and intercepting any
27 // GtkMenuBar found. Thankfully, these systems don't check to see if the menu 32 // GtkMenuBar found. Thankfully, these systems don't check to see if the menu
28 // bar itself is visible, so we insert a GtkMenuBar into the window hierarchy 33 // bar itself is visible, so we insert a GtkMenuBar into the window hierarchy
29 // and set it to be invisible. 34 // and set it to be invisible.
30 class GlobalMenuBar : public CommandUpdater::CommandObserver, 35 class GlobalMenuBar : public CommandUpdater::CommandObserver,
31 public NotificationObserver { 36 public NotificationObserver,
37 public TabRestoreServiceObserver {
32 public: 38 public:
33 GlobalMenuBar(Browser* browser, BrowserWindowGtk* window); 39 explicit GlobalMenuBar(Browser* browser);
34 virtual ~GlobalMenuBar(); 40 virtual ~GlobalMenuBar();
35 41
36 GtkWidget* widget() { return menu_bar_; } 42 GtkWidget* widget() { return menu_bar_.get(); }
37 43
38 private: 44 private:
39 typedef std::map<int, GtkWidget*> IDMenuItemMap; 45 friend class GlobalMenuBarTest;
46
47 class HistoryItem;
48 struct ClearMenuClosure;
49 struct GetIndexClosure;
50
51 typedef std::map<int, GtkWidget*> CommandIDMenuItemMap;
52 typedef std::map<GtkWidget*, HistoryItem*> MenuItemToHistoryMap;
40 53
41 // Helper function that builds the data. 54 // Helper function that builds the data.
42 void BuildGtkMenuFrom(int menu_str_id, 55 GtkWidget* BuildGtkMenuFrom(int menu_str_id,
43 std::map<int, GtkWidget*>* id_to_menu_item, 56 std::map<int, GtkWidget*>* id_to_menu_item,
44 GlobalMenuBarCommand* commands); 57 GlobalMenuBarCommand* commands);
58
59 // Builds an individual menu item.
60 GtkWidget* BuildMenuItem(int string_id,
61 int command_id,
62 int tag_id,
63 std::map<int, GtkWidget*>* id_to_menu_item,
64 GtkWidget* menu_to_add_to);
65
66 // Returns the currently existing HistoryItem associated with
67 // |menu_item|. Can return NULL.
68 HistoryItem* HistoryItemForMenuItem(GtkWidget* menu_item);
69
70 // Returns whether there's a valid HistoryItem representation of |entry|.
71 bool HasValidHistoryItemForTab(const TabRestoreService::Tab& entry);
72
73 // Creates a HistoryItem from the data in |entry|.
74 HistoryItem* HistoryItemForTab(const TabRestoreService::Tab& entry);
75
76 // Creates a menu item form |item| and inserts it in |menu| at |index|.
77 GtkWidget* AddHistoryItemToMenu(HistoryItem* item,
78 GtkWidget* menu,
79 int tag,
80 int index);
81
82 // Requests a FavIcon; we'll receive the data in the future through the
83 // GotFaviconData() callback.
84 void GetFaviconForHistoryItem(HistoryItem* item);
85
86 // Callback for GetFaviconForHistoryItem().
87 void GotFaviconData(FaviconService::Handle handle,
88 history::FaviconData favicon);
89
90 // Cancels an outstanding favicon request.
91 void CancelFaviconRequest(HistoryItem* item);
92
93 // Find the first index of the item in |menu| with the tag |tag_id|.
94 int GetIndexOfMenuItemWithTag(GtkWidget* menu, int tag_id);
95
96 // This will remove all menu items in |menu| with |tag| as their tag. This
97 // clears state about HistoryItems* that we keep to prevent that data from
98 // going stale. That's why this method recurses into its child menus.
99 void ClearMenuSection(GtkWidget* menu, int tag);
100
101 // Implementation detail of GetIndexOfMenuItemWithTag.
102 static void GetIndexCallback(GtkWidget* widget, GetIndexClosure* closure);
103
104 // Implementation detail of ClearMenuSection.
105 static void ClearMenuCallback(GtkWidget* widget, ClearMenuClosure* closure);
45 106
46 // CommandUpdater::CommandObserver: 107 // CommandUpdater::CommandObserver:
47 virtual void EnabledStateChangedForCommand(int id, bool enabled); 108 virtual void EnabledStateChangedForCommand(int id, bool enabled);
48 109
49 // NotificationObserver: 110 // NotificationObserver:
50 virtual void Observe(NotificationType type, 111 virtual void Observe(NotificationType type,
51 const NotificationSource& source, 112 const NotificationSource& source,
52 const NotificationDetails& details); 113 const NotificationDetails& details);
53 114
115 // For TabRestoreServiceObserver
116 virtual void TabRestoreServiceChanged(TabRestoreService* service);
117 virtual void TabRestoreServiceDestroyed(TabRestoreService* service);
118
54 CHROMEGTK_CALLBACK_0(GlobalMenuBar, void, OnItemActivated); 119 CHROMEGTK_CALLBACK_0(GlobalMenuBar, void, OnItemActivated);
55 120
121 CHROMEGTK_CALLBACK_0(GlobalMenuBar, void, OnRecentlyClosedItemActivated);
122
56 Browser* browser_; 123 Browser* browser_;
57 BrowserWindowGtk* browser_window_; 124 Profile* profile_;
58 125
59 NotificationRegistrar registrar_; 126 NotificationRegistrar registrar_;
60 127
128 GdkPixbuf* default_favicon_;
129
61 // Our menu bar widget. 130 // Our menu bar widget.
62 GtkWidget* menu_bar_; 131 OwnedWidgetGtk menu_bar_;
63 132
64 // For some menu items, we want to show the accelerator, but not actually 133 // For some menu items, we want to show the accelerator, but not actually
65 // explicitly handle it. To this end we connect those menu items' accelerators 134 // explicitly handle it. To this end we connect those menu items' accelerators
66 // to this group, but don't attach this group to any top level window. 135 // to this group, but don't attach this group to any top level window.
67 GtkAccelGroup* dummy_accel_group_; 136 GtkAccelGroup* dummy_accel_group_;
68 137
69 // A mapping from command ids to GtkMenuItem objects. We use this to update 138 // A mapping from command ids to GtkMenuItem objects. We use this to update
70 // the enable state since we are a . 139 // the command enable state.
71 IDMenuItemMap id_to_menu_item_; 140 CommandIDMenuItemMap id_to_menu_item_;
72 141
73 // gtk_check_menu_item_set_active() will call the "activate" signal. We need 142 // gtk_check_menu_item_set_active() will call the "activate" signal. We need
74 // to block this activation while we change the checked state. 143 // to block this activation while we change the checked state.
75 bool block_activation_; 144 bool block_activation_;
145
146 // The history menu. We keep this since we need to rewrite parts of it
147 // periodically.
148 GtkWidget* history_menu_;
149
150 TabRestoreService* tab_restore_service_; // weak
151
152 // A mapping from GtkMenuItems to HistoryItems that maintain data.
153 MenuItemToHistoryMap menu_item_history_map_;
154
155 // Maps HistoryItems to favicon request Handles.
156 CancelableRequestConsumerTSimple<HistoryItem*> favicon_consumer_;
76 }; 157 };
77 158
78 #endif // CHROME_BROWSER_UI_GTK_GLOBAL_MENU_BAR_H_ 159 #endif // CHROME_BROWSER_UI_GTK_GLOBAL_MENU_BAR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698