| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 // This class replicates some menubar behaviors that are tricky to get right. | 5 // This class replicates some menubar behaviors that are tricky to get right. |
| 6 // It is used to create a more native feel for the bookmark bar and the | 6 // It is used to create a more native feel for the bookmark bar and the |
| 7 // page/app menus. | 7 // page/app menus. |
| 8 | 8 |
| 9 #ifndef CHROME_BROWSER_GTK_MENU_BAR_HELPER_H_ | 9 #ifndef CHROME_BROWSER_GTK_MENU_BAR_HELPER_H_ |
| 10 #define CHROME_BROWSER_GTK_MENU_BAR_HELPER_H_ | 10 #define CHROME_BROWSER_GTK_MENU_BAR_HELPER_H_ |
| 11 | 11 |
| 12 #include <gtk/gtk.h> | 12 #include <gtk/gtk.h> |
| 13 | 13 |
| 14 #include <vector> | 14 #include <vector> |
| 15 | 15 |
| 16 #include "app/gtk_signal.h" |
| 17 #include "base/scoped_ptr.h" |
| 18 |
| 16 class MenuBarHelper { | 19 class MenuBarHelper { |
| 17 public: | 20 public: |
| 18 class Delegate { | 21 class Delegate { |
| 19 public: | 22 public: |
| 20 virtual ~Delegate() {} | 23 virtual ~Delegate() {} |
| 21 | 24 |
| 22 // Called when a the menu for a button ought to be triggered. | 25 // Called when a the menu for a button ought to be triggered. |
| 23 virtual void PopupForButton(GtkWidget* button) = 0; | 26 virtual void PopupForButton(GtkWidget* button) = 0; |
| 24 virtual void PopupForButtonNextTo(GtkWidget* button, | 27 virtual void PopupForButtonNextTo(GtkWidget* button, |
| 25 GtkMenuDirectionType dir) = 0; | 28 GtkMenuDirectionType dir) = 0; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 36 // Add |button| to the set of buttons we care about. | 39 // Add |button| to the set of buttons we care about. |
| 37 void Add(GtkWidget* button); | 40 void Add(GtkWidget* button); |
| 38 | 41 |
| 39 // Remove |button| from the set of buttons we care about. | 42 // Remove |button| from the set of buttons we care about. |
| 40 void Remove(GtkWidget* button); | 43 void Remove(GtkWidget* button); |
| 41 | 44 |
| 42 // Clear all buttons from the set. | 45 // Clear all buttons from the set. |
| 43 void Clear(); | 46 void Clear(); |
| 44 | 47 |
| 45 private: | 48 private: |
| 46 static gboolean OnMenuMotionNotifyThunk(GtkWidget* menu, | 49 CHROMEGTK_CALLBACK_1(MenuBarHelper, gboolean, OnMenuMotionNotify, |
| 47 GdkEventMotion* motion, | 50 GdkEventMotion*); |
| 48 MenuBarHelper* helper) { | 51 CHROMEGTK_CALLBACK_0(MenuBarHelper, void, OnMenuHidden); |
| 49 return helper->OnMenuMotionNotify(menu, motion); | 52 CHROMEGTK_CALLBACK_1(MenuBarHelper, void, OnMenuMoveCurrent, |
| 50 } | 53 GtkMenuDirectionType); |
| 51 gboolean OnMenuMotionNotify(GtkWidget* menu, GdkEventMotion* motion); | |
| 52 | |
| 53 static void OnMenuHiddenThunk(GtkWidget* menu, MenuBarHelper* helper) { | |
| 54 helper->OnMenuHidden(menu); | |
| 55 } | |
| 56 void OnMenuHidden(GtkWidget* menu); | |
| 57 | |
| 58 static void OnMenuMoveCurrentThunk(GtkWidget* menu, | |
| 59 GtkMenuDirectionType dir, | |
| 60 MenuBarHelper* helper) { | |
| 61 helper->OnMenuMoveCurrent(menu, dir); | |
| 62 } | |
| 63 void OnMenuMoveCurrent(GtkWidget* menu, GtkMenuDirectionType dir); | |
| 64 | 54 |
| 65 // The buttons for which we pop up menus. We do not own these, or even add | 55 // The buttons for which we pop up menus. We do not own these, or even add |
| 66 // refs to them. | 56 // refs to them. |
| 67 std::vector<GtkWidget*> buttons_; | 57 std::vector<GtkWidget*> buttons_; |
| 68 | 58 |
| 69 // The button that is currently showing a menu, or NULL. | 59 // The button that is currently showing a menu, or NULL. |
| 70 GtkWidget* button_showing_menu_; | 60 GtkWidget* button_showing_menu_; |
| 71 | 61 |
| 72 // The highest level menu that is currently showing, or NULL. | 62 // The highest level menu that is currently showing, or NULL. |
| 73 GtkWidget* showing_menu_; | 63 GtkWidget* showing_menu_; |
| 74 | 64 |
| 75 // All the submenus of |showing_menu_|. We connect to motion events on all | 65 // All the submenus of |showing_menu_|. We connect to motion events on all |
| 76 // of them. | 66 // of them. |
| 77 std::vector<GtkWidget*> submenus_; | 67 std::vector<GtkWidget*> submenus_; |
| 78 | 68 |
| 69 // Signal handlers that are attached only between the "show" and "hide" events |
| 70 // for the menu. |
| 71 scoped_ptr<GtkSignalRegistrar> signal_handlers_; |
| 72 |
| 79 Delegate* delegate_; | 73 Delegate* delegate_; |
| 80 }; | 74 }; |
| 81 | 75 |
| 82 #endif // CHROME_BROWSER_GTK_MENU_BAR_HELPER_H_ | 76 #endif // CHROME_BROWSER_GTK_MENU_BAR_HELPER_H_ |
| OLD | NEW |