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

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: Maybe abandoning this way 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 "chrome/browser/command_updater.h" 10 #include "chrome/browser/command_updater.h"
11 #include "chrome/browser/ui/gtk/global_history_menu.h"
12 #include "chrome/browser/ui/gtk/gtk_menu_creator.h"
13 #include "chrome/browser/ui/gtk/owned_widget_gtk.h"
11 #include "content/common/notification_observer.h" 14 #include "content/common/notification_observer.h"
12 #include "content/common/notification_registrar.h" 15 #include "content/common/notification_registrar.h"
16 #include "ui/base/models/simple_menu_model.h"
13 #include "ui/base/gtk/gtk_signal.h" 17 #include "ui/base/gtk/gtk_signal.h"
14 18
15 class Browser; 19 class Browser;
16 class BrowserWindowGtk;
17 struct GlobalMenuBarCommand; 20 struct GlobalMenuBarCommand;
18 21
19 typedef struct _GtkAccelGroup GtkAccelGroup; 22 typedef struct _GtkAccelGroup GtkAccelGroup;
20 typedef struct _GtkWidget GtkWidget; 23 typedef struct _GtkWidget GtkWidget;
21 24
22 // Controls the Mac style menu bar on Linux. 25 // Controls the Mac style menu bar on Linux.
23 // 26 //
24 // Unity and some configurations of GNOME have a Apple-like menu bar at the top 27 // 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 28 // of the screen that changes depending on the active window. These mainly work
26 // by inspecting the application's widget hierarchy, and intercepting any 29 // by inspecting the application's widget hierarchy, and intercepting any
27 // GtkMenuBar found. Thankfully, these systems don't check to see if the menu 30 // 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 31 // bar itself is visible, so we insert a GtkMenuBar into the window hierarchy
29 // and set it to be invisible. 32 // and set it to be invisible.
30 class GlobalMenuBar : public CommandUpdater::CommandObserver, 33 class GlobalMenuBar : public CommandUpdater::CommandObserver,
31 public NotificationObserver { 34 public NotificationObserver,
35 public GtkMenuCreator,
36 public GtkMenuCreator::IconSource,
37 public ui::SimpleMenuModel::Delegate {
32 public: 38 public:
33 GlobalMenuBar(Browser* browser, BrowserWindowGtk* window); 39 // Command IDs under 4000 are reserved for us.
40 static const int TAG_NORMAL = 0;
41 static const int TAG_MOST_VISITED = 1;
42 static const int TAG_RECENTLY_CLOSED = 2;
43 static const int TAG_MOST_VISITED_HEADER = 3;
44 static const int TAG_RECENTLY_CLOSED_HEADER = 4;
45
46 explicit GlobalMenuBar(Browser* browser);
34 virtual ~GlobalMenuBar(); 47 virtual ~GlobalMenuBar();
35 48
36 GtkWidget* widget() { return menu_bar_; } 49 GtkWidget* widget() { return menu_bar_.get(); }
37 50
38 private: 51 private:
39 typedef std::map<int, GtkWidget*> IDMenuItemMap; 52 typedef std::map<int, GtkWidget*> CommandIDMenuItemMap;
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 ui::MenuModel* model);
44 GlobalMenuBarCommand* commands); 57
58 // Builds an individual menu item.
59 GtkWidget* BuildMenuItem(int string_id,
60 int command_id,
61 int tag_id,
62 std::map<int, GtkWidget*>* id_to_menu_item,
63 GtkWidget* menu_to_add_to);
45 64
46 // CommandUpdater::CommandObserver: 65 // CommandUpdater::CommandObserver:
47 virtual void EnabledStateChangedForCommand(int id, bool enabled); 66 virtual void EnabledStateChangedForCommand(int id, bool enabled);
48 67
49 // NotificationObserver: 68 // NotificationObserver:
50 virtual void Observe(NotificationType type, 69 virtual void Observe(NotificationType type,
51 const NotificationSource& source, 70 const NotificationSource& source,
52 const NotificationDetails& details); 71 const NotificationDetails& details);
53 72
73 // MenuCreator:
74 virtual GtkWidget* BuildButtonMenuItem(ui::ButtonMenuItemModel* model,
75 GtkWidget* menu);
76 virtual GtkWidget* AppendMenuItemToMenu(int index,
77 ui::MenuModel* model,
78 GtkWidget* menu_item,
79 GtkWidget* menu);
80
81 // SimpleMenuModel::Delegate:
82 //
83 // We only implement enough of this interface to allow us to get accelerators
84 // into MenuCreator. We don't rely on the command dispatch capabilities.
85 virtual bool IsCommandIdChecked(int command_id) const;
86 virtual bool IsCommandIdEnabled(int command_id) const;
87 virtual bool GetAcceleratorForCommandId(
88 int command_id,
89 ui::Accelerator* accelerator);
90 virtual void ExecuteCommand(int command_id);
91
54 CHROMEGTK_CALLBACK_0(GlobalMenuBar, void, OnItemActivated); 92 CHROMEGTK_CALLBACK_0(GlobalMenuBar, void, OnItemActivated);
55 93
56 Browser* browser_; 94 Browser* browser_;
57 BrowserWindowGtk* browser_window_; 95 Profile* profile_;
58 96
59 NotificationRegistrar registrar_; 97 NotificationRegistrar registrar_;
60 98
61 // Our menu bar widget. 99 // Our menu bar widget.
62 GtkWidget* menu_bar_; 100 OwnedWidgetGtk menu_bar_;
63 101
64 // For some menu items, we want to show the accelerator, but not actually 102 // Listens to the TabRestoreService and the HistoryService and keeps the
65 // explicitly handle it. To this end we connect those menu items' accelerators 103 // history menu fresh.
66 // to this group, but don't attach this group to any top level window. 104 GlobalHistoryMenu history_menu_;
67 GtkAccelGroup* dummy_accel_group_;
68 105
69 // A mapping from command ids to GtkMenuItem objects. We use this to update 106 // A mapping from command ids to GtkMenuItem objects. We use this to update
70 // the enable state since we are a . 107 // the command enable state.
71 IDMenuItemMap id_to_menu_item_; 108 CommandIDMenuItemMap id_to_menu_item_;
72 109
73 // gtk_check_menu_item_set_active() will call the "activate" signal. We need 110 // gtk_check_menu_item_set_active() will call the "activate" signal. We need
74 // to block this activation while we change the checked state. 111 // to block this activation while we change the checked state.
75 bool block_activation_; 112 bool block_activation_;
76 }; 113 };
77 114
78 #endif // CHROME_BROWSER_UI_GTK_GLOBAL_MENU_BAR_H_ 115 #endif // CHROME_BROWSER_UI_GTK_GLOBAL_MENU_BAR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698