OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_BROWSER_CHROMEOS_NOTIFICATIONS_BALLOON_COLLECTION_IMPL_H_ | |
6 #define CHROME_BROWSER_CHROMEOS_NOTIFICATIONS_BALLOON_COLLECTION_IMPL_H_ | |
7 #pragma once | |
8 | |
9 #include <string> | |
10 | |
11 #include "base/basictypes.h" | |
12 #include "base/memory/scoped_ptr.h" | |
13 #include "chrome/browser/chromeos/notifications/balloon_view_host.h" | |
14 #include "chrome/browser/notifications/balloon_collection.h" | |
15 #include "chrome/browser/notifications/balloon_collection_base.h" | |
16 #include "content/public/browser/notification_registrar.h" | |
17 #include "ui/gfx/point.h" | |
18 #include "ui/gfx/rect.h" | |
19 | |
20 namespace gfx { | |
21 class Size; | |
22 } // namespace gfx | |
23 | |
24 namespace chromeos { | |
25 | |
26 class BalloonViewImpl; | |
27 | |
28 // A balloon collection represents a set of notification balloons being | |
29 // shown in the chromeos notification panel. Unlike other platforms, | |
30 // chromeos shows the all notifications in the notification panel, and | |
31 // this class does not manage the location of balloons. | |
32 class BalloonCollectionImpl : public BalloonCollection, | |
33 public content::NotificationObserver { | |
34 public: | |
35 // An interface to display balloons on the screen. | |
36 // This is used for unit tests to inject a mock ui implementation. | |
37 class NotificationUI { | |
38 public: | |
39 NotificationUI() {} | |
40 virtual ~NotificationUI() {} | |
41 | |
42 // Add, remove, resize and show the balloon. | |
43 virtual void Add(Balloon* balloon) = 0; | |
44 virtual bool Update(Balloon* balloon) = 0; | |
45 virtual void Remove(Balloon* balloon) = 0; | |
46 virtual void Show(Balloon* balloon) = 0; | |
47 | |
48 // Resize notification from webkit. | |
49 virtual void ResizeNotification(Balloon* balloon, | |
50 const gfx::Size& size) = 0; | |
51 | |
52 // Sets the active view. | |
53 virtual void SetActiveView(BalloonViewImpl* view) = 0; | |
54 private: | |
55 DISALLOW_COPY_AND_ASSIGN(NotificationUI); | |
56 }; | |
57 | |
58 BalloonCollectionImpl(); | |
59 virtual ~BalloonCollectionImpl(); | |
60 | |
61 // BalloonCollectionInterface overrides | |
62 virtual void Add(const Notification& notification, | |
63 Profile* profile) OVERRIDE; | |
64 virtual bool RemoveById(const std::string& id) OVERRIDE; | |
65 virtual bool RemoveBySourceOrigin(const GURL& origin) OVERRIDE; | |
66 virtual void RemoveAll() OVERRIDE; | |
67 virtual bool HasSpace() const OVERRIDE; | |
68 virtual void ResizeBalloon(Balloon* balloon, const gfx::Size& size) OVERRIDE; | |
69 virtual void SetPositionPreference(PositionPreference position) OVERRIDE {} | |
70 virtual void DisplayChanged() OVERRIDE {} | |
71 virtual void OnBalloonClosed(Balloon* source) OVERRIDE; | |
72 virtual const Balloons& GetActiveBalloons() OVERRIDE; | |
73 | |
74 // NotificationObserver overrides: | |
75 virtual void Observe(int type, | |
76 const content::NotificationSource& source, | |
77 const content::NotificationDetails& details) OVERRIDE; | |
78 | |
79 // Adds a callback for WebUI message. Returns true if the callback | |
80 // is succssfully registered, or false otherwise. It fails to add if | |
81 // there is no notification that matches NotificationDelegate::id(), | |
82 // or a callback for given message already exists. The callback | |
83 // object is owned and deleted by callee. | |
84 bool AddWebUIMessageCallback( | |
85 const Notification& notification, | |
86 const std::string& message, | |
87 const BalloonViewHost::MessageCallback& callback); | |
88 | |
89 // Adds new system notification. | |
90 // |sticky| is used to indicate that the notification | |
91 // is sticky and cannot be dismissed by a user. | |
92 void AddSystemNotification(const Notification& notification, | |
93 Profile* profile, | |
94 bool sticky); | |
95 | |
96 // Updates the notification's content. It uses | |
97 // NotificationDelegate::id() to check the equality of notifications. | |
98 // Returns true if the notification has been updated. False if | |
99 // no corresponding notification is found. This will not change the | |
100 // visibility of the notification. | |
101 bool UpdateNotification(const Notification& notification); | |
102 | |
103 // Updates and shows the notification. It will open the notification panel | |
104 // if it's closed or minimized, and scroll the viewport so that | |
105 // the updated notification is visible. | |
106 bool UpdateAndShowNotification(const Notification& notification); | |
107 | |
108 // base_ is embedded, so this is a simple accessor for the number of | |
109 // balloons in the collection. | |
110 int count() const { return base_.count(); } | |
111 | |
112 // Injects notification ui. Used to inject a mock implementation in tests. | |
113 void set_notification_ui(NotificationUI* ui) { | |
114 notification_ui_.reset(ui); | |
115 } | |
116 | |
117 NotificationUI* notification_ui() { | |
118 return notification_ui_.get(); | |
119 } | |
120 | |
121 protected: | |
122 // Creates a new balloon. Overridable by unit tests. The caller is | |
123 // responsible for freeing the pointer returned. | |
124 virtual Balloon* MakeBalloon(const Notification& notification, | |
125 Profile* profile); | |
126 | |
127 // Base implementation for the collection of active balloons. | |
128 BalloonCollectionBase base_; | |
129 | |
130 private: | |
131 friend class NotificationPanelTester; | |
132 | |
133 // Shutdown the notification ui. | |
134 void Shutdown(); | |
135 | |
136 Balloon* FindBalloon(const Notification& notification) { | |
137 return base_.FindBalloon(notification); | |
138 } | |
139 | |
140 scoped_ptr<NotificationUI> notification_ui_; | |
141 | |
142 content::NotificationRegistrar registrar_; | |
143 | |
144 DISALLOW_COPY_AND_ASSIGN(BalloonCollectionImpl); | |
145 }; | |
146 | |
147 } // namespace chromeos | |
148 | |
149 #endif // CHROME_BROWSER_CHROMEOS_NOTIFICATIONS_BALLOON_COLLECTION_IMPL_H_ | |
OLD | NEW |