| 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..603af58dc9e4c9426d91d73e1b13e26208903297 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 GdkPixbuf;
|
| typedef struct _GtkAccelGroup GtkAccelGroup;
|
| typedef struct _GtkWidget GtkWidget;
|
|
|
| @@ -28,20 +33,76 @@ 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);
|
| +
|
| + // Returns whether there's a valid HistoryItem representation of |entry|.
|
| + bool HasValidHistoryItemForTab(const TabRestoreService::Tab& entry);
|
| +
|
| + // 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 +112,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_;
|
|
|
| + GdkPixbuf* default_favicon_;
|
| +
|
| // 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 +136,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_
|
|
|