• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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   // Called when the login status is changed.
78   void UpdateAfterLoginStatusChange(user::LoginStatus login_status);
79 
80   // Overridden from TrayBackgroundView.
81   virtual void SetShelfAlignment(ShelfAlignment alignment) OVERRIDE;
82   virtual void AnchorUpdated() OVERRIDE;
83   virtual base::string16 GetAccessibleNameForTray() OVERRIDE;
84   virtual void HideBubbleWithView(
85       const views::TrayBubbleView* bubble_view) OVERRIDE;
86   virtual bool ClickedOutsideBubble() OVERRIDE;
87 
88   // Overridden from internal::ActionableView.
89   virtual bool PerformAction(const ui::Event& event) OVERRIDE;
90 
91   // Overridden from views::TrayBubbleView::Delegate.
92   virtual void BubbleViewDestroyed() OVERRIDE;
93   virtual void OnMouseEnteredView() OVERRIDE;
94   virtual void OnMouseExitedView() OVERRIDE;
95   virtual base::string16 GetAccessibleNameForBubble() OVERRIDE;
96   virtual gfx::Rect GetAnchorRect(views::Widget* anchor_widget,
97                                   AnchorType anchor_type,
98                                   AnchorAlignment anchor_alignment) OVERRIDE;
99   virtual void HideBubble(const views::TrayBubbleView* bubble_view) OVERRIDE;
100 
101   // Overridden from ButtonListener.
102   virtual void ButtonPressed(views::Button* sender,
103                              const ui::Event& event) OVERRIDE;
104 
105   // Overridden from MessageCenterTrayDelegate.
106   virtual void OnMessageCenterTrayChanged() OVERRIDE;
107   virtual bool ShowMessageCenter() OVERRIDE;
108   virtual void HideMessageCenter() OVERRIDE;
109   virtual bool ShowPopups() OVERRIDE;
110   virtual void HidePopups() OVERRIDE;
111   virtual bool ShowNotifierSettings() OVERRIDE;
112   virtual message_center::MessageCenterTray* GetMessageCenterTray() OVERRIDE;
113 
114   // Overridden from SimpleMenuModel::Delegate.
115   virtual bool IsCommandIdChecked(int command_id) const OVERRIDE;
116   virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE;
117   virtual bool GetAcceleratorForCommandId(
118       int command_id,
119       ui::Accelerator* accelerator) OVERRIDE;
120   virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE;
121 
122   message_center::MessageCenter* message_center() const;
123 
124  private:
125   friend class WebNotificationTrayTest;
126 
127   FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, WebNotifications);
128   FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, WebNotificationPopupBubble);
129   FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest,
130                            ManyMessageCenterNotifications);
131   FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, ManyPopupNotifications);
132   FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, PopupShownOnBothDisplays);
133   FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, PopupAndSystemTray);
134   FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, PopupAndAutoHideShelf);
135 
136   void UpdateTrayContent();
137 
138   // The actual process to show the message center. Set |show_settings| to true
139   // if the message center should be initialized with the settings visible.
140   // Returns true if the center is successfully created.
141   bool ShowMessageCenterInternal(bool show_settings);
142 
143   // Queries login status and the status area widget to determine visibility of
144   // the message center.
145   bool ShouldShowMessageCenter();
146 
147   // Returns true if it should show the quiet mode menu.
148   bool ShouldShowQuietModeMenu(const ui::Event& event);
149 
150   // Shows the quiet mode menu.
151   void ShowQuietModeMenu(const ui::Event& event);
152 
153   // Creates the menu model for quiet mode and returns it.
154   ui::MenuModel* CreateQuietModeMenu();
155 
message_center_bubble()156   internal::WebNotificationBubbleWrapper* message_center_bubble() const {
157     return message_center_bubble_.get();
158   }
159 
160   // Testing accessors.
161   bool IsPopupVisible() const;
162   message_center::MessageCenterBubble* GetMessageCenterBubbleForTest();
163 
164   scoped_ptr<message_center::MessageCenterTray> message_center_tray_;
165   scoped_ptr<internal::WebNotificationBubbleWrapper> message_center_bubble_;
166   scoped_ptr<message_center::MessagePopupCollection> popup_collection_;
167   internal::WebNotificationButton* button_;
168 
169   bool show_message_center_on_unlock_;
170 
171   bool should_update_tray_content_;
172 
173   // True when the shelf auto hide behavior has to be blocked. Previously
174   // this was done by checking |message_center_bubble_| but actually
175   // the check can be called when creating this object, so it would cause
176   // flickers of the shelf from hidden to shown. See: crbug.com/181213
177   bool should_block_shelf_auto_hide_;
178 
179   // Observes the work area for |popup_collection_| and notifies to it.
180   scoped_ptr<internal::WorkAreaObserver> work_area_observer_;
181 
182   DISALLOW_COPY_AND_ASSIGN(WebNotificationTray);
183 };
184 
185 }  // namespace ash
186 
187 #endif  // ASH_SYSTEM_WEB_NOTIFICATION_WEB_NOTIFICATION_TRAY_H_
188