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 #ifndef CHROME_BROWSER_GTK_BROWSER_ACTIONS_TOOLBAR_GTK_H_ | 5 #ifndef CHROME_BROWSER_GTK_BROWSER_ACTIONS_TOOLBAR_GTK_H_ |
6 #define CHROME_BROWSER_GTK_BROWSER_ACTIONS_TOOLBAR_GTK_H_ | 6 #define CHROME_BROWSER_GTK_BROWSER_ACTIONS_TOOLBAR_GTK_H_ |
7 | 7 |
| 8 #include <gtk/gtk.h> |
| 9 |
8 #include <map> | 10 #include <map> |
9 #include <string> | 11 #include <string> |
10 | 12 |
11 #include "base/linked_ptr.h" | 13 #include "base/linked_ptr.h" |
12 #include "chrome/browser/extensions/extension_toolbar_model.h" | 14 #include "chrome/browser/extensions/extension_toolbar_model.h" |
13 #include "chrome/common/notification_observer.h" | 15 #include "chrome/common/notification_observer.h" |
14 #include "chrome/common/notification_registrar.h" | 16 #include "chrome/common/notification_registrar.h" |
15 #include "chrome/common/owned_widget_gtk.h" | 17 #include "chrome/common/owned_widget_gtk.h" |
16 | 18 |
17 class Browser; | 19 class Browser; |
(...skipping 14 matching lines...) Expand all Loading... |
32 | 34 |
33 Browser* browser() { return browser_; } | 35 Browser* browser() { return browser_; } |
34 | 36 |
35 // Returns the currently selected tab ID, or -1 if there is none. | 37 // Returns the currently selected tab ID, or -1 if there is none. |
36 int GetCurrentTabId(); | 38 int GetCurrentTabId(); |
37 | 39 |
38 // Update the display of all buttons. | 40 // Update the display of all buttons. |
39 void Update(); | 41 void Update(); |
40 | 42 |
41 private: | 43 private: |
| 44 friend class BrowserActionButton; |
| 45 |
| 46 // Initialize drag and drop. |
| 47 void SetupDrags(); |
| 48 |
42 // Query the extensions service for all extensions with browser actions, | 49 // Query the extensions service for all extensions with browser actions, |
43 // and create the UI for them. | 50 // and create the UI for them. |
44 void CreateAllButtons(); | 51 void CreateAllButtons(); |
45 | 52 |
46 // Create the UI for a single browser action. This will stick the button | 53 // Create the UI for a single browser action. This will stick the button |
47 // at the end of the toolbar. | 54 // at the end of the toolbar. |
48 // TODO(estade): is this OK, or does it need to place it in a specific | 55 void CreateButtonForExtension(Extension* extension, int index); |
49 // location on the toolbar? | |
50 void CreateButtonForExtension(Extension* extension); | |
51 | 56 |
52 // Delete resources associated with UI for a browser action. | 57 // Delete resources associated with UI for a browser action. |
53 void RemoveButtonForExtension(Extension* extension); | 58 void RemoveButtonForExtension(Extension* extension); |
54 | 59 |
55 // Change the visibility of widget() based on whether we have any buttons | 60 // Change the visibility of widget() based on whether we have any buttons |
56 // to show. | 61 // to show. |
57 void UpdateVisibility(); | 62 void UpdateVisibility(); |
58 | 63 |
59 // ExtensionToolbarModel::Observer implementation. | 64 // ExtensionToolbarModel::Observer implementation. |
60 virtual void BrowserActionAdded(Extension* extension, int index); | 65 virtual void BrowserActionAdded(Extension* extension, int index); |
61 virtual void BrowserActionRemoved(Extension* extension); | 66 virtual void BrowserActionRemoved(Extension* extension); |
| 67 virtual void BrowserActionMoved(Extension* extension, int index); |
| 68 |
| 69 // Called by the BrowserActionButton in response to drag-begin. |
| 70 void DragStarted(BrowserActionButton* button, GdkDragContext* drag_context); |
| 71 |
| 72 static gboolean OnDragMotionThunk(GtkWidget* widget, |
| 73 GdkDragContext* drag_context, |
| 74 gint x, gint y, guint time, |
| 75 BrowserActionsToolbarGtk* toolbar) { |
| 76 return toolbar->OnDragMotion(widget, drag_context, x, y, time); |
| 77 } |
| 78 gboolean OnDragMotion(GtkWidget* widget, |
| 79 GdkDragContext* drag_context, |
| 80 gint x, gint y, guint time); |
| 81 |
| 82 static void OnDragEndThunk(GtkWidget* button, |
| 83 GdkDragContext* drag_context, |
| 84 BrowserActionsToolbarGtk* toolbar) { |
| 85 toolbar->OnDragEnd(button, drag_context); |
| 86 } |
| 87 void OnDragEnd(GtkWidget* button, GdkDragContext* drag_context); |
62 | 88 |
63 Browser* browser_; | 89 Browser* browser_; |
64 | 90 |
65 Profile* profile_; | 91 Profile* profile_; |
66 | 92 |
67 ExtensionToolbarModel* model_; | 93 ExtensionToolbarModel* model_; |
68 | 94 |
69 OwnedWidgetGtk hbox_; | 95 OwnedWidgetGtk hbox_; |
70 | 96 |
| 97 // The button that is currently being dragged, or NULL. |
| 98 BrowserActionButton* drag_button_; |
| 99 |
| 100 // The new position of the button in the drag, or -1. |
| 101 int drop_index_; |
| 102 |
71 // Map from extension ID to BrowserActionButton, which is a wrapper for | 103 // Map from extension ID to BrowserActionButton, which is a wrapper for |
72 // a chrome button and related functionality. There should be one entry | 104 // a chrome button and related functionality. There should be one entry |
73 // for every extension that has a browser action. | 105 // for every extension that has a browser action. |
74 typedef std::map<std::string, linked_ptr<BrowserActionButton> > | 106 typedef std::map<std::string, linked_ptr<BrowserActionButton> > |
75 ExtensionButtonMap; | 107 ExtensionButtonMap; |
76 ExtensionButtonMap extension_button_map_; | 108 ExtensionButtonMap extension_button_map_; |
77 | 109 |
78 DISALLOW_COPY_AND_ASSIGN(BrowserActionsToolbarGtk); | 110 DISALLOW_COPY_AND_ASSIGN(BrowserActionsToolbarGtk); |
79 }; | 111 }; |
80 | 112 |
81 #endif // CHROME_BROWSER_GTK_BROWSER_ACTIONS_TOOLBAR_GTK_H_ | 113 #endif // CHROME_BROWSER_GTK_BROWSER_ACTIONS_TOOLBAR_GTK_H_ |
OLD | NEW |