summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/cocoa/notifications/message_center_tray_bridge.h
blob: f336db45c09e9018632b3b6550955593c057b20e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_UI_COCOA_NOTIFICATIONS_MESSAGE_CENTER_TRAY_BRIDGE_H_
#define CHROME_BROWSER_UI_COCOA_NOTIFICATIONS_MESSAGE_CENTER_TRAY_BRIDGE_H_

#import <AppKit/AppKit.h>

#include "base/basictypes.h"
#include "base/mac/scoped_nsobject.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/prefs/pref_member.h"
#include "ui/message_center/message_center.h"
#include "ui/message_center/message_center_tray_delegate.h"

@class MCPopupCollection;
@class MCStatusItemView;
@class MCTrayController;

namespace message_center {
class MessageCenter;
class MessageCenterTray;
}

// MessageCenterTrayBridge is the owner of all the Cocoa UI objects for the
// message_center. It bridges C++ notifications from the MessageCenterTray to
// the various UI objects.
class MessageCenterTrayBridge :
    public message_center::MessageCenterTrayDelegate {
 public:
  explicit MessageCenterTrayBridge(
      message_center::MessageCenter* message_center);
  virtual ~MessageCenterTrayBridge();

  // message_center::MessageCenterTrayDelegate:
  virtual void OnMessageCenterTrayChanged() override;
  virtual bool ShowPopups() override;
  virtual void HidePopups() override;
  virtual bool ShowMessageCenter() override;
  virtual void HideMessageCenter() override;
  virtual bool ShowNotifierSettings() override;
  virtual bool IsContextMenuEnabled() const override;
  virtual message_center::MessageCenterTray* GetMessageCenterTray() override;

  message_center::MessageCenter* message_center() { return message_center_; }

 private:
  friend class MessageCenterTrayBridgeTest;

  // Updates the unread count on the status item.
  void UpdateStatusItem();

  // Opens the message center tray.
  void OpenTrayWindow();

  // Uses the pref controlled by the main menu to determine whether the status
  // item should be shown.
  bool ShouldShowStatusItem() const;

  // Notifies that the user has changed the show menubar item preference.
  void OnShowStatusItemChanged();

  // The global, singleton message center model object. Weak.
  message_center::MessageCenter* message_center_;

  // C++ controller for the notification tray UI.
  scoped_ptr<message_center::MessageCenterTray> tray_;

  // Obj-C window controller for the notification tray.
  base::scoped_nsobject<MCTrayController> tray_controller_;

  // View that is displayed on the system menu bar item.
  base::scoped_nsobject<MCStatusItemView> status_item_view_;

  // Obj-C controller for the on-screen popup notifications.
  base::scoped_nsobject<MCPopupCollection> popup_collection_;

  // A PrefMember that calls OnShowStatusItemChanged when the pref is updated
  // by the user's selection in the main menu.
  BooleanPrefMember show_status_item_;

  // Weak pointer factory to posts tasks to self.
  base::WeakPtrFactory<MessageCenterTrayBridge> weak_ptr_factory_;

  DISALLOW_COPY_AND_ASSIGN(MessageCenterTrayBridge);
};

#endif  // CHROME_BROWSER_UI_COCOA_NOTIFICATIONS_MESSAGE_CENTER_TRAY_BRIDGE_H_