Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / ui / message_center / views / message_popup_collection.h
index f747fa1..6586b41 100644 (file)
@@ -18,6 +18,8 @@
 #include "ui/gfx/rect.h"
 #include "ui/message_center/message_center_export.h"
 #include "ui/message_center/message_center_observer.h"
+#include "ui/message_center/views/message_center_controller.h"
+#include "ui/message_center/views/toast_contents_view.h"
 #include "ui/views/widget/widget_observer.h"
 
 namespace base {
@@ -40,7 +42,7 @@ class MessagePopupCollectionTest;
 
 class MessageCenter;
 class MessageCenterTray;
-class ToastContentsView;
+class MessageViewContextMenuController;
 
 enum PopupAlignment {
   POPUP_ALIGNMENT_TOP = 1 << 0,
@@ -55,9 +57,9 @@ enum PopupAlignment {
 // contents of each toast are for the message center and layout strategy would
 // be slightly different.
 class MESSAGE_CENTER_EXPORT MessagePopupCollection
-    : public MessageCenterObserver,
-      public gfx::DisplayObserver,
-      public base::SupportsWeakPtr<MessagePopupCollection> {
+    : public MessageCenterController,
+      public MessageCenterObserver,
+      public gfx::DisplayObserver {
  public:
   // |parent| specifies the parent widget of the toast windows. The default
   // parent will be used for NULL. Usually each icon is spacing against its
@@ -69,8 +71,18 @@ class MESSAGE_CENTER_EXPORT MessagePopupCollection
                          bool first_item_has_no_margin);
   virtual ~MessagePopupCollection();
 
-  // Called by ToastContentsView when its window is closed.
-  void RemoveToast(ToastContentsView* toast);
+  // Overridden from MessageCenterController:
+  virtual void ClickOnNotification(const std::string& notification_id) OVERRIDE;
+  virtual void RemoveNotification(const std::string& notification_id,
+                                  bool by_user) OVERRIDE;
+  virtual scoped_ptr<ui::MenuModel> CreateMenuModel(
+      const NotifierId& notifier_id,
+      const base::string16& display_source) OVERRIDE;
+  virtual bool HasClickedListener(const std::string& notification_id) OVERRIDE;
+  virtual void ClickOnNotificationButton(const std::string& notification_id,
+                                         int button_index) OVERRIDE;
+
+  void MarkAllPopupsShown();
 
   // Since these events are really coming from individual toast widgets,
   // it helps to be able to keep track of the sender.
@@ -89,6 +101,10 @@ class MESSAGE_CENTER_EXPORT MessagePopupCollection
   // zero. Otherwise, simply waits when it becomes zero.
   void DoUpdateIfPossible();
 
+  // Removes the toast from our internal list of toasts; this is called when the
+  // toast is irrevocably closed (such as within RemoveToast).
+  void ForgetToast(ToastContentsView* toast);
+
   // Updates |work_area_| and re-calculates the alignment of notification toasts
   // rearranging them if necessary.
   // This is separated from methods from OnDisplayBoundsChanged(), since
@@ -104,6 +120,9 @@ class MESSAGE_CENTER_EXPORT MessagePopupCollection
   virtual void OnDisplayAdded(const gfx::Display& new_display) OVERRIDE;
   virtual void OnDisplayRemoved(const gfx::Display& old_display) OVERRIDE;
 
+  // Used by ToastContentsView to locate itself.
+  gfx::NativeView parent() const { return parent_; }
+
  private:
   FRIEND_TEST_ALL_PREFIXES(ash::WebNotificationTrayTest,
                            ManyPopupNotifications);
@@ -111,13 +130,14 @@ class MESSAGE_CENTER_EXPORT MessagePopupCollection
   friend class ash::WebNotificationTrayTest;
   typedef std::list<ToastContentsView*> Toasts;
 
-  void CloseAllWidgets();
+  // Iterates toasts and starts closing them.
+  std::set<std::string> CloseAllWidgets();
 
-  // Returns the x-origin for the given toast bounds in the current work area.
-  int GetToastOriginX(const gfx::Rect& toast_bounds);
+  // Called by ToastContentsView when its window is closed.
+  void RemoveToast(ToastContentsView* toast, bool mark_as_shown);
 
-  // Iterates toasts and starts closing the expired ones.
-  void CloseToasts();
+  // Returns the x-origin for the given toast bounds in the current work area.
+  int GetToastOriginX(const gfx::Rect& toast_bounds) const;
 
   // Creates new widgets for new toast notifications, and updates |toasts_| and
   // |widgets_| correctly.
@@ -135,7 +155,7 @@ class MESSAGE_CENTER_EXPORT MessagePopupCollection
 
   // The base line is an (imaginary) line that would touch the bottom of the
   // next created notification if bottom-aligned or its top if top-aligned.
-  int GetBaseLine(ToastContentsView* last_toast);
+  int GetBaseLine(ToastContentsView* last_toast) const;
 
   // Overridden from MessageCenterObserver:
   virtual void OnNotificationAdded(const std::string& notification_id) OVERRIDE;
@@ -144,19 +164,19 @@ class MESSAGE_CENTER_EXPORT MessagePopupCollection
   virtual void OnNotificationUpdated(
       const std::string& notification_id) OVERRIDE;
 
-  ToastContentsView* FindToast(const std::string& notification_id);
+  ToastContentsView* FindToast(const std::string& notification_id) const;
 
   // While the toasts are animated, avoid updating the collection, to reduce
   // user confusion. Instead, update the collection when all animations are
   // done. This method is run when defer counter is zero, may initiate next
   // update/animation step.
-  void PerformDeferredTasks();
   void OnDeferTimerExpired();
 
   // "ForTest" methods.
-  views::Widget* GetWidgetForTest(const std::string& id);
-  void RunLoopForTest();
-  gfx::Rect GetToastRectAt(size_t index);
+  views::Widget* GetWidgetForTest(const std::string& id) const;
+  void CreateRunLoopForTest();
+  void WaitForTest();
+  gfx::Rect GetToastRectAt(size_t index) const;
 
   gfx::NativeView parent_;
   MessageCenter* message_center_;
@@ -192,6 +212,12 @@ class MESSAGE_CENTER_EXPORT MessagePopupCollection
   // True if the first item should not have spacing against the tray.
   bool first_item_has_no_margin_;
 
+  scoped_ptr<MessageViewContextMenuController> context_menu_controller_;
+
+  // Gives out weak pointers to toast contents views which have an unrelated
+  // lifetime.  Must remain the last member variable.
+  base::WeakPtrFactory<MessagePopupCollection> weak_factory_;
+
   DISALLOW_COPY_AND_ASSIGN(MessagePopupCollection);
 };