15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef ASH_SYSTEM_WEB_NOTIFICATION_WEB_NOTIFICATION_TRAY_H_
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define ASH_SYSTEM_WEB_NOTIFICATION_WEB_NOTIFICATION_TRAY_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/ash_export.h"
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/system/tray/tray_background_view.h"
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/system/user/login_status.h"
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/gtest_prod_util.h"
122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/memory/scoped_ptr.h"
13c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "base/memory/weak_ptr.h"
14424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)#include "ui/base/models/simple_menu_model.h"
152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/message_center/message_center_tray.h"
162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/message_center/message_center_tray_delegate.h"
172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/views/bubble/tray_bubble_view.h"
182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/views/controls/button/button.h"
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Status area tray for showing browser and app notifications. This hosts
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// a MessageCenter class which manages the notification list. This class
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// contains the Ash specific tray implementation.
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Note: These are not related to system notifications (i.e NotificationView
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// generated by SystemTrayItem). Visibility of one notification type or other
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// is controlled by StatusAreaWidget.
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace views {
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ImageButton;
302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class MenuRunner;
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace message_center {
342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class MessageBubbleBase;
352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class MessageCenter;
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class MessageCenterBubble;
372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class MessagePopupCollection;
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace ash {
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class StatusAreaWidget;
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class WebNotificationBubbleWrapper;
43c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)class WebNotificationButton;
44ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdochclass WorkAreaObserver;
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ASH_EXPORT WebNotificationTray
47c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    : public TrayBackgroundView,
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      public views::TrayBubbleView::Delegate,
492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      public message_center::MessageCenterTrayDelegate,
50c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      public views::ButtonListener,
51424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)      public base::SupportsWeakPtr<WebNotificationTray>,
52424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)      public ui::SimpleMenuModel::Delegate {
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
54c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  explicit WebNotificationTray(StatusAreaWidget* status_area_widget);
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~WebNotificationTray();
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
57a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // Sets the height of the system tray from the edge of the work area so that
58a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // the notification popups don't overlap with the tray. Passes 0 if no UI is
59a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // shown in the system tray side.
60a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  void SetSystemTrayHeight(int height);
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Returns true if it should block the auto hide behavior of the shelf.
635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  bool ShouldBlockShelfAutoHide() const;
642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if the message center bubble is visible.
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool IsMessageCenterBubbleVisible() const;
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if the mouse is inside the notification bubble.
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool IsMouseInNotificationBubble() const;
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Shows the message center bubble.
722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void ShowMessageCenterBubble();
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
74f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Called when the login status is changed.
75f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  void UpdateAfterLoginStatusChange(user::LoginStatus login_status);
76f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Overridden from TrayBackgroundView.
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void SetShelfAlignment(ShelfAlignment alignment) OVERRIDE;
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void AnchorUpdated() OVERRIDE;
80c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  virtual base::string16 GetAccessibleNameForTray() OVERRIDE;
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void HideBubbleWithView(
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const views::TrayBubbleView* bubble_view) OVERRIDE;
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool ClickedOutsideBubble() OVERRIDE;
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // Overridden from ActionableView.
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool PerformAction(const ui::Event& event) OVERRIDE;
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Overridden from views::TrayBubbleView::Delegate.
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void BubbleViewDestroyed() OVERRIDE;
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void OnMouseEnteredView() OVERRIDE;
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void OnMouseExitedView() OVERRIDE;
92c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  virtual base::string16 GetAccessibleNameForBubble() OVERRIDE;
93cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  virtual gfx::Rect GetAnchorRect(
94cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      views::Widget* anchor_widget,
95cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      AnchorType anchor_type,
96cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      AnchorAlignment anchor_alignment) const OVERRIDE;
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void HideBubble(const views::TrayBubbleView* bubble_view) OVERRIDE;
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Overridden from ButtonListener.
1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void ButtonPressed(views::Button* sender,
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                             const ui::Event& event) OVERRIDE;
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Overridden from MessageCenterTrayDelegate.
1042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void OnMessageCenterTrayChanged() OVERRIDE;
1052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual bool ShowMessageCenter() OVERRIDE;
1062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void HideMessageCenter() OVERRIDE;
1072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual bool ShowPopups() OVERRIDE;
1082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void HidePopups() OVERRIDE;
109eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  virtual bool ShowNotifierSettings() OVERRIDE;
1105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual bool IsContextMenuEnabled() const OVERRIDE;
1112385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch  virtual message_center::MessageCenterTray* GetMessageCenterTray() OVERRIDE;
1122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
113424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // Overridden from SimpleMenuModel::Delegate.
114424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  virtual bool IsCommandIdChecked(int command_id) const OVERRIDE;
115424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE;
116424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  virtual bool GetAcceleratorForCommandId(
117424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)      int command_id,
118424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)      ui::Accelerator* accelerator) OVERRIDE;
119424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE;
120424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
121424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  message_center::MessageCenter* message_center() const;
1222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
124a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  friend class WebNotificationTrayTest;
125a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, WebNotifications);
1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, WebNotificationPopupBubble);
1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest,
1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                           ManyMessageCenterNotifications);
1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, ManyPopupNotifications);
131558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, PopupShownOnBothDisplays);
132a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, PopupAndSystemTray);
1333551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, PopupAndAutoHideShelf);
1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
135c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  void UpdateTrayContent();
136c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
137eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // The actual process to show the message center. Set |show_settings| to true
138eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // if the message center should be initialized with the settings visible.
139eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // Returns true if the center is successfully created.
140eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  bool ShowMessageCenterInternal(bool show_settings);
141eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
1422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Queries login status and the status area widget to determine visibility of
1432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // the message center.
1442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool ShouldShowMessageCenter();
1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Returns true if it should show the quiet mode menu.
1472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool ShouldShowQuietModeMenu(const ui::Event& event);
1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Shows the quiet mode menu.
1507d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  void ShowQuietModeMenu(const ui::Event& event);
1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
152424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // Creates the menu model for quiet mode and returns it.
153424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  ui::MenuModel* CreateQuietModeMenu();
154424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
155c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  WebNotificationBubbleWrapper* message_center_bubble() const {
1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return message_center_bubble_.get();
1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Testing accessors.
1602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool IsPopupVisible() const;
1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  message_center::MessageCenterBubble* GetMessageCenterBubbleForTest();
1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  scoped_ptr<message_center::MessageCenterTray> message_center_tray_;
164c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  scoped_ptr<WebNotificationBubbleWrapper> message_center_bubble_;
1652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  scoped_ptr<message_center::MessagePopupCollection> popup_collection_;
166c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  WebNotificationButton* button_;
1672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool show_message_center_on_unlock_;
1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
170c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  bool should_update_tray_content_;
171c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
172c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // True when the shelf auto hide behavior has to be blocked. Previously
173c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // this was done by checking |message_center_bubble_| but actually
174c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // the check can be called when creating this object, so it would cause
175c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // flickers of the shelf from hidden to shown. See: crbug.com/181213
176c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  bool should_block_shelf_auto_hide_;
177c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
178ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Observes the work area for |popup_collection_| and notifies to it.
179c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  scoped_ptr<WorkAreaObserver> work_area_observer_;
180ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(WebNotificationTray);
1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace ash
1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // ASH_SYSTEM_WEB_NOTIFICATION_WEB_NOTIFICATION_TRAY_H_
187