Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(370)

Side by Side Diff: chrome/browser/notifications/balloons.h

Issue 194108: adds DesktopNotificationService to Profile (Closed)
Patch Set: more feedback Created 11 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2009 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 // Handles the visible notification (or balloons).
6
7 #ifndef CHROME_BROWSER_NOTIFICATIONS_BALLOONS_H_
8 #define CHROME_BROWSER_NOTIFICATIONS_BALLOONS_H_
9
10 #include <deque>
11 #include <vector>
12
13 #include "base/basictypes.h"
14 #include "base/gfx/point.h"
15 #include "base/gfx/rect.h"
16 #include "base/gfx/size.h"
17 #include "base/scoped_ptr.h"
18 #include "chrome/browser/notifications/notification.h"
19
20 class Balloon;
21 class BalloonView;
22 class Profile;
23 class SiteInstance;
24
25 class BalloonCloseListener {
26 public:
27 // Called when a balloon is closed.
28 virtual void OnBalloonClosed(Balloon* source) = 0;
29 };
30
31 class BalloonSpaceChangeListener {
michaeln 2009/10/10 19:10:51 you probably want virtual empty dtor's on each of
32 public:
33 // Called when there is more or less space for balloons due to
34 // monitor size changes or balloons disappearing.
35 virtual void OnBalloonSpaceChanged() = 0;
36 };
37
38 class BalloonCollectionInterface {
39 public:
40 virtual ~BalloonCollectionInterface() {}
41
42 // Adds a new balloon for the specified notification.
43 virtual void Add(const Notification& notification,
44 Profile* profile,
45 SiteInstance* site_instance) = 0;
46
47 // Is there room to add another notification?
48 virtual bool HasSpace() const = 0;
49 };
50
51 typedef std::deque<Balloon*> Balloons;
52
53 // Represents a Notification on the screen.
54 class Balloon {
55 public:
56 Balloon(const Notification& notification,
57 Profile* profile,
58 SiteInstance* site_instance,
59 BalloonCloseListener* listener);
60 ~Balloon();
61
62 const Notification& notification() const {
63 return notification_;
64 }
65
66 Profile* profile() const {
67 return profile_;
68 }
69
70 SiteInstance* site_instance() const {
71 return site_instance_;
72 }
73
74 void SetPosition(const gfx::Point& upper_left, bool reposition);
75 void SetSize(const gfx::Size& size);
76 void Show();
77 void Close();
78
79 const gfx::Point& position() const;
80 const gfx::Size& size() const;
81
82 private:
83 Profile* profile_;
84 SiteInstance* site_instance_;
85 Notification notification_;
86 BalloonCloseListener* close_listener_;
87 scoped_ptr<BalloonView> balloon_view_;
88 gfx::Point position_;
89 gfx::Size size_;
90 DISALLOW_COPY_AND_ASSIGN(Balloon);
91 };
92
93 class BalloonCollection : public BalloonCollectionInterface,
94 public BalloonCloseListener {
95 public:
96 explicit BalloonCollection();
michaeln 2009/10/10 19:10:51 is explicit needed?
97
98 BalloonSpaceChangeListener* spaceChangeListener() { return listener_; }
michaeln 2009/10/10 19:10:51 space_change_listener() set_space_cache_listener(x
99 void set_spaceChangeListener(BalloonSpaceChangeListener* listener) {
100 listener_ = listener;
101 }
102
103 // BalloonCollectionInterface overrides
104 virtual void Add(const Notification& notification,
105 Profile* profile,
106 SiteInstance* site_instance);
107 virtual void ShowAll();
108 virtual void HideAll();
109 virtual bool HasSpace() const;
110
111 // BalloonCloseListener interface
112 virtual void OnBalloonClosed(Balloon* source);
113
114 protected:
115 // Overridable by unit tests.
116 virtual Balloon* MakeBalloon(const Notification& notification,
117 Profile* profile,
118 SiteInstance* site_instance) {
119 return new Balloon(notification, profile, site_instance, this);
120 }
121
122 private:
123 // The number of balloons being displayed.
124 int count() const { return balloons_.size(); }
125
126 // Calculates layout values for the balloons including
127 // the scaling, the max/min sizes, and the upper left corner of each.
128 class Layout {
129 public:
130 Layout();
131
132 // Refresh the work area and balloon placement.
133 void OnDisplaySettingsChanged();
134
135 int min_balloon_width() const;
136 int max_balloon_width() const;
137 int min_balloon_height() const;
138 int max_balloon_height() const;
139
140 // Returns both the total length available and the maximum
141 // allowed per balloon.
142 //
143 // The length may be a height or length depending on the way that
144 // balloons are laid out.
145 const void GetMaxLengths(int* max_balloon_length, int* total_length) const;
146
147 // Scale the size to count in the system font factor.
148 int ScaleSize(int size) const;
149
150 // Refresh the cached values for work area and drawing metrics.
151 // This is done automatically first time and the application should
152 // call this method to re-acquire metrics after any
153 // resolution or settings change.
154 //
155 // Return true if and only if a metric changed.
156 bool RefreshSystemMetrics();
157
158 // Returns the starting value for NextUpperLeftPosition.
159 gfx::Point GetStartPosition() const;
160
161 // Compute the position for the next balloon.
162 // Modifies origin.
163 // Returns the position of the upper left coordinate for the given
164 // balloon.
165 gfx::Point NextPosition(const gfx::Size& balloon_size,
166 gfx::Point* origin) const;
167
168 private:
169 enum Placement {
170 HORIZONTALLY_FROM_BOTTOM_LEFT,
171 HORIZONTALLY_FROM_BOTTOM_RIGHT,
172 VERTICALLY_FROM_TOP_RIGHT,
173 VERTICALLY_FROM_BOTTOM_RIGHT
174 };
175
176 // Minimum and maximum size of balloon
177 static const int kBalloonMinWidth = 300;
178 static const int kBalloonMaxWidth = 300;
179 static const int kBalloonMinHeight = 90;
180 static const int kBalloonMaxHeight = 120;
181
182 static Placement placement_;
183 gfx::Rect work_area_;
184 double font_scale_factor_;
185 DISALLOW_COPY_AND_ASSIGN(Layout);
186 };
187
188 // Non-owned pointer to an object listening for space changes.
189 BalloonSpaceChangeListener* listener_;
190
191 Balloons balloons_;
192 Layout layout_;
193 DISALLOW_COPY_AND_ASSIGN(BalloonCollection);
194 };
195
196 #endif // CHROME_BROWSER_NOTIFICATIONS_BALLOONS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698