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
ash / system / notification_center / views / notification_actions_view.h [blame]
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_SYSTEM_NOTIFICATION_CENTER_VIEWS_NOTIFICATION_ACTIONS_VIEW_H_
#define ASH_SYSTEM_NOTIFICATION_CENTER_VIEWS_NOTIFICATION_ACTIONS_VIEW_H_
#include <ash/ash_export.h>
#include <string>
#include "base/functional/callback_forward.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/views/controls/textfield/textfield_controller.h"
#include "ui/views/view.h"
namespace message_center {
class Notification;
}
namespace ui {
class KeyEvent;
}
namespace views {
class FlexLayoutView;
class Textfield;
} // namespace views
namespace ash {
class SystemTextfield;
class IconButton;
// Displays Notification action buttons and inline reply and forwards responses
// to `message_center::MessageCenter`.
class ASH_EXPORT NotificationActionsView : public views::View,
views::TextfieldController {
METADATA_HEADER(NotificationActionsView, views::View)
public:
NotificationActionsView();
NotificationActionsView(const NotificationActionsView&) = delete;
NotificationActionsView& operator=(const NotificationActionsView&) = delete;
~NotificationActionsView() override;
// Updates relevant views with data from the provided `notification`.
void UpdateWithNotification(const message_center::Notification& notification);
// Updates the visibility of the `inline_reply_container` and
// `buttons_container_` and sets up the `send_reply_callback_` after a reply
// button is pressed.
void ReplyButtonPressed(const std::string notification_id,
const int button_index,
const std::u16string placeholder);
// Sends an input response when the `send_button_` is pressed.
void SendButtonPressed();
// Updates the view for the provided expanded state.
void SetExpanded(bool expanded);
private:
friend class NotificationActionsViewTest;
// views::TextfieldController:
bool HandleKeyEvent(views::Textfield* sender,
const ui::KeyEvent& key_event) override;
void OnAfterUserAction(views::Textfield* sender) override;
// Sends the input reply contained in `textfield_` to
// `message_center::MessageCenter`.
void SendReply(const std::string& notification_id, const int button_index);
// Animates the view to a collapsed state.
void AnimateCollapse();
// Animates the view to an expanded state.
void AnimateExpand();
// Color used for buttons in this view.
SkColor button_and_icon_background_color_;
// Owned by the views hierarchy
base::RepeatingCallback<void()> send_reply_callback_;
raw_ptr<views::FlexLayoutView> buttons_container_ = nullptr;
raw_ptr<views::FlexLayoutView> inline_reply_container_ = nullptr;
raw_ptr<SystemTextfield> textfield_ = nullptr;
raw_ptr<IconButton> send_button_ = nullptr;
base::WeakPtrFactory<NotificationActionsView> weak_factory_{this};
};
} // namespace ash
#endif // ASH_SYSTEM_NOTIFICATION_CENTER_VIEWS_NOTIFICATION_ACTIONS_VIEW_H_