| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_MENU_GTK_H_ | 5 #ifndef CHROME_BROWSER_UI_GTK_MENU_GTK_H_ |
| 6 #define CHROME_BROWSER_UI_GTK_MENU_GTK_H_ | 6 #define CHROME_BROWSER_UI_GTK_MENU_GTK_H_ |
| 7 | 7 |
| 8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "ui/base/gtk/gtk_signal.h" | 14 #include "ui/base/gtk/gtk_signal.h" |
| 15 #include "ui/base/gtk/gtk_signal_registrar.h" | 15 #include "ui/base/gtk/gtk_signal_registrar.h" |
| 16 #include "ui/gfx/point.h" | 16 #include "ui/gfx/point.h" |
| 17 | 17 |
| 18 class SkBitmap; | 18 namespace gfx { |
| 19 class Image; |
| 20 } |
| 19 | 21 |
| 20 namespace ui { | 22 namespace ui { |
| 21 class ButtonMenuItemModel; | 23 class ButtonMenuItemModel; |
| 22 class MenuModel; | 24 class MenuModel; |
| 23 } | 25 } |
| 24 | 26 |
| 25 class MenuGtk { | 27 class MenuGtk { |
| 26 public: | 28 public: |
| 27 // Delegate class that lets another class control the status of the menu. | 29 // Delegate class that lets another class control the status of the menu. |
| 28 class Delegate { | 30 class Delegate { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 57 MenuGtk(MenuGtk::Delegate* delegate, ui::MenuModel* model); | 59 MenuGtk(MenuGtk::Delegate* delegate, ui::MenuModel* model); |
| 58 virtual ~MenuGtk(); | 60 virtual ~MenuGtk(); |
| 59 | 61 |
| 60 // Initialize GTK signal handlers. | 62 // Initialize GTK signal handlers. |
| 61 void ConnectSignalHandlers(); | 63 void ConnectSignalHandlers(); |
| 62 | 64 |
| 63 // These methods are used to build the menu dynamically. The return value | 65 // These methods are used to build the menu dynamically. The return value |
| 64 // is the new menu item. | 66 // is the new menu item. |
| 65 GtkWidget* AppendMenuItemWithLabel(int command_id, const std::string& label); | 67 GtkWidget* AppendMenuItemWithLabel(int command_id, const std::string& label); |
| 66 GtkWidget* AppendMenuItemWithIcon(int command_id, const std::string& label, | 68 GtkWidget* AppendMenuItemWithIcon(int command_id, const std::string& label, |
| 67 const SkBitmap& icon); | 69 const gfx::Image& icon); |
| 68 GtkWidget* AppendCheckMenuItemWithLabel(int command_id, | 70 GtkWidget* AppendCheckMenuItemWithLabel(int command_id, |
| 69 const std::string& label); | 71 const std::string& label); |
| 70 GtkWidget* AppendSeparator(); | 72 GtkWidget* AppendSeparator(); |
| 71 GtkWidget* AppendMenuItem(int command_id, GtkWidget* menu_item); | 73 GtkWidget* AppendMenuItem(int command_id, GtkWidget* menu_item); |
| 72 GtkWidget* AppendMenuItemToMenu(int index, | 74 GtkWidget* AppendMenuItemToMenu(int index, |
| 73 ui::MenuModel* model, | 75 ui::MenuModel* model, |
| 74 GtkWidget* menu_item, | 76 GtkWidget* menu_item, |
| 75 GtkWidget* menu, | 77 GtkWidget* menu, |
| 76 bool connect_to_activate); | 78 bool connect_to_activate); |
| 77 | 79 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 gpointer userdata); | 120 gpointer userdata); |
| 119 | 121 |
| 120 GtkWidget* widget() const { return menu_; } | 122 GtkWidget* widget() const { return menu_; } |
| 121 | 123 |
| 122 // Updates all the enabled/checked states and the dynamic labels. | 124 // Updates all the enabled/checked states and the dynamic labels. |
| 123 void UpdateMenu(); | 125 void UpdateMenu(); |
| 124 | 126 |
| 125 private: | 127 private: |
| 126 // Builds a GtkImageMenuItem. | 128 // Builds a GtkImageMenuItem. |
| 127 GtkWidget* BuildMenuItemWithImage(const std::string& label, | 129 GtkWidget* BuildMenuItemWithImage(const std::string& label, |
| 128 const SkBitmap& icon); | 130 const gfx::Image& icon); |
| 129 | 131 |
| 130 GtkWidget* BuildMenuItemWithImage(const std::string& label, | 132 GtkWidget* BuildMenuItemWithImage(const std::string& label, |
| 131 GtkWidget* image); | 133 GtkWidget* image); |
| 132 | 134 |
| 133 GtkWidget* BuildMenuItemWithLabel(const std::string& label, | 135 GtkWidget* BuildMenuItemWithLabel(const std::string& label, |
| 134 int command_id); | 136 int command_id); |
| 135 | 137 |
| 136 // A function that creates a GtkMenu from |model_|. | 138 // A function that creates a GtkMenu from |model_|. |
| 137 void BuildMenuFromModel(); | 139 void BuildMenuFromModel(); |
| 138 // Implementation of the above; called recursively. | 140 // Implementation of the above; called recursively. |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 // menu items from getting activated when we are setting up the | 201 // menu items from getting activated when we are setting up the |
| 200 // menu. | 202 // menu. |
| 201 static bool block_activation_; | 203 static bool block_activation_; |
| 202 | 204 |
| 203 ui::GtkSignalRegistrar signal_; | 205 ui::GtkSignalRegistrar signal_; |
| 204 | 206 |
| 205 base::WeakPtrFactory<MenuGtk> weak_factory_; | 207 base::WeakPtrFactory<MenuGtk> weak_factory_; |
| 206 }; | 208 }; |
| 207 | 209 |
| 208 #endif // CHROME_BROWSER_UI_GTK_MENU_GTK_H_ | 210 #endif // CHROME_BROWSER_UI_GTK_MENU_GTK_H_ |
| OLD | NEW |