OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #pragma once | 9 #pragma once |
10 | 10 |
11 #include <deque> | 11 #include <deque> |
12 | 12 |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "base/message_loop.h" | 16 #include "base/message_loop.h" |
17 #include "chrome/browser/notifications/balloon_collection.h" | 17 #include "chrome/browser/notifications/balloon_collection.h" |
18 #include "chrome/browser/notifications/balloon_collection_base.h" | 18 #include "chrome/browser/notifications/balloon_collection_base.h" |
19 #include "content/public/browser/notification_observer.h" | |
20 #include "content/public/browser/notification_registrar.h" | |
19 #include "ui/gfx/point.h" | 21 #include "ui/gfx/point.h" |
20 #include "ui/gfx/rect.h" | 22 #include "ui/gfx/rect.h" |
21 | 23 |
22 // Mac balloons grow from the top down and have close buttons on top, so | 24 // Mac balloons grow from the top down and have close buttons on top, so |
23 // offsetting is not necessary for easy multiple-closing. Other platforms grow | 25 // offsetting is not necessary for easy multiple-closing. Other platforms grow |
24 // from the bottom up and have close buttons on top, so it is necessary. | 26 // from the bottom up and have close buttons on top, so it is necessary. |
25 #if defined(OS_MACOSX) | 27 #if defined(OS_MACOSX) |
26 #define USE_OFFSETS 0 | 28 #define USE_OFFSETS 0 |
27 #else | 29 #else |
28 #define USE_OFFSETS 1 | 30 #define USE_OFFSETS 1 |
29 #endif | 31 #endif |
30 | 32 |
33 class Browser; | |
34 | |
31 // A balloon collection represents a set of notification balloons being | 35 // A balloon collection represents a set of notification balloons being |
32 // shown on the screen. It positions new notifications according to | 36 // shown on the screen. It positions new notifications according to |
33 // a layout, and monitors for balloons being closed, which it reports | 37 // a layout, and monitors for balloons being closed, which it reports |
34 // up to its parent, the notification UI manager. | 38 // up to its parent, the notification UI manager. |
35 class BalloonCollectionImpl : public BalloonCollection | 39 class BalloonCollectionImpl : public BalloonCollection, |
40 public content::NotificationObserver | |
36 #if USE_OFFSETS | 41 #if USE_OFFSETS |
37 , public MessageLoopForUI::Observer | 42 , public MessageLoopForUI::Observer |
38 #endif | 43 #endif |
39 { | 44 { |
40 public: | 45 public: |
41 BalloonCollectionImpl(); | 46 BalloonCollectionImpl(); |
42 virtual ~BalloonCollectionImpl(); | 47 virtual ~BalloonCollectionImpl(); |
43 | 48 |
44 // BalloonCollection interface. | 49 // BalloonCollection interface. |
45 virtual void Add(const Notification& notification, | 50 virtual void Add(const Notification& notification, |
46 Profile* profile); | 51 Profile* profile); |
47 virtual bool RemoveById(const std::string& id); | 52 virtual bool RemoveById(const std::string& id); |
48 virtual bool RemoveBySourceOrigin(const GURL& source_origin); | 53 virtual bool RemoveBySourceOrigin(const GURL& source_origin); |
49 virtual void RemoveAll(); | 54 virtual void RemoveAll(); |
50 virtual bool HasSpace() const; | 55 virtual bool HasSpace() const; |
51 virtual void ResizeBalloon(Balloon* balloon, const gfx::Size& size); | 56 virtual void ResizeBalloon(Balloon* balloon, const gfx::Size& size); |
52 virtual void SetPositionPreference(PositionPreference position); | 57 virtual void SetPositionPreference(PositionPreference position); |
53 virtual void DisplayChanged(); | 58 virtual void DisplayChanged(); |
54 virtual void OnBalloonClosed(Balloon* source); | 59 virtual void OnBalloonClosed(Balloon* source); |
55 virtual const Balloons& GetActiveBalloons(); | 60 virtual const Balloons& GetActiveBalloons(); |
56 | 61 |
62 // content::NotificationObserver interface. | |
63 virtual void Observe(int type, | |
64 const content::NotificationSource& source, | |
65 const content::NotificationDetails& details) OVERRIDE; | |
66 | |
57 // MessageLoopForUI::Observer interface. | 67 // MessageLoopForUI::Observer interface. |
58 #if defined(OS_WIN) || defined(TOUCH_UI) || defined(USE_AURA) | 68 #if defined(OS_WIN) || defined(TOUCH_UI) || defined(USE_AURA) |
59 virtual base::EventStatus WillProcessEvent( | 69 virtual base::EventStatus WillProcessEvent( |
60 const base::NativeEvent& event) OVERRIDE; | 70 const base::NativeEvent& event) OVERRIDE; |
61 virtual void DidProcessEvent(const base::NativeEvent& event) OVERRIDE; | 71 virtual void DidProcessEvent(const base::NativeEvent& event) OVERRIDE; |
62 #elif defined(TOOLKIT_USES_GTK) | 72 #elif defined(TOOLKIT_USES_GTK) |
63 virtual void WillProcessEvent(GdkEvent* event) OVERRIDE; | 73 virtual void WillProcessEvent(GdkEvent* event) OVERRIDE; |
64 virtual void DidProcessEvent(GdkEvent* event) OVERRIDE; | 74 virtual void DidProcessEvent(GdkEvent* event) OVERRIDE; |
65 #endif | 75 #endif |
66 | 76 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
120 gfx::Point* position_iterator) const; | 130 gfx::Point* position_iterator) const; |
121 | 131 |
122 // Return a offscreen location which is offscreen for this layout, | 132 // Return a offscreen location which is offscreen for this layout, |
123 // to be used as the initial position for an animation into view. | 133 // to be used as the initial position for an animation into view. |
124 gfx::Point OffScreenLocation() const; | 134 gfx::Point OffScreenLocation() const; |
125 | 135 |
126 // Returns true if the layout requires offsetting for keeping the close | 136 // Returns true if the layout requires offsetting for keeping the close |
127 // buttons under the cursor during rapid-close interaction. | 137 // buttons under the cursor during rapid-close interaction. |
128 bool RequiresOffsets() const; | 138 bool RequiresOffsets() const; |
129 | 139 |
140 // Returns true if there is change to offsets. Passing |closed_browser| | |
jennb
2011/11/10 19:17:13
s/Passing/Pass in
?
(Irrelevant if you change to
jianli
2011/11/11 00:38:30
Done.
| |
141 // if a panel is being closed. | |
142 bool ComputeOffsetsToMoveAbovePanels(Browser* closed_browser); | |
143 | |
130 private: | 144 private: |
131 // Layout parameters | 145 // Layout parameters |
132 int VerticalEdgeMargin() const; | 146 int VerticalEdgeMargin() const; |
133 int HorizontalEdgeMargin() const; | 147 int HorizontalEdgeMargin() const; |
134 int InterBalloonMargin() const; | 148 int InterBalloonMargin() const; |
135 | 149 |
136 // Minimum and maximum size of balloon content. | 150 // Minimum and maximum size of balloon content. |
137 static const int kBalloonMinWidth = 300; | 151 static const int kBalloonMinWidth = 300; |
138 static const int kBalloonMaxWidth = 300; | 152 static const int kBalloonMaxWidth = 300; |
139 static const int kBalloonMinHeight = 24; | 153 static const int kBalloonMinHeight = 24; |
140 static const int kBalloonMaxHeight = 160; | 154 static const int kBalloonMaxHeight = 160; |
141 | 155 |
142 Placement placement_; | 156 Placement placement_; |
143 gfx::Rect work_area_; | 157 gfx::Rect work_area_; |
158 | |
159 // The offsets that guarantees that the notificaitons shown in the | |
jennb
2011/11/10 19:17:13
typo: notifications
jianli
2011/11/11 00:38:30
Done.
| |
160 // bottom-right or bottom-left corner of the screen will go above currently | |
161 // shown panels and will not be obscured by them. | |
162 int bottom_left_offset_to_move_above_panels_; | |
163 int bottom_right_offset_to_move_above_panels_; | |
164 | |
144 DISALLOW_COPY_AND_ASSIGN(Layout); | 165 DISALLOW_COPY_AND_ASSIGN(Layout); |
145 }; | 166 }; |
146 | 167 |
147 // Creates a new balloon. Overridable by unit tests. The caller is | 168 // Creates a new balloon. Overridable by unit tests. The caller is |
148 // responsible for freeing the pointer returned. | 169 // responsible for freeing the pointer returned. |
149 virtual Balloon* MakeBalloon(const Notification& notification, | 170 virtual Balloon* MakeBalloon(const Notification& notification, |
150 Profile* profile); | 171 Profile* profile); |
151 | 172 |
152 // Gets a bounding box for all the current balloons in screen coordinates. | 173 // Gets a bounding box for all the current balloons in screen coordinates. |
153 gfx::Rect GetBalloonsBoundingBox() const; | 174 gfx::Rect GetBalloonsBoundingBox() const; |
(...skipping 10 matching lines...) Expand all Loading... | |
164 // Get the work area on Mac OS, without inverting the coordinates. | 185 // Get the work area on Mac OS, without inverting the coordinates. |
165 static gfx::Rect GetMacWorkArea(); | 186 static gfx::Rect GetMacWorkArea(); |
166 #endif | 187 #endif |
167 | 188 |
168 // Base implementation for the collection of active balloons. | 189 // Base implementation for the collection of active balloons. |
169 BalloonCollectionBase base_; | 190 BalloonCollectionBase base_; |
170 | 191 |
171 // The layout parameters for balloons in this collection. | 192 // The layout parameters for balloons in this collection. |
172 Layout layout_; | 193 Layout layout_; |
173 | 194 |
195 content::NotificationRegistrar registrar_; | |
196 | |
174 #if USE_OFFSETS | 197 #if USE_OFFSETS |
175 // Start and stop observing all UI events. | 198 // Start and stop observing all UI events. |
176 void AddMessageLoopObserver(); | 199 void AddMessageLoopObserver(); |
177 void RemoveMessageLoopObserver(); | 200 void RemoveMessageLoopObserver(); |
178 | 201 |
179 // Cancel all offset and reposition the balloons normally. | 202 // Cancel all offset and reposition the balloons normally. |
180 void CancelOffsets(); | 203 void CancelOffsets(); |
181 | 204 |
182 // Handles a mouse motion while the balloons are temporarily offset. | 205 // Handles a mouse motion while the balloons are temporarily offset. |
183 void HandleMouseMoveEvent(); | 206 void HandleMouseMoveEvent(); |
184 | 207 |
185 // Is the current cursor in the balloon area? | 208 // Is the current cursor in the balloon area? |
186 bool IsCursorInBalloonCollection() const; | 209 bool IsCursorInBalloonCollection() const; |
187 | 210 |
188 // Factory for generating delayed reposition tasks on mouse motion. | 211 // Factory for generating delayed reposition tasks on mouse motion. |
189 base::WeakPtrFactory<BalloonCollectionImpl> reposition_factory_; | 212 base::WeakPtrFactory<BalloonCollectionImpl> reposition_factory_; |
190 | 213 |
191 // Is the balloon collection currently listening for UI events? | 214 // Is the balloon collection currently listening for UI events? |
192 bool added_as_message_loop_observer_; | 215 bool added_as_message_loop_observer_; |
193 #endif | 216 #endif |
194 | 217 |
195 DISALLOW_COPY_AND_ASSIGN(BalloonCollectionImpl); | 218 DISALLOW_COPY_AND_ASSIGN(BalloonCollectionImpl); |
196 }; | 219 }; |
197 | 220 |
198 #endif // CHROME_BROWSER_NOTIFICATIONS_BALLOON_COLLECTION_IMPL_H_ | 221 #endif // CHROME_BROWSER_NOTIFICATIONS_BALLOON_COLLECTION_IMPL_H_ |
OLD | NEW |