diff options
author | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-23 19:53:23 +0000 |
---|---|---|
committer | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-23 19:53:23 +0000 |
commit | 7351bdb22c983770065aad6caaebbd49e9c31964 (patch) | |
tree | 9380eeb1a726b4c598c3664fa8ca594bec1162d2 | |
parent | 4a27569a34bcd476a834b54c4dac6a99bb402705 (diff) | |
download | chromium_src-7351bdb22c983770065aad6caaebbd49e9c31964.zip chromium_src-7351bdb22c983770065aad6caaebbd49e9c31964.tar.gz chromium_src-7351bdb22c983770065aad6caaebbd49e9c31964.tar.bz2 |
GTK: Take 2: Bring global menu out of about:flags.
This makes some substantial changes to
1) The ownership model needed to change slightly; Global{Bookmark,History}Menu needed to own its GtkMenu due to timing issues. (The other possible way to do this (use gtk_widget_destroyed to NULL out the reference) was discussed and rejected in a similar recent code review).
2) The first connection to the TabRestoreService needs to happen lazily. While this doesn't appear to have any affect during normal startup, it breaks the majority of browser, ui and unit tests that depend on the TabRestoreService because they all depend on controlling the loading state. We can't use the OnShow/PostTask method (see previous CL) so connect to the GtkMenuItem's activate signal.
BUG=30213
TEST=ui_tests and browser_tests pass
Review URL: http://codereview.chromium.org/7017028
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86328 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/app/generated_resources.grd | 6 | ||||
-rw-r--r-- | chrome/browser/about_flags.cc | 9 | ||||
-rw-r--r-- | chrome/browser/ui/gtk/browser_window_gtk.cc | 6 | ||||
-rw-r--r-- | chrome/browser/ui/gtk/global_bookmark_menu.cc | 17 | ||||
-rw-r--r-- | chrome/browser/ui/gtk/global_bookmark_menu.h | 9 | ||||
-rw-r--r-- | chrome/browser/ui/gtk/global_history_menu.cc | 58 | ||||
-rw-r--r-- | chrome/browser/ui/gtk/global_history_menu.h | 27 | ||||
-rw-r--r-- | chrome/browser/ui/gtk/global_menu_bar.cc | 44 | ||||
-rw-r--r-- | chrome/browser/ui/gtk/global_menu_bar.h | 8 | ||||
-rw-r--r-- | chrome/browser/ui/gtk/global_menu_owner.h | 21 | ||||
-rw-r--r-- | chrome/common/chrome_switches.cc | 5 | ||||
-rw-r--r-- | chrome/common/chrome_switches.h | 4 |
12 files changed, 114 insertions, 100 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index ae3d2fb..5ca1ba4 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -4248,12 +4248,6 @@ Keep your key file in a safe place. You will need it to create new versions of y <message name="IDS_FLAGS_PPAPI_FLASH_IN_PROCESS_DESCRIPTION" desc="Description for the flag to run the custom flash in-process"> If the PPAPI version of Flash is in use, run it in each renderer process rather than in a dedicated plugin process. </message> - <message name="IDS_FLAGS_LINUX_GLOBAL_MENUBAR_NAME" desc="Title for the flag to show a global menu bar on linux."> - Experimental GNOME menu bar support. - </message> - <message name="IDS_FLAGS_LINUX_GLOBAL_MENUBAR_DESCRIPTION" desc="Description for the flag to show a global menu bar on linux."> - Newer versions of Unity and GNOME (including the upcoming Ubuntu Natty Narwhal) show an OSX style menubar across the top of the screen. - </message> <message name="IDS_FLAGS_ENABLE_VPN_NAME" desc="Title for the flag to enable VPN support"> VPN support </message> diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc index 827a6fe..fe4a613 100644 --- a/chrome/browser/about_flags.cc +++ b/chrome/browser/about_flags.cc @@ -290,15 +290,6 @@ const Experiment kExperiments[] = { kOsAll, SINGLE_VALUE_TYPE(switches::kPpapiFlashInProcess) }, -#if defined(TOOLKIT_GTK) - { - "global-gnome-menu", - IDS_FLAGS_LINUX_GLOBAL_MENUBAR_NAME, - IDS_FLAGS_LINUX_GLOBAL_MENUBAR_DESCRIPTION, - kOsLinux, - SINGLE_VALUE_TYPE(switches::kGlobalGnomeMenu) - }, -#endif { "enable-vpn", IDS_FLAGS_ENABLE_VPN_NAME, diff --git a/chrome/browser/ui/gtk/browser_window_gtk.cc b/chrome/browser/ui/gtk/browser_window_gtk.cc index cdb8b01..ff48ba5 100644 --- a/chrome/browser/ui/gtk/browser_window_gtk.cc +++ b/chrome/browser/ui/gtk/browser_window_gtk.cc @@ -1611,10 +1611,8 @@ void BrowserWindowGtk::InitWidgets() { // fool the Unity desktop, which will mirror the contents of the first // GtkMenuBar it sees into the global menu bar. (It doesn't seem to check the // visibility of the GtkMenuBar, so we can just permanently hide it.) - if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kGlobalGnomeMenu)) { - global_menu_bar_.reset(new GlobalMenuBar(browser_.get())); - gtk_container_add(GTK_CONTAINER(window_vbox_), global_menu_bar_->widget()); - } + global_menu_bar_.reset(new GlobalMenuBar(browser_.get())); + gtk_container_add(GTK_CONTAINER(window_vbox_), global_menu_bar_->widget()); // The window container draws the custom browser frame. window_container_ = gtk_alignment_new(0.0, 0.0, 1.0, 1.0); diff --git a/chrome/browser/ui/gtk/global_bookmark_menu.cc b/chrome/browser/ui/gtk/global_bookmark_menu.cc index 5fc74ce..0003883 100644 --- a/chrome/browser/ui/gtk/global_bookmark_menu.cc +++ b/chrome/browser/ui/gtk/global_bookmark_menu.cc @@ -68,8 +68,9 @@ GlobalBookmarkMenu::~GlobalBookmarkMenu() { profile_->GetBookmarkModel()->RemoveObserver(this); } -void GlobalBookmarkMenu::Init(GtkWidget* bookmark_menu) { - bookmark_menu_ = bookmark_menu; +void GlobalBookmarkMenu::Init(GtkWidget* bookmark_menu, + GtkWidget* bookmark_menu_item) { + bookmark_menu_.Own(bookmark_menu); EnsureMenuItemFunctions(); if (gtk_menu_item_set_label_sym) { @@ -88,8 +89,6 @@ void GlobalBookmarkMenu::RebuildMenuInFuture() { } void GlobalBookmarkMenu::RebuildMenu() { - - BookmarkModel* model = profile_->GetBookmarkModel(); DCHECK(model); DCHECK(model->IsLoaded()); @@ -98,8 +97,8 @@ void GlobalBookmarkMenu::RebuildMenu() { const BookmarkNode* bar_node = model->GetBookmarkBarNode(); if (bar_node->child_count()) { - AddBookmarkMenuItem(bookmark_menu_, gtk_separator_menu_item_new()); - AddNodeToMenu(bar_node, bookmark_menu_); + AddBookmarkMenuItem(bookmark_menu_.get(), gtk_separator_menu_item_new()); + AddNodeToMenu(bar_node, bookmark_menu_.get()); } // Only display the other bookmarks folder in the menu if it has items in it. @@ -108,7 +107,7 @@ void GlobalBookmarkMenu::RebuildMenu() { GtkWidget* submenu = gtk_menu_new(); AddNodeToMenu(other_node, submenu); - AddBookmarkMenuItem(bookmark_menu_, gtk_separator_menu_item_new()); + AddBookmarkMenuItem(bookmark_menu_.get(), gtk_separator_menu_item_new()); GtkWidget* menu_item = gtk_image_menu_item_new_with_label( l10n_util::GetStringUTF8(IDS_BOOMARK_BAR_OTHER_FOLDER_NAME).c_str()); @@ -117,7 +116,7 @@ void GlobalBookmarkMenu::RebuildMenu() { GTK_IMAGE_MENU_ITEM(menu_item), gtk_image_new_from_pixbuf(default_folder_)); - AddBookmarkMenuItem(bookmark_menu_, menu_item); + AddBookmarkMenuItem(bookmark_menu_.get(), menu_item); } } @@ -205,7 +204,7 @@ GtkWidget* GlobalBookmarkMenu::MenuItemForNode(const BookmarkNode* node) { void GlobalBookmarkMenu::ClearBookmarkMenu() { bookmark_nodes_.clear(); - gtk_container_foreach(GTK_CONTAINER(bookmark_menu_), + gtk_container_foreach(GTK_CONTAINER(bookmark_menu_.get()), &ClearBookmarkItemCallback, NULL); } diff --git a/chrome/browser/ui/gtk/global_bookmark_menu.h b/chrome/browser/ui/gtk/global_bookmark_menu.h index 0874243..eae9e0b 100644 --- a/chrome/browser/ui/gtk/global_bookmark_menu.h +++ b/chrome/browser/ui/gtk/global_bookmark_menu.h @@ -10,6 +10,8 @@ #include "base/compiler_specific.h" #include "base/task.h" #include "chrome/browser/bookmarks/bookmark_model_observer.h" +#include "chrome/browser/ui/gtk/global_menu_owner.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" @@ -28,14 +30,15 @@ typedef struct _GtkWidget GtkWidget; // need to update the menu in the background (instead of building it on showing // and not updating it if the model changes). I'm not even thinking about // making these draggable since these items aren't displayed in our process. -class GlobalBookmarkMenu : public NotificationObserver, +class GlobalBookmarkMenu : public GlobalMenuOwner, + public NotificationObserver, public BookmarkModelObserver { public: explicit GlobalBookmarkMenu(Browser* browser); virtual ~GlobalBookmarkMenu(); // Takes the bookmark menu we need to modify based on bookmark state. - void Init(GtkWidget* bookmark_menu); + virtual void Init(GtkWidget* bookmark_menu, GtkWidget* bookmark_menu_item); private: // Schedules the menu to be rebuilt. The mac version sets a boolean and @@ -111,7 +114,7 @@ class GlobalBookmarkMenu : public NotificationObserver, GdkPixbuf* default_favicon_; GdkPixbuf* default_folder_; - GtkWidget* bookmark_menu_; + OwnedWidgetGtk bookmark_menu_; // We use this factory to create callback tasks for ThreadWatcher object. We // use this during ping-pong messaging between WatchDog thread and watched diff --git a/chrome/browser/ui/gtk/global_history_menu.cc b/chrome/browser/ui/gtk/global_history_menu.cc index 119e8c7..d579448 100644 --- a/chrome/browser/ui/gtk/global_history_menu.cc +++ b/chrome/browser/ui/gtk/global_history_menu.cc @@ -113,8 +113,15 @@ GlobalHistoryMenu::~GlobalHistoryMenu() { menu_item_history_map_.clear(); } -void GlobalHistoryMenu::Init(GtkWidget* history_menu) { - history_menu_ = history_menu; +void GlobalHistoryMenu::Init(GtkWidget* history_menu, + GtkWidget* history_menu_item) { + history_menu_.Own(history_menu); + + // We have to connect to |history_menu_item|'s "activate" signal instead of + // |history_menu|'s "show" signal because we are not supposed to modify the + // menu during "show" + g_signal_connect(history_menu_item, "activate", + G_CALLBACK(OnMenuActivateThunk), this); default_favicon_ = GtkThemeService::GetDefaultFavicon(true); @@ -129,17 +136,6 @@ void GlobalHistoryMenu::Init(GtkWidget* history_menu) { Source<history::TopSites>(top_sites_)); } - tab_restore_service_ = TabRestoreServiceFactory::GetForProfile(profile_); - if (tab_restore_service_) { - tab_restore_service_->LoadTabsFromLastSession(); - tab_restore_service_->AddObserver(this); - - // If LoadTabsFromLastSession doesn't load tabs, it won't call - // TabRestoreServiceChanged(). This ensures that all new windows after - // the first one will have their menus populated correctly. - TabRestoreServiceChanged(tab_restore_service_); - } - registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, Source<Profile>(profile_)); } @@ -155,10 +151,10 @@ void GlobalHistoryMenu::GetTopSitesData() { void GlobalHistoryMenu::OnTopSitesReceived( const history::MostVisitedURLList& visited_list) { - ClearMenuSection(history_menu_, GlobalMenuBar::TAG_MOST_VISITED); + ClearMenuSection(history_menu_.get(), GlobalMenuBar::TAG_MOST_VISITED); int index = GetIndexOfMenuItemWithTag( - history_menu_, + history_menu_.get(), GlobalMenuBar::TAG_MOST_VISITED_HEADER) + 1; for (size_t i = 0; i < visited_list.size() && i < kMostVisitedCount; ++i) { @@ -170,12 +166,12 @@ void GlobalHistoryMenu::OnTopSitesReceived( item->title = visited.title; item->url = visited.url; - // The TopSites system doesn't give us icons; it gives us chrome:// urls to - // icons so fetch the icons normally. + // The TopSites system doesn't give us icons; it gives us chrome:// urls + // to icons so fetch the icons normally. GetFaviconForHistoryItem(item); AddHistoryItemToMenu(item, - history_menu_, + history_menu_.get(), GlobalMenuBar::TAG_MOST_VISITED, index++); } @@ -375,7 +371,8 @@ void GlobalHistoryMenu::Observe(NotificationType type, // we'll update on the next menu change event. default_favicon_ = GtkThemeService::GetDefaultFavicon(true); } else if (type.value == NotificationType::TOP_SITES_CHANGED) { - GetTopSitesData(); + if (Source<history::TopSites>(source).ptr() == top_sites_) + GetTopSitesData(); } else { NOTREACHED(); } @@ -384,12 +381,12 @@ void GlobalHistoryMenu::Observe(NotificationType type, void GlobalHistoryMenu::TabRestoreServiceChanged(TabRestoreService* service) { const TabRestoreService::Entries& entries = service->entries(); - ClearMenuSection(history_menu_, GlobalMenuBar::TAG_RECENTLY_CLOSED); + ClearMenuSection(history_menu_.get(), GlobalMenuBar::TAG_RECENTLY_CLOSED); // We'll get the index the "Recently Closed" header. (This can vary depending // on the number of "Most Visited" items. int index = GetIndexOfMenuItemWithTag( - history_menu_, + history_menu_.get(), GlobalMenuBar::TAG_RECENTLY_CLOSED_HEADER) + 1; unsigned int added_count = 0; @@ -477,7 +474,7 @@ void GlobalHistoryMenu::TabRestoreServiceChanged(TabRestoreService* service) { GINT_TO_POINTER(GlobalMenuBar::TAG_RECENTLY_CLOSED)); gtk_menu_item_set_submenu(GTK_MENU_ITEM(parent_item), submenu); - gtk_menu_shell_insert(GTK_MENU_SHELL(history_menu_), parent_item, + gtk_menu_shell_insert(GTK_MENU_SHELL(history_menu_.get()), parent_item, index++); ++added_count; } else if (entry->type == TabRestoreService::TAB) { @@ -486,7 +483,7 @@ void GlobalHistoryMenu::TabRestoreServiceChanged(TabRestoreService* service) { HistoryItem* item = HistoryItemForTab(*tab); if (item) { AddHistoryItemToMenu(item, - history_menu_, + history_menu_.get(), GlobalMenuBar::TAG_RECENTLY_CLOSED, index++); ++added_count; @@ -518,3 +515,18 @@ void GlobalHistoryMenu::OnRecentlyClosedItemActivated(GtkWidget* sender) { PageTransition::AUTO_BOOKMARK); } } + +void GlobalHistoryMenu::OnMenuActivate(GtkWidget* sender) { + if (!tab_restore_service_) { + tab_restore_service_ = TabRestoreServiceFactory::GetForProfile(profile_); + if (tab_restore_service_) { + tab_restore_service_->LoadTabsFromLastSession(); + tab_restore_service_->AddObserver(this); + + // If LoadTabsFromLastSession doesn't load tabs, it won't call + // TabRestoreServiceChanged(). This ensures that all new windows after + // the first one will have their menus populated correctly. + TabRestoreServiceChanged(tab_restore_service_); + } + } +} diff --git a/chrome/browser/ui/gtk/global_history_menu.h b/chrome/browser/ui/gtk/global_history_menu.h index ca2d1e1..0959fc2 100644 --- a/chrome/browser/ui/gtk/global_history_menu.h +++ b/chrome/browser/ui/gtk/global_history_menu.h @@ -11,6 +11,8 @@ #include "chrome/browser/history/history_types.h" #include "chrome/browser/sessions/tab_restore_service.h" #include "chrome/browser/sessions/tab_restore_service_observer.h" +#include "chrome/browser/ui/gtk/global_menu_owner.h" +#include "chrome/browser/ui/gtk/owned_widget_gtk.h" #include "content/browser/cancelable_request.h" #include "content/common/notification_observer.h" #include "content/common/notification_registrar.h" @@ -25,7 +27,8 @@ class TopSites; typedef struct _GdkPixbuf GdkPixbuf; // Controls the History menu. -class GlobalHistoryMenu : public NotificationObserver, +class GlobalHistoryMenu : public GlobalMenuOwner, + public NotificationObserver, public TabRestoreServiceObserver { public: explicit GlobalHistoryMenu(Browser* browser); @@ -33,7 +36,7 @@ class GlobalHistoryMenu : public NotificationObserver, // Takes the history menu we need to modify based on the tab restore/most // visited state. - void Init(GtkWidget* history_menu); + virtual void Init(GtkWidget* history_menu, GtkWidget* history_menu_item); private: class HistoryItem; @@ -100,20 +103,26 @@ class GlobalHistoryMenu : public NotificationObserver, CHROMEGTK_CALLBACK_0(GlobalHistoryMenu, void, OnRecentlyClosedItemActivated); + // Listen for the first menu show command so we can then connect to the + // TabRestoreService. With how the global menus work, I'd prefer to register + // with the TabRestoreService as soon as we're constructed, but this breaks + // unit tests which test the service (because they force different + // construction ordering while us connecting to the TabRestoreService loads + // data now!) + CHROMEGTK_CALLBACK_0(GlobalHistoryMenu, void, OnMenuActivate); + Browser* browser_; Profile* profile_; + // The history menu. We keep this since we need to rewrite parts of it + // periodically. + OwnedWidgetGtk history_menu_; + history::TopSites* top_sites_; CancelableRequestConsumer top_sites_consumer_; - NotificationRegistrar registrar_; - GdkPixbuf* default_favicon_; - // 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. @@ -121,6 +130,8 @@ class GlobalHistoryMenu : public NotificationObserver, // Maps HistoryItems to favicon request Handles. CancelableRequestConsumerTSimple<HistoryItem*> favicon_consumer_; + + NotificationRegistrar registrar_; }; #endif // CHROME_BROWSER_UI_GTK_GLOBAL_HISTORY_MENU_H_ diff --git a/chrome/browser/ui/gtk/global_menu_bar.cc b/chrome/browser/ui/gtk/global_menu_bar.cc index 6e6f9fd..76ac9ba 100644 --- a/chrome/browser/ui/gtk/global_menu_bar.cc +++ b/chrome/browser/ui/gtk/global_menu_bar.cc @@ -56,24 +56,13 @@ GlobalMenuBarCommand file_menu[] = { { MENU_END, MENU_END } }; -// TODO(erg): Need to add support for undo/redo/other editing commands that -// don't go through the command id framework. GlobalMenuBarCommand edit_menu[] = { - // TODO(erg): Undo - // TODO(erg): Redo - - // TODO(erg): Separator - { IDS_CUT, IDC_CUT }, { IDS_COPY, IDC_COPY }, { IDS_PASTE, IDC_PASTE }, - // TODO(erg): Delete { MENU_SEPARATOR, MENU_SEPARATOR }, - // TODO(erg): Select All - // TODO(erg): Another separator - { IDS_FIND, IDC_FIND }, { MENU_SEPARATOR, MENU_SEPARATOR }, @@ -83,8 +72,6 @@ GlobalMenuBarCommand edit_menu[] = { { MENU_END, MENU_END } }; -// TODO(erg): The View menu should be overhauled and based on the Firefox view -// menu. GlobalMenuBarCommand view_menu[] = { { IDS_SHOW_BOOKMARK_BAR, IDC_SHOW_BOOKMARK_BAR }, @@ -176,15 +163,15 @@ GlobalMenuBar::GlobalMenuBar(Browser* browser) // Set a nice name so it shows up in gtkparasite and others. gtk_widget_set_name(menu_bar_.get(), "chrome-hidden-global-menubar"); - BuildGtkMenuFrom(IDS_FILE_MENU_LINUX, &id_to_menu_item_, file_menu); - BuildGtkMenuFrom(IDS_EDIT_MENU_LINUX, &id_to_menu_item_, edit_menu); - BuildGtkMenuFrom(IDS_VIEW_MENU_LINUX, &id_to_menu_item_, view_menu); - history_menu_.Init(BuildGtkMenuFrom(IDS_HISTORY_MENU_LINUX, &id_to_menu_item_, - history_menu)); - bookmark_menu_.Init(BuildGtkMenuFrom(IDS_BOOKMARKS_MENU_LINUX, - &id_to_menu_item_, bookmark_menu)); - BuildGtkMenuFrom(IDS_TOOLS_MENU_LINUX, &id_to_menu_item_, tools_menu); - BuildGtkMenuFrom(IDS_HELP_MENU_LINUX, &id_to_menu_item_, help_menu); + BuildGtkMenuFrom(IDS_FILE_MENU_LINUX, &id_to_menu_item_, file_menu, NULL); + BuildGtkMenuFrom(IDS_EDIT_MENU_LINUX, &id_to_menu_item_, edit_menu, NULL); + BuildGtkMenuFrom(IDS_VIEW_MENU_LINUX, &id_to_menu_item_, view_menu, NULL); + BuildGtkMenuFrom(IDS_HISTORY_MENU_LINUX, &id_to_menu_item_, + history_menu, &history_menu_); + BuildGtkMenuFrom(IDS_BOOKMARKS_MENU_LINUX, &id_to_menu_item_, bookmark_menu, + &bookmark_menu_); + BuildGtkMenuFrom(IDS_TOOLS_MENU_LINUX, &id_to_menu_item_, tools_menu, NULL); + BuildGtkMenuFrom(IDS_HELP_MENU_LINUX, &id_to_menu_item_, help_menu, NULL); for (CommandIDMenuItemMap::const_iterator it = id_to_menu_item_.begin(); it != id_to_menu_item_.end(); ++it) { @@ -226,10 +213,11 @@ GlobalMenuBar::~GlobalMenuBar() { g_object_unref(dummy_accel_group_); } -GtkWidget* GlobalMenuBar::BuildGtkMenuFrom( +void GlobalMenuBar::BuildGtkMenuFrom( int menu_str_id, std::map<int, GtkWidget*>* id_to_menu_item, - GlobalMenuBarCommand* commands) { + GlobalMenuBarCommand* commands, + GlobalMenuOwner* owner) { GtkWidget* menu = gtk_menu_new(); for (int i = 0; commands[i].str_id != MENU_END; ++i) { GtkWidget* menu_item = BuildMenuItem( @@ -243,11 +231,15 @@ GtkWidget* GlobalMenuBar::BuildGtkMenuFrom( GtkWidget* menu_item = gtk_menu_item_new_with_mnemonic( gfx::ConvertAcceleratorsFromWindowsStyle( l10n_util::GetStringUTF8(menu_str_id)).c_str()); + + // Give the owner a chance to sink the reference before we add it to the menu + // bar. + if (owner) + owner->Init(menu, menu_item); + gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu_item), menu); gtk_widget_show(menu_item); gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar_.get()), menu_item); - - return menu; } GtkWidget* GlobalMenuBar::BuildMenuItem( diff --git a/chrome/browser/ui/gtk/global_menu_bar.h b/chrome/browser/ui/gtk/global_menu_bar.h index 1364e51..b375e57 100644 --- a/chrome/browser/ui/gtk/global_menu_bar.h +++ b/chrome/browser/ui/gtk/global_menu_bar.h @@ -17,6 +17,7 @@ class Browser; struct GlobalMenuBarCommand; +class GlobalMenuOwner; typedef struct _GtkAccelGroup GtkAccelGroup; typedef struct _GtkWidget GtkWidget; @@ -48,9 +49,10 @@ class GlobalMenuBar : public CommandUpdater::CommandObserver, typedef std::map<int, GtkWidget*> CommandIDMenuItemMap; // Helper function that builds the data. - GtkWidget* BuildGtkMenuFrom(int menu_str_id, - std::map<int, GtkWidget*>* id_to_menu_item, - GlobalMenuBarCommand* commands); + void BuildGtkMenuFrom(int menu_str_id, + std::map<int, GtkWidget*>* id_to_menu_item, + GlobalMenuBarCommand* commands, + GlobalMenuOwner* owner); // Builds an individual menu item. GtkWidget* BuildMenuItem(int string_id, diff --git a/chrome/browser/ui/gtk/global_menu_owner.h b/chrome/browser/ui/gtk/global_menu_owner.h new file mode 100644 index 0000000..8594f79 --- /dev/null +++ b/chrome/browser/ui/gtk/global_menu_owner.h @@ -0,0 +1,21 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_UI_GTK_GLOBAL_MENU_OWNER_H_ +#define CHROME_BROWSER_UI_GTK_GLOBAL_MENU_OWNER_H_ + +typedef struct _GtkWidget GtkWidget; + +// A simple interface that states that this class will own the Init-ed GtkMenu*. +class GlobalMenuOwner { + public: + virtual ~GlobalMenuOwner() {} + + // Should take OwnedWidgetship of |menu|. |menu_item| is passed in for + // convenience since some some subclasses will want to listen to signals on + // that. + virtual void Init(GtkWidget* menu, GtkWidget* menu_item) = 0; +}; + +#endif // CHROME_BROWSER_UI_GTK_GLOBAL_MENU_OWNER_H_ diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc index 14765b8..d8ff05d 100644 --- a/chrome/common/chrome_switches.cc +++ b/chrome/common/chrome_switches.cc @@ -1132,11 +1132,6 @@ const char kEnableExposeForTabs[] = "enable-expose-for-tabs"; const char kKioskMode[] = "kiosk"; #endif -// Enables the experimental global gnome menu. -#if defined(TOOLKIT_GTK) -extern const char kGlobalGnomeMenu[] = "global-gnome-menu"; -#endif - // Enables debug paint in views framework. Enabling this causes the damaged // region being painted to flash in red. #if defined(TOOLKIT_VIEWS) diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h index f16581f..52b3055 100644 --- a/chrome/common/chrome_switches.h +++ b/chrome/common/chrome_switches.h @@ -328,10 +328,6 @@ extern const char kEnableExposeForTabs[]; extern const char kKioskMode[]; #endif -#if defined(TOOLKIT_GTK) -extern const char kGlobalGnomeMenu[]; -#endif - #if defined(TOOLKIT_VIEWS) extern const char kDebugViewsPaint[]; #endif |