| OLD | NEW |
| 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_notification_item.h" | 5 #include "ui/arc/notification/arc_notification_item.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 // cursor on hover. | 53 // cursor on hover. |
| 54 // TODO(yoshiki): Return the correct value according to the content intent | 54 // TODO(yoshiki): Return the correct value according to the content intent |
| 55 // and the flags. | 55 // and the flags. |
| 56 bool HasClickedListener() override { return true; } | 56 bool HasClickedListener() override { return true; } |
| 57 | 57 |
| 58 void Click() override { | 58 void Click() override { |
| 59 if (item_) | 59 if (item_) |
| 60 item_->Click(); | 60 item_->Click(); |
| 61 } | 61 } |
| 62 | 62 |
| 63 void ButtonClick(int button_index) override { |
| 64 if (item_) |
| 65 item_->ButtonClick(button_index); |
| 66 } |
| 67 |
| 63 private: | 68 private: |
| 64 // The destructor is private since this class is ref-counted. | 69 // The destructor is private since this class is ref-counted. |
| 65 ~ArcNotificationDelegate() override {} | 70 ~ArcNotificationDelegate() override {} |
| 66 | 71 |
| 67 base::WeakPtr<ArcNotificationItem> item_; | 72 base::WeakPtr<ArcNotificationItem> item_; |
| 68 | 73 |
| 69 DISALLOW_COPY_AND_ASSIGN(ArcNotificationDelegate); | 74 DISALLOW_COPY_AND_ASSIGN(ArcNotificationDelegate); |
| 70 }; | 75 }; |
| 71 | 76 |
| 72 } // anonymous namespace | 77 } // anonymous namespace |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 base::TimeDelta::FromMilliseconds(data.time); | 123 base::TimeDelta::FromMilliseconds(data.time); |
| 119 rich_data.progress = std::max( | 124 rich_data.progress = std::max( |
| 120 0, std::min(100, static_cast<int>(std::round( | 125 0, std::min(100, static_cast<int>(std::round( |
| 121 static_cast<float>(data.progress_current) / | 126 static_cast<float>(data.progress_current) / |
| 122 data.progress_max * 100)))); | 127 data.progress_max * 100)))); |
| 123 break; | 128 break; |
| 124 } | 129 } |
| 125 DCHECK(0 <= data.type && data.type <= ARC_NOTIFICATION_TYPE_MAX) | 130 DCHECK(0 <= data.type && data.type <= ARC_NOTIFICATION_TYPE_MAX) |
| 126 << "Unsupported notification type: " << data.type; | 131 << "Unsupported notification type: " << data.type; |
| 127 | 132 |
| 133 for (size_t i = 0; i < data.buttons.size(); i++) { |
| 134 rich_data.buttons.push_back(message_center::ButtonInfo( |
| 135 base::UTF8ToUTF16(data.buttons.at(i)->label.get()))); |
| 136 } |
| 137 |
| 128 // The identifier of the notifier, which is used to distinguish the notifiers | 138 // The identifier of the notifier, which is used to distinguish the notifiers |
| 129 // in the message center. | 139 // in the message center. |
| 130 message_center::NotifierId notifier_id( | 140 message_center::NotifierId notifier_id( |
| 131 message_center::NotifierId::SYSTEM_COMPONENT, kNotifierId); | 141 message_center::NotifierId::SYSTEM_COMPONENT, kNotifierId); |
| 132 notifier_id.profile_id = profile_id_.GetUserEmail(); | 142 notifier_id.profile_id = profile_id_.GetUserEmail(); |
| 133 | 143 |
| 134 DCHECK(!data.title.is_null()); | 144 DCHECK(!data.title.is_null()); |
| 135 DCHECK(!data.message.is_null()); | 145 DCHECK(!data.message.is_null()); |
| 136 notification_.reset(new message_center::Notification( | 146 notification_.reset(new message_center::Notification( |
| 137 type, notification_id_, base::UTF8ToUTF16(data.title.get()), | 147 type, notification_id_, base::UTF8ToUTF16(data.title.get()), |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 | 182 |
| 173 // Do not touch its any members afterwards, because this instance will be | 183 // Do not touch its any members afterwards, because this instance will be |
| 174 // destroyed in the following call | 184 // destroyed in the following call |
| 175 manager_->SendNotificationRemovedFromChrome(notification_key_); | 185 manager_->SendNotificationRemovedFromChrome(notification_key_); |
| 176 } | 186 } |
| 177 | 187 |
| 178 void ArcNotificationItem::Click() { | 188 void ArcNotificationItem::Click() { |
| 179 manager_->SendNotificationClickedOnChrome(notification_key_); | 189 manager_->SendNotificationClickedOnChrome(notification_key_); |
| 180 } | 190 } |
| 181 | 191 |
| 192 void ArcNotificationItem::ButtonClick(int button_index) { |
| 193 manager_->SendNotificationButtonClickedOnChrome( |
| 194 notification_key_, button_index); |
| 195 } |
| 196 |
| 182 void ArcNotificationItem::OnImageDecoded(const SkBitmap& bitmap) { | 197 void ArcNotificationItem::OnImageDecoded(const SkBitmap& bitmap) { |
| 183 DCHECK(thread_checker_.CalledOnValidThread()); | 198 DCHECK(thread_checker_.CalledOnValidThread()); |
| 184 | 199 |
| 185 gfx::Image image = gfx::Image::CreateFrom1xBitmap(bitmap); | 200 gfx::Image image = gfx::Image::CreateFrom1xBitmap(bitmap); |
| 186 notification_->set_icon(image); | 201 notification_->set_icon(image); |
| 187 | 202 |
| 188 DCHECK(notification_); | 203 DCHECK(notification_); |
| 189 message_center_->AddNotification(std::move(notification_)); | 204 message_center_->AddNotification(std::move(notification_)); |
| 190 | 205 |
| 191 if (newer_data_) { | 206 if (newer_data_) { |
| 192 // There is the newer data, so updates again. | 207 // There is the newer data, so updates again. |
| 193 ArcNotificationDataPtr data(std::move(newer_data_)); | 208 ArcNotificationDataPtr data(std::move(newer_data_)); |
| 194 UpdateWithArcNotificationData(*data); | 209 UpdateWithArcNotificationData(*data); |
| 195 } | 210 } |
| 196 } | 211 } |
| 197 | 212 |
| 198 } // namespace arc | 213 } // namespace arc |
| OLD | NEW |