Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 GdkPixubf; | |
| 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 // Creates a HistoryItem from the data in |entry|. | |
| 71 HistoryItem* HistoryItemForTab(const TabRestoreService::Tab& entry); | |
| 72 | |
| 73 // Creates a menu item form |item| and inserts it in |menu| at |index|. | |
| 74 GtkWidget* AddHistoryItemToMenu(HistoryItem* item, | |
| 75 GtkWidget* menu, | |
| 76 int tag, | |
| 77 int index); | |
| 78 | |
| 79 // Requests a FavIcon; we'll receive the data in the future through the | |
| 80 // GotFaviconData() callback. | |
| 81 void GetFaviconForHistoryItem(HistoryItem* item); | |
| 82 | |
| 83 // Callback for GetFaviconForHistoryItem(). | |
| 84 void GotFaviconData(FaviconService::Handle handle, | |
| 85 history::FaviconData favicon); | |
| 86 | |
| 87 // Cancels an outstanding favicon request. | |
| 88 void CancelFaviconRequest(HistoryItem* item); | |
| 89 | |
| 90 // Find the first index of the item in |menu| with the tag |tag_id|. | |
| 91 int GetIndexOfMenuItemWithTag(GtkWidget* menu, int tag_id); | |
| 92 | |
| 93 // This will remove all menu items in |menu| with |tag| as their tag. This | |
| 94 // clears state about HistoryItems* that we keep to prevent that data from | |
| 95 // going stale. That's why this method recurses into its child menus. | |
| 96 void ClearMenuSection(GtkWidget* menu, int tag); | |
| 97 | |
| 98 // Implementation detail of GetIndexOfMenuItemWithTag. | |
| 99 static void GetIndexCallback(GtkWidget* widget, GetIndexClosure* closure); | |
| 100 | |
| 101 // Implementation detail of ClearMenuSection. | |
| 102 static void ClearMenuCallback(GtkWidget* widget, ClearMenuClosure* closure); | |
| 45 | 103 |
| 46 // CommandUpdater::CommandObserver: | 104 // CommandUpdater::CommandObserver: |
| 47 virtual void EnabledStateChangedForCommand(int id, bool enabled); | 105 virtual void EnabledStateChangedForCommand(int id, bool enabled); |
| 48 | 106 |
| 49 // NotificationObserver: | 107 // NotificationObserver: |
| 50 virtual void Observe(NotificationType type, | 108 virtual void Observe(NotificationType type, |
| 51 const NotificationSource& source, | 109 const NotificationSource& source, |
| 52 const NotificationDetails& details); | 110 const NotificationDetails& details); |
| 53 | 111 |
| 112 // For TabRestoreServiceObserver | |
| 113 virtual void TabRestoreServiceChanged(TabRestoreService* service); | |
| 114 virtual void TabRestoreServiceDestroyed(TabRestoreService* service); | |
| 115 | |
| 54 CHROMEGTK_CALLBACK_0(GlobalMenuBar, void, OnItemActivated); | 116 CHROMEGTK_CALLBACK_0(GlobalMenuBar, void, OnItemActivated); |
| 55 | 117 |
| 118 CHROMEGTK_CALLBACK_0(GlobalMenuBar, void, OnRecentlyClosedItemActivated); | |
| 119 | |
| 56 Browser* browser_; | 120 Browser* browser_; |
| 57 BrowserWindowGtk* browser_window_; | 121 Profile* profile_; |
| 58 | 122 |
| 59 NotificationRegistrar registrar_; | 123 NotificationRegistrar registrar_; |
| 60 | 124 |
| 125 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
| |
| 126 | |
| 61 // Our menu bar widget. | 127 // Our menu bar widget. |
| 62 GtkWidget* menu_bar_; | 128 OwnedWidgetGtk menu_bar_; |
| 63 | 129 |
| 64 // For some menu items, we want to show the accelerator, but not actually | 130 // 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 | 131 // 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. | 132 // to this group, but don't attach this group to any top level window. |
| 67 GtkAccelGroup* dummy_accel_group_; | 133 GtkAccelGroup* dummy_accel_group_; |
| 68 | 134 |
| 69 // A mapping from command ids to GtkMenuItem objects. We use this to update | 135 // A mapping from command ids to GtkMenuItem objects. We use this to update |
| 70 // the enable state since we are a . | 136 // the command enable state. |
| 71 IDMenuItemMap id_to_menu_item_; | 137 CommandIDMenuItemMap id_to_menu_item_; |
| 72 | 138 |
| 73 // gtk_check_menu_item_set_active() will call the "activate" signal. We need | 139 // gtk_check_menu_item_set_active() will call the "activate" signal. We need |
| 74 // to block this activation while we change the checked state. | 140 // to block this activation while we change the checked state. |
| 75 bool block_activation_; | 141 bool block_activation_; |
| 142 | |
| 143 // The history menu. We keep this since we need to rewrite parts of it | |
| 144 // periodically. | |
| 145 GtkWidget* history_menu_; | |
| 146 | |
| 147 TabRestoreService* tab_restore_service_; // weak | |
| 148 | |
| 149 // A mapping from GtkMenuItems to HistoryItems that maintain data. | |
| 150 MenuItemToHistoryMap menu_item_history_map_; | |
| 151 | |
| 152 // Maps HistoryItems to favicon request Handles. | |
| 153 CancelableRequestConsumerTSimple<HistoryItem*> favicon_consumer_; | |
| 76 }; | 154 }; |
| 77 | 155 |
| 78 #endif // CHROME_BROWSER_UI_GTK_GLOBAL_MENU_BAR_H_ | 156 #endif // CHROME_BROWSER_UI_GTK_GLOBAL_MENU_BAR_H_ |
| OLD | NEW |