summaryrefslogtreecommitdiffstats
path: root/chrome/browser/gtk/extension_shelf_gtk.h
blob: b5ea977dfd3ab88534f451375775001e6bf7a464 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_GTK_EXTENSION_SHELF_GTK_H_
#define CHROME_BROWSER_GTK_EXTENSION_SHELF_GTK_H_

#include <gtk/gtk.h>

#include <set>

#include "base/scoped_ptr.h"
#include "chrome/browser/extensions/extension_shelf_model.h"
#include "chrome/common/notification_registrar.h"
#include "chrome/common/owned_widget_gtk.h"

class Browser;
class BrowserWindowGtk;
class CustomContainerButton;
class NineBox;
class Profile;
struct GtkThemeProvider;

class ExtensionShelfGtk : public ExtensionShelfModelObserver,
                          public NotificationObserver {
 public:
  ExtensionShelfGtk(Profile* profile, Browser* browser);
  virtual ~ExtensionShelfGtk();

  // Change the visibility of the bookmarks bar. (Starts out hidden, per GTK's
  // default behaviour).
  void Show();
  void Hide();

  // ExtensionShelfModelObserver
  virtual void ToolstripInsertedAt(ExtensionHost* host, int index);
  virtual void ToolstripRemovingAt(ExtensionHost* host, int index);
  virtual void ToolstripMoved(ExtensionHost* host,
                              int from_index,
                              int to_index);
  virtual void ToolstripChanged(ExtensionShelfModel::iterator toolstrip);
  virtual void ExtensionShelfEmpty();
  virtual void ShelfModelReloaded();
  virtual void ShelfModelDeleting();

  // NotificationObserver
  virtual void Observe(NotificationType type,
                       const NotificationSource& source,
                       const NotificationDetails& details);

  GtkWidget* widget() {
    return event_box_.get();
  }

 private:
  class Toolstrip;

  // Create the contents of the extension shelf.
  void Init(Profile* profile);

  // Lazily initialize background bitmap. Can be called many times.
  void InitBackground();

  // Determines what is our target height and sets it.
  void AdjustHeight();

  void LoadFromModel();

  Toolstrip* ToolstripAtIndex(int index);

  // GtkHBox callbacks.
  static gboolean OnHBoxExpose(GtkWidget* widget, GdkEventExpose* event,
                               ExtensionShelfGtk* window);

  Browser* browser_;

  // Top level event box which draws the one pixel border.
  GtkWidget* top_border_;

  // Contains |shelf_hbox_|. Event box exists to prevent leakage of
  // background color from the toplevel application window's GDK window.
  OwnedWidgetGtk event_box_;

  // Used to position all children.
  GtkWidget* shelf_hbox_;

  // Lazily-initialized background for toolstrips.
  scoped_ptr<SkBitmap> background_;

  GtkThemeProvider* theme_provider_;

  // The model representing the toolstrips on the shelf.
  ExtensionShelfModel* model_;

  // Set of toolstrip views which are really on the shelf.
  std::set<Toolstrip*> toolstrips_;

  NotificationRegistrar registrar_;

  DISALLOW_COPY_AND_ASSIGN(ExtensionShelfGtk);
};

#endif  // CHROME_BROWSER_EXTENSION_SHELF_GTK_H_