Chromium Code Reviews| Index: ui/arc/notification/arc_notification_item.cc |
| diff --git a/ui/arc/notification/arc_notification_item.cc b/ui/arc/notification/arc_notification_item.cc |
| index f0d791bbe90a717801dd2373026421d141a116f1..dde7878a50f0cc49dbcd3f6e44dde3eb51688a7a 100644 |
| --- a/ui/arc/notification/arc_notification_item.cc |
| +++ b/ui/arc/notification/arc_notification_item.cc |
| @@ -12,9 +12,12 @@ |
| #include "base/task_runner.h" |
| #include "base/task_runner_util.h" |
| #include "base/threading/worker_pool.h" |
| +#include "third_party/skia/include/core/SkCanvas.h" |
| +#include "third_party/skia/include/core/SkPaint.h" |
| #include "ui/gfx/codec/png_codec.h" |
| #include "ui/gfx/geometry/size.h" |
| #include "ui/gfx/image/image.h" |
| +#include "ui/gfx/text_elider.h" |
| #include "ui/message_center/message_center_style.h" |
| #include "ui/message_center/notification.h" |
| #include "ui/message_center/notification_types.h" |
| @@ -39,6 +42,69 @@ SkBitmap DecodeImage(const std::vector<uint8_t>& data) { |
| return bitmap; |
| } |
| +SkBitmap ConvertBitmap( |
| + const mojo::StructPtr<ArcNotificationBitmap>& arcBitmap) { |
|
dcheng
2016/04/13 23:55:20
1) This seems like it should be a type converter o
yoshiki
2016/04/15 00:32:34
Thanks. I made it a type converter.
|
| + if (arcBitmap.is_null()) |
| + return SkBitmap(); |
| + |
| + // Creates the SkBitmap object which wraps the arc bitmap pixels. |
| + SkBitmap bitmap; |
| + if (!bitmap.installPixels( |
| + SkImageInfo::Make(arcBitmap->width, arcBitmap->height, |
| + kRGBA_8888_SkColorType, kPremul_SkAlphaType), |
| + &arcBitmap->pixel_data[0], (arcBitmap->width * 4))) { |
|
dcheng
2016/04/13 23:55:20
This doesn't work if pixel_data has no data.
mojo
yoshiki
2016/04/15 00:32:34
Done.
|
| + return SkBitmap(); |
| + } |
| + |
| + // Copy the pixels with converting color type. |
| + SkBitmap nativeColorBitmap; |
| + if (!bitmap.copyTo(&nativeColorBitmap, kN32_SkColorType)) |
| + return SkBitmap(); |
| + |
| + return nativeColorBitmap; |
| +} |
| + |
| +SkBitmap CropImage(const SkBitmap& original_bitmap) { |
| + DCHECK_NE(0, original_bitmap.width()); |
| + DCHECK_NE(0, original_bitmap.height()); |
| + |
| + const SkSize container_size = SkSize::Make( |
| + message_center::kNotificationPreferredImageWidth, |
| + message_center::kNotificationPreferredImageHeight); |
| + const float container_aspect_ratio = |
| + static_cast<float>(message_center::kNotificationPreferredImageWidth) / |
| + message_center::kNotificationPreferredImageHeight; |
| + const float image_aspect_ratio = |
| + static_cast<float>(original_bitmap.width()) / original_bitmap.height(); |
| + |
| + SkRect source_rect; |
| + if (image_aspect_ratio > container_aspect_ratio) { |
| + float width = original_bitmap.height() * container_aspect_ratio; |
| + source_rect = SkRect::MakeXYWH((original_bitmap.width() - width) / 2, |
| + 0, |
| + width, |
| + original_bitmap.height()); |
| + } else { |
| + float height = original_bitmap.width() / container_aspect_ratio; |
| + source_rect = SkRect::MakeXYWH(0, |
| + (original_bitmap.height() - height) / 2, |
| + original_bitmap.width(), |
| + height); |
| + } |
| + |
| + SkBitmap container_bitmap; |
| + container_bitmap.allocN32Pixels(container_size.width(), |
| + container_size.height()); |
| + SkPaint paint; |
| + paint.setFilterQuality(kHigh_SkFilterQuality); |
| + SkCanvas container_image(container_bitmap); |
| + container_image.drawColor(message_center::kImageBackgroundColor); |
| + container_image.drawBitmapRect( |
| + original_bitmap, source_rect, SkRect::MakeSize(container_size), &paint); |
| + |
| + return container_bitmap; |
| +} |
| + |
| class ArcNotificationDelegate : public message_center::NotificationDelegate { |
| public: |
| explicit ArcNotificationDelegate(base::WeakPtr<ArcNotificationItem> item) |
| @@ -112,10 +178,38 @@ void ArcNotificationItem::UpdateWithArcNotificationData( |
| case ArcNotificationType::BASIC: |
| type = message_center::NOTIFICATION_TYPE_BASE_FORMAT; |
| break; |
| + case ArcNotificationType::LIST: |
| + type = message_center::NOTIFICATION_TYPE_MULTIPLE; |
| + |
| + if (data.texts.is_null()) |
| + break; |
| + |
| + for (size_t i = 0; |
| + i < std::min(data.texts.size(), |
| + message_center::kNotificationMaximumItems - 1); |
| + i++) { |
| + rich_data.items.emplace_back( |
| + base::string16(), base::UTF8ToUTF16(data.texts.at(i).get())); |
| + } |
| + |
| + if (data.texts.size() > message_center::kNotificationMaximumItems) { |
| + // Show an elipsis as the 5th item if there are more than 5 items. |
| + rich_data.items.emplace_back(base::string16(), gfx::kEllipsisUTF16); |
| + } else if (data.texts.size() == |
| + message_center::kNotificationMaximumItems) { |
| + // Show the 5th item if there are exact 5 items. |
| + rich_data.items.emplace_back( |
| + base::string16(), |
| + base::UTF8ToUTF16(data.texts.at(data.texts.size() - 1).get())); |
| + } |
| + break; |
| case ArcNotificationType::IMAGE: |
| - // TODO(yoshiki): Implement this types. |
| - type = message_center::NOTIFICATION_TYPE_BASE_FORMAT; |
| - LOG(ERROR) << "Unsupported notification type: image"; |
| + type = message_center::NOTIFICATION_TYPE_IMAGE; |
| + |
| + if (!data.big_picture.is_null()) { |
| + rich_data.image = gfx::Image::CreateFrom1xBitmap( |
| + CropImage(ConvertBitmap(data.big_picture))); |
| + } |
| break; |
| case ArcNotificationType::PROGRESS: |
| type = message_center::NOTIFICATION_TYPE_PROGRESS; |
| @@ -131,8 +225,8 @@ void ArcNotificationItem::UpdateWithArcNotificationData( |
| << data.type; |
| for (size_t i = 0; i < data.buttons.size(); i++) { |
| - rich_data.buttons.push_back(message_center::ButtonInfo( |
| - base::UTF8ToUTF16(data.buttons.at(i)->label.get()))); |
| + rich_data.buttons.emplace_back( |
| + base::UTF8ToUTF16(data.buttons.at(i)->label.get())); |
| } |
| // If the client is old (version < 1), both |no_clear| and |ongoing_event| |