• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 // Draws the view for the balloons.
6 
7 #ifndef CHROME_BROWSER_UI_GTK_NOTIFICATIONS_BALLOON_VIEW_GTK_H_
8 #define CHROME_BROWSER_UI_GTK_NOTIFICATIONS_BALLOON_VIEW_GTK_H_
9 #pragma once
10 
11 #include "base/basictypes.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "chrome/browser/notifications/balloon.h"
14 #include "chrome/browser/ui/gtk/menu_gtk.h"
15 #include "chrome/browser/ui/gtk/notifications/balloon_view_host_gtk.h"
16 #include "content/common/notification_observer.h"
17 #include "content/common/notification_registrar.h"
18 #include "ui/base/animation/animation_delegate.h"
19 #include "ui/base/gtk/gtk_signal.h"
20 #include "ui/gfx/point.h"
21 #include "ui/gfx/rect.h"
22 #include "ui/gfx/size.h"
23 
24 class BalloonCollection;
25 class CustomDrawButton;
26 class GtkThemeService;
27 class MenuGtk;
28 class NotificationDetails;
29 class NotificationOptionsMenuModel;
30 class NotificationSource;
31 
32 namespace ui {
33 class SlideAnimation;
34 }
35 
36 // A balloon view is the UI component for desktop notification toasts.
37 // It draws a border, and within the border an HTML renderer.
38 class BalloonViewImpl : public BalloonView,
39                         public MenuGtk::Delegate,
40                         public NotificationObserver,
41                         public ui::AnimationDelegate {
42  public:
43   explicit BalloonViewImpl(BalloonCollection* collection);
44   virtual ~BalloonViewImpl();
45 
46   // BalloonView interface.
47   virtual void Show(Balloon* balloon);
48   virtual void Update();
49   virtual void RepositionToBalloon();
50   virtual void Close(bool by_user);
51   virtual gfx::Size GetSize() const;
52   virtual BalloonHost* GetHost() const;
53 
54   // MenuGtk::Delegate interface.
55   virtual void StoppedShowing();
56 
57  private:
58   // NotificationObserver interface.
59   virtual void Observe(NotificationType type,
60                        const NotificationSource& source,
61                        const NotificationDetails& details);
62 
63   // ui::AnimationDelegate interface.
64   virtual void AnimationProgressed(const ui::Animation* animation);
65 
66   // Do the delayed close work.  The balloon and all view components will be
67   // destroyed at this time, so it shouldn't be called while still processing
68   // an event that relies on them.
69   void DelayedClose(bool by_user);
70 
71   // The height of the balloon's shelf.
72   // The shelf is where is close button is located.
73   int GetShelfHeight() const;
74 
75   // The width and height that the frame should be.  If the balloon inside
76   // changes size, this will not be the same as the actual frame size until
77   // RepositionToBalloon() has been called and the animation completes.
78   int GetDesiredTotalWidth() const;
79   int GetDesiredTotalHeight() const;
80 
81   // Where the balloon contents should be placed with respect to the top left
82   // of the frame.
83   gfx::Point GetContentsOffset() const;
84 
85   // Where the balloon contents should be in screen coordinates.
86   gfx::Rect GetContentsRectangle() const;
87 
88   CHROMEGTK_CALLBACK_1(BalloonViewImpl, gboolean, OnContentsExpose,
89                        GdkEventExpose*);
90   CHROMEGTK_CALLBACK_0(BalloonViewImpl, void, OnCloseButton);
91   CHROMEGTK_CALLBACK_1(BalloonViewImpl, gboolean, OnExpose, GdkEventExpose*);
92   CHROMEGTK_CALLBACK_1(BalloonViewImpl, void, OnOptionsMenuButton,
93                        GdkEventButton*);
94   CHROMEGTK_CALLBACK_0(BalloonViewImpl, gboolean, OnDestroy);
95 
96   // Non-owned pointer to the balloon which owns this object.
97   Balloon* balloon_;
98 
99   GtkThemeService* theme_service_;
100 
101   // The window that contains the frame of the notification.
102   GtkWidget* frame_container_;
103 
104   // The widget that contains the shelf.
105   GtkWidget* shelf_;
106 
107   // The hbox within the shelf that contains the buttons.
108   GtkWidget* hbox_;
109 
110   // The window that contains the contents of the notification.
111   GtkWidget* html_container_;
112 
113   // The renderer of the HTML contents.
114   scoped_ptr<BalloonViewHost> html_contents_;
115 
116   // The following factory is used to call methods at a later time.
117   ScopedRunnableMethodFactory<BalloonViewImpl> method_factory_;
118 
119   // Close button.
120   scoped_ptr<CustomDrawButton> close_button_;
121 
122   // An animation to move the balloon on the screen as its position changes.
123   scoped_ptr<ui::SlideAnimation> animation_;
124   gfx::Rect anim_frame_start_;
125   gfx::Rect anim_frame_end_;
126 
127   // The options menu.
128   scoped_ptr<MenuGtk> options_menu_;
129   scoped_ptr<NotificationOptionsMenuModel> options_menu_model_;
130   // The button to open the options menu.
131   scoped_ptr<CustomDrawButton> options_menu_button_;
132 
133   NotificationRegistrar notification_registrar_;
134 
135   // Is the menu currently showing?
136   bool menu_showing_;
137 
138   // Is there a pending system-initiated close?
139   bool pending_close_;
140 
141   DISALLOW_COPY_AND_ASSIGN(BalloonViewImpl);
142 };
143 
144 #endif  // CHROME_BROWSER_UI_GTK_NOTIFICATIONS_BALLOON_VIEW_GTK_H_
145