| 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 // Draws the view for the balloons. | 5 // Draws the view for the balloons. |
| 6 | 6 |
| 7 #ifndef CHROME_BROWSER_CHROMEOS_NOTIFICATIONS_NOTIFICATION_PANEL_H_ | 7 #ifndef CHROME_BROWSER_CHROMEOS_NOTIFICATIONS_NOTIFICATION_PANEL_H_ |
| 8 #define CHROME_BROWSER_CHROMEOS_NOTIFICATIONS_NOTIFICATION_PANEL_H_ | 8 #define CHROME_BROWSER_CHROMEOS_NOTIFICATIONS_NOTIFICATION_PANEL_H_ |
| 9 | 9 |
| 10 #include "base/task.h" | 10 #include "base/task.h" |
| 11 #include "base/scoped_ptr.h" | 11 #include "base/scoped_ptr.h" |
| 12 #include "chrome/browser/chromeos/frame/panel_controller.h" | 12 #include "chrome/browser/chromeos/frame/panel_controller.h" |
| 13 #include "chrome/browser/chromeos/notifications/balloon_collection_impl.h" | 13 #include "chrome/browser/chromeos/notifications/balloon_collection_impl.h" |
| 14 #include "gfx/rect.h" | 14 #include "gfx/rect.h" |
| 15 | 15 |
| 16 class Balloon; | 16 class Balloon; |
| 17 | 17 |
| 18 namespace views { | 18 namespace views { |
| 19 class ScrollView; | 19 class ScrollView; |
| 20 } // namespace views | 20 } // namespace views |
| 21 | 21 |
| 22 namespace chromeos { | 22 namespace chromeos { |
| 23 | 23 |
| 24 class BalloonContainer; | 24 class BalloonContainer; |
| 25 class BalloonViewImpl; | 25 class BalloonViewImpl; |
| 26 class NotificationPanelTester; |
| 26 | 27 |
| 27 // NotificationPanel is a panel that displays notifications. It has | 28 // NotificationPanel is a panel that displays notifications. It has |
| 28 // several states and displays the different portion of notifications | 29 // several states and displays the different portion of notifications |
| 29 // depending on in which state the panel is. The following shows | 30 // depending on in which state the panel is. The following shows |
| 30 // how the panel's state changes in response to various events. | 31 // how the panel's state changes in response to various events. |
| 31 // | 32 // |
| 32 // Event List: | 33 // Event List: |
| 33 // close: a user pressed close button on the title bar, | 34 // close: a user pressed close button on the title bar, |
| 34 // or the system closed the panel. | 35 // or the system closed the panel. |
| 35 // new : a new notification is added. | 36 // new : a new notification is added. |
| 36 // stale: one of new notifications became stale. | 37 // stale: one of new notifications became stale. |
| 37 // expand: a user pressed minimized panel to expand. | 38 // expand: a user pressed minimized panel to expand. |
| 38 // minimize: a user pressed the panel's title bar to minimize. | 39 // minimize: a user pressed the panel's title bar to minimize. |
| 40 // user: the user's mouse moved over the panel, indicates |
| 41 // that user is trying to interact with the panel. |
| 39 // For state, see State enum's description below. | 42 // For state, see State enum's description below. |
| 40 // | 43 // |
| 41 // CLOSE<--(event=close)-+ +--(event=stale, cond=has new|sticky) | 44 // |
| 45 // [CLOSE]<-(event=close)-+ +--(event=stale, cond=has new|sticky) |
| 42 // | | | (event=new) | 46 // | | | (event=new) |
| 43 // | | V | | 47 // | | V | |
| 44 // +--(event=new)--> STICKY_AND_NEW----------+ | 48 // +--(event=new)-->[STICKY_AND_NEW]----- +--------(event=user) |
| 45 // | | ^ | 49 // | ^ | | |
| 46 // | (event=stale, | | 50 // | | (event=stale, V |
| 47 // | cond=has new, no sticy) (event=new) | 51 // | | cond=has new, no sticy) +[ KEEP_SIZE ]<-+ |
| 48 // | (event=minimize) | | 52 // | (event=new) (event=minimize) | | | |
| 49 // | | | | 53 // | | | | | | |
| 50 // | V | | 54 // | | | (event=minimize)(event=close)| |
| 51 // | MINIMIZED ---(event=close)--> [CLOSE] | 55 // | | +---------------+ | | |
| 52 // | | ^ | 56 // | | V V | |
| 53 // | | | | 57 // | [ MINIMIZED ]---(event=close)--> [CLOSE] | |
| 54 // | (event=expand) (event=minmize) | 58 // | | ^ | |
| 55 // | V | | 59 // | | | | |
| 56 // +--(event=open)----> FULL --(event=stale)(event=new) | 60 // | (event=expand) (event=minmize) (event=user) |
| 57 // | | | | 61 // | V | | |
| 58 // (event=close) +--------------+ | 62 // +--(event=open)---->[ FULL ]-------------+-------------------+ |
| 63 // | ^ | |
| 64 // (event=close) +-------(event=stale)(event=new) |
| 59 // | | 65 // | |
| 60 // [CLOSE] <------+ | 66 // [CLOSE] <------+ |
| 61 // | 67 // |
| 62 class NotificationPanel : public PanelController::Delegate, | 68 class NotificationPanel : public PanelController::Delegate, |
| 63 public BalloonCollectionImpl::NotificationUI { | 69 public BalloonCollectionImpl::NotificationUI { |
| 64 public: | 70 public: |
| 71 enum State { |
| 72 FULL, // Show all notifications |
| 73 KEEP_SIZE, // Don't change the size. |
| 74 STICKY_AND_NEW, // Show only new and sticky notifications. |
| 75 MINIMIZED, // The panel is minimized. |
| 76 CLOSED, // The panel is closed. |
| 77 }; |
| 78 |
| 65 NotificationPanel(); | 79 NotificationPanel(); |
| 66 virtual ~NotificationPanel(); | 80 virtual ~NotificationPanel(); |
| 67 | 81 |
| 68 // Shows/Hides the Panel. | 82 // Shows/Hides the Panel. |
| 69 void Show(); | 83 void Show(); |
| 70 void Hide(); | 84 void Hide(); |
| 71 | 85 |
| 72 // BalloonCollectionImpl::NotificationUI overrides.. | 86 // BalloonCollectionImpl::NotificationUI overrides.. |
| 73 virtual void Add(Balloon* balloon); | 87 virtual void Add(Balloon* balloon); |
| 74 virtual bool Update(Balloon* balloon); | 88 virtual bool Update(Balloon* balloon); |
| 75 virtual void Remove(Balloon* balloon); | 89 virtual void Remove(Balloon* balloon); |
| 76 virtual void ResizeNotification(Balloon* balloon, | 90 virtual void ResizeNotification(Balloon* balloon, |
| 77 const gfx::Size& size); | 91 const gfx::Size& size); |
| 78 | 92 |
| 79 // PanelController overrides. | 93 // PanelController overrides. |
| 80 virtual string16 GetPanelTitle(); | 94 virtual string16 GetPanelTitle(); |
| 81 virtual SkBitmap GetPanelIcon(); | 95 virtual SkBitmap GetPanelIcon(); |
| 82 virtual void ClosePanel(); | 96 virtual void ClosePanel(); |
| 83 virtual void OnPanelStateChanged(PanelController::State state); | 97 virtual void OnPanelStateChanged(PanelController::State state); |
| 84 | 98 |
| 85 // Called when a mouse left the panel window. | 99 // Called when a mouse left the panel window. |
| 86 void OnMouseLeave(); | 100 void OnMouseLeave(); |
| 101 void OnMouseMotion(); |
| 87 | 102 |
| 88 // Tells that the panel should not update the size or state | 103 NotificationPanelTester* GetTester(); |
| 89 // when a notification becomes stale. | |
| 90 void DontUpdatePanelOnStale(); | |
| 91 | |
| 92 // Returns number of of sticky notifications. | |
| 93 int GetStickyNotificationCount() const; | |
| 94 | |
| 95 // Returns number of new notifications. | |
| 96 int GetNewNotificationCount() const; | |
| 97 | 104 |
| 98 private: | 105 private: |
| 99 enum State { | 106 friend class NotificationPanelTester; |
| 100 FULL, // Show all notifications | |
| 101 STICKY_AND_NEW, // Show only new and sticky notifications. | |
| 102 MINIMIZED, // The panel is minimized. | |
| 103 CLOSED, // The panel is closed. | |
| 104 }; | |
| 105 | 107 |
| 106 void Init(); | 108 void Init(); |
| 107 | 109 |
| 108 // Update the Panel Size according to its state. | 110 // Update the Panel Size according to its state. |
| 109 void UpdatePanel(bool contents_changed); | 111 void UpdatePanel(bool contents_changed); |
| 110 | 112 |
| 111 // Returns the panel's preferred bounds in the screen's coordinates. | 113 // Returns the panel's preferred bounds in the screen's coordinates. |
| 112 // The position will be controlled by window manager so | 114 // The position will be controlled by window manager so |
| 113 // the origin is always (0, 0). | 115 // the origin is always (0, 0). |
| 114 gfx::Rect GetPreferredBounds(); | 116 gfx::Rect GetPreferredBounds(); |
| 115 | 117 |
| 116 // Returns the bounds that covers sticky and new notifications. | 118 // Returns the bounds that covers sticky and new notifications. |
| 117 gfx::Rect GetStickyNewBounds(); | 119 gfx::Rect GetStickyNewBounds(); |
| 118 | 120 |
| 119 void StartStaleTimer(Balloon* balloon); | 121 void StartStaleTimer(Balloon* balloon); |
| 120 | 122 |
| 121 // A callback function that is called when the notification | 123 // A callback function that is called when the notification |
| 122 // (that the view is associated with) becomes stale after a timeout. | 124 // (that the view is associated with) becomes stale after a timeout. |
| 123 // |token| is a unique id assigned to a callback task and is | 125 void OnStale(BalloonViewImpl* view); |
| 124 // used to cancel the task. | |
| 125 void OnStale(BalloonViewImpl* view, int token); | |
| 126 | 126 |
| 127 BalloonContainer* balloon_container_; | 127 BalloonContainer* balloon_container_; |
| 128 scoped_ptr<views::Widget> panel_widget_; | 128 scoped_ptr<views::Widget> panel_widget_; |
| 129 scoped_ptr<PanelController> panel_controller_; | 129 scoped_ptr<PanelController> panel_controller_; |
| 130 scoped_ptr<views::ScrollView> scroll_view_; | 130 scoped_ptr<views::ScrollView> scroll_view_; |
| 131 State state_; | 131 State state_; |
| 132 ScopedRunnableMethodFactory<NotificationPanel> task_factory_; | 132 ScopedRunnableMethodFactory<NotificationPanel> task_factory_; |
| 133 bool update_panel_on_mouse_leave_; | 133 gfx::Rect min_bounds_; |
| 134 | 134 |
| 135 // Task token is an integer value assigned to each task, and | 135 scoped_ptr<NotificationPanelTester> tester_; |
| 136 // used to cancel the tasks. | |
| 137 // The latest task token. | |
| 138 int latest_token_; | |
| 139 // A task whose token is smaller than this value is stale and skipped. | |
| 140 int stale_token_; | |
| 141 | 136 |
| 142 DISALLOW_COPY_AND_ASSIGN(NotificationPanel); | 137 DISALLOW_COPY_AND_ASSIGN(NotificationPanel); |
| 143 }; | 138 }; |
| 144 | 139 |
| 140 class NotificationPanelTester { |
| 141 public: |
| 142 explicit NotificationPanelTester(NotificationPanel* panel) |
| 143 : panel_(panel) { |
| 144 } |
| 145 |
| 146 NotificationPanel::State state() { |
| 147 return panel_->state_; |
| 148 } |
| 149 |
| 150 // Returns number of of sticky and new notifications. |
| 151 int GetNotificationCount() const; |
| 152 |
| 153 // Returns number of new notifications. |
| 154 int GetNewNotificationCount() const; |
| 155 |
| 156 // Returns number of of sticky notifications. |
| 157 int GetStickyNotificationCount() const; |
| 158 |
| 159 private: |
| 160 NotificationPanel* panel_; |
| 161 DISALLOW_COPY_AND_ASSIGN(NotificationPanelTester); |
| 162 }; |
| 163 |
| 145 } // namespace chromeos | 164 } // namespace chromeos |
| 146 | 165 |
| 147 #endif // CHROME_BROWSER_CHROMEOS_NOTIFICATIONS_NOTIFICATION_PANEL_H_ | 166 #endif // CHROME_BROWSER_CHROMEOS_NOTIFICATIONS_NOTIFICATION_PANEL_H_ |
| OLD | NEW |