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

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: changed name smallIconto appIconMask 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
« no previous file with comments | « ui/message_center/views/message_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
34 } // namespace 35 } // namespace
35 36
37 namespace {
dewittj 2014/06/27 02:43:56 Just combine the two unnamed namespaces
liyanhou 2014/06/27 03:18:40 Done.
38 const gfx::ImageSkia CreateImage(int width, int height, SkColor color) {
39 SkBitmap bitmap;
40 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height);
41 bitmap.allocPixels();
42 bitmap.eraseColor(color);
43 return gfx::ImageSkia::CreateFrom1xBitmap(bitmap);
44 }
45
46 // Take the alpha channel of small_image, mask it with the foreground,
47 // then add the masked foreground on top of the background
48 const gfx::ImageSkia GetMaskedSmallImage(const gfx::ImageSkia& small_image) {
49 int width = small_image.width();
50 int height = small_image.height();
51
52 // Background color grey
53 const gfx::ImageSkia background = CreateImage(
54 width, height, message_center::kSmallImageMaskBackgroundColor);
55 // Foreground color white
56 const gfx::ImageSkia foreground = CreateImage(
57 width, height, message_center::kSmallImageMaskForegroundColor);
58 const gfx::ImageSkia masked_small_image =
59 gfx::ImageSkiaOperations::CreateMaskedImage(foreground, small_image);
60 return gfx::ImageSkiaOperations::CreateSuperimposedImage(background,
61 masked_small_image);
62 }
63
64 } // namespace
65
36 namespace message_center { 66 namespace message_center {
37 67
38 MessageView::MessageView(MessageViewController* controller, 68 MessageView::MessageView(MessageViewController* controller,
39 const std::string& notification_id, 69 const std::string& notification_id,
40 const NotifierId& notifier_id, 70 const NotifierId& notifier_id,
41 const gfx::ImageSkia& small_image, 71 const gfx::ImageSkia& small_image,
42 const base::string16& display_source) 72 const base::string16& display_source)
43 : controller_(controller), 73 : controller_(controller),
44 notification_id_(notification_id), 74 notification_id_(notification_id),
45 notifier_id_(notifier_id), 75 notifier_id_(notifier_id),
46 background_view_(NULL), 76 background_view_(NULL),
47 scroller_(NULL), 77 scroller_(NULL),
48 display_source_(display_source) { 78 display_source_(display_source) {
49 SetFocusable(true); 79 SetFocusable(true);
50 80
51 // Create the opaque background that's above the view's shadow. 81 // Create the opaque background that's above the view's shadow.
52 background_view_ = new views::View(); 82 background_view_ = new views::View();
53 background_view_->set_background( 83 background_view_->set_background(
54 views::Background::CreateSolidBackground(kNotificationBackgroundColor)); 84 views::Background::CreateSolidBackground(kNotificationBackgroundColor));
55 AddChildView(background_view_); 85 AddChildView(background_view_);
56 86
87 const gfx::ImageSkia masked_small_image = GetMaskedSmallImage(small_image);
57 views::ImageView* small_image_view = new views::ImageView(); 88 views::ImageView* small_image_view = new views::ImageView();
58 small_image_view->SetImage(small_image); 89 small_image_view->SetImage(masked_small_image);
59 small_image_view->SetImageSize(gfx::Size(kSmallImageSize, kSmallImageSize)); 90 small_image_view->SetImageSize(gfx::Size(kSmallImageSize, kSmallImageSize));
60 // The small image view should be added to view hierarchy by the derived 91 // 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. 92 // class. This ensures that it is on top of other views.
62 small_image_view->set_owned_by_client(); 93 small_image_view->set_owned_by_client();
63 small_image_view_.reset(small_image_view); 94 small_image_view_.reset(small_image_view);
64 95
65 PaddedButton *close = new PaddedButton(this); 96 PaddedButton *close = new PaddedButton(this);
66 close->SetPadding(-kCloseIconRightPadding, kCloseIconTopPadding); 97 close->SetPadding(-kCloseIconRightPadding, kCloseIconTopPadding);
67 close->SetNormalImage(IDR_NOTIFICATION_CLOSE); 98 close->SetNormalImage(IDR_NOTIFICATION_CLOSE);
68 close->SetHoveredImage(IDR_NOTIFICATION_CLOSE_HOVER); 99 close->SetHoveredImage(IDR_NOTIFICATION_CLOSE_HOVER);
69 close->SetPressedImage(IDR_NOTIFICATION_CLOSE_PRESSED); 100 close->SetPressedImage(IDR_NOTIFICATION_CLOSE_PRESSED);
70 close->set_animate_on_state_change(false); 101 close->set_animate_on_state_change(false);
71 close->SetAccessibleName(l10n_util::GetStringUTF16( 102 close->SetAccessibleName(l10n_util::GetStringUTF16(
72 IDS_MESSAGE_CENTER_CLOSE_NOTIFICATION_BUTTON_ACCESSIBLE_NAME)); 103 IDS_MESSAGE_CENTER_CLOSE_NOTIFICATION_BUTTON_ACCESSIBLE_NAME));
73 // The close button should be added to view hierarchy by the derived class. 104 // The close button should be added to view hierarchy by the derived class.
74 // This ensures that it is on top of other views. 105 // This ensures that it is on top of other views.
75 close->set_owned_by_client(); 106 close->set_owned_by_client();
76 close_button_.reset(close); 107 close_button_.reset(close);
77 108
78 focus_painter_ = views::Painter::CreateSolidFocusPainter( 109 focus_painter_ = views::Painter::CreateSolidFocusPainter(
79 kFocusBorderColor, 110 kFocusBorderColor,
80 gfx::Insets(0, 1, 3, 2)).Pass(); 111 gfx::Insets(0, 1, 3, 2)).Pass();
81 } 112 }
82 113
83 MessageView::~MessageView() { 114 MessageView::~MessageView() {
84 } 115 }
85 116
86 void MessageView::UpdateWithNotification(const Notification& notification) { 117 void MessageView::UpdateWithNotification(const Notification& notification) {
87 small_image_view_->SetImage(notification.small_image().AsImageSkia()); 118 const gfx::ImageSkia masked_small_image =
119 GetMaskedSmallImage(notification.small_image().AsImageSkia());
120 small_image_view_->SetImage(masked_small_image);
88 display_source_ = notification.display_source(); 121 display_source_ = notification.display_source();
89 } 122 }
90 123
91 // static 124 // static
92 gfx::Insets MessageView::GetShadowInsets() { 125 gfx::Insets MessageView::GetShadowInsets() {
93 return gfx::Insets(kShadowBlur / 2 - kShadowOffset, 126 return gfx::Insets(kShadowBlur / 2 - kShadowOffset,
94 kShadowBlur / 2, 127 kShadowBlur / 2,
95 kShadowBlur / 2 + kShadowOffset, 128 kShadowBlur / 2 + kShadowOffset,
96 kShadowBlur / 2); 129 kShadowBlur / 2);
97 } 130 }
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 if (sender == close_button()) { 252 if (sender == close_button()) {
220 controller_->RemoveNotification(notification_id_, true); // By user. 253 controller_->RemoveNotification(notification_id_, true); // By user.
221 } 254 }
222 } 255 }
223 256
224 void MessageView::OnSlideOut() { 257 void MessageView::OnSlideOut() {
225 controller_->RemoveNotification(notification_id_, true); // By user. 258 controller_->RemoveNotification(notification_id_, true); // By user.
226 } 259 }
227 260
228 } // namespace message_center 261 } // namespace message_center
OLDNEW
« no previous file with comments | « 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