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..980c375d01f67a6d8484664c620921b5a9b393a8 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" |
@@ -33,6 +34,35 @@ const int kShadowBlur = 4; |
} // namespace |
+namespace { |
dewittj
2014/06/27 02:43:56
Just combine the two unnamed namespaces
liyanhou
2014/06/27 03:18:40
Done.
|
+const gfx::ImageSkia CreateImage(int width, int height, SkColor color) { |
+ SkBitmap bitmap; |
+ bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); |
+ bitmap.allocPixels(); |
+ 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 { |
MessageView::MessageView(MessageViewController* controller, |
@@ -54,8 +84,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 +115,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(); |
} |