OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
16 #include "chrome/browser/notifications/balloon_collection.h" | 16 #include "chrome/browser/notifications/balloon_collection.h" |
17 #include "chrome/browser/notifications/balloon_collection_base.h" | 17 #include "chrome/browser/notifications/balloon_collection_base.h" |
18 #include "content/public/browser/notification_observer.h" | 18 #include "content/public/browser/notification_observer.h" |
19 #include "content/public/browser/notification_registrar.h" | 19 #include "content/public/browser/notification_registrar.h" |
20 #include "ui/gfx/point.h" | 20 #include "ui/gfx/point.h" |
21 #include "ui/gfx/rect.h" | 21 #include "ui/gfx/rect.h" |
22 | 22 |
23 // Mac balloons grow from the top down and have close buttons on top, so | |
24 // offsetting is not necessary for easy multiple-closing. Other platforms grow | |
25 // from the bottom up and have close buttons on top, so it is necessary. | |
26 #if defined(OS_MACOSX) | |
27 #define USE_OFFSETS 0 | |
28 #else | |
29 #define USE_OFFSETS 1 | |
30 #endif | |
31 | |
32 // A balloon collection represents a set of notification balloons being | 23 // A balloon collection represents a set of notification balloons being |
33 // shown on the screen. It positions new notifications according to | 24 // shown on the screen. It positions new notifications according to |
34 // a layout, and monitors for balloons being closed, which it reports | 25 // a layout, and monitors for balloons being closed, which it reports |
35 // up to its parent, the notification UI manager. | 26 // up to its parent, the notification UI manager. |
36 class BalloonCollectionImpl : public BalloonCollection, | 27 class BalloonCollectionImpl : public BalloonCollection, |
37 public content::NotificationObserver | 28 public content::NotificationObserver, |
38 #if USE_OFFSETS | 29 public base::MessageLoopForUI::Observer { |
39 , public base::MessageLoopForUI::Observer | |
40 #endif | |
41 { | |
42 public: | 30 public: |
43 BalloonCollectionImpl(); | 31 BalloonCollectionImpl(); |
44 virtual ~BalloonCollectionImpl(); | 32 virtual ~BalloonCollectionImpl(); |
45 | 33 |
46 // BalloonCollection interface. | 34 // BalloonCollection interface. |
47 virtual void Add(const Notification& notification, | 35 virtual void Add(const Notification& notification, |
48 Profile* profile) OVERRIDE; | 36 Profile* profile) OVERRIDE; |
49 virtual const Notification* FindById(const std::string& id) const OVERRIDE; | 37 virtual const Notification* FindById(const std::string& id) const OVERRIDE; |
50 virtual bool RemoveById(const std::string& id) OVERRIDE; | 38 virtual bool RemoveById(const std::string& id) OVERRIDE; |
51 virtual bool RemoveBySourceOrigin(const GURL& source_origin) OVERRIDE; | 39 virtual bool RemoveBySourceOrigin(const GURL& source_origin) OVERRIDE; |
52 virtual bool RemoveByProfile(Profile* profile) OVERRIDE; | 40 virtual bool RemoveByProfile(Profile* profile) OVERRIDE; |
53 virtual void RemoveAll() OVERRIDE; | 41 virtual void RemoveAll() OVERRIDE; |
54 virtual bool HasSpace() const OVERRIDE; | 42 virtual bool HasSpace() const OVERRIDE; |
55 virtual void ResizeBalloon(Balloon* balloon, const gfx::Size& size) OVERRIDE; | 43 virtual void ResizeBalloon(Balloon* balloon, const gfx::Size& size) OVERRIDE; |
56 virtual void SetPositionPreference(PositionPreference position) OVERRIDE; | 44 virtual void SetPositionPreference(PositionPreference position) OVERRIDE; |
57 virtual void DisplayChanged() OVERRIDE; | 45 virtual void DisplayChanged() OVERRIDE; |
58 virtual void OnBalloonClosed(Balloon* source) OVERRIDE; | 46 virtual void OnBalloonClosed(Balloon* source) OVERRIDE; |
59 virtual const Balloons& GetActiveBalloons() OVERRIDE; | 47 virtual const Balloons& GetActiveBalloons() OVERRIDE; |
60 | 48 |
61 // content::NotificationObserver interface. | 49 // content::NotificationObserver interface. |
62 virtual void Observe(int type, | 50 virtual void Observe(int type, |
63 const content::NotificationSource& source, | 51 const content::NotificationSource& source, |
64 const content::NotificationDetails& details) OVERRIDE; | 52 const content::NotificationDetails& details) OVERRIDE; |
65 | 53 |
66 // MessageLoopForUI::Observer interface. | 54 // MessageLoopForUI::Observer interface. |
67 #if defined(OS_WIN) || defined(USE_AURA) | |
68 virtual void WillProcessEvent(const base::NativeEvent& event) OVERRIDE; | |
69 virtual void DidProcessEvent(const base::NativeEvent& event) OVERRIDE; | |
70 #elif defined(TOOLKIT_GTK) | |
71 virtual void WillProcessEvent(GdkEvent* event) OVERRIDE; | 55 virtual void WillProcessEvent(GdkEvent* event) OVERRIDE; |
72 virtual void DidProcessEvent(GdkEvent* event) OVERRIDE; | 56 virtual void DidProcessEvent(GdkEvent* event) OVERRIDE; |
73 #endif | |
74 | 57 |
75 // base_ is embedded, so this is a simple accessor for the number of | 58 // base_ is embedded, so this is a simple accessor for the number of |
76 // balloons in the collection. | 59 // balloons in the collection. |
77 int count() const { return base_.count(); } | 60 int count() const { return base_.count(); } |
78 | 61 |
79 static int min_balloon_width() { return Layout::min_balloon_width(); } | 62 static int min_balloon_width() { return Layout::min_balloon_width(); } |
80 static int max_balloon_width() { return Layout::max_balloon_width(); } | 63 static int max_balloon_width() { return Layout::max_balloon_width(); } |
81 static int min_balloon_height() { return Layout::min_balloon_height(); } | 64 static int min_balloon_height() { return Layout::min_balloon_height(); } |
82 static int max_balloon_height() { return Layout::max_balloon_height(); } | 65 static int max_balloon_height() { return Layout::max_balloon_height(); } |
83 | 66 |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 Layout& layout() { return layout_; } | 183 Layout& layout() { return layout_; } |
201 | 184 |
202 private: | 185 private: |
203 // Adjusts the positions of the balloons (e.g., when one is closed). | 186 // Adjusts the positions of the balloons (e.g., when one is closed). |
204 // Implemented by each platform for specific UI requirements. | 187 // Implemented by each platform for specific UI requirements. |
205 void PositionBalloons(bool is_reposition); | 188 void PositionBalloons(bool is_reposition); |
206 | 189 |
207 // Cross-platform internal implementation for PositionBalloons. | 190 // Cross-platform internal implementation for PositionBalloons. |
208 void PositionBalloonsInternal(bool is_reposition); | 191 void PositionBalloonsInternal(bool is_reposition); |
209 | 192 |
210 #if defined(OS_MACOSX) | |
211 // Get the work area on Mac OS, without inverting the coordinates. | |
212 static gfx::Rect GetMacWorkArea(); | |
213 #endif | |
214 | |
215 // Base implementation for the collection of active balloons. | 193 // Base implementation for the collection of active balloons. |
216 BalloonCollectionBase base_; | 194 BalloonCollectionBase base_; |
217 | 195 |
218 // The layout parameters for balloons in this collection. | 196 // The layout parameters for balloons in this collection. |
219 Layout layout_; | 197 Layout layout_; |
220 | 198 |
221 content::NotificationRegistrar registrar_; | 199 content::NotificationRegistrar registrar_; |
222 | 200 |
223 #if USE_OFFSETS | |
224 // Start and stop observing all UI events. | 201 // Start and stop observing all UI events. |
225 void AddMessageLoopObserver(); | 202 void AddMessageLoopObserver(); |
226 void RemoveMessageLoopObserver(); | 203 void RemoveMessageLoopObserver(); |
227 | 204 |
228 // Cancel all offset and reposition the balloons normally. | 205 // Cancel all offset and reposition the balloons normally. |
229 void CancelOffsets(); | 206 void CancelOffsets(); |
230 | 207 |
231 // Handles a mouse motion while the balloons are temporarily offset. | 208 // Handles a mouse motion while the balloons are temporarily offset. |
232 void HandleMouseMoveEvent(); | 209 void HandleMouseMoveEvent(); |
233 | 210 |
234 // Is the current cursor in the balloon area? | 211 // Is the current cursor in the balloon area? |
235 bool IsCursorInBalloonCollection() const; | 212 bool IsCursorInBalloonCollection() const; |
236 | 213 |
237 // Factory for generating delayed reposition tasks on mouse motion. | 214 // Factory for generating delayed reposition tasks on mouse motion. |
238 base::WeakPtrFactory<BalloonCollectionImpl> reposition_factory_; | 215 base::WeakPtrFactory<BalloonCollectionImpl> reposition_factory_; |
239 | 216 |
240 // Is the balloon collection currently listening for UI events? | 217 // Is the balloon collection currently listening for UI events? |
241 bool added_as_message_loop_observer_; | 218 bool added_as_message_loop_observer_; |
242 #endif | |
243 | 219 |
244 DISALLOW_COPY_AND_ASSIGN(BalloonCollectionImpl); | 220 DISALLOW_COPY_AND_ASSIGN(BalloonCollectionImpl); |
245 }; | 221 }; |
246 | 222 |
247 #endif // CHROME_BROWSER_NOTIFICATIONS_BALLOON_COLLECTION_IMPL_H_ | 223 #endif // CHROME_BROWSER_NOTIFICATIONS_BALLOON_COLLECTION_IMPL_H_ |
OLD | NEW |