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

Side by Side Diff: ui/message_center/views/message_view.cc

Issue 308053004: Add appIconMask to notification API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed comments Created 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/message_center/views/message_view.h" 5 #include "ui/message_center/views/message_view.h"
6 6
7 #include "grit/ui_resources.h" 7 #include "grit/ui_resources.h"
8 #include "grit/ui_strings.h" 8 #include "grit/ui_strings.h"
9 #include "ui/accessibility/ax_view_state.h" 9 #include "ui/accessibility/ax_view_state.h"
10 #include "ui/base/l10n/l10n_util.h" 10 #include "ui/base/l10n/l10n_util.h"
11 #include "ui/base/models/simple_menu_model.h" 11 #include "ui/base/models/simple_menu_model.h"
12 #include "ui/base/resource/resource_bundle.h" 12 #include "ui/base/resource/resource_bundle.h"
13 #include "ui/compositor/scoped_layer_animation_settings.h" 13 #include "ui/compositor/scoped_layer_animation_settings.h"
14 #include "ui/gfx/canvas.h" 14 #include "ui/gfx/canvas.h"
15 #include "ui/gfx/image/image_skia_operations.h"
15 #include "ui/message_center/message_center.h" 16 #include "ui/message_center/message_center.h"
16 #include "ui/message_center/message_center_style.h" 17 #include "ui/message_center/message_center_style.h"
17 #include "ui/message_center/views/padded_button.h" 18 #include "ui/message_center/views/padded_button.h"
18 #include "ui/views/background.h" 19 #include "ui/views/background.h"
19 #include "ui/views/controls/button/image_button.h" 20 #include "ui/views/controls/button/image_button.h"
20 #include "ui/views/controls/image_view.h" 21 #include "ui/views/controls/image_view.h"
21 #include "ui/views/controls/scroll_view.h" 22 #include "ui/views/controls/scroll_view.h"
22 #include "ui/views/focus/focus_manager.h" 23 #include "ui/views/focus/focus_manager.h"
23 #include "ui/views/painter.h" 24 #include "ui/views/painter.h"
24 #include "ui/views/shadow_border.h" 25 #include "ui/views/shadow_border.h"
25 26
26 namespace { 27 namespace {
27 28
28 const int kCloseIconTopPadding = 5; 29 const int kCloseIconTopPadding = 5;
29 const int kCloseIconRightPadding = 5; 30 const int kCloseIconRightPadding = 5;
30 31
31 const int kShadowOffset = 1; 32 const int kShadowOffset = 1;
32 const int kShadowBlur = 4; 33 const int kShadowBlur = 4;
33 34
35 const gfx::ImageSkia CreateImage(int width, int height, SkColor color) {
36 SkBitmap bitmap;
37 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height);
38 bitmap.allocPixels();
39 bitmap.eraseColor(color);
40 return gfx::ImageSkia::CreateFrom1xBitmap(bitmap);
41 }
42
43 // Take the alpha channel of small_image, mask it with the foreground,
44 // then add the masked foreground on top of the background
45 const gfx::ImageSkia GetMaskedSmallImage(const gfx::ImageSkia& small_image) {
46 int width = small_image.width();
47 int height = small_image.height();
48
49 // Background color grey
50 const gfx::ImageSkia background = CreateImage(
51 width, height, message_center::kSmallImageMaskBackgroundColor);
52 // Foreground color white
53 const gfx::ImageSkia foreground = CreateImage(
54 width, height, message_center::kSmallImageMaskForegroundColor);
55 const gfx::ImageSkia masked_small_image =
56 gfx::ImageSkiaOperations::CreateMaskedImage(foreground, small_image);
57 return gfx::ImageSkiaOperations::CreateSuperimposedImage(background,
58 masked_small_image);
59 }
60
34 } // namespace 61 } // namespace
35 62
36 namespace message_center { 63 namespace message_center {
37 64
38 MessageView::MessageView(MessageViewController* controller, 65 MessageView::MessageView(MessageViewController* controller,
39 const std::string& notification_id, 66 const std::string& notification_id,
40 const NotifierId& notifier_id, 67 const NotifierId& notifier_id,
41 const gfx::ImageSkia& small_image, 68 const gfx::ImageSkia& small_image,
42 const base::string16& display_source) 69 const base::string16& display_source)
43 : controller_(controller), 70 : controller_(controller),
44 notification_id_(notification_id), 71 notification_id_(notification_id),
45 notifier_id_(notifier_id), 72 notifier_id_(notifier_id),
46 background_view_(NULL), 73 background_view_(NULL),
47 scroller_(NULL), 74 scroller_(NULL),
48 display_source_(display_source) { 75 display_source_(display_source) {
49 SetFocusable(true); 76 SetFocusable(true);
50 77
51 // Create the opaque background that's above the view's shadow. 78 // Create the opaque background that's above the view's shadow.
52 background_view_ = new views::View(); 79 background_view_ = new views::View();
53 background_view_->set_background( 80 background_view_->set_background(
54 views::Background::CreateSolidBackground(kNotificationBackgroundColor)); 81 views::Background::CreateSolidBackground(kNotificationBackgroundColor));
55 AddChildView(background_view_); 82 AddChildView(background_view_);
56 83
84 const gfx::ImageSkia masked_small_image = GetMaskedSmallImage(small_image);
57 views::ImageView* small_image_view = new views::ImageView(); 85 views::ImageView* small_image_view = new views::ImageView();
58 small_image_view->SetImage(small_image); 86 small_image_view->SetImage(masked_small_image);
59 small_image_view->SetImageSize(gfx::Size(kSmallImageSize, kSmallImageSize)); 87 small_image_view->SetImageSize(gfx::Size(kSmallImageSize, kSmallImageSize));
60 // The small image view should be added to view hierarchy by the derived 88 // The small image view should be added to view hierarchy by the derived
61 // class. This ensures that it is on top of other views. 89 // class. This ensures that it is on top of other views.
62 small_image_view->set_owned_by_client(); 90 small_image_view->set_owned_by_client();
63 small_image_view_.reset(small_image_view); 91 small_image_view_.reset(small_image_view);
64 92
65 PaddedButton *close = new PaddedButton(this); 93 PaddedButton *close = new PaddedButton(this);
66 close->SetPadding(-kCloseIconRightPadding, kCloseIconTopPadding); 94 close->SetPadding(-kCloseIconRightPadding, kCloseIconTopPadding);
67 close->SetNormalImage(IDR_NOTIFICATION_CLOSE); 95 close->SetNormalImage(IDR_NOTIFICATION_CLOSE);
68 close->SetHoveredImage(IDR_NOTIFICATION_CLOSE_HOVER); 96 close->SetHoveredImage(IDR_NOTIFICATION_CLOSE_HOVER);
69 close->SetPressedImage(IDR_NOTIFICATION_CLOSE_PRESSED); 97 close->SetPressedImage(IDR_NOTIFICATION_CLOSE_PRESSED);
70 close->set_animate_on_state_change(false); 98 close->set_animate_on_state_change(false);
71 close->SetAccessibleName(l10n_util::GetStringUTF16( 99 close->SetAccessibleName(l10n_util::GetStringUTF16(
72 IDS_MESSAGE_CENTER_CLOSE_NOTIFICATION_BUTTON_ACCESSIBLE_NAME)); 100 IDS_MESSAGE_CENTER_CLOSE_NOTIFICATION_BUTTON_ACCESSIBLE_NAME));
73 // The close button should be added to view hierarchy by the derived class. 101 // The close button should be added to view hierarchy by the derived class.
74 // This ensures that it is on top of other views. 102 // This ensures that it is on top of other views.
75 close->set_owned_by_client(); 103 close->set_owned_by_client();
76 close_button_.reset(close); 104 close_button_.reset(close);
77 105
78 focus_painter_ = views::Painter::CreateSolidFocusPainter( 106 focus_painter_ = views::Painter::CreateSolidFocusPainter(
79 kFocusBorderColor, 107 kFocusBorderColor,
80 gfx::Insets(0, 1, 3, 2)).Pass(); 108 gfx::Insets(0, 1, 3, 2)).Pass();
81 } 109 }
82 110
83 MessageView::~MessageView() { 111 MessageView::~MessageView() {
84 } 112 }
85 113
86 void MessageView::UpdateWithNotification(const Notification& notification) { 114 void MessageView::UpdateWithNotification(const Notification& notification) {
87 small_image_view_->SetImage(notification.small_image().AsImageSkia()); 115 const gfx::ImageSkia masked_small_image =
116 GetMaskedSmallImage(notification.small_image().AsImageSkia());
117 small_image_view_->SetImage(masked_small_image);
88 display_source_ = notification.display_source(); 118 display_source_ = notification.display_source();
89 } 119 }
90 120
91 // static 121 // static
92 gfx::Insets MessageView::GetShadowInsets() { 122 gfx::Insets MessageView::GetShadowInsets() {
93 return gfx::Insets(kShadowBlur / 2 - kShadowOffset, 123 return gfx::Insets(kShadowBlur / 2 - kShadowOffset,
94 kShadowBlur / 2, 124 kShadowBlur / 2,
95 kShadowBlur / 2 + kShadowOffset, 125 kShadowBlur / 2 + kShadowOffset,
96 kShadowBlur / 2); 126 kShadowBlur / 2);
97 } 127 }
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 if (sender == close_button()) { 249 if (sender == close_button()) {
220 controller_->RemoveNotification(notification_id_, true); // By user. 250 controller_->RemoveNotification(notification_id_, true); // By user.
221 } 251 }
222 } 252 }
223 253
224 void MessageView::OnSlideOut() { 254 void MessageView::OnSlideOut() {
225 controller_->RemoveNotification(notification_id_, true); // By user. 255 controller_->RemoveNotification(notification_id_, true); // By user.
226 } 256 }
227 257
228 } // namespace message_center 258 } // namespace message_center
OLDNEW
« chrome/common/extensions/api/notifications.idl ('K') | « ui/message_center/views/message_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698