| OLD | NEW |
| 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_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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <gtk/gtk.h> | 9 #include <gtk/gtk.h> |
| 10 | 10 |
| 11 #include <string> | 11 #include <string> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/task.h" | 14 #include "base/task.h" |
| 15 #include "ui/base/gtk/gtk_signal.h" | 15 #include "ui/base/gtk/gtk_signal.h" |
| 16 #include "ui/base/models/menu_model.h" |
| 16 #include "ui/gfx/point.h" | 17 #include "ui/gfx/point.h" |
| 17 | 18 |
| 18 class SkBitmap; | 19 class SkBitmap; |
| 19 | 20 |
| 20 namespace ui { | 21 namespace ui { |
| 21 class ButtonMenuItemModel; | 22 class ButtonMenuItemModel; |
| 22 class MenuModel; | |
| 23 } | 23 } |
| 24 | 24 |
| 25 class MenuGtk { | 25 class MenuGtk : public ui::MenuModelDelegate { |
| 26 public: | 26 public: |
| 27 // Delegate class that lets another class control the status of the menu. | 27 // Delegate class that lets another class control the status of the menu. |
| 28 class Delegate { | 28 class Delegate { |
| 29 public: | 29 public: |
| 30 virtual ~Delegate() { } | 30 virtual ~Delegate() { } |
| 31 | 31 |
| 32 // Called before a command is executed. This exists for the case where a | 32 // Called before a command is executed. This exists for the case where a |
| 33 // model is handling the actual execution of commands, but the delegate | 33 // model is handling the actual execution of commands, but the delegate |
| 34 // still needs to know that some command got executed. This is called before | 34 // still needs to know that some command got executed. This is called before |
| 35 // and not after the command is executed because its execution may delete | 35 // and not after the command is executed because its execution may delete |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 void PopupAsContextForStatusIcon(guint32 event_time, guint32 button, | 91 void PopupAsContextForStatusIcon(guint32 event_time, guint32 button, |
| 92 GtkStatusIcon* icon); | 92 GtkStatusIcon* icon); |
| 93 | 93 |
| 94 // Displays the menu following a keyboard event (such as selecting |widget| | 94 // Displays the menu following a keyboard event (such as selecting |widget| |
| 95 // and pressing "enter"). | 95 // and pressing "enter"). |
| 96 void PopupAsFromKeyEvent(GtkWidget* widget); | 96 void PopupAsFromKeyEvent(GtkWidget* widget); |
| 97 | 97 |
| 98 // Closes the menu. | 98 // Closes the menu. |
| 99 void Cancel(); | 99 void Cancel(); |
| 100 | 100 |
| 101 // From ui::MenuModelDelegate, called when a favicon is loaded from history. |
| 102 virtual void OnIconChanged(int model_index) OVERRIDE; |
| 103 |
| 101 // Repositions the menu to be right under the button. Alignment is set as | 104 // Repositions the menu to be right under the button. Alignment is set as |
| 102 // object data on |void_widget| with the tag "left_align". If "left_align" | 105 // object data on |void_widget| with the tag "left_align". If "left_align" |
| 103 // is true, it aligns the left side of the menu with the left side of the | 106 // is true, it aligns the left side of the menu with the left side of the |
| 104 // button. Otherwise it aligns the right side of the menu with the right side | 107 // button. Otherwise it aligns the right side of the menu with the right side |
| 105 // of the button. Public since some menus have odd requirements that don't | 108 // of the button. Public since some menus have odd requirements that don't |
| 106 // belong in a public class. | 109 // belong in a public class. |
| 107 static void WidgetMenuPositionFunc(GtkMenu* menu, | 110 static void WidgetMenuPositionFunc(GtkMenu* menu, |
| 108 int* x, | 111 int* x, |
| 109 int* y, | 112 int* y, |
| 110 gboolean* push_in, | 113 gboolean* push_in, |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 // Sets the activating widget back to a normal appearance. | 162 // Sets the activating widget back to a normal appearance. |
| 160 CHROMEGTK_CALLBACK_0(MenuGtk, void, OnMenuHidden); | 163 CHROMEGTK_CALLBACK_0(MenuGtk, void, OnMenuHidden); |
| 161 | 164 |
| 162 // Sets the enable/disabled state and dynamic labels on our menu items. | 165 // Sets the enable/disabled state and dynamic labels on our menu items. |
| 163 static void SetButtonItemInfo(GtkWidget* button, gpointer userdata); | 166 static void SetButtonItemInfo(GtkWidget* button, gpointer userdata); |
| 164 | 167 |
| 165 // Sets the check mark, enabled/disabled state and dynamic labels on our menu | 168 // Sets the check mark, enabled/disabled state and dynamic labels on our menu |
| 166 // items. | 169 // items. |
| 167 static void SetMenuItemInfo(GtkWidget* widget, void* raw_menu); | 170 static void SetMenuItemInfo(GtkWidget* widget, void* raw_menu); |
| 168 | 171 |
| 172 // Update the icon for a particular menu_item (widget). |
| 173 static void UpdateMenuIcon(GtkWidget* widget, gpointer userdata); |
| 174 |
| 169 // Queries this object about the menu state. | 175 // Queries this object about the menu state. |
| 170 MenuGtk::Delegate* delegate_; | 176 MenuGtk::Delegate* delegate_; |
| 171 | 177 |
| 172 // If non-NULL, the MenuModel that we use to populate and control the GTK | 178 // If non-NULL, the MenuModel that we use to populate and control the GTK |
| 173 // menu (overriding the delegate as a controller). | 179 // menu (overriding the delegate as a controller). |
| 174 ui::MenuModel* model_; | 180 ui::MenuModel* model_; |
| 175 | 181 |
| 176 // For some menu items, we want to show the accelerator, but not actually | 182 // For some menu items, we want to show the accelerator, but not actually |
| 177 // explicitly handle it. To this end we connect those menu items' accelerators | 183 // explicitly handle it. To this end we connect those menu items' accelerators |
| 178 // to this group, but don't attach this group to any top level window. | 184 // to this group, but don't attach this group to any top level window. |
| 179 GtkAccelGroup* dummy_accel_group_; | 185 GtkAccelGroup* dummy_accel_group_; |
| 180 | 186 |
| 181 // gtk_menu_popup() does not appear to take ownership of popup menus, so | 187 // gtk_menu_popup() does not appear to take ownership of popup menus, so |
| 182 // MenuGtk explicitly manages the lifetime of the menu. | 188 // MenuGtk explicitly manages the lifetime of the menu. |
| 183 GtkWidget* menu_; | 189 GtkWidget* menu_; |
| 184 | 190 |
| 185 // True when we should ignore "activate" signals. Used to prevent | 191 // True when we should ignore "activate" signals. Used to prevent |
| 186 // menu items from getting activated when we are setting up the | 192 // menu items from getting activated when we are setting up the |
| 187 // menu. | 193 // menu. |
| 188 static bool block_activation_; | 194 static bool block_activation_; |
| 189 | 195 |
| 190 // We must free these at shutdown. | 196 // We must free these at shutdown. |
| 191 std::vector<MenuGtk*> submenus_we_own_; | 197 std::vector<MenuGtk*> submenus_we_own_; |
| 192 | 198 |
| 193 ScopedRunnableMethodFactory<MenuGtk> factory_; | 199 ScopedRunnableMethodFactory<MenuGtk> factory_; |
| 194 }; | 200 }; |
| 195 | 201 |
| 196 #endif // CHROME_BROWSER_UI_GTK_MENU_GTK_H_ | 202 #endif // CHROME_BROWSER_UI_GTK_MENU_GTK_H_ |
| OLD | NEW |