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

Unified 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: Add bookmark menu stub for string freeze reasons 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/gtk/global_menu_bar.h
diff --git a/chrome/browser/ui/gtk/global_menu_bar.h b/chrome/browser/ui/gtk/global_menu_bar.h
index 5ff88e7e068c46d27f3189682708f09693d12f2e..5d20af84182886f9c3383511e75ca45a5fa17d56 100644
--- a/chrome/browser/ui/gtk/global_menu_bar.h
+++ b/chrome/browser/ui/gtk/global_menu_bar.h
@@ -7,15 +7,20 @@
#include <map>
+#include "content/browser/cancelable_request.h"
#include "chrome/browser/command_updater.h"
+#include "chrome/browser/favicon_service.h"
+#include "chrome/browser/sessions/tab_restore_service.h"
+#include "chrome/browser/sessions/tab_restore_service_observer.h"
+#include "chrome/browser/ui/gtk/owned_widget_gtk.h"
#include "content/common/notification_observer.h"
#include "content/common/notification_registrar.h"
#include "ui/base/gtk/gtk_signal.h"
class Browser;
-class BrowserWindowGtk;
struct GlobalMenuBarCommand;
+typedef struct _GdkPixbuf GdkPixubf;
typedef struct _GtkAccelGroup GtkAccelGroup;
typedef struct _GtkWidget GtkWidget;
@@ -28,20 +33,73 @@ typedef struct _GtkWidget GtkWidget;
// bar itself is visible, so we insert a GtkMenuBar into the window hierarchy
// and set it to be invisible.
class GlobalMenuBar : public CommandUpdater::CommandObserver,
- public NotificationObserver {
+ public NotificationObserver,
+ public TabRestoreServiceObserver {
public:
- GlobalMenuBar(Browser* browser, BrowserWindowGtk* window);
+ explicit GlobalMenuBar(Browser* browser);
virtual ~GlobalMenuBar();
- GtkWidget* widget() { return menu_bar_; }
+ GtkWidget* widget() { return menu_bar_.get(); }
private:
- typedef std::map<int, GtkWidget*> IDMenuItemMap;
+ friend class GlobalMenuBarTest;
+
+ class HistoryItem;
+ struct ClearMenuClosure;
+ struct GetIndexClosure;
+
+ typedef std::map<int, GtkWidget*> CommandIDMenuItemMap;
+ typedef std::map<GtkWidget*, HistoryItem*> MenuItemToHistoryMap;
// Helper function that builds the data.
- void BuildGtkMenuFrom(int menu_str_id,
- std::map<int, GtkWidget*>* id_to_menu_item,
- GlobalMenuBarCommand* commands);
+ GtkWidget* BuildGtkMenuFrom(int menu_str_id,
+ std::map<int, GtkWidget*>* id_to_menu_item,
+ GlobalMenuBarCommand* commands);
+
+ // Builds an individual menu item.
+ GtkWidget* BuildMenuItem(int string_id,
+ int command_id,
+ int tag_id,
+ std::map<int, GtkWidget*>* id_to_menu_item,
+ GtkWidget* menu_to_add_to);
+
+ // Returns the currently existing HistoryItem associated with
+ // |menu_item|. Can return NULL.
+ HistoryItem* HistoryItemForMenuItem(GtkWidget* 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|.
+ GtkWidget* AddHistoryItemToMenu(HistoryItem* item,
+ GtkWidget* menu,
+ int tag,
+ int index);
+
+ // Requests a FavIcon; we'll receive the data in the future through the
+ // GotFaviconData() callback.
+ void GetFaviconForHistoryItem(HistoryItem* item);
+
+ // Callback for GetFaviconForHistoryItem().
+ void GotFaviconData(FaviconService::Handle handle,
+ history::FaviconData favicon);
+
+ // Cancels an outstanding favicon request.
+ void CancelFaviconRequest(HistoryItem* item);
+
+ // Find the first index of the item in |menu| with the tag |tag_id|.
+ int GetIndexOfMenuItemWithTag(GtkWidget* 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(GtkWidget* menu, int tag);
+
+ // Implementation detail of GetIndexOfMenuItemWithTag.
+ static void GetIndexCallback(GtkWidget* widget, GetIndexClosure* closure);
+
+ // Implementation detail of ClearMenuSection.
+ static void ClearMenuCallback(GtkWidget* widget, ClearMenuClosure* closure);
// CommandUpdater::CommandObserver:
virtual void EnabledStateChangedForCommand(int id, bool enabled);
@@ -51,15 +109,23 @@ class GlobalMenuBar : public CommandUpdater::CommandObserver,
const NotificationSource& source,
const NotificationDetails& details);
+ // For TabRestoreServiceObserver
+ virtual void TabRestoreServiceChanged(TabRestoreService* service);
+ virtual void TabRestoreServiceDestroyed(TabRestoreService* service);
+
CHROMEGTK_CALLBACK_0(GlobalMenuBar, void, OnItemActivated);
+ CHROMEGTK_CALLBACK_0(GlobalMenuBar, void, OnRecentlyClosedItemActivated);
+
Browser* browser_;
- BrowserWindowGtk* browser_window_;
+ Profile* profile_;
NotificationRegistrar registrar_;
+ GdkPixubf* default_favicon_;
Evan Stade 2011/04/15 19:00:41 pixubf?
Elliot Glaysher 2011/04/15 20:29:03 Yeap. I can't store the image because the image is
Evan Stade 2011/04/15 20:40:32 comment was about spelling
+
// Our menu bar widget.
- GtkWidget* menu_bar_;
+ OwnedWidgetGtk menu_bar_;
// For some menu items, we want to show the accelerator, but not actually
// explicitly handle it. To this end we connect those menu items' accelerators
@@ -67,12 +133,24 @@ class GlobalMenuBar : public CommandUpdater::CommandObserver,
GtkAccelGroup* dummy_accel_group_;
// A mapping from command ids to GtkMenuItem objects. We use this to update
- // the enable state since we are a .
- IDMenuItemMap id_to_menu_item_;
+ // the command enable state.
+ CommandIDMenuItemMap id_to_menu_item_;
// gtk_check_menu_item_set_active() will call the "activate" signal. We need
// to block this activation while we change the checked state.
bool block_activation_;
+
+ // The history menu. We keep this since we need to rewrite parts of it
+ // periodically.
+ GtkWidget* history_menu_;
+
+ TabRestoreService* tab_restore_service_; // weak
+
+ // A mapping from GtkMenuItems to HistoryItems that maintain data.
+ MenuItemToHistoryMap menu_item_history_map_;
+
+ // Maps HistoryItems to favicon request Handles.
+ CancelableRequestConsumerTSimple<HistoryItem*> favicon_consumer_;
};
#endif // CHROME_BROWSER_UI_GTK_GLOBAL_MENU_BAR_H_

Powered by Google App Engine
This is Rietveld 408576698