1 // Copyright (c) 2012 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.
5 // Draws the view for the balloons.
7 #ifndef CHROME_BROWSER_UI_GTK_NOTIFICATIONS_BALLOON_VIEW_GTK_H_
8 #define CHROME_BROWSER_UI_GTK_NOTIFICATIONS_BALLOON_VIEW_GTK_H_
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "chrome/browser/notifications/balloon.h"
15 #include "chrome/browser/ui/gtk/menu_gtk.h"
16 #include "chrome/browser/ui/gtk/notifications/balloon_view_host_gtk.h"
17 #include "content/public/browser/notification_observer.h"
18 #include "content/public/browser/notification_registrar.h"
19 #include "ui/base/gtk/gtk_signal.h"
20 #include "ui/gfx/animation/animation_delegate.h"
21 #include "ui/gfx/point.h"
22 #include "ui/gfx/rect.h"
23 #include "ui/gfx/size.h"
25 class BalloonCollection
;
26 class CustomDrawButton
;
27 class GtkThemeService
;
29 class NotificationOptionsMenuModel
;
35 // A balloon view is the UI component for desktop notification toasts.
36 // It draws a border, and within the border an HTML renderer.
37 class BalloonViewImpl
: public BalloonView
,
38 public MenuGtk::Delegate
,
39 public content::NotificationObserver
,
40 public gfx::AnimationDelegate
{
42 explicit BalloonViewImpl(BalloonCollection
* collection
);
43 virtual ~BalloonViewImpl();
45 // BalloonView interface.
46 virtual void Show(Balloon
* balloon
) OVERRIDE
;
47 virtual void Update() OVERRIDE
;
48 virtual void RepositionToBalloon() OVERRIDE
;
49 virtual void Close(bool by_user
) OVERRIDE
;
50 virtual gfx::Size
GetSize() const OVERRIDE
;
51 virtual BalloonHost
* GetHost() const OVERRIDE
;
53 // MenuGtk::Delegate interface.
54 virtual void StoppedShowing() OVERRIDE
;
57 // content::NotificationObserver interface.
58 virtual void Observe(int type
,
59 const content::NotificationSource
& source
,
60 const content::NotificationDetails
& details
) OVERRIDE
;
62 // gfx::AnimationDelegate interface.
63 virtual void AnimationProgressed(const gfx::Animation
* animation
) OVERRIDE
;
65 // Do the delayed close work. The balloon and all view components will be
66 // destroyed at this time, so it shouldn't be called while still processing
67 // an event that relies on them.
68 void DelayedClose(bool by_user
);
70 // The height of the balloon's shelf.
71 // The shelf is where is close button is located.
72 int GetShelfHeight() const;
74 // The width and height that the frame should be. If the balloon inside
75 // changes size, this will not be the same as the actual frame size until
76 // RepositionToBalloon() has been called and the animation completes.
77 int GetDesiredTotalWidth() const;
78 int GetDesiredTotalHeight() const;
80 // Where the balloon contents should be placed with respect to the top left
82 gfx::Point
GetContentsOffset() const;
84 // Where the balloon contents should be in screen coordinates.
85 gfx::Rect
GetContentsRectangle() const;
87 CHROMEGTK_CALLBACK_1(BalloonViewImpl
, gboolean
, OnContentsExpose
,
89 CHROMEGTK_CALLBACK_0(BalloonViewImpl
, void, OnCloseButton
);
90 CHROMEGTK_CALLBACK_1(BalloonViewImpl
, gboolean
, OnExpose
, GdkEventExpose
*);
91 CHROMEGTK_CALLBACK_1(BalloonViewImpl
, void, OnOptionsMenuButton
,
93 CHROMEGTK_CALLBACK_0(BalloonViewImpl
, gboolean
, OnDestroy
);
95 // Non-owned pointer to the balloon which owns this object.
98 GtkThemeService
* theme_service_
;
100 // The window that contains the frame of the notification.
101 GtkWidget
* frame_container_
;
103 // The widget that contains the shelf.
106 // The hbox within the shelf that contains the buttons.
109 // The window that contains the contents of the notification.
110 GtkWidget
* html_container_
;
112 // The renderer of the HTML contents.
113 scoped_ptr
<BalloonViewHost
> html_contents_
;
116 scoped_ptr
<CustomDrawButton
> close_button_
;
118 // An animation to move the balloon on the screen as its position changes.
119 scoped_ptr
<gfx::SlideAnimation
> animation_
;
120 gfx::Rect anim_frame_start_
;
121 gfx::Rect anim_frame_end_
;
124 scoped_ptr
<MenuGtk
> options_menu_
;
125 scoped_ptr
<NotificationOptionsMenuModel
> options_menu_model_
;
126 // The button to open the options menu.
127 scoped_ptr
<CustomDrawButton
> options_menu_button_
;
129 content::NotificationRegistrar notification_registrar_
;
131 // Is the menu currently showing?
134 // Is there a pending system-initiated close?
137 base::WeakPtrFactory
<BalloonViewImpl
> weak_factory_
;
139 DISALLOW_COPY_AND_ASSIGN(BalloonViewImpl
);
142 #endif // CHROME_BROWSER_UI_GTK_NOTIFICATIONS_BALLOON_VIEW_GTK_H_