- add sources.
[platform/framework/web/crosswalk.git] / src / ash / system / web_notification / web_notification_tray.h
1 // Copyright (c) 2012 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 #ifndef ASH_SYSTEM_WEB_NOTIFICATION_WEB_NOTIFICATION_TRAY_H_
6 #define ASH_SYSTEM_WEB_NOTIFICATION_WEB_NOTIFICATION_TRAY_H_
7
8 #include "ash/ash_export.h"
9 #include "ash/system/tray/tray_background_view.h"
10 #include "ash/system/user/login_status.h"
11 #include "base/gtest_prod_util.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "ui/base/models/simple_menu_model.h"
15 #include "ui/message_center/message_center_tray.h"
16 #include "ui/message_center/message_center_tray_delegate.h"
17 #include "ui/views/bubble/tray_bubble_view.h"
18 #include "ui/views/controls/button/button.h"
19
20 // Status area tray for showing browser and app notifications. This hosts
21 // a MessageCenter class which manages the notification list. This class
22 // contains the Ash specific tray implementation.
23 //
24 // Note: These are not related to system notifications (i.e NotificationView
25 // generated by SystemTrayItem). Visibility of one notification type or other
26 // is controlled by StatusAreaWidget.
27
28 namespace views {
29 class ImageButton;
30 class MenuRunner;
31 }
32
33 namespace message_center {
34 class MessageBubbleBase;
35 class MessageCenter;
36 class MessageCenterBubble;
37 class MessagePopupCollection;
38 }
39
40 namespace ash {
41 namespace internal {
42 class StatusAreaWidget;
43 class WebNotificationBubbleWrapper;
44 class WebNotificationButton;
45 class WorkAreaObserver;
46 }
47
48 class ASH_EXPORT WebNotificationTray
49     : public internal::TrayBackgroundView,
50       public views::TrayBubbleView::Delegate,
51       public message_center::MessageCenterTrayDelegate,
52       public views::ButtonListener,
53       public base::SupportsWeakPtr<WebNotificationTray>,
54       public ui::SimpleMenuModel::Delegate {
55  public:
56   explicit WebNotificationTray(
57       internal::StatusAreaWidget* status_area_widget);
58   virtual ~WebNotificationTray();
59
60   // Sets the height of the system tray from the edge of the work area so that
61   // the notification popups don't overlap with the tray. Passes 0 if no UI is
62   // shown in the system tray side.
63   void SetSystemTrayHeight(int height);
64
65   // Returns true if it should block the auto hide behavior of the launcher.
66   bool ShouldBlockLauncherAutoHide() const;
67
68   // Returns true if the message center bubble is visible.
69   bool IsMessageCenterBubbleVisible() const;
70
71   // Returns true if the mouse is inside the notification bubble.
72   bool IsMouseInNotificationBubble() const;
73
74   // Shows the message center bubble.
75   void ShowMessageCenterBubble();
76
77   // Overridden from TrayBackgroundView.
78   virtual void SetShelfAlignment(ShelfAlignment alignment) OVERRIDE;
79   virtual void AnchorUpdated() OVERRIDE;
80   virtual base::string16 GetAccessibleNameForTray() OVERRIDE;
81   virtual void HideBubbleWithView(
82       const views::TrayBubbleView* bubble_view) OVERRIDE;
83   virtual bool ClickedOutsideBubble() OVERRIDE;
84
85   // Overridden from internal::ActionableView.
86   virtual bool PerformAction(const ui::Event& event) OVERRIDE;
87
88   // Overridden from views::TrayBubbleView::Delegate.
89   virtual void BubbleViewDestroyed() OVERRIDE;
90   virtual void OnMouseEnteredView() OVERRIDE;
91   virtual void OnMouseExitedView() OVERRIDE;
92   virtual base::string16 GetAccessibleNameForBubble() OVERRIDE;
93   virtual gfx::Rect GetAnchorRect(views::Widget* anchor_widget,
94                                   AnchorType anchor_type,
95                                   AnchorAlignment anchor_alignment) OVERRIDE;
96   virtual void HideBubble(const views::TrayBubbleView* bubble_view) OVERRIDE;
97
98   // Overridden from ButtonListener.
99   virtual void ButtonPressed(views::Button* sender,
100                              const ui::Event& event) OVERRIDE;
101
102   // Overridden from MessageCenterTrayDelegate.
103   virtual void OnMessageCenterTrayChanged() OVERRIDE;
104   virtual bool ShowMessageCenter() OVERRIDE;
105   virtual void HideMessageCenter() OVERRIDE;
106   virtual bool ShowPopups() OVERRIDE;
107   virtual void HidePopups() OVERRIDE;
108   virtual bool ShowNotifierSettings() OVERRIDE;
109   virtual message_center::MessageCenterTray* GetMessageCenterTray() OVERRIDE;
110
111   // Overridden from SimpleMenuModel::Delegate.
112   virtual bool IsCommandIdChecked(int command_id) const OVERRIDE;
113   virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE;
114   virtual bool GetAcceleratorForCommandId(
115       int command_id,
116       ui::Accelerator* accelerator) OVERRIDE;
117   virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE;
118
119   message_center::MessageCenter* message_center() const;
120
121  private:
122   friend class WebNotificationTrayTest;
123
124   FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, WebNotifications);
125   FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, WebNotificationPopupBubble);
126   FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest,
127                            ManyMessageCenterNotifications);
128   FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, ManyPopupNotifications);
129   FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, PopupShownOnBothDisplays);
130   FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, PopupAndSystemTray);
131   FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, PopupAndAutoHideShelf);
132
133   void UpdateTrayContent();
134
135   // The actual process to show the message center. Set |show_settings| to true
136   // if the message center should be initialized with the settings visible.
137   // Returns true if the center is successfully created.
138   bool ShowMessageCenterInternal(bool show_settings);
139
140   // Queries login status and the status area widget to determine visibility of
141   // the message center.
142   bool ShouldShowMessageCenter();
143
144   // Returns true if it should show the quiet mode menu.
145   bool ShouldShowQuietModeMenu(const ui::Event& event);
146
147   // Shows the quiet mode menu.
148   void ShowQuietModeMenu(const ui::Event& event);
149
150   // Creates the menu model for quiet mode and returns it.
151   ui::MenuModel* CreateQuietModeMenu();
152
153   internal::WebNotificationBubbleWrapper* message_center_bubble() const {
154     return message_center_bubble_.get();
155   }
156
157   // Testing accessors.
158   bool IsPopupVisible() const;
159   message_center::MessageCenterBubble* GetMessageCenterBubbleForTest();
160
161   scoped_ptr<message_center::MessageCenterTray> message_center_tray_;
162   scoped_ptr<internal::WebNotificationBubbleWrapper> message_center_bubble_;
163   scoped_ptr<message_center::MessagePopupCollection> popup_collection_;
164   internal::WebNotificationButton* button_;
165
166   bool show_message_center_on_unlock_;
167
168   bool should_update_tray_content_;
169
170   // True when the shelf auto hide behavior has to be blocked. Previously
171   // this was done by checking |message_center_bubble_| but actually
172   // the check can be called when creating this object, so it would cause
173   // flickers of the shelf from hidden to shown. See: crbug.com/181213
174   bool should_block_shelf_auto_hide_;
175
176   // Observes the work area for |popup_collection_| and notifies to it.
177   scoped_ptr<internal::WorkAreaObserver> work_area_observer_;
178
179   DISALLOW_COPY_AND_ASSIGN(WebNotificationTray);
180 };
181
182 }  // namespace ash
183
184 #endif  // ASH_SYSTEM_WEB_NOTIFICATION_WEB_NOTIFICATION_TRAY_H_