Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: ui/arc/notification/arc_custom_notification_item.cc

Issue 2093563007: Add a floating close button for arc custom notification (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix typo Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/arc/notification/arc_custom_notification_item.h" 5 #include "ui/arc/notification/arc_custom_notification_item.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/strings/string16.h" 8 #include "base/strings/string16.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "components/exo/notification_surface.h" 10 #include "components/exo/notification_surface.h"
11 #include "ui/arc/notification/arc_custom_notification_view.h" 11 #include "ui/arc/notification/arc_custom_notification_view.h"
12 #include "ui/message_center/notification.h" 12 #include "ui/message_center/notification.h"
13 #include "ui/message_center/notification_types.h" 13 #include "ui/message_center/notification_types.h"
14 14
15 namespace arc { 15 namespace arc {
16 16
17 namespace { 17 namespace {
18 18
19 constexpr char kNotifierId[] = "ARC_NOTIFICATION"; 19 constexpr char kNotifierId[] = "ARC_NOTIFICATION";
20 20
21 class ArcNotificationDelegate : public message_center::NotificationDelegate { 21 class ArcNotificationDelegate : public message_center::NotificationDelegate {
22 public: 22 public:
23 ArcNotificationDelegate() {} 23 explicit ArcNotificationDelegate(ArcCustomNotificationItem* item)
24 : item_(item) {}
24 25
25 std::unique_ptr<views::View> CreateCustomContent() override { 26 std::unique_ptr<views::View> CreateCustomContent() override {
26 if (!surface_) 27 if (!surface_)
27 return nullptr; 28 return nullptr;
28 29
29 return base::MakeUnique<ArcCustomNotificationView>(surface_); 30 return base::MakeUnique<ArcCustomNotificationView>(item_, surface_);
30 } 31 }
31 32
32 void set_notification_surface(exo::NotificationSurface* surface) { 33 void set_notification_surface(exo::NotificationSurface* surface) {
33 surface_ = surface; 34 surface_ = surface;
34 } 35 }
35 36
36 private: 37 private:
37 // The destructor is private since this class is ref-counted. 38 // The destructor is private since this class is ref-counted.
38 ~ArcNotificationDelegate() override {} 39 ~ArcNotificationDelegate() override {}
39 40
41 ArcCustomNotificationItem* const item_;
40 exo::NotificationSurface* surface_ = nullptr; 42 exo::NotificationSurface* surface_ = nullptr;
41 43
42 DISALLOW_COPY_AND_ASSIGN(ArcNotificationDelegate); 44 DISALLOW_COPY_AND_ASSIGN(ArcNotificationDelegate);
43 }; 45 };
44 46
45 } // namespace 47 } // namespace
46 48
47 ArcCustomNotificationItem::ArcCustomNotificationItem( 49 ArcCustomNotificationItem::ArcCustomNotificationItem(
48 ArcNotificationManager* manager, 50 ArcNotificationManager* manager,
49 message_center::MessageCenter* message_center, 51 message_center::MessageCenter* message_center,
50 const std::string& notification_key, 52 const std::string& notification_key,
51 const AccountId& profile_id) 53 const AccountId& profile_id)
52 : ArcNotificationItem(manager, 54 : ArcNotificationItem(manager,
53 message_center, 55 message_center,
54 notification_key, 56 notification_key,
55 profile_id) {} 57 profile_id) {}
56 58
57 ArcCustomNotificationItem::~ArcCustomNotificationItem() { 59 ArcCustomNotificationItem::~ArcCustomNotificationItem() {
58 if (ArcNotificationSurfaceManager::Get()) 60 if (ArcNotificationSurfaceManager::Get())
59 ArcNotificationSurfaceManager::Get()->RemoveObserver(this); 61 ArcNotificationSurfaceManager::Get()->RemoveObserver(this);
62
63 FOR_EACH_OBSERVER(Observer, observers_, OnItemDestroying());
60 } 64 }
61 65
62 void ArcCustomNotificationItem::UpdateWithArcNotificationData( 66 void ArcCustomNotificationItem::UpdateWithArcNotificationData(
63 const mojom::ArcNotificationData& data) { 67 const mojom::ArcNotificationData& data) {
64 DCHECK(CalledOnValidThread()); 68 DCHECK(CalledOnValidThread());
65 DCHECK_EQ(notification_key(), data.key); 69 DCHECK_EQ(notification_key(), data.key);
66 70
67 if (CacheArcNotificationData(data)) 71 if (CacheArcNotificationData(data))
68 return; 72 return;
69 73
70 message_center::RichNotificationData rich_data; 74 message_center::RichNotificationData rich_data;
71 rich_data.pinned = (data.no_clear || data.ongoing_event); 75 rich_data.pinned = (data.no_clear || data.ongoing_event);
72 rich_data.priority = ConvertAndroidPriority(data.priority); 76 rich_data.priority = ConvertAndroidPriority(data.priority);
73 77
74 message_center::NotifierId notifier_id( 78 message_center::NotifierId notifier_id(
75 message_center::NotifierId::SYSTEM_COMPONENT, kNotifierId); 79 message_center::NotifierId::SYSTEM_COMPONENT, kNotifierId);
76 notifier_id.profile_id = profile_id().GetUserEmail(); 80 notifier_id.profile_id = profile_id().GetUserEmail();
77 81
78 DCHECK(!data.title.is_null()); 82 DCHECK(!data.title.is_null());
79 DCHECK(!data.message.is_null()); 83 DCHECK(!data.message.is_null());
80 SetNotification(base::MakeUnique<message_center::Notification>( 84 SetNotification(base::MakeUnique<message_center::Notification>(
81 message_center::NOTIFICATION_TYPE_CUSTOM, notification_id(), 85 message_center::NOTIFICATION_TYPE_CUSTOM, notification_id(),
82 base::UTF8ToUTF16(data.title.get()), 86 base::UTF8ToUTF16(data.title.get()),
83 base::UTF8ToUTF16(data.message.get()), gfx::Image(), 87 base::UTF8ToUTF16(data.message.get()), gfx::Image(),
84 base::UTF8ToUTF16("arc"), // display source 88 base::UTF8ToUTF16("arc"), // display source
85 GURL(), // empty origin url, for system component 89 GURL(), // empty origin url, for system component
86 notifier_id, rich_data, new ArcNotificationDelegate())); 90 notifier_id, rich_data, new ArcNotificationDelegate(this)));
87 91
88 exo::NotificationSurface* surface = 92 exo::NotificationSurface* surface =
89 ArcNotificationSurfaceManager::Get()->GetSurface(notification_key()); 93 ArcNotificationSurfaceManager::Get()->GetSurface(notification_key());
90 if (surface) 94 if (surface)
91 OnNotificationSurfaceAdded(surface); 95 OnNotificationSurfaceAdded(surface);
92 else 96 else
93 ArcNotificationSurfaceManager::Get()->AddObserver(this); 97 ArcNotificationSurfaceManager::Get()->AddObserver(this);
98
99 pinned_ = rich_data.pinned;
100 FOR_EACH_OBSERVER(Observer, observers_, OnItemPinnedChanged());
101 }
102
103 void ArcCustomNotificationItem::CloseFromCloseButton() {
104 // Needs to manually remove notification from MessageCenter because
105 // the floating close button is not part of MessageCenter.
106 message_center()->RemoveNotification(notification_id(), true);
107 Close(true);
108 }
109
110 void ArcCustomNotificationItem::AddObserver(Observer* observer) {
111 observers_.AddObserver(observer);
112 }
113
114 void ArcCustomNotificationItem::RemoveObserver(Observer* observer) {
115 observers_.RemoveObserver(observer);
94 } 116 }
95 117
96 void ArcCustomNotificationItem::OnNotificationSurfaceAdded( 118 void ArcCustomNotificationItem::OnNotificationSurfaceAdded(
97 exo::NotificationSurface* surface) { 119 exo::NotificationSurface* surface) {
98 if (!pending_notification() || 120 if (!pending_notification() ||
99 surface->notification_id() != notification_key()) { 121 surface->notification_id() != notification_key()) {
100 return; 122 return;
101 } 123 }
102 124
103 static_cast<ArcNotificationDelegate*>(pending_notification()->delegate()) 125 static_cast<ArcNotificationDelegate*>(pending_notification()->delegate())
104 ->set_notification_surface(surface); 126 ->set_notification_surface(surface);
105 AddToMessageCenter(); 127 AddToMessageCenter();
106 } 128 }
107 129
108 void ArcCustomNotificationItem::OnNotificationSurfaceRemoved( 130 void ArcCustomNotificationItem::OnNotificationSurfaceRemoved(
109 exo::NotificationSurface* surface) { 131 exo::NotificationSurface* surface) {
110 if (surface->notification_id() != notification_key()) 132 if (surface->notification_id() != notification_key())
111 return; 133 return;
112 134
113 OnClosedFromAndroid(false); 135 OnClosedFromAndroid(false);
114 } 136 }
115 137
116 } // namespace arc 138 } // namespace arc
OLDNEW
« no previous file with comments | « ui/arc/notification/arc_custom_notification_item.h ('k') | ui/arc/notification/arc_custom_notification_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698