Chromium Code Reviews| Index: chrome/browser/ui/gtk/gtk_menu_creator.h |
| diff --git a/chrome/browser/ui/gtk/gtk_menu_creator.h b/chrome/browser/ui/gtk/gtk_menu_creator.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..eb5c1a57fdc5d16bca592c8c99a6bde7b008f731 |
| --- /dev/null |
| +++ b/chrome/browser/ui/gtk/gtk_menu_creator.h |
| @@ -0,0 +1,81 @@ |
| +// 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_GTK_MENU_CREATOR_H_ |
| +#define CHROME_BROWSER_UI_GTK_GTK_MENU_CREATOR_H_ |
| + |
| +#include <string> |
| + |
| +class SkBitmap; |
| + |
| +namespace ui { |
| +class ButtonMenuItemModel; |
| +class MenuModel; |
| +} |
| + |
| +typedef struct _GtkAccelGroup GtkAccelGroup; |
| +typedef struct _GtkIconSet GtkIconSet; |
| +typedef struct _GtkWidget GtkWidget; |
| + |
| +// We have multiple places in the code that actually build menus and have |
|
Evan Stade
2011/04/25 20:08:22
can you make this comment more specific? e.g. give
|
| +// wildly different requirements. |
| +class GtkMenuCreator { |
| + public: |
| + class IconSource { |
| + public: |
| + virtual ~IconSource() {} |
| + |
| + // Return true if we should override the "gtk-menu-images" system setting |
| + // when showing image menu items for this menu. |
| + virtual bool AlwaysShowIconForCmd(int command_id) const; |
| + |
| + // Returns an icon for the menu item, if available. |
| + virtual GtkWidget* GetImageForCommandId(int command_id) const; |
| + |
| + // Returns a tinted image used in button in a menu. |
| + virtual GtkIconSet* GetIconSetForId(int idr); |
| + }; |
| + |
| + static GtkWidget* GetDefaultImageForCommandId(int command_id); |
| + |
| + protected: |
| + explicit GtkMenuCreator(IconSource* icon_source); |
| + virtual ~GtkMenuCreator(); |
| + |
| + // Creates the menu items specified in |model| and places them into |menu|. |
| + void BuildSubmenuFromModel(ui::MenuModel* model, GtkWidget* menu); |
| + |
| + // Builds a GtkImageMenuItem. |
| + GtkWidget* BuildMenuItemWithImage(const std::string& label, |
| + const SkBitmap& icon) const; |
| + |
| + GtkWidget* BuildMenuItemWithImage(const std::string& label, |
| + GtkWidget* image) const; |
| + |
| + GtkWidget* BuildMenuItemWithLabel(const std::string& label, |
| + int command_id) const; |
| + |
| + // Called to build one of our custom menu button items. Some menus we |
| + // construct can't support this type (due to tight integration with our |
| + // GtkCustomMenu); in that case always return NULL. |
| + virtual GtkWidget* BuildButtonMenuItem(ui::ButtonMenuItemModel* model, |
| + GtkWidget* menu) = 0; |
| + |
| + // Called after every |menu_item| created. It's this method's responsibility |
| + // to add the |menu_item| to |menu|, to hook up signals, etc. |
| + virtual GtkWidget* AppendMenuItemToMenu(int index, |
| + ui::MenuModel* model, |
| + GtkWidget* menu_item, |
| + GtkWidget* menu) = 0; |
| + |
| + private: |
| + IconSource* icon_source_; |
| + |
| + // 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 |
| + // to this group, but don't attach this group to any top level window. |
| + GtkAccelGroup* dummy_accel_group_; |
| +}; |
| + |
| +#endif // CHROME_BROWSER_UI_GTK_GTK_MENU_CREATOR_H_ |