OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_UI_GTK_GLOBAL_MENU_BAR_H_ |
| 6 #define CHROME_BROWSER_UI_GTK_GLOBAL_MENU_BAR_H_ |
| 7 |
| 8 #include <map> |
| 9 |
| 10 #include "chrome/browser/command_updater.h" |
| 11 #include "content/common/notification_observer.h" |
| 12 #include "content/common/notification_registrar.h" |
| 13 #include "ui/base/gtk/gtk_signal.h" |
| 14 |
| 15 class Browser; |
| 16 class BrowserWindowGtk; |
| 17 struct GlobalMenuBarCommand; |
| 18 |
| 19 typedef struct _GtkAccelGroup GtkAccelGroup; |
| 20 typedef struct _GtkWidget GtkWidget; |
| 21 |
| 22 // Controls the Mac style menu bar on Linux. |
| 23 // |
| 24 // 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 |
| 26 // by inspecting the application's widget hierarchy, and intercepting any |
| 27 // 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 |
| 29 // and set it to be invisible. |
| 30 class GlobalMenuBar : public CommandUpdater::CommandObserver, |
| 31 public NotificationObserver { |
| 32 public: |
| 33 GlobalMenuBar(Browser* browser, BrowserWindowGtk* window); |
| 34 virtual ~GlobalMenuBar(); |
| 35 |
| 36 GtkWidget* widget() { return menu_bar_; } |
| 37 |
| 38 private: |
| 39 typedef std::map<int, GtkWidget*> IDMenuItemMap; |
| 40 |
| 41 // Helper function that builds the data. |
| 42 void BuildGtkMenuFrom(int menu_str_id, |
| 43 std::map<int, GtkWidget*>* id_to_menu_item, |
| 44 GlobalMenuBarCommand* commands); |
| 45 |
| 46 // CommandUpdater::CommandObserver: |
| 47 virtual void EnabledStateChangedForCommand(int id, bool enabled); |
| 48 |
| 49 // NotificationObserver: |
| 50 virtual void Observe(NotificationType type, |
| 51 const NotificationSource& source, |
| 52 const NotificationDetails& details); |
| 53 |
| 54 CHROMEGTK_CALLBACK_0(GlobalMenuBar, void, OnItemActivated); |
| 55 |
| 56 Browser* browser_; |
| 57 BrowserWindowGtk* browser_window_; |
| 58 |
| 59 NotificationRegistrar registrar_; |
| 60 |
| 61 // Our menu bar widget. |
| 62 GtkWidget* menu_bar_; |
| 63 |
| 64 // 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 |
| 66 // to this group, but don't attach this group to any top level window. |
| 67 GtkAccelGroup* dummy_accel_group_; |
| 68 |
| 69 // A mapping from command ids to GtkMenuItem objects. We use this to update |
| 70 // the enable state since we are a . |
| 71 IDMenuItemMap id_to_menu_item_; |
| 72 |
| 73 // gtk_check_menu_item_set_active() will call the "activate" signal. We need |
| 74 // to block this activation while we change the checked state. |
| 75 bool block_activation_; |
| 76 }; |
| 77 |
| 78 #endif // CHROME_BROWSER_UI_GTK_GLOBAL_MENU_BAR_H_ |
OLD | NEW |