Index: ui/message_center/views/message_view.cc |
diff --git a/ui/message_center/views/message_view.cc b/ui/message_center/views/message_view.cc |
index 11ff5485f86612ed4314d70b68a786060404df56..3b8900c35a945aa9f1c6ae4018857d7309db9818 100644 |
--- a/ui/message_center/views/message_view.cc |
+++ b/ui/message_center/views/message_view.cc |
@@ -12,6 +12,7 @@ |
#include "ui/base/resource/resource_bundle.h" |
#include "ui/compositor/scoped_layer_animation_settings.h" |
#include "ui/gfx/canvas.h" |
+#include "ui/gfx/image/image_skia_operations.h" |
#include "ui/message_center/message_center.h" |
#include "ui/message_center/message_center_style.h" |
#include "ui/message_center/views/padded_button.h" |
@@ -31,6 +32,31 @@ const int kCloseIconRightPadding = 5; |
const int kShadowOffset = 1; |
const int kShadowBlur = 4; |
+const gfx::ImageSkia CreateImage(int width, int height, SkColor color) { |
+ SkBitmap bitmap; |
+ bitmap.allocN32Pixels(width, height); |
+ bitmap.eraseColor(color); |
+ return gfx::ImageSkia::CreateFrom1xBitmap(bitmap); |
+} |
+ |
+// Take the alpha channel of small_image, mask it with the foreground, |
+// then add the masked foreground on top of the background |
+const gfx::ImageSkia GetMaskedSmallImage(const gfx::ImageSkia& small_image) { |
+ int width = small_image.width(); |
+ int height = small_image.height(); |
+ |
+ // Background color grey |
+ const gfx::ImageSkia background = CreateImage( |
+ width, height, message_center::kSmallImageMaskBackgroundColor); |
+ // Foreground color white |
+ const gfx::ImageSkia foreground = CreateImage( |
+ width, height, message_center::kSmallImageMaskForegroundColor); |
+ const gfx::ImageSkia masked_small_image = |
+ gfx::ImageSkiaOperations::CreateMaskedImage(foreground, small_image); |
+ return gfx::ImageSkiaOperations::CreateSuperimposedImage(background, |
+ masked_small_image); |
+} |
+ |
} // namespace |
namespace message_center { |
@@ -54,8 +80,9 @@ MessageView::MessageView(MessageViewController* controller, |
views::Background::CreateSolidBackground(kNotificationBackgroundColor)); |
AddChildView(background_view_); |
+ const gfx::ImageSkia masked_small_image = GetMaskedSmallImage(small_image); |
views::ImageView* small_image_view = new views::ImageView(); |
- small_image_view->SetImage(small_image); |
+ small_image_view->SetImage(masked_small_image); |
small_image_view->SetImageSize(gfx::Size(kSmallImageSize, kSmallImageSize)); |
// The small image view should be added to view hierarchy by the derived |
// class. This ensures that it is on top of other views. |
@@ -84,7 +111,9 @@ MessageView::~MessageView() { |
} |
void MessageView::UpdateWithNotification(const Notification& notification) { |
- small_image_view_->SetImage(notification.small_image().AsImageSkia()); |
+ const gfx::ImageSkia masked_small_image = |
+ GetMaskedSmallImage(notification.small_image().AsImageSkia()); |
+ small_image_view_->SetImage(masked_small_image); |
display_source_ = notification.display_source(); |
} |