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 |
31 // A balloon collection represents a set of notification balloons being | 33 // A balloon collection represents a set of notification balloons being |
32 // shown on the screen. It positions new notifications according to | 34 // shown on the screen. It positions new notifications according to |
33 // a layout, and monitors for balloons being closed, which it reports | 35 // a layout, and monitors for balloons being closed, which it reports |
34 // up to its parent, the notification UI manager. | 36 // up to its parent, the notification UI manager. |
35 class BalloonCollectionImpl : public BalloonCollection | 37 class BalloonCollectionImpl : public BalloonCollection, |
| 38 public content::NotificationObserver |
36 #if USE_OFFSETS | 39 #if USE_OFFSETS |
37 , public MessageLoopForUI::Observer | 40 , public MessageLoopForUI::Observer |
38 #endif | 41 #endif |
39 { | 42 { |
40 public: | 43 public: |
41 BalloonCollectionImpl(); | 44 BalloonCollectionImpl(); |
42 virtual ~BalloonCollectionImpl(); | 45 virtual ~BalloonCollectionImpl(); |
43 | 46 |
44 // BalloonCollection interface. | 47 // BalloonCollection interface. |
45 virtual void Add(const Notification& notification, | 48 virtual void Add(const Notification& notification, |
46 Profile* profile); | 49 Profile* profile); |
47 virtual bool RemoveById(const std::string& id); | 50 virtual bool RemoveById(const std::string& id); |
48 virtual bool RemoveBySourceOrigin(const GURL& source_origin); | 51 virtual bool RemoveBySourceOrigin(const GURL& source_origin); |
49 virtual void RemoveAll(); | 52 virtual void RemoveAll(); |
50 virtual bool HasSpace() const; | 53 virtual bool HasSpace() const; |
51 virtual void ResizeBalloon(Balloon* balloon, const gfx::Size& size); | 54 virtual void ResizeBalloon(Balloon* balloon, const gfx::Size& size); |
52 virtual void SetPositionPreference(PositionPreference position); | 55 virtual void SetPositionPreference(PositionPreference position); |
53 virtual void DisplayChanged(); | 56 virtual void DisplayChanged(); |
54 virtual void OnBalloonClosed(Balloon* source); | 57 virtual void OnBalloonClosed(Balloon* source); |
55 virtual const Balloons& GetActiveBalloons(); | 58 virtual const Balloons& GetActiveBalloons(); |
56 | 59 |
| 60 // content::NotificationObserver interface. |
| 61 virtual void Observe(int type, |
| 62 const content::NotificationSource& source, |
| 63 const content::NotificationDetails& details) OVERRIDE; |
| 64 |
57 // MessageLoopForUI::Observer interface. | 65 // MessageLoopForUI::Observer interface. |
58 #if defined(OS_WIN) || defined(TOUCH_UI) || defined(USE_AURA) | 66 #if defined(OS_WIN) || defined(TOUCH_UI) || defined(USE_AURA) |
59 virtual base::EventStatus WillProcessEvent( | 67 virtual base::EventStatus WillProcessEvent( |
60 const base::NativeEvent& event) OVERRIDE; | 68 const base::NativeEvent& event) OVERRIDE; |
61 virtual void DidProcessEvent(const base::NativeEvent& event) OVERRIDE; | 69 virtual void DidProcessEvent(const base::NativeEvent& event) OVERRIDE; |
62 #elif defined(TOOLKIT_USES_GTK) | 70 #elif defined(TOOLKIT_USES_GTK) |
63 virtual void WillProcessEvent(GdkEvent* event) OVERRIDE; | 71 virtual void WillProcessEvent(GdkEvent* event) OVERRIDE; |
64 virtual void DidProcessEvent(GdkEvent* event) OVERRIDE; | 72 virtual void DidProcessEvent(GdkEvent* event) OVERRIDE; |
65 #endif | 73 #endif |
66 | 74 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 gfx::Point* position_iterator) const; | 128 gfx::Point* position_iterator) const; |
121 | 129 |
122 // Return a offscreen location which is offscreen for this layout, | 130 // Return a offscreen location which is offscreen for this layout, |
123 // to be used as the initial position for an animation into view. | 131 // to be used as the initial position for an animation into view. |
124 gfx::Point OffScreenLocation() const; | 132 gfx::Point OffScreenLocation() const; |
125 | 133 |
126 // Returns true if the layout requires offsetting for keeping the close | 134 // Returns true if the layout requires offsetting for keeping the close |
127 // buttons under the cursor during rapid-close interaction. | 135 // buttons under the cursor during rapid-close interaction. |
128 bool RequiresOffsets() const; | 136 bool RequiresOffsets() const; |
129 | 137 |
| 138 // Returns true if there is change to the offset that requires the balloons |
| 139 // to be repositioned. |
| 140 bool ComputeOffsetToMoveAbovePanels(const gfx::Rect& panel_bounds); |
| 141 |
130 private: | 142 private: |
131 // Layout parameters | 143 // Layout parameters |
132 int VerticalEdgeMargin() const; | 144 int VerticalEdgeMargin() const; |
133 int HorizontalEdgeMargin() const; | 145 int HorizontalEdgeMargin() const; |
134 int InterBalloonMargin() const; | 146 int InterBalloonMargin() const; |
135 | 147 |
| 148 bool NeedToMoveAboveLeftSidePanels() const; |
| 149 bool NeedToMoveAboveRightSidePanels() const; |
| 150 |
136 // Minimum and maximum size of balloon content. | 151 // Minimum and maximum size of balloon content. |
137 static const int kBalloonMinWidth = 300; | 152 static const int kBalloonMinWidth = 300; |
138 static const int kBalloonMaxWidth = 300; | 153 static const int kBalloonMaxWidth = 300; |
139 static const int kBalloonMinHeight = 24; | 154 static const int kBalloonMinHeight = 24; |
140 static const int kBalloonMaxHeight = 160; | 155 static const int kBalloonMaxHeight = 160; |
141 | 156 |
142 Placement placement_; | 157 Placement placement_; |
143 gfx::Rect work_area_; | 158 gfx::Rect work_area_; |
| 159 |
| 160 // The offset that guarantees that the notificaitions shown in the |
| 161 // lower-right or lower-left corner of the screen will go above currently |
| 162 // shown panels and will not be obscured by them. |
| 163 int 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 |