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

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

Issue 208068: Desktop Notifications UI (for windows) (Closed)
Patch Set: Created 11 years, 3 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 BalloonCollectionObserver {
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 typedef std::vector<BalloonCollectionObserver*> BalloonObservers;
53
54 // Represents a Notification on the screen.
55 class Balloon {
56 public:
57 Balloon(const Notification& notification,
58 Profile* profile,
59 SiteInstance* site_instance,
60 BalloonCloseListener* listener);
61 ~Balloon();
62
63 const Notification& notification() const {
64 return notification_;
65 }
66
67 Profile* profile() const {
68 return profile_;
69 }
70
71 SiteInstance* site_instance() const {
72 return site_instance_;
73 }
74
75 virtual void SetPosition(const gfx::Point& upper_left, bool reposition);
76 virtual void SetSize(const gfx::Size& size);
77 virtual void Show();
78 virtual void Close();
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();
97
98 void AddObserver(BalloonCollectionObserver* observer);
99
100 // BalloonCollectionInterface overrides
101 virtual void Add(const Notification& notification,
102 Profile* profile,
103 SiteInstance* site_instance);
104 virtual void ShowAll();
105 virtual void HideAll();
106 virtual bool HasSpace() const;
107
108 // BalloonCloseListener interface
109 virtual void OnBalloonClosed(Balloon* source);
110
111 protected:
112 // Overridable by unit tests.
113 virtual Balloon* MakeBalloon(const Notification& notification,
114 Profile* profile,
115 SiteInstance* site_instance) {
116 return new Balloon(notification, profile, site_instance, this);
117 }
118
119 private:
120 // The number of balloons being displayed.
121 int count() const { return balloons_.size(); }
122
123 // Calculates layout values for the balloons including
124 // the scaling, the max/min sizes, and the upper left corner of each.
125 class Layout {
126 public:
127 Layout();
128
129 // Refresh the work area and balloon placement.
130 void OnDisplaySettingsChanged();
131
132 int min_balloon_width() const;
133 int max_balloon_width() const;
134 int min_balloon_height() const;
135 int max_balloon_height() const;
136
137 // Returns both the total length available and the maximum
138 // allowed per balloon.
139 //
140 // The length may be a height or length depending on the way that
141 // balloons are laid out.
142 const void GetMaxLengths(int* max_balloon_length, int* total_length) const;
143
144 // Scale the size to count in the system font factor.
145 int ScaleSize(int size) const;
146
147 // Refresh the cached values for work area and drawing metrics.
148 // This is done automatically first time and the application should
149 // call this method to re-acquire metrics after any
150 // resolution or settings change.
151 //
152 // Return true if and only if a metric changed.
153 bool RefreshSystemMetrics();
154
155 // Returns the starting value for NextUpperLeftPosition.
156 gfx::Point GetOrigin() const;
157
158 // Compute the position for the next balloon.
159 // Modifies origin.
160 // Returns the position of the upper left coordinate for the given
161 // balloon.
162 gfx::Point NextPosition(const gfx::Size& balloon_size,
163 gfx::Point* origin) const;
164
165 private:
166 enum Placement {
167 HORIZONTALLY_FROM_BOTTOM_LEFT,
168 HORIZONTALLY_FROM_BOTTOM_RIGHT,
169 VERTICALLY_FROM_TOP_RIGHT,
170 VERTICALLY_FROM_BOTTOM_RIGHT
171 };
172
173 // Minimum and maximum size of balloon
174 const static int kBalloonMinWidth = 300;
175 const static int kBalloonMaxWidth = 300;
176 const static int kBalloonMinHeight = 90;
177 const static int kBalloonMaxHeight = 120;
178
179 static Placement placement_;
180 gfx::Rect work_area_;
181 double font_scale_factor_;
182 DISALLOW_COPY_AND_ASSIGN(Layout);
183 };
184
185 std::vector<BalloonCollectionObserver*> observers_;
186 Balloons balloons_;
187 Layout layout_;
188 DISALLOW_COPY_AND_ASSIGN(BalloonCollection);
189 };
190
191 #endif // CHROME_BROWSER_NOTIFICATIONS_BALLOONS_H_
OLDNEW
« no previous file with comments | « chrome/browser/notifications/balloon_win.cc ('k') | chrome/browser/notifications/notification.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698