172a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen// Copyright (c) 2011 The Chromium Authors. All rights reserved.
2c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// Use of this source code is governed by a BSD-style license that can be
3c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// found in the LICENSE file.
4c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
5c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// Draws the view for the balloons.
6c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
772a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen#ifndef CHROME_BROWSER_UI_GTK_NOTIFICATIONS_BALLOON_VIEW_GTK_H_
872a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen#define CHROME_BROWSER_UI_GTK_NOTIFICATIONS_BALLOON_VIEW_GTK_H_
93345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick#pragma once
10c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
11c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "base/basictypes.h"
12ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen#include "base/memory/scoped_ptr.h"
13c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "chrome/browser/notifications/balloon.h"
1472a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen#include "chrome/browser/ui/gtk/menu_gtk.h"
1572a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen#include "chrome/browser/ui/gtk/notifications/balloon_view_host_gtk.h"
16dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen#include "content/common/notification_observer.h"
17dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen#include "content/common/notification_registrar.h"
183f50c38dc070f4bb515c1b64450dae14f316474eKristian Monsen#include "ui/base/animation/animation_delegate.h"
1972a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen#include "ui/base/gtk/gtk_signal.h"
2072a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen#include "ui/gfx/point.h"
2172a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen#include "ui/gfx/rect.h"
2272a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen#include "ui/gfx/size.h"
23c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
24c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass BalloonCollection;
25c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass CustomDrawButton;
26ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsenclass GtkThemeService;
27c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass MenuGtk;
28c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass NotificationDetails;
29c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass NotificationOptionsMenuModel;
30c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass NotificationSource;
313f50c38dc070f4bb515c1b64450dae14f316474eKristian Monsen
323f50c38dc070f4bb515c1b64450dae14f316474eKristian Monsennamespace ui {
33c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass SlideAnimation;
343f50c38dc070f4bb515c1b64450dae14f316474eKristian Monsen}
35c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
36c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// A balloon view is the UI component for desktop notification toasts.
37c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// It draws a border, and within the border an HTML renderer.
38c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass BalloonViewImpl : public BalloonView,
39c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch                        public MenuGtk::Delegate,
40c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch                        public NotificationObserver,
413f50c38dc070f4bb515c1b64450dae14f316474eKristian Monsen                        public ui::AnimationDelegate {
42c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch public:
43c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  explicit BalloonViewImpl(BalloonCollection* collection);
4472a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  virtual ~BalloonViewImpl();
45c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
46c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // BalloonView interface.
47c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual void Show(Balloon* balloon);
48c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual void Update();
49c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual void RepositionToBalloon();
50c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual void Close(bool by_user);
51c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual gfx::Size GetSize() const;
5221d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen  virtual BalloonHost* GetHost() const;
53c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
5472a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  // MenuGtk::Delegate interface.
5572a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  virtual void StoppedShowing();
5672a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
57c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch private:
58c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // NotificationObserver interface.
59c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual void Observe(NotificationType type,
60c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch                       const NotificationSource& source,
61c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch                       const NotificationDetails& details);
62c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
633f50c38dc070f4bb515c1b64450dae14f316474eKristian Monsen  // ui::AnimationDelegate interface.
643f50c38dc070f4bb515c1b64450dae14f316474eKristian Monsen  virtual void AnimationProgressed(const ui::Animation* animation);
65c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
66dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen  // Do the delayed close work.  The balloon and all view components will be
67dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen  // destroyed at this time, so it shouldn't be called while still processing
68dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen  // an event that relies on them.
69c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void DelayedClose(bool by_user);
70c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
71c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // The height of the balloon's shelf.
72c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // The shelf is where is close button is located.
73c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  int GetShelfHeight() const;
74c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
75c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // The width and height that the frame should be.  If the balloon inside
76c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // changes size, this will not be the same as the actual frame size until
77c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // RepositionToBalloon() has been called and the animation completes.
78c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  int GetDesiredTotalWidth() const;
79c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  int GetDesiredTotalHeight() const;
80c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
81c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Where the balloon contents should be placed with respect to the top left
82c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // of the frame.
83c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  gfx::Point GetContentsOffset() const;
84c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
85c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Where the balloon contents should be in screen coordinates.
86c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  gfx::Rect GetContentsRectangle() const;
87c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
8872a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  CHROMEGTK_CALLBACK_1(BalloonViewImpl, gboolean, OnContentsExpose,
8972a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen                       GdkEventExpose*);
903345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  CHROMEGTK_CALLBACK_0(BalloonViewImpl, void, OnCloseButton);
91c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  CHROMEGTK_CALLBACK_1(BalloonViewImpl, gboolean, OnExpose, GdkEventExpose*);
9272a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  CHROMEGTK_CALLBACK_1(BalloonViewImpl, void, OnOptionsMenuButton,
9372a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen                       GdkEventButton*);
94c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  CHROMEGTK_CALLBACK_0(BalloonViewImpl, gboolean, OnDestroy);
95c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
96c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Non-owned pointer to the balloon which owns this object.
97c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  Balloon* balloon_;
98c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
99ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  GtkThemeService* theme_service_;
100c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
101c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // The window that contains the frame of the notification.
102c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  GtkWidget* frame_container_;
103c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
104c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // The widget that contains the shelf.
105c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  GtkWidget* shelf_;
106c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
107c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // The hbox within the shelf that contains the buttons.
108c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  GtkWidget* hbox_;
109c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
110c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // The window that contains the contents of the notification.
111c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  GtkWidget* html_container_;
112c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
113c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // The renderer of the HTML contents.
114c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  scoped_ptr<BalloonViewHost> html_contents_;
115c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
116c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // The following factory is used to call methods at a later time.
117c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  ScopedRunnableMethodFactory<BalloonViewImpl> method_factory_;
118c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
119c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Close button.
120c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  scoped_ptr<CustomDrawButton> close_button_;
121c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
122c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // An animation to move the balloon on the screen as its position changes.
1233f50c38dc070f4bb515c1b64450dae14f316474eKristian Monsen  scoped_ptr<ui::SlideAnimation> animation_;
124c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  gfx::Rect anim_frame_start_;
125c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  gfx::Rect anim_frame_end_;
126c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
127c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // The options menu.
128c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  scoped_ptr<MenuGtk> options_menu_;
129c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  scoped_ptr<NotificationOptionsMenuModel> options_menu_model_;
130c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // The button to open the options menu.
131c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  scoped_ptr<CustomDrawButton> options_menu_button_;
132c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
133c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  NotificationRegistrar notification_registrar_;
134c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
13572a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  // Is the menu currently showing?
13672a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  bool menu_showing_;
13772a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
13872a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  // Is there a pending system-initiated close?
13972a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  bool pending_close_;
14072a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
141c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  DISALLOW_COPY_AND_ASSIGN(BalloonViewImpl);
142c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch};
143c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
14472a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen#endif  // CHROME_BROWSER_UI_GTK_NOTIFICATIONS_BALLOON_VIEW_GTK_H_
145