forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmedia_notification_view.h
146 lines (112 loc) · 4.69 KB
/
media_notification_view.h
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
146
// Copyright 2018 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_MEDIA_MEDIA_NOTIFICATION_VIEW_H_
#define ASH_MEDIA_MEDIA_NOTIFICATION_VIEW_H_
#include "ash/ash_export.h"
#include "services/media_session/public/mojom/media_session.mojom.h"
#include "ui/message_center/views/message_view.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/controls/button/image_button.h"
#include "ui/views/controls/label.h"
namespace gfx {
class ImageSkia;
} // namespace gfx
namespace media_session {
struct MediaMetadata;
} // namespace media_session
namespace media_session {
enum class MediaSessionAction;
} // namespace media_session
namespace message_center {
class NotificationHeaderView;
} // namespace message_center
namespace views {
class BoxLayout;
class ToggleImageButton;
class View;
} // namespace views
namespace ash {
class MediaNotificationBackground;
// MediaNotificationView will show up as a custom notification. It will show the
// currently playing media and provide playback controls. There will also be
// control buttons (e.g. close) in the top right corner that will hide and show
// if the notification is hovered.
class ASH_EXPORT MediaNotificationView : public message_center::MessageView,
public views::ButtonListener {
public:
// The name of the histogram used when recorded whether the artwork was
// present.
static const char kArtworkHistogramName[];
// The name of the histogram used when recording the type of metadata that was
// displayed.
static const char kMetadataHistogramName[];
// The type of metadata that was displayed. This is used in metrics so new
// values must only be added to the end.
enum class Metadata {
kTitle,
kArtist,
kAlbum,
kCount,
kMaxValue = kCount,
};
explicit MediaNotificationView(
const message_center::Notification& notification);
~MediaNotificationView() override;
// message_center::MessageView:
void UpdateWithNotification(
const message_center::Notification& notification) override;
message_center::NotificationControlButtonsView* GetControlButtonsView()
const override;
void SetExpanded(bool expanded) override;
void UpdateCornerRadius(int top_radius, int bottom_radius) override;
// views::View:
void OnMouseEvent(ui::MouseEvent* event) override;
// views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
void UpdateWithMediaSessionInfo(
const media_session::mojom::MediaSessionInfoPtr& session_info);
void UpdateWithMediaMetadata(const media_session::MediaMetadata& metadata);
void UpdateWithMediaActions(
const std::set<media_session::mojom::MediaSessionAction>& actions);
void UpdateWithMediaArtwork(const gfx::ImageSkia& image);
void UpdateWithMediaIcon(const gfx::ImageSkia& image);
private:
friend class MediaNotificationViewTest;
void UpdateControlButtonsVisibilityWithNotification(
const message_center::Notification& notification);
// Creates an image button with an icon that matches |action| and adds it
// to |button_row_|. When clicked it will trigger |action| on the session.
// |accessible_name| is the text used for screen readers.
void CreateMediaButton(media_session::mojom::MediaSessionAction action,
const base::string16& accessible_name);
void UpdateActionButtonsVisibility();
void UpdateViewForExpandedState();
MediaNotificationBackground* GetMediaNotificationBackground();
bool IsExpandable() const;
bool IsActuallyExpanded() const;
std::set<media_session::mojom::MediaSessionAction> CalculateVisibleActions(
bool expanded) const;
void UpdateForegroundColor();
// View containing close and settings buttons.
std::unique_ptr<message_center::NotificationControlButtonsView>
control_buttons_view_;
bool has_artwork_ = false;
// Whether this notification is expanded or not.
bool expanded_ = false;
// Set of enabled actions.
std::set<media_session::mojom::MediaSessionAction> enabled_actions_;
// Container views directly attached to this view.
message_center::NotificationHeaderView* header_row_ = nullptr;
views::View* button_row_ = nullptr;
views::ToggleImageButton* play_pause_button_ = nullptr;
views::View* title_artist_row_ = nullptr;
views::Label* title_label_ = nullptr;
views::Label* artist_label_ = nullptr;
views::View* layout_row_ = nullptr;
views::View* main_row_ = nullptr;
views::BoxLayout* title_artist_row_layout_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(MediaNotificationView);
};
} // namespace ash
#endif // ASH_MEDIA_MEDIA_NOTIFICATION_VIEW_H_