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

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

Issue 2915003: position the balloons after closing in a way that will keep the next one's cl... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 5 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Handles the visible notification (or balloons). 5 // Handles the visible notification (or balloons).
6 6
7 #ifndef CHROME_BROWSER_NOTIFICATIONS_BALLOON_COLLECTION_IMPL_H_ 7 #ifndef CHROME_BROWSER_NOTIFICATIONS_BALLOON_COLLECTION_IMPL_H_
8 #define CHROME_BROWSER_NOTIFICATIONS_BALLOON_COLLECTION_IMPL_H_ 8 #define CHROME_BROWSER_NOTIFICATIONS_BALLOON_COLLECTION_IMPL_H_
9 9
10 #include <deque> 10 #include <deque>
11 11
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/message_loop.h"
13 #include "chrome/browser/notifications/balloon_collection.h" 14 #include "chrome/browser/notifications/balloon_collection.h"
14 #include "gfx/point.h" 15 #include "gfx/point.h"
15 #include "gfx/rect.h" 16 #include "gfx/rect.h"
16 17
18 // Mac balloons grow from the top down and have close buttons on top, so
19 // offsetting is not necessary for easy multiple-closing. Other platforms grow
20 // from the bottom up and have close buttons on top, so it is necessary.
21 #if defined(OS_MACOSX)
22 #define USE_OFFSETS 0
23 #else
24 #define USE_OFFSETS 1
25 #endif
26
17 // A balloon collection represents a set of notification balloons being 27 // A balloon collection represents a set of notification balloons being
18 // shown on the screen. It positions new notifications according to 28 // shown on the screen. It positions new notifications according to
19 // a layout, and monitors for balloons being closed, which it reports 29 // a layout, and monitors for balloons being closed, which it reports
20 // up to its parent, the notification UI manager. 30 // up to its parent, the notification UI manager.
21 class BalloonCollectionImpl : public BalloonCollection { 31 class BalloonCollectionImpl : public BalloonCollection
32 #if USE_OFFSETS
33 , public MessageLoopForUI::Observer
34 #endif
35 {
22 public: 36 public:
23 BalloonCollectionImpl(); 37 BalloonCollectionImpl();
24 virtual ~BalloonCollectionImpl(); 38 virtual ~BalloonCollectionImpl();
25 39
26 // BalloonCollectionInterface overrides 40 // BalloonCollection interface.
27 virtual void Add(const Notification& notification, 41 virtual void Add(const Notification& notification,
28 Profile* profile); 42 Profile* profile);
29 virtual bool Remove(const Notification& notification); 43 virtual bool Remove(const Notification& notification);
30 virtual bool HasSpace() const; 44 virtual bool HasSpace() const;
31 virtual void ResizeBalloon(Balloon* balloon, const gfx::Size& size); 45 virtual void ResizeBalloon(Balloon* balloon, const gfx::Size& size);
32 virtual void DisplayChanged(); 46 virtual void DisplayChanged();
33 virtual void OnBalloonClosed(Balloon* source); 47 virtual void OnBalloonClosed(Balloon* source);
34 virtual const Balloons& GetActiveBalloons() { 48 virtual const Balloons& GetActiveBalloons() {
35 return balloons_; 49 return balloons_;
36 } 50 }
37 51
52 // MessageLoopForUI::Observer interface.
53 #if defined(OS_WIN)
54 virtual void WillProcessMessage(const MSG& event) {}
55 virtual void DidProcessMessage(const MSG& event);
56 #endif
57 #if defined(OS_LINUX)
58 virtual void WillProcessEvent(GdkEvent* event) {}
59 virtual void DidProcessEvent(GdkEvent* event);
60 #endif
61
38 protected: 62 protected:
39 // Calculates layout values for the balloons including 63 // Calculates layout values for the balloons including
40 // the scaling, the max/min sizes, and the upper left corner of each. 64 // the scaling, the max/min sizes, and the upper left corner of each.
41 class Layout { 65 class Layout {
42 public: 66 public:
43 Layout(); 67 Layout();
44 68
45 // Refresh the work area and balloon placement. 69 // Refresh the work area and balloon placement.
46 void OnDisplaySettingsChanged(); 70 void OnDisplaySettingsChanged();
47 71
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 int count() const { return balloons_.size(); } 138 int count() const { return balloons_.size(); }
115 139
116 // Adjusts the positions of the balloons (e.g., when one is closed). 140 // Adjusts the positions of the balloons (e.g., when one is closed).
117 void PositionBalloons(bool is_reposition); 141 void PositionBalloons(bool is_reposition);
118 142
119 #if defined(OS_MACOSX) 143 #if defined(OS_MACOSX)
120 // Get the work area on Mac OS, without inverting the coordinates. 144 // Get the work area on Mac OS, without inverting the coordinates.
121 static gfx::Rect GetMacWorkArea(); 145 static gfx::Rect GetMacWorkArea();
122 #endif 146 #endif
123 147
148 #if USE_OFFSETS
149 // Start and stop observing all UI events.
150 void AddMessageLoopObserver();
151 void RemoveMessageLoopObserver();
152
153 // Cancel all offset and reposition the balloons normally.
154 void CancelOffsets();
155
156 // Handles a mouse motion while the balloons are temporarily offset.
157 void HandleMouseMoveEvent();
158
159 // Is the current cursor in the balloon area?
160 bool IsCursorInBalloonCollection() const;
161 #endif
162
124 // Queue of active balloons. 163 // Queue of active balloons.
125 typedef std::deque<Balloon*> Balloons; 164 typedef std::deque<Balloon*> Balloons;
126 Balloons balloons_; 165 Balloons balloons_;
127 166
128 // The layout parameters for balloons in this collection. 167 // The layout parameters for balloons in this collection.
129 Layout layout_; 168 Layout layout_;
130 169
170 #if USE_OFFSETS
171 // Factory for generating delayed reposition tasks on mouse motion.
172 ScopedRunnableMethodFactory<BalloonCollectionImpl> reposition_factory_;
173
174 // Is the balloon collection currently listening for UI events?
175 bool added_as_message_loop_observer_;
176 #endif
177
131 DISALLOW_COPY_AND_ASSIGN(BalloonCollectionImpl); 178 DISALLOW_COPY_AND_ASSIGN(BalloonCollectionImpl);
132 }; 179 };
133 180
134 #endif // CHROME_BROWSER_NOTIFICATIONS_BALLOON_COLLECTION_IMPL_H_ 181 #endif // CHROME_BROWSER_NOTIFICATIONS_BALLOON_COLLECTION_IMPL_H_
OLDNEW
« no previous file with comments | « chrome/browser/notifications/balloon_collection.cc ('k') | chrome/browser/notifications/balloon_collection_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698