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
3 // found in the LICENSE file.
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.
8 #ifndef CHROME_BROWSER_UI_GTK_MENU_BAR_HELPER_H_
9 #define CHROME_BROWSER_UI_GTK_MENU_BAR_HELPER_H_
15 #include "base/memory/scoped_ptr.h"
16 #include "ui/base/gtk/gtk_signal.h"
19 class GtkSignalRegistrar
;
26 virtual ~Delegate() {}
28 // Called when a the menu for a button ought to be triggered.
29 virtual void PopupForButton(GtkWidget
* button
) = 0;
30 virtual void PopupForButtonNextTo(GtkWidget
* button
,
31 GtkMenuDirectionType dir
) = 0;
34 // |delegate| cannot be null.
35 explicit MenuBarHelper(Delegate
* delegate
);
38 // Must be called whenever a button's menu starts showing. It triggers the
39 // MenuBarHelper to start listening for certain events.
40 void MenuStartedShowing(GtkWidget
* button
, GtkWidget
* menu
);
42 // Add |button| to the set of buttons we care about.
43 void Add(GtkWidget
* button
);
45 // Remove |button| from the set of buttons we care about.
46 void Remove(GtkWidget
* button
);
48 // Clear all buttons from the set.
52 CHROMEGTK_CALLBACK_0(MenuBarHelper
, void, OnMenuHiddenOrDestroyed
);
53 CHROMEGTK_CALLBACK_1(MenuBarHelper
, gboolean
, OnMenuMotionNotify
,
55 CHROMEGTK_CALLBACK_1(MenuBarHelper
, void, OnMenuMoveCurrent
,
56 GtkMenuDirectionType
);
58 // The buttons for which we pop up menus. We do not own these, or even add
60 std::vector
<GtkWidget
*> buttons_
;
62 // The button that is currently showing a menu, or NULL.
63 GtkWidget
* button_showing_menu_
;
65 // The highest level menu that is currently showing, or NULL.
66 GtkWidget
* showing_menu_
;
68 // All the submenus of |showing_menu_|. We connect to motion events on all
70 std::vector
<GtkWidget
*> submenus_
;
72 // Signal handlers that are attached only between the "show" and "hide" events
74 scoped_ptr
<ui::GtkSignalRegistrar
> signal_handlers_
;
79 #endif // CHROME_BROWSER_UI_GTK_MENU_BAR_HELPER_H_