| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 // Draws the view for the balloons. | |
| 6 | |
| 7 #ifndef CHROME_BROWSER_CHROMEOS_NOTIFICATIONS_NOTIFICATION_PANEL_H_ | |
| 8 #define CHROME_BROWSER_CHROMEOS_NOTIFICATIONS_NOTIFICATION_PANEL_H_ | |
| 9 #pragma once | |
| 10 | |
| 11 #include "base/memory/weak_ptr.h" | |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "chrome/browser/chromeos/frame/panel_controller.h" | |
| 14 #include "chrome/browser/chromeos/notifications/balloon_collection_impl.h" | |
| 15 #include "content/public/browser/notification_registrar.h" | |
| 16 #include "ui/gfx/rect.h" | |
| 17 | |
| 18 class Balloon; | |
| 19 class Notification; | |
| 20 | |
| 21 namespace views { | |
| 22 class ScrollView; | |
| 23 } // namespace views | |
| 24 | |
| 25 namespace chromeos { | |
| 26 | |
| 27 class BalloonContainer; | |
| 28 class BalloonViewImpl; | |
| 29 class NotificationPanelTester; | |
| 30 | |
| 31 // NotificationPanel is a panel that displays notifications. It has | |
| 32 // several states and displays the different portion of notifications | |
| 33 // depending on in which state the panel is. The following shows | |
| 34 // how the panel's state changes in response to various events. | |
| 35 // | |
| 36 // TODO(oshima): add remove event and fix state transition graph below. | |
| 37 // Event List: | |
| 38 // close: a user pressed close button on the title bar, | |
| 39 // or the system closed the panel. | |
| 40 // new : a new notification is added. | |
| 41 // stale: one of new notifications became stale. | |
| 42 // expand: a user pressed minimized panel to expand. | |
| 43 // minimize: a user pressed the panel's title bar to minimize. | |
| 44 // user: the user's mouse moved over the panel, indicates | |
| 45 // that user is trying to interact with the panel. | |
| 46 // For state, see State enum's description below. | |
| 47 // | |
| 48 // | |
| 49 // [CLOSE]<-(event=close)-+ +--(event=stale, cond=has new|sticky) | |
| 50 // | | | (event=new) | |
| 51 // | | V | | |
| 52 // +--(event=new)-->[STICKY_AND_NEW]----- +--------(event=user) | |
| 53 // | ^ | | | |
| 54 // | | (event=stale, V | |
| 55 // | | cond=has new, no sticy) +[ KEEP_SIZE ]<-+ | |
| 56 // | (event=new) (event=minimize) | | | | |
| 57 // | | | | | | | |
| 58 // | | | (event=minimize)(event=close)| | |
| 59 // | | +---------------+ | | | |
| 60 // | | V V | | |
| 61 // | [ MINIMIZED ]---(event=close)--> [CLOSE] | | |
| 62 // | | ^ | | |
| 63 // | | | | | |
| 64 // | (event=expand) (event=minmize) (event=user) | |
| 65 // | V | | | |
| 66 // +--(event=open)---->[ FULL ]-------------+-------------------+ | |
| 67 // | ^ | | |
| 68 // (event=close) +-------(event=stale)(event=new) | |
| 69 // | | |
| 70 // [CLOSE] <------+ | |
| 71 // | |
| 72 class NotificationPanel : public PanelController::Delegate, | |
| 73 public BalloonCollectionImpl::NotificationUI, | |
| 74 public content::NotificationObserver, | |
| 75 public base::SupportsWeakPtr<NotificationPanel> { | |
| 76 public: | |
| 77 enum State { | |
| 78 FULL, // Show all notifications | |
| 79 KEEP_SIZE, // Don't change the size. | |
| 80 STICKY_AND_NEW, // Show only new and sticky notifications. | |
| 81 MINIMIZED, // The panel is minimized. | |
| 82 CLOSED, // The panel is closed. | |
| 83 }; | |
| 84 | |
| 85 NotificationPanel(); | |
| 86 virtual ~NotificationPanel(); | |
| 87 | |
| 88 // Shows/Hides the Panel. | |
| 89 void Show(); | |
| 90 void Hide(); | |
| 91 | |
| 92 // BalloonCollectionImpl::NotificationUI overrides.. | |
| 93 virtual void Add(Balloon* balloon) OVERRIDE; | |
| 94 virtual bool Update(Balloon* balloon) OVERRIDE; | |
| 95 virtual void Remove(Balloon* balloon) OVERRIDE; | |
| 96 virtual void Show(Balloon* balloon) OVERRIDE; | |
| 97 virtual void ResizeNotification(Balloon* balloon, | |
| 98 const gfx::Size& size) OVERRIDE; | |
| 99 virtual void SetActiveView(BalloonViewImpl* view) OVERRIDE; | |
| 100 | |
| 101 // PanelController::Delegate overrides. | |
| 102 virtual string16 GetPanelTitle() OVERRIDE; | |
| 103 virtual SkBitmap GetPanelIcon() OVERRIDE; | |
| 104 virtual bool CanClosePanel() OVERRIDE; | |
| 105 virtual void ClosePanel() OVERRIDE; | |
| 106 virtual void ActivatePanel() OVERRIDE; | |
| 107 | |
| 108 // NotificationObserver overrides: | |
| 109 virtual void Observe(int type, | |
| 110 const content::NotificationSource& source, | |
| 111 const content::NotificationDetails& details) OVERRIDE; | |
| 112 | |
| 113 // Called when a mouse left the panel window. | |
| 114 void OnMouseLeave(); | |
| 115 void OnMouseMotion(const gfx::Point& point); | |
| 116 | |
| 117 NotificationPanelTester* GetTester(); | |
| 118 | |
| 119 private: | |
| 120 friend class NotificationPanelTester; | |
| 121 | |
| 122 void Init(); | |
| 123 | |
| 124 // Unregister the panel's state change notification. | |
| 125 void UnregisterNotification(); | |
| 126 | |
| 127 // Update the Panel Size according to its state. | |
| 128 void UpdatePanel(bool update_panel_size); | |
| 129 | |
| 130 // Scroll the panel so that the |balloon| is visible. | |
| 131 void ScrollBalloonToVisible(Balloon* balloon); | |
| 132 | |
| 133 // Update the container's bounds so that it can show all notifications. | |
| 134 void UpdateContainerBounds(); | |
| 135 | |
| 136 // Update the notification's control view state. | |
| 137 void UpdateControl(); | |
| 138 | |
| 139 // Returns the panel's preferred bounds in the screen's coordinates. | |
| 140 // The position will be controlled by window manager so | |
| 141 // the origin is always (0, 0). | |
| 142 gfx::Rect GetPreferredBounds(); | |
| 143 | |
| 144 // Returns the bounds that covers sticky and new notifications. | |
| 145 gfx::Rect GetStickyNewBounds(); | |
| 146 | |
| 147 void StartStaleTimer(Balloon* balloon); | |
| 148 | |
| 149 // A callback function that is called when the notification | |
| 150 // (that the view is associated with) becomes stale after a timeout. | |
| 151 void OnStale(BalloonViewImpl* view); | |
| 152 | |
| 153 // Set the state. It can also print the | |
| 154 void SetState(State, const char* method_name); | |
| 155 | |
| 156 // Mark the given notification as stale. | |
| 157 void MarkStale(const Notification& notification); | |
| 158 | |
| 159 // Contains all notifications. This is owned by the panel so that we can | |
| 160 // re-attach to the widget when closing and opening the panel. | |
| 161 scoped_ptr<BalloonContainer> balloon_container_; | |
| 162 | |
| 163 // The notification panel's widget. | |
| 164 views::Widget* panel_widget_; | |
| 165 | |
| 166 // The notification panel's widget. | |
| 167 views::Widget* container_host_; | |
| 168 | |
| 169 // Panel controller for the notification panel. | |
| 170 // This is owned by the panel to compute the panel size before | |
| 171 // actually opening the panel. | |
| 172 scoped_ptr<PanelController> panel_controller_; | |
| 173 | |
| 174 // A scrollable parent of the BalloonContainer. | |
| 175 scoped_ptr<views::ScrollView> scroll_view_; | |
| 176 | |
| 177 // Panel's state. | |
| 178 State state_; | |
| 179 | |
| 180 // The minimum size of a notification. | |
| 181 gfx::Rect min_bounds_; | |
| 182 | |
| 183 // Stale timeout. | |
| 184 int stale_timeout_; | |
| 185 | |
| 186 // A registrar to subscribe PANEL_STATE_CHANGED event. | |
| 187 content::NotificationRegistrar registrar_; | |
| 188 | |
| 189 // The notification a mouse pointer is currently on. NULL if the mouse | |
| 190 // is out of the panel. | |
| 191 BalloonViewImpl* active_; | |
| 192 | |
| 193 // A balloon that should be visible when it gets some size. | |
| 194 Balloon* scroll_to_; | |
| 195 | |
| 196 // An object that provides interfacce for tests. | |
| 197 scoped_ptr<NotificationPanelTester> tester_; | |
| 198 | |
| 199 DISALLOW_COPY_AND_ASSIGN(NotificationPanel); | |
| 200 }; | |
| 201 | |
| 202 class NotificationPanelTester { | |
| 203 public: | |
| 204 explicit NotificationPanelTester(NotificationPanel* panel) | |
| 205 : panel_(panel) { | |
| 206 } | |
| 207 | |
| 208 NotificationPanel::State state() { | |
| 209 return panel_->state_; | |
| 210 } | |
| 211 | |
| 212 // Returns number of of sticky and new notifications. | |
| 213 int GetNotificationCount() const; | |
| 214 | |
| 215 // Returns number of new notifications. | |
| 216 int GetNewNotificationCount() const; | |
| 217 | |
| 218 // Returns number of of sticky notifications. | |
| 219 int GetStickyNotificationCount() const; | |
| 220 | |
| 221 // Sets the timeout for a notification to become stale. | |
| 222 void SetStaleTimeout(int timeout); | |
| 223 | |
| 224 // Mark the given notification as stale. | |
| 225 void MarkStale(const Notification& notification); | |
| 226 | |
| 227 // Returns the notification panel's PanelController. | |
| 228 PanelController* GetPanelController() const; | |
| 229 | |
| 230 // Returns the BalloonView object of the notification. | |
| 231 BalloonViewImpl* GetBalloonView(BalloonCollectionImpl* collection, | |
| 232 const Notification& notification); | |
| 233 | |
| 234 // True if the view is in visible in the ScrollView. | |
| 235 bool IsVisible(const BalloonViewImpl* view) const; | |
| 236 | |
| 237 // True if the view is currently active. | |
| 238 bool IsActive(const BalloonViewImpl* view) const; | |
| 239 | |
| 240 private: | |
| 241 NotificationPanel* panel_; | |
| 242 DISALLOW_COPY_AND_ASSIGN(NotificationPanelTester); | |
| 243 }; | |
| 244 | |
| 245 } // namespace chromeos | |
| 246 | |
| 247 #endif // CHROME_BROWSER_CHROMEOS_NOTIFICATIONS_NOTIFICATION_PANEL_H_ | |
| OLD | NEW |