OLD | NEW |
1 // Copyright (c) 2010 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 // | |
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. | |
7 | 4 |
8 #ifndef CHROME_BROWSER_GTK_MENU_BAR_HELPER_H_ | 5 #ifndef CHROME_BROWSER_GTK_MENU_BAR_HELPER_H_ |
9 #define CHROME_BROWSER_GTK_MENU_BAR_HELPER_H_ | 6 #define CHROME_BROWSER_GTK_MENU_BAR_HELPER_H_ |
10 #pragma once | 7 #pragma once |
11 | 8 |
12 #include <gtk/gtk.h> | 9 #include "chrome/browser/ui/gtk/menu_bar_helper.h" |
13 | 10 // TODO(msw): remove this file once all includes have been updated. |
14 #include <vector> | |
15 | |
16 #include "app/gtk_signal.h" | |
17 #include "base/scoped_ptr.h" | |
18 | |
19 class GtkSignalRegistrar; | |
20 | |
21 class MenuBarHelper { | |
22 public: | |
23 class Delegate { | |
24 public: | |
25 virtual ~Delegate() {} | |
26 | |
27 // Called when a the menu for a button ought to be triggered. | |
28 virtual void PopupForButton(GtkWidget* button) = 0; | |
29 virtual void PopupForButtonNextTo(GtkWidget* button, | |
30 GtkMenuDirectionType dir) = 0; | |
31 }; | |
32 | |
33 // |delegate| cannot be null. | |
34 explicit MenuBarHelper(Delegate* delegate); | |
35 virtual ~MenuBarHelper(); | |
36 | |
37 // Must be called whenever a button's menu starts showing. It triggers the | |
38 // MenuBarHelper to start listening for certain events. | |
39 void MenuStartedShowing(GtkWidget* button, GtkWidget* menu); | |
40 | |
41 // Add |button| to the set of buttons we care about. | |
42 void Add(GtkWidget* button); | |
43 | |
44 // Remove |button| from the set of buttons we care about. | |
45 void Remove(GtkWidget* button); | |
46 | |
47 // Clear all buttons from the set. | |
48 void Clear(); | |
49 | |
50 private: | |
51 CHROMEGTK_CALLBACK_0(MenuBarHelper, void, OnMenuHiddenOrDestroyed); | |
52 CHROMEGTK_CALLBACK_1(MenuBarHelper, gboolean, OnMenuMotionNotify, | |
53 GdkEventMotion*); | |
54 CHROMEGTK_CALLBACK_1(MenuBarHelper, void, OnMenuMoveCurrent, | |
55 GtkMenuDirectionType); | |
56 | |
57 // The buttons for which we pop up menus. We do not own these, or even add | |
58 // refs to them. | |
59 std::vector<GtkWidget*> buttons_; | |
60 | |
61 // The button that is currently showing a menu, or NULL. | |
62 GtkWidget* button_showing_menu_; | |
63 | |
64 // The highest level menu that is currently showing, or NULL. | |
65 GtkWidget* showing_menu_; | |
66 | |
67 // All the submenus of |showing_menu_|. We connect to motion events on all | |
68 // of them. | |
69 std::vector<GtkWidget*> submenus_; | |
70 | |
71 // Signal handlers that are attached only between the "show" and "hide" events | |
72 // for the menu. | |
73 scoped_ptr<GtkSignalRegistrar> signal_handlers_; | |
74 | |
75 Delegate* delegate_; | |
76 }; | |
77 | 11 |
78 #endif // CHROME_BROWSER_GTK_MENU_BAR_HELPER_H_ | 12 #endif // CHROME_BROWSER_GTK_MENU_BAR_HELPER_H_ |
OLD | NEW |