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