summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/gtk/avatar_menu_bubble_gtk.h
blob: c7dce71b14b341d9c8e3c8a15abdbf72201b68d0 (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
// Copyright (c) 2012 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_UI_GTK_AVATAR_MENU_BUBBLE_GTK_H_
#define CHROME_BROWSER_UI_GTK_AVATAR_MENU_BUBBLE_GTK_H_

#include <gtk/gtk.h>

#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/scoped_vector.h"
#include "chrome/browser/profiles/avatar_menu_model_observer.h"
#include "chrome/browser/ui/gtk/avatar_menu_item_gtk.h"
#include "chrome/browser/ui/gtk/bubble/bubble_gtk.h"
#include "ui/base/gtk/gtk_signal.h"

class AvatarMenuModel;
class Browser;
class GtkThemeService;

// This bubble is displayed when the user clicks on the avatar button.
// It displays a list of profiles and allows users to switch between profiles.
class AvatarMenuBubbleGtk : public BubbleDelegateGtk,
                            public AvatarMenuModelObserver,
                            public AvatarMenuItemGtk::Delegate {
 public:
  AvatarMenuBubbleGtk(Browser* browser,
                      GtkWidget* anchor,
                      BubbleGtk::FrameStyle arrow,
                      const gfx::Rect* rect);
  virtual ~AvatarMenuBubbleGtk();

  // BubbleDelegateGtk implementation.
  virtual void BubbleClosing(BubbleGtk* bubble,
                             bool closed_by_escape) OVERRIDE;

  // AvatarMenuModelObserver implementation.
  virtual void OnAvatarMenuModelChanged(
      AvatarMenuModel* avatar_menu_model) OVERRIDE;

  // AvatarMenuItemGtk::Delegate implementation.
  virtual void OpenProfile(size_t profile_index) OVERRIDE;
  virtual void EditProfile(size_t profile_index) OVERRIDE;

 private:
  // Notified when |contents_| is destroyed so we can delete our instance.
  CHROMEGTK_CALLBACK_0(AvatarMenuBubbleGtk, void, OnDestroy);
  CHROMEGTK_CALLBACK_1(AvatarMenuBubbleGtk, void, OnSizeRequest,
                       GtkRequisition*);
  CHROMEGTK_CALLBACK_0(AvatarMenuBubbleGtk, void, OnNewProfileLinkClicked);

  // Create all widgets in this bubble.
  void InitContents();

  // Close the bubble and set bubble_ to NULL.
  void CloseBubble();

  // A model of all the profile information to be displayed in the menu.
  scoped_ptr<AvatarMenuModel> avatar_menu_model_;

  // A weak pointer to the parent widget of all widgets in the bubble.
  GtkWidget* contents_;

  // A weak pointer to the bubble window.
  BubbleGtk* bubble_;

  // A weak pointer to the theme service.
  GtkThemeService* theme_service_;

  // A weak pointer to the new proifle link to keep its theme information
  // updated.
  GtkWidget* new_profile_link_;

  // A vector of all profile items in the menu.
  ScopedVector<AvatarMenuItemGtk> items_;

  // The minimum width to display the bubble. This is used to prevent the bubble
  // from automatically reducing its size when hovering over a profile item.
  int minimum_width_;

  DISALLOW_COPY_AND_ASSIGN(AvatarMenuBubbleGtk);
};

#endif  // CHROME_BROWSER_UI_GTK_AVATAR_MENU_BUBBLE_GTK_H_