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_CHROMEOS_NOTIFICATIONS_BALLOON_VIEW_H_
8#define CHROME_BROWSER_CHROMEOS_NOTIFICATIONS_BALLOON_VIEW_H_
9#pragma once
10
11#include "base/basictypes.h"
12#include "base/memory/scoped_ptr.h"
13#include "base/task.h"
14#include "chrome/browser/notifications/balloon.h"
15#include "content/common/notification_observer.h"
16#include "content/common/notification_registrar.h"
17#include "ui/gfx/path.h"
18#include "ui/gfx/point.h"
19#include "ui/gfx/rect.h"
20#include "ui/gfx/size.h"
21#include "views/view.h"
22
23namespace views {
24class Menu2;
25class MenuButton;
26class MouseEvent;
27class TextButton;
28class Widget;
29}  // namespace views
30
31class Notification;
32class NotificationDetails;
33class NotificationSource;
34
35namespace chromeos {
36
37class BalloonViewHost;
38class NotificationControlView;
39
40// A balloon view is the UI component for a notification panel.
41class BalloonViewImpl : public BalloonView,
42                        public views::View,
43                        public NotificationObserver {
44 public:
45  BalloonViewImpl(bool sticky, bool controls, bool web_ui);
46  virtual ~BalloonViewImpl();
47
48  // views::View interface.
49  virtual void Layout();
50  virtual void ViewHierarchyChanged(bool is_add, View* parent, View* child);
51
52  // BalloonView interface.
53  virtual void Show(Balloon* balloon);
54  virtual void Update();
55  virtual void Close(bool by_user);
56  virtual void RepositionToBalloon();
57  gfx::Size GetSize() const;
58  virtual BalloonHost* GetHost() const;
59
60  // True if the notification is stale. False if the notification is new.
61  bool stale() const { return stale_; }
62
63  // Makes the notification stale.
64  void set_stale() { stale_ = true; }
65
66  // True if the notification is sticky.
67  bool sticky() const { return sticky_; }
68
69  // True if the notification is being closed.
70  bool closed() const { return closed_; }
71
72  // True if the balloon is for the given |notification|.
73  bool IsFor(const Notification& notification) const;
74
75  // Called when the notification becomes active (mouse is on).
76  void Activated();
77
78  // Called when the notification becomes inactive.
79  void Deactivated();
80
81 private:
82  friend class NotificationControlView;
83
84  // views::View interface.
85  virtual gfx::Size GetPreferredSize() {
86    return gfx::Size(1000, 1000);
87  }
88
89  // NotificationObserver interface.
90  virtual void Observe(NotificationType type,
91                       const NotificationSource& source,
92                       const NotificationDetails& details);
93
94  // Initializes the options menu.
95  void CreateOptionsMenu();
96
97  // Do the delayed close work.
98  void DelayedClose(bool by_user);
99
100  // Denies the permission to show the ballooon from its source.
101  void DenyPermission();
102
103  // Returns the renderer's native view.
104  gfx::NativeView GetParentNativeView();
105
106  // Non-owned pointer to the balloon which owns this object.
107  Balloon* balloon_;
108
109  // The renderer of the HTML contents. Pointer owned by the views hierarchy.
110  BalloonViewHost* html_contents_;
111
112  // The following factory is used to call methods at a later time.
113  ScopedRunnableMethodFactory<BalloonViewImpl> method_factory_;
114
115  // A widget for ControlView.
116  scoped_ptr<views::Widget> control_view_host_;
117
118  bool stale_;
119  NotificationRegistrar notification_registrar_;
120  // A sticky flag. A sticky notification cannot be dismissed by a user.
121  bool sticky_;
122  // True if a notification should have info/option/dismiss label/buttons.
123  bool controls_;
124  // True if the notification is being closed.
125  bool closed_;
126  // True to enable WebUI in the notification.
127  bool web_ui_;
128
129  DISALLOW_COPY_AND_ASSIGN(BalloonViewImpl);
130};
131
132}  // namespace chromeos
133
134#endif  // CHROME_BROWSER_CHROMEOS_NOTIFICATIONS_BALLOON_VIEW_H_
135