summaryrefslogtreecommitdiff
path: root/chromium/ash/system/chromeos/screen_security/screen_tray_item.h
blob: f078a39f0e2686bb5c4bb2fab6974c7f0f8041bd (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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// Copyright 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 ASH_SYSTEM_CHROMEOS_SCREEN_TRAY_ITEM_H_
#define ASH_SYSTEM_CHROMEOS_SCREEN_TRAY_ITEM_H_

#include "ash/system/tray/system_tray.h"
#include "ash/system/tray/system_tray_item.h"
#include "ash/system/tray/system_tray_notifier.h"
#include "ash/system/tray/tray_item_view.h"
#include "ash/system/tray/tray_notification_view.h"
#include "ash/system/tray/tray_popup_label_button.h"
#include "ui/message_center/notification_delegate.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/controls/image_view.h"

namespace views {
class View;
}

namespace ash {
namespace internal {

class ScreenTrayItem;

namespace tray {

class ScreenTrayView : public TrayItemView {
 public:
  ScreenTrayView(ScreenTrayItem* screen_tray_item, int icon_id);
  virtual ~ScreenTrayView();

  void Update();

 private:
  ScreenTrayItem* screen_tray_item_;

  DISALLOW_COPY_AND_ASSIGN(ScreenTrayView);
};

class ScreenStatusView : public views::View,
                         public views::ButtonListener {
 public:
  ScreenStatusView(ScreenTrayItem* screen_tray_item,
                   int icon_id,
                   const base::string16& label_text,
                   const base::string16& stop_button_text);
  virtual ~ScreenStatusView();

  // Overridden from views::View.
  virtual void Layout() OVERRIDE;

  // Overridden from views::ButtonListener.
  virtual void ButtonPressed(views::Button* sender,
                             const ui::Event& event) OVERRIDE;

  void CreateItems();
  void Update();

 private:
  ScreenTrayItem* screen_tray_item_;
  views::ImageView* icon_;
  views::Label* label_;
  TrayPopupLabelButton* stop_button_;
  int icon_id_;
  base::string16 label_text_;
  base::string16 stop_button_text_;

  DISALLOW_COPY_AND_ASSIGN(ScreenStatusView);
};

class ScreenNotificationDelegate : public message_center::NotificationDelegate {
 public:
  explicit ScreenNotificationDelegate(ScreenTrayItem* screen_tray);

  // message_center::NotificationDelegate overrides:
  virtual void Display() OVERRIDE;
  virtual void Error() OVERRIDE;
  virtual void Close(bool by_user) OVERRIDE;
  virtual void Click() OVERRIDE;
  virtual void ButtonClick(int button_index) OVERRIDE;

 protected:
  virtual ~ScreenNotificationDelegate();

 private:
  ScreenTrayItem* screen_tray_;

  DISALLOW_COPY_AND_ASSIGN(ScreenNotificationDelegate);
};

}  // namespace tray


// The base tray item for screen capture and screen sharing. The
// Start method brings up a notification and a tray item, and the user
// can stop the screen capture/sharing by pressing the stop button.
class ASH_EXPORT ScreenTrayItem : public SystemTrayItem {
 public:
  explicit ScreenTrayItem(SystemTray* system_tray);
  virtual ~ScreenTrayItem();

  tray::ScreenTrayView* tray_view() { return tray_view_; }
  void set_tray_view(tray::ScreenTrayView* tray_view) {
    tray_view_ = tray_view;
  }

  tray::ScreenStatusView* default_view() { return default_view_; }
  void set_default_view(tray::ScreenStatusView* default_view) {
    default_view_ = default_view;
  }

  bool is_started() const { return is_started_; }
  void set_is_started(bool is_started) { is_started_ = is_started; }

  void Update();
  void Start(const base::Closure& stop_callback);
  void Stop();

  // Creates or updates the notification for the tray item.
  virtual void CreateOrUpdateNotification() = 0;

  // Returns the id of the notification for the tray item.
  virtual std::string GetNotificationId() = 0;

  // Overridden from SystemTrayItem.
  virtual views::View* CreateTrayView(user::LoginStatus status) OVERRIDE = 0;
  virtual views::View* CreateDefaultView(user::LoginStatus status) OVERRIDE = 0;
  virtual void DestroyTrayView() OVERRIDE;
  virtual void DestroyDefaultView() OVERRIDE;

 private:
  tray::ScreenTrayView* tray_view_;
  tray::ScreenStatusView* default_view_;
  bool is_started_;
  base::Closure stop_callback_;

  DISALLOW_COPY_AND_ASSIGN(ScreenTrayItem);
};

}  // namespace internal
}  // namespace ash

#endif  // ASH_SYSTEM_CHROMEOS_SCREEN_TRAY_ITEM_H_