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_EXTENSION_SHELF_GTK_H_ | 5 #ifndef CHROME_BROWSER_GTK_EXTENSION_SHELF_GTK_H_ |
6 #define CHROME_BROWSER_GTK_EXTENSION_SHELF_GTK_H_ | 6 #define CHROME_BROWSER_GTK_EXTENSION_SHELF_GTK_H_ |
7 | 7 |
8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
9 | 9 |
10 #include <set> | 10 #include <set> |
11 | 11 |
12 #include "base/scoped_ptr.h" | 12 #include "base/scoped_ptr.h" |
13 #include "chrome/browser/extensions/extension_shelf_model.h" | 13 #include "chrome/browser/extensions/extension_shelf_model.h" |
| 14 #include "chrome/common/notification_registrar.h" |
14 #include "chrome/common/owned_widget_gtk.h" | 15 #include "chrome/common/owned_widget_gtk.h" |
15 | 16 |
16 class Browser; | 17 class Browser; |
17 class BrowserWindowGtk; | 18 class BrowserWindowGtk; |
18 class CustomContainerButton; | 19 class CustomContainerButton; |
19 class NineBox; | 20 class NineBox; |
20 class Profile; | 21 class Profile; |
21 struct GtkThemeProvider; | 22 struct GtkThemeProvider; |
22 | 23 |
23 class ExtensionShelfGtk : public ExtensionShelfModelObserver { | 24 class ExtensionShelfGtk : public ExtensionShelfModelObserver, |
| 25 public NotificationObserver { |
24 public: | 26 public: |
25 ExtensionShelfGtk(Profile* profile, Browser* browser); | 27 ExtensionShelfGtk(Profile* profile, Browser* browser); |
26 virtual ~ExtensionShelfGtk(); | 28 virtual ~ExtensionShelfGtk(); |
27 | 29 |
28 // Adds this GTK shelf into a sizing box. | 30 // Adds this GTK shelf into a sizing box. |
29 void AddShelfToBox(GtkWidget* box); | 31 void AddShelfToBox(GtkWidget* box); |
30 | 32 |
31 // Change the visibility of the bookmarks bar. (Starts out hidden, per GTK's | 33 // Change the visibility of the bookmarks bar. (Starts out hidden, per GTK's |
32 // default behaviour). | 34 // default behaviour). |
33 void Show(); | 35 void Show(); |
34 void Hide(); | 36 void Hide(); |
35 | 37 |
36 // ExtensionShelfModelObserver | 38 // ExtensionShelfModelObserver |
37 virtual void ToolstripInsertedAt(ExtensionHost* host, int index); | 39 virtual void ToolstripInsertedAt(ExtensionHost* host, int index); |
38 virtual void ToolstripRemovingAt(ExtensionHost* host, int index); | 40 virtual void ToolstripRemovingAt(ExtensionHost* host, int index); |
39 virtual void ToolstripMoved(ExtensionHost* host, | 41 virtual void ToolstripMoved(ExtensionHost* host, |
40 int from_index, | 42 int from_index, |
41 int to_index); | 43 int to_index); |
42 virtual void ToolstripChanged(ExtensionShelfModel::iterator toolstrip); | 44 virtual void ToolstripChanged(ExtensionShelfModel::iterator toolstrip); |
43 virtual void ExtensionShelfEmpty(); | 45 virtual void ExtensionShelfEmpty(); |
44 virtual void ShelfModelReloaded(); | 46 virtual void ShelfModelReloaded(); |
45 virtual void ShelfModelDeleting(); | 47 virtual void ShelfModelDeleting(); |
46 | 48 |
| 49 // NotificationObserver |
| 50 virtual void Observe(NotificationType type, |
| 51 const NotificationSource& source, |
| 52 const NotificationDetails& details); |
| 53 |
47 private: | 54 private: |
48 class Toolstrip; | 55 class Toolstrip; |
49 | 56 |
50 // Create the contents of the extension shelf. | 57 // Create the contents of the extension shelf. |
51 void Init(Profile* profile); | 58 void Init(Profile* profile); |
52 | 59 |
53 // Determines what is our target height and sets it. | 60 // Determines what is our target height and sets it. |
54 void AdjustHeight(); | 61 void AdjustHeight(); |
55 | 62 |
56 void LoadFromModel(); | 63 void LoadFromModel(); |
57 | 64 |
58 Toolstrip* ToolstripAtIndex(int index); | 65 Toolstrip* ToolstripAtIndex(int index); |
59 | 66 |
60 // GtkHBox callbacks. | 67 // GtkHBox callbacks. |
61 static gboolean OnHBoxExpose(GtkWidget* widget, GdkEventExpose* event, | 68 static gboolean OnHBoxExpose(GtkWidget* widget, GdkEventExpose* event, |
62 ExtensionShelfGtk* window); | 69 ExtensionShelfGtk* window); |
63 | 70 |
64 Browser* browser_; | 71 Browser* browser_; |
65 | 72 |
| 73 // Top level event box which draws the one pixel border. |
| 74 GtkWidget* top_border_; |
| 75 |
66 // Contains |shelf_hbox_|. Event box exists to prevent leakage of | 76 // Contains |shelf_hbox_|. Event box exists to prevent leakage of |
67 // background color from the toplevel application window's GDK window. | 77 // background color from the toplevel application window's GDK window. |
68 OwnedWidgetGtk event_box_; | 78 OwnedWidgetGtk event_box_; |
69 | 79 |
70 // Used to position all children. | 80 // Used to position all children. |
71 GtkWidget* shelf_hbox_; | 81 GtkWidget* shelf_hbox_; |
72 | 82 |
73 GtkThemeProvider* theme_provider_; | 83 GtkThemeProvider* theme_provider_; |
74 | 84 |
75 // The model representing the toolstrips on the shelf. | 85 // The model representing the toolstrips on the shelf. |
76 ExtensionShelfModel* model_; | 86 ExtensionShelfModel* model_; |
77 | 87 |
78 // Set of toolstrip views which are really on the shelf. | 88 // Set of toolstrip views which are really on the shelf. |
79 std::set<Toolstrip*> toolstrips_; | 89 std::set<Toolstrip*> toolstrips_; |
80 | 90 |
| 91 NotificationRegistrar registrar_; |
| 92 |
81 DISALLOW_COPY_AND_ASSIGN(ExtensionShelfGtk); | 93 DISALLOW_COPY_AND_ASSIGN(ExtensionShelfGtk); |
82 }; | 94 }; |
83 | 95 |
84 #endif // CHROME_BROWSER_EXTENSION_SHELF_GTK_H_ | 96 #endif // CHROME_BROWSER_EXTENSION_SHELF_GTK_H_ |
OLD | NEW |