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

Side by Side Diff: chrome/browser/ui/views/message_center/web_notification_tray_win.cc

Issue 14192025: Update message center systray icon. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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 | « chrome/app/theme/theme_resources.grd ('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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "chrome/browser/ui/views/message_center/web_notification_tray_win.h" 5 #include "chrome/browser/ui/views/message_center/web_notification_tray_win.h"
6 6
7 #include "base/i18n/number_formatting.h" 7 #include "base/i18n/number_formatting.h"
8 #include "base/string16.h" 8 #include "base/string16.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/status_icons/status_icon.h" 11 #include "chrome/browser/status_icons/status_icon.h"
12 #include "chrome/browser/status_icons/status_tray.h" 12 #include "chrome/browser/status_icons/status_tray.h"
13 #include "chrome/browser/ui/views/message_center/notification_bubble_wrapper_win .h" 13 #include "chrome/browser/ui/views/message_center/notification_bubble_wrapper_win .h"
14 #include "chrome/browser/ui/views/status_icons/status_icon_win.h" 14 #include "chrome/browser/ui/views/status_icons/status_icon_win.h"
15 #include "grit/chromium_strings.h" 15 #include "grit/chromium_strings.h"
16 #include "grit/theme_resources.h" 16 #include "grit/theme_resources.h"
17 #include "grit/ui_strings.h" 17 #include "grit/ui_strings.h"
18 #include "ui/base/l10n/l10n_util.h" 18 #include "ui/base/l10n/l10n_util.h"
19 #include "ui/base/models/simple_menu_model.h" 19 #include "ui/base/models/simple_menu_model.h"
20 #include "ui/base/resource/resource_bundle.h" 20 #include "ui/base/resource/resource_bundle.h"
21 #include "ui/base/win/hwnd_util.h" 21 #include "ui/base/win/hwnd_util.h"
22 #include "ui/gfx/canvas.h"
22 #include "ui/gfx/image/image_skia_operations.h" 23 #include "ui/gfx/image/image_skia_operations.h"
24 #include "ui/gfx/rect.h"
23 #include "ui/gfx/screen.h" 25 #include "ui/gfx/screen.h"
26 #include "ui/gfx/size.h"
24 #include "ui/message_center/message_center_tray.h" 27 #include "ui/message_center/message_center_tray.h"
25 #include "ui/message_center/message_center_tray_delegate.h" 28 #include "ui/message_center/message_center_tray_delegate.h"
26 #include "ui/message_center/views/message_bubble_base.h" 29 #include "ui/message_center/views/message_bubble_base.h"
27 #include "ui/message_center/views/message_center_bubble.h" 30 #include "ui/message_center/views/message_center_bubble.h"
28 #include "ui/message_center/views/message_popup_collection.h" 31 #include "ui/message_center/views/message_popup_collection.h"
29 #include "ui/views/widget/widget.h" 32 #include "ui/views/widget/widget.h"
30 33
31 namespace { 34 namespace {
32 35
33 // Tray constants 36 // Tray constants
34 const int kScreenEdgePadding = 2; 37 const int kScreenEdgePadding = 2;
35 38
39 const int kSystemTrayWidth = 16;
40 const int kSystemTrayHeight = 16;
41 const int kNumberOfSystemTraySprites = 10;
42
36 gfx::Rect GetCornerAnchorRect() { 43 gfx::Rect GetCornerAnchorRect() {
37 // TODO(dewittj): Use the preference to determine which corner to anchor from. 44 // TODO(dewittj): Use the preference to determine which corner to anchor from.
38 gfx::Screen* screen = gfx::Screen::GetNativeScreen(); 45 gfx::Screen* screen = gfx::Screen::GetNativeScreen();
39 gfx::Rect rect = screen->GetPrimaryDisplay().work_area(); 46 gfx::Rect rect = screen->GetPrimaryDisplay().work_area();
40 rect.Inset(kScreenEdgePadding, kScreenEdgePadding); 47 rect.Inset(kScreenEdgePadding, kScreenEdgePadding);
41 return gfx::Rect(rect.bottom_right(), gfx::Size()); 48 return gfx::Rect(rect.bottom_right(), gfx::Size());
42 } 49 }
43 50
44 gfx::Point GetClosestCorner(gfx::Rect rect, gfx::Point query) { 51 gfx::Point GetClosestCorner(gfx::Rect rect, gfx::Point query) {
45 gfx::Point center_point = rect.CenterPoint(); 52 gfx::Point center_point = rect.CenterPoint();
(...skipping 19 matching lines...) Expand all
65 // TODO(dewittj): GetNativeScreen could be wrong for Aura. 72 // TODO(dewittj): GetNativeScreen could be wrong for Aura.
66 gfx::Screen* screen = gfx::Screen::GetNativeScreen(); 73 gfx::Screen* screen = gfx::Screen::GetNativeScreen();
67 gfx::Rect work_area = screen->GetPrimaryDisplay().work_area(); 74 gfx::Rect work_area = screen->GetPrimaryDisplay().work_area();
68 work_area.Inset(kScreenEdgePadding, kScreenEdgePadding); 75 work_area.Inset(kScreenEdgePadding, kScreenEdgePadding);
69 gfx::Point corner = GetClosestCorner(work_area, cursor); 76 gfx::Point corner = GetClosestCorner(work_area, cursor);
70 77
71 gfx::Rect mouse_anchor_rect(gfx::BoundingRect(cursor, corner)); 78 gfx::Rect mouse_anchor_rect(gfx::BoundingRect(cursor, corner));
72 return mouse_anchor_rect; 79 return mouse_anchor_rect;
73 } 80 }
74 81
75 gfx::ImageSkia GetIcon(bool has_unread) { 82 gfx::ImageSkia GetIcon(int unread_count) {
83 bool has_unread = unread_count > 0;
76 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 84 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
77 gfx::ImageSkia* icon = rb.GetImageSkiaNamed( 85 if (!has_unread)
78 has_unread ? IDR_NOTIFICATION_TRAY_LIT : IDR_NOTIFICATION_TRAY_DIM); 86 return *rb.GetImageSkiaNamed(IDR_NOTIFICATION_TRAY_DIM);
Jun Mukai 2013/04/19 19:00:50 Do we use DIM for the default icon? not LIT? Bette
dewittj 2013/04/19 22:10:28 I had the correct icon, but didn't change the name
79 DCHECK(icon); 87
80 return *icon; 88 // TODO(dewittj): Use scale factors other than 100P.
89 scoped_ptr<gfx::Canvas> canvas(new gfx::Canvas(
90 gfx::Size(kSystemTrayWidth, kSystemTrayHeight),
91 ui::SCALE_FACTOR_100P,
92 false));
93
94 // Draw the attention-grabbing background image.
95 canvas->DrawImageInt(*rb.GetImageSkiaNamed(IDR_NOTIFICATION_TRAY_LIT), 0, 0);
96
97 // |numbers| is a sprite map with the image of a number from 1-9 and 9+. They
98 // are arranged horizontally, and have a transparent background.
99 gfx::ImageSkia* numbers = rb.GetImageSkiaNamed(IDR_NOTIFICATION_TRAY_NUMBERS);
100
101 // Assume that the last sprite is the catch-all for higher numbers of
102 // notifications.
103 int effective_unread = std::min(unread_count, kNumberOfSystemTraySprites);
104 int x_offset = (effective_unread - 1) * kSystemTrayWidth;
105
106 canvas->DrawImageInt(*numbers,
107 x_offset, 0, kSystemTrayWidth, kSystemTrayHeight,
108 0, 0, kSystemTrayWidth, kSystemTrayHeight,
109 false);
110
111 return gfx::ImageSkia(canvas->ExtractImageRep());
81 } 112 }
82 113
83 } // namespace 114 } // namespace
84 115
85 namespace message_center { 116 namespace message_center {
86 117
87 MessageCenterTrayDelegate* CreateMessageCenterTray() { 118 MessageCenterTrayDelegate* CreateMessageCenterTray() {
88 return new WebNotificationTrayWin(); 119 return new WebNotificationTrayWin();
89 } 120 }
90 121
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 } 237 }
207 return views::TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM; 238 return views::TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM;
208 } 239 }
209 240
210 gfx::NativeView WebNotificationTrayWin::GetBubbleWindowContainer() { 241 gfx::NativeView WebNotificationTrayWin::GetBubbleWindowContainer() {
211 return NULL; 242 return NULL;
212 } 243 }
213 244
214 void WebNotificationTrayWin::UpdateStatusIcon() { 245 void WebNotificationTrayWin::UpdateStatusIcon() {
215 int unread_notifications = message_center()->UnreadNotificationCount(); 246 int unread_notifications = message_center()->UnreadNotificationCount();
216 status_icon_->SetImage(GetIcon(unread_notifications > 0)); 247 status_icon_->SetImage(GetIcon(unread_notifications));
217 248
218 string16 product_name(l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)); 249 string16 product_name(l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME));
219 if (unread_notifications > 0) { 250 if (unread_notifications > 0) {
220 string16 str_unread_count = base::FormatNumber(unread_notifications); 251 string16 str_unread_count = base::FormatNumber(unread_notifications);
221 status_icon_->SetToolTip(l10n_util::GetStringFUTF16( 252 status_icon_->SetToolTip(l10n_util::GetStringFUTF16(
222 IDS_MESSAGE_CENTER_TOOLTIP_UNREAD, product_name, str_unread_count)); 253 IDS_MESSAGE_CENTER_TOOLTIP_UNREAD, product_name, str_unread_count));
223 } else { 254 } else {
224 status_icon_->SetToolTip(l10n_util::GetStringFUTF16( 255 status_icon_->SetToolTip(l10n_util::GetStringFUTF16(
225 IDS_MESSAGE_CENTER_TOOLTIP, product_name)); 256 IDS_MESSAGE_CENTER_TOOLTIP, product_name));
226 } 257 }
(...skipping 21 matching lines...) Expand all
248 279
249 message_center::MessageCenterBubble* 280 message_center::MessageCenterBubble*
250 WebNotificationTrayWin::GetMessageCenterBubbleForTest() { 281 WebNotificationTrayWin::GetMessageCenterBubbleForTest() {
251 if (!message_center_bubble_.get()) 282 if (!message_center_bubble_.get())
252 return NULL; 283 return NULL;
253 return static_cast<message_center::MessageCenterBubble*>( 284 return static_cast<message_center::MessageCenterBubble*>(
254 message_center_bubble_->bubble()); 285 message_center_bubble_->bubble());
255 } 286 }
256 287
257 } // namespace message_center 288 } // namespace message_center
OLDNEW
« no previous file with comments | « chrome/app/theme/theme_resources.grd ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698