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

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

Issue 8503037: Fix the problem that notifications and panels overlap. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 1 month 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) 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
130 private: 138 private:
131 // Layout parameters 139 // Layout parameters
132 int VerticalEdgeMargin() const; 140 int VerticalEdgeMargin() const;
133 int HorizontalEdgeMargin() const; 141 int HorizontalEdgeMargin() const;
134 int InterBalloonMargin() const; 142 int InterBalloonMargin() const;
135 143
144 int GetPanelHeightBase() const;
Dmitry Titov 2011/11/09 03:09:57 Not clear why "Base". Maybe GetPositionAbovePanels
jianli 2011/11/09 19:04:40 Renamed to ComputeOffsetsToMoveAbovePanels. Also c
145
136 // Minimum and maximum size of balloon content. 146 // Minimum and maximum size of balloon content.
137 static const int kBalloonMinWidth = 300; 147 static const int kBalloonMinWidth = 300;
138 static const int kBalloonMaxWidth = 300; 148 static const int kBalloonMaxWidth = 300;
139 static const int kBalloonMinHeight = 24; 149 static const int kBalloonMinHeight = 24;
140 static const int kBalloonMaxHeight = 160; 150 static const int kBalloonMaxHeight = 160;
141 151
142 Placement placement_; 152 Placement placement_;
143 gfx::Rect work_area_; 153 gfx::Rect work_area_;
154
155 // The height of right-most panels we're currently using as a base to allign
Dmitry Titov 2011/11/09 03:09:57 allign->align
jianli 2011/11/09 19:04:40 Removed with the comment change as suggested below
156 // those virtically-from-bottom-right balloons to prevent them from being
Dmitry Titov 2011/11/09 03:09:57 virtically->vertically May be change wording of th
jianli 2011/11/09 19:04:40 Done.
157 // overlapped with the panels.
158 int panel_height_base_;
159
144 DISALLOW_COPY_AND_ASSIGN(Layout); 160 DISALLOW_COPY_AND_ASSIGN(Layout);
145 }; 161 };
146 162
147 // Creates a new balloon. Overridable by unit tests. The caller is 163 // Creates a new balloon. Overridable by unit tests. The caller is
148 // responsible for freeing the pointer returned. 164 // responsible for freeing the pointer returned.
149 virtual Balloon* MakeBalloon(const Notification& notification, 165 virtual Balloon* MakeBalloon(const Notification& notification,
150 Profile* profile); 166 Profile* profile);
151 167
152 // Gets a bounding box for all the current balloons in screen coordinates. 168 // Gets a bounding box for all the current balloons in screen coordinates.
153 gfx::Rect GetBalloonsBoundingBox() const; 169 gfx::Rect GetBalloonsBoundingBox() const;
(...skipping 10 matching lines...) Expand all
164 // Get the work area on Mac OS, without inverting the coordinates. 180 // Get the work area on Mac OS, without inverting the coordinates.
165 static gfx::Rect GetMacWorkArea(); 181 static gfx::Rect GetMacWorkArea();
166 #endif 182 #endif
167 183
168 // Base implementation for the collection of active balloons. 184 // Base implementation for the collection of active balloons.
169 BalloonCollectionBase base_; 185 BalloonCollectionBase base_;
170 186
171 // The layout parameters for balloons in this collection. 187 // The layout parameters for balloons in this collection.
172 Layout layout_; 188 Layout layout_;
173 189
190 content::NotificationRegistrar registrar_;
191
174 #if USE_OFFSETS 192 #if USE_OFFSETS
175 // Start and stop observing all UI events. 193 // Start and stop observing all UI events.
176 void AddMessageLoopObserver(); 194 void AddMessageLoopObserver();
177 void RemoveMessageLoopObserver(); 195 void RemoveMessageLoopObserver();
178 196
179 // Cancel all offset and reposition the balloons normally. 197 // Cancel all offset and reposition the balloons normally.
180 void CancelOffsets(); 198 void CancelOffsets();
181 199
182 // Handles a mouse motion while the balloons are temporarily offset. 200 // Handles a mouse motion while the balloons are temporarily offset.
183 void HandleMouseMoveEvent(); 201 void HandleMouseMoveEvent();
184 202
185 // Is the current cursor in the balloon area? 203 // Is the current cursor in the balloon area?
186 bool IsCursorInBalloonCollection() const; 204 bool IsCursorInBalloonCollection() const;
187 205
188 // Factory for generating delayed reposition tasks on mouse motion. 206 // Factory for generating delayed reposition tasks on mouse motion.
189 base::WeakPtrFactory<BalloonCollectionImpl> reposition_factory_; 207 base::WeakPtrFactory<BalloonCollectionImpl> reposition_factory_;
190 208
191 // Is the balloon collection currently listening for UI events? 209 // Is the balloon collection currently listening for UI events?
192 bool added_as_message_loop_observer_; 210 bool added_as_message_loop_observer_;
193 #endif 211 #endif
194 212
195 DISALLOW_COPY_AND_ASSIGN(BalloonCollectionImpl); 213 DISALLOW_COPY_AND_ASSIGN(BalloonCollectionImpl);
196 }; 214 };
197 215
198 #endif // CHROME_BROWSER_NOTIFICATIONS_BALLOON_COLLECTION_IMPL_H_ 216 #endif // CHROME_BROWSER_NOTIFICATIONS_BALLOON_COLLECTION_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698