| OLD | NEW | 
|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/message_loop.h" | 14 #include "base/message_loop.h" | 
| 15 #include "chrome/browser/notifications/balloon_collection.h" | 15 #include "chrome/browser/notifications/balloon_collection.h" | 
|  | 16 #include "chrome/browser/notifications/balloon_collection_base.h" | 
| 16 #include "gfx/point.h" | 17 #include "gfx/point.h" | 
| 17 #include "gfx/rect.h" | 18 #include "gfx/rect.h" | 
| 18 | 19 | 
| 19 // Mac balloons grow from the top down and have close buttons on top, so | 20 // Mac balloons grow from the top down and have close buttons on top, so | 
| 20 // offsetting is not necessary for easy multiple-closing.  Other platforms grow | 21 // offsetting is not necessary for easy multiple-closing.  Other platforms grow | 
| 21 // from the bottom up and have close buttons on top, so it is necessary. | 22 // from the bottom up and have close buttons on top, so it is necessary. | 
| 22 #if defined(OS_MACOSX) | 23 #if defined(OS_MACOSX) | 
| 23 #define USE_OFFSETS 0 | 24 #define USE_OFFSETS 0 | 
| 24 #else | 25 #else | 
| 25 #define USE_OFFSETS 1 | 26 #define USE_OFFSETS 1 | 
| 26 #endif | 27 #endif | 
| 27 | 28 | 
| 28 // A balloon collection represents a set of notification balloons being | 29 // A balloon collection represents a set of notification balloons being | 
| 29 // shown on the screen.  It positions new notifications according to | 30 // shown on the screen.  It positions new notifications according to | 
| 30 // a layout, and monitors for balloons being closed, which it reports | 31 // a layout, and monitors for balloons being closed, which it reports | 
| 31 // up to its parent, the notification UI manager. | 32 // up to its parent, the notification UI manager. | 
| 32 class BalloonCollectionImpl : public BalloonCollection | 33 class BalloonCollectionImpl : public BalloonCollection | 
| 33 #if USE_OFFSETS | 34 #if USE_OFFSETS | 
| 34                             , public MessageLoopForUI::Observer | 35                             , public MessageLoopForUI::Observer | 
| 35 #endif | 36 #endif | 
| 36 { | 37 { | 
| 37  public: | 38  public: | 
| 38   BalloonCollectionImpl(); | 39   BalloonCollectionImpl(); | 
| 39   virtual ~BalloonCollectionImpl(); | 40   virtual ~BalloonCollectionImpl(); | 
| 40 | 41 | 
| 41   // BalloonCollection interface. | 42   // BalloonCollection interface. | 
| 42   virtual void Add(const Notification& notification, | 43   virtual void Add(const Notification& notification, | 
| 43                    Profile* profile); | 44                    Profile* profile); | 
| 44   virtual bool Remove(const Notification& notification); | 45   virtual bool RemoveById(const std::string& id); | 
|  | 46   virtual bool RemoveBySourceOrigin(const GURL& source_origin); | 
| 45   virtual bool HasSpace() const; | 47   virtual bool HasSpace() const; | 
| 46   virtual void ResizeBalloon(Balloon* balloon, const gfx::Size& size); | 48   virtual void ResizeBalloon(Balloon* balloon, const gfx::Size& size); | 
| 47   virtual void DisplayChanged(); | 49   virtual void DisplayChanged(); | 
| 48   virtual void OnBalloonClosed(Balloon* source); | 50   virtual void OnBalloonClosed(Balloon* source); | 
| 49   virtual const Balloons& GetActiveBalloons() { | 51   virtual const Balloons& GetActiveBalloons() { return base_.balloons(); } | 
| 50     return balloons_; |  | 
| 51   } |  | 
| 52 | 52 | 
| 53   // MessageLoopForUI::Observer interface. | 53   // MessageLoopForUI::Observer interface. | 
| 54 #if defined(OS_WIN) | 54 #if defined(OS_WIN) | 
| 55   virtual void WillProcessMessage(const MSG& event) {} | 55   virtual void WillProcessMessage(const MSG& event) {} | 
| 56   virtual void DidProcessMessage(const MSG& event); | 56   virtual void DidProcessMessage(const MSG& event); | 
| 57 #endif | 57 #endif | 
| 58 #if defined(OS_LINUX) | 58 #if defined(OS_LINUX) | 
| 59   virtual void WillProcessEvent(GdkEvent* event) {} | 59   virtual void WillProcessEvent(GdkEvent* event) {} | 
| 60   virtual void DidProcessEvent(GdkEvent* event); | 60   virtual void DidProcessEvent(GdkEvent* event); | 
| 61 #endif | 61 #endif | 
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 128     gfx::Rect work_area_; | 128     gfx::Rect work_area_; | 
| 129     DISALLOW_COPY_AND_ASSIGN(Layout); | 129     DISALLOW_COPY_AND_ASSIGN(Layout); | 
| 130   }; | 130   }; | 
| 131 | 131 | 
| 132   // Creates a new balloon. Overridable by unit tests.  The caller is | 132   // Creates a new balloon. Overridable by unit tests.  The caller is | 
| 133   // responsible for freeing the pointer returned. | 133   // responsible for freeing the pointer returned. | 
| 134   virtual Balloon* MakeBalloon(const Notification& notification, | 134   virtual Balloon* MakeBalloon(const Notification& notification, | 
| 135                                Profile* profile); | 135                                Profile* profile); | 
| 136 | 136 | 
| 137  private: | 137  private: | 
| 138   // The number of balloons being displayed. |  | 
| 139   int count() const { return balloons_.size(); } |  | 
| 140 |  | 
| 141   // Adjusts the positions of the balloons (e.g., when one is closed). | 138   // Adjusts the positions of the balloons (e.g., when one is closed). | 
| 142   // Implemented by each platform for specific UI requirements. | 139   // Implemented by each platform for specific UI requirements. | 
| 143   void PositionBalloons(bool is_reposition); | 140   void PositionBalloons(bool is_reposition); | 
| 144 | 141 | 
| 145   // Cross-platform internal implementation for PositionBalloons. | 142   // Cross-platform internal implementation for PositionBalloons. | 
| 146   void PositionBalloonsInternal(bool is_reposition); | 143   void PositionBalloonsInternal(bool is_reposition); | 
| 147 | 144 | 
| 148 #if defined(OS_MACOSX) | 145 #if defined(OS_MACOSX) | 
| 149   // Get the work area on Mac OS, without inverting the coordinates. | 146   // Get the work area on Mac OS, without inverting the coordinates. | 
| 150   static gfx::Rect GetMacWorkArea(); | 147   static gfx::Rect GetMacWorkArea(); | 
| 151 #endif | 148 #endif | 
| 152 | 149 | 
|  | 150   // Base implementation for the collection of active balloons. | 
|  | 151   BalloonCollectionBase base_; | 
|  | 152 | 
|  | 153   // The layout parameters for balloons in this collection. | 
|  | 154   Layout layout_; | 
|  | 155 | 
| 153 #if USE_OFFSETS | 156 #if USE_OFFSETS | 
| 154   // Start and stop observing all UI events. | 157   // Start and stop observing all UI events. | 
| 155   void AddMessageLoopObserver(); | 158   void AddMessageLoopObserver(); | 
| 156   void RemoveMessageLoopObserver(); | 159   void RemoveMessageLoopObserver(); | 
| 157 | 160 | 
| 158   // Cancel all offset and reposition the balloons normally. | 161   // Cancel all offset and reposition the balloons normally. | 
| 159   void CancelOffsets(); | 162   void CancelOffsets(); | 
| 160 | 163 | 
| 161   // Handles a mouse motion while the balloons are temporarily offset. | 164   // Handles a mouse motion while the balloons are temporarily offset. | 
| 162   void HandleMouseMoveEvent(); | 165   void HandleMouseMoveEvent(); | 
| 163 | 166 | 
| 164   // Is the current cursor in the balloon area? | 167   // Is the current cursor in the balloon area? | 
| 165   bool IsCursorInBalloonCollection() const; | 168   bool IsCursorInBalloonCollection() const; | 
| 166 #endif |  | 
| 167 | 169 | 
| 168   // Queue of active balloons. |  | 
| 169   typedef std::deque<Balloon*> Balloons; |  | 
| 170   Balloons balloons_; |  | 
| 171 |  | 
| 172   // The layout parameters for balloons in this collection. |  | 
| 173   Layout layout_; |  | 
| 174 |  | 
| 175 #if USE_OFFSETS |  | 
| 176   // Factory for generating delayed reposition tasks on mouse motion. | 170   // Factory for generating delayed reposition tasks on mouse motion. | 
| 177   ScopedRunnableMethodFactory<BalloonCollectionImpl> reposition_factory_; | 171   ScopedRunnableMethodFactory<BalloonCollectionImpl> reposition_factory_; | 
| 178 | 172 | 
| 179   // Is the balloon collection currently listening for UI events? | 173   // Is the balloon collection currently listening for UI events? | 
| 180   bool added_as_message_loop_observer_; | 174   bool added_as_message_loop_observer_; | 
| 181 #endif | 175 #endif | 
| 182 | 176 | 
| 183   DISALLOW_COPY_AND_ASSIGN(BalloonCollectionImpl); | 177   DISALLOW_COPY_AND_ASSIGN(BalloonCollectionImpl); | 
| 184 }; | 178 }; | 
| 185 | 179 | 
| 186 #endif  // CHROME_BROWSER_NOTIFICATIONS_BALLOON_COLLECTION_IMPL_H_ | 180 #endif  // CHROME_BROWSER_NOTIFICATIONS_BALLOON_COLLECTION_IMPL_H_ | 
| OLD | NEW | 
|---|