OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 // |
| 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 |
| 7 // page/app menus. |
| 8 |
| 9 #ifndef CHROME_BROWSER_GTK_MENU_BAR_HELPER_H_ |
| 10 #define CHROME_BROWSER_GTK_MENU_BAR_HELPER_H_ |
| 11 |
| 12 #include <gtk/gtk.h> |
| 13 |
| 14 #include <vector> |
| 15 |
| 16 class MenuBarHelper { |
| 17 public: |
| 18 class Delegate { |
| 19 public: |
| 20 virtual ~Delegate() {} |
| 21 |
| 22 // Called when a the menu for a button ought to be triggered. |
| 23 virtual void PopupForButton(GtkWidget* button) = 0; |
| 24 virtual void PopupForButtonNextTo(GtkWidget* button, |
| 25 GtkMenuDirectionType dir) = 0; |
| 26 }; |
| 27 |
| 28 // |delegate| cannot be null. |
| 29 explicit MenuBarHelper(Delegate* delegate); |
| 30 ~MenuBarHelper(); |
| 31 |
| 32 // Must be called whenever a button's menu starts showing. It triggers the |
| 33 // MenuBarHelper to start listening for certain events. |
| 34 void MenuStartedShowing(GtkWidget* button, GtkWidget* menu); |
| 35 |
| 36 // Add |button| to the set of buttons we care about. |
| 37 void Add(GtkWidget* button); |
| 38 |
| 39 // Remove |button| from the set of buttons we care about. |
| 40 void Remove(GtkWidget* button); |
| 41 |
| 42 // Clear all buttons from the set. |
| 43 void Clear(); |
| 44 |
| 45 private: |
| 46 static gboolean OnMenuMotionNotifyThunk(GtkWidget* menu, |
| 47 GdkEventMotion* motion, |
| 48 MenuBarHelper* helper) { |
| 49 return helper->OnMenuMotionNotify(menu, motion); |
| 50 } |
| 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 |
| 65 // The buttons for which we pop up menus. We do not own these, or even add |
| 66 // refs to them. |
| 67 std::vector<GtkWidget*> buttons_; |
| 68 |
| 69 // The button that is currently showing a menu, or NULL. |
| 70 GtkWidget* button_showing_menu_; |
| 71 |
| 72 // The highest level menu that is currently showing, or NULL. |
| 73 GtkWidget* showing_menu_; |
| 74 |
| 75 // All the submenus of |showing_menu_|. We connect to motion events on all |
| 76 // of them. |
| 77 std::vector<GtkWidget*> submenus_; |
| 78 |
| 79 Delegate* delegate_; |
| 80 }; |
| 81 |
| 82 #endif // CHROME_BROWSER_GTK_MENU_BAR_HELPER_H_ |
OLD | NEW |