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

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

Issue 18662006: Support creating progress bar notification for Windows (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix per feedbacks Created 7 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/notification_view.h ('k') | ui/views/controls/progress_bar.cc » ('j') | 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/notification_view.h" 5 #include "ui/message_center/views/notification_view.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "grit/ui_resources.h" 10 #include "grit/ui_resources.h"
11 #include "ui/base/layout.h" 11 #include "ui/base/layout.h"
12 #include "ui/base/resource/resource_bundle.h" 12 #include "ui/base/resource/resource_bundle.h"
13 #include "ui/base/text/text_elider.h" 13 #include "ui/base/text/text_elider.h"
14 #include "ui/gfx/canvas.h" 14 #include "ui/gfx/canvas.h"
15 #include "ui/gfx/size.h" 15 #include "ui/gfx/size.h"
16 #include "ui/message_center/message_center.h" 16 #include "ui/message_center/message_center.h"
17 #include "ui/message_center/message_center_style.h" 17 #include "ui/message_center/message_center_style.h"
18 #include "ui/message_center/message_center_switches.h" 18 #include "ui/message_center/message_center_switches.h"
19 #include "ui/message_center/message_center_util.h" 19 #include "ui/message_center/message_center_util.h"
20 #include "ui/message_center/notification.h" 20 #include "ui/message_center/notification.h"
21 #include "ui/message_center/notification_types.h" 21 #include "ui/message_center/notification_types.h"
22 #include "ui/message_center/views/bounded_label.h" 22 #include "ui/message_center/views/bounded_label.h"
23 #include "ui/native_theme/native_theme.h" 23 #include "ui/native_theme/native_theme.h"
24 #include "ui/views/controls/button/image_button.h" 24 #include "ui/views/controls/button/image_button.h"
25 #include "ui/views/controls/image_view.h" 25 #include "ui/views/controls/image_view.h"
26 #include "ui/views/controls/label.h" 26 #include "ui/views/controls/label.h"
27 #include "ui/views/controls/progress_bar.h"
27 #include "ui/views/layout/box_layout.h" 28 #include "ui/views/layout/box_layout.h"
28 #include "ui/views/layout/fill_layout.h" 29 #include "ui/views/layout/fill_layout.h"
29 #include "ui/views/widget/widget.h" 30 #include "ui/views/widget/widget.h"
30 31
31 namespace { 32 namespace {
32 33
33 // Dimensions. 34 // Dimensions.
34 const int kIconSize = message_center::kNotificationIconSize; 35 const int kIconSize = message_center::kNotificationIconSize;
35 const int kLegacyIconSize = 40; 36 const int kLegacyIconSize = 40;
36 const int kIconBottomPadding = 16; 37 const int kIconBottomPadding = 16;
37 const int kTextLeftPadding = kIconSize + message_center::kIconToTextPadding; 38 const int kTextLeftPadding = kIconSize + message_center::kIconToTextPadding;
38 const int kTextBottomPadding = 12; 39 const int kTextBottomPadding = 12;
39 const int kTextRightPadding = 23; 40 const int kTextRightPadding = 23;
40 const int kItemTitleToMessagePadding = 3; 41 const int kItemTitleToMessagePadding = 3;
42 const int kProgressBarWidth = message_center::kNotificationWidth -
43 kTextLeftPadding - kTextRightPadding;
44 const int kProgressBarHeight = 8;
45 const int kProgressBarTopPadding = 12;
46 const int kProgressBarBottomPadding = 2;
41 const int kButtonVecticalPadding = 0; 47 const int kButtonVecticalPadding = 0;
42 const int kButtonTitleTopPadding = 0; 48 const int kButtonTitleTopPadding = 0;
43 49
44 // Character limits: Displayed text will be subject to the line limits above, 50 // Character limits: Displayed text will be subject to the line limits above,
45 // but we also remove trailing characters from text to reduce processing cost. 51 // but we also remove trailing characters from text to reduce processing cost.
46 // Character limit = pixels per line * line limit / min. pixels per character. 52 // Character limit = pixels per line * line limit / min. pixels per character.
47 const size_t kTitleCharacterLimit = 53 const size_t kTitleCharacterLimit =
48 message_center::kNotificationWidth * message_center::kTitleLineLimit / 4; 54 message_center::kNotificationWidth * message_center::kTitleLineLimit / 4;
49 const size_t kMessageCharacterLimit = 55 const size_t kMessageCharacterLimit =
50 message_center::kNotificationWidth * 56 message_center::kNotificationWidth *
(...skipping 17 matching lines...) Expand all
68 } 74 }
69 75
70 // static 76 // static
71 views::Border* MakeTextBorder(int padding, int top, int bottom) { 77 views::Border* MakeTextBorder(int padding, int top, int bottom) {
72 // Split the padding between the top and the bottom, then add the extra space. 78 // Split the padding between the top and the bottom, then add the extra space.
73 return MakeEmptyBorder(padding / 2 + top, kTextLeftPadding, 79 return MakeEmptyBorder(padding / 2 + top, kTextLeftPadding,
74 (padding + 1) / 2 + bottom, kTextRightPadding); 80 (padding + 1) / 2 + bottom, kTextRightPadding);
75 } 81 }
76 82
77 // static 83 // static
84 views::Border* MakeProgressBarBorder(int top, int bottom) {
85 return MakeEmptyBorder(top, kTextLeftPadding, bottom, kTextRightPadding);
86 }
87
88 // static
78 views::Border* MakeSeparatorBorder(int top, int left, SkColor color) { 89 views::Border* MakeSeparatorBorder(int top, int left, SkColor color) {
79 return views::Border::CreateSolidSidedBorder(top, left, 0, 0, color); 90 return views::Border::CreateSolidSidedBorder(top, left, 0, 0, color);
80 } 91 }
81 92
82 // static 93 // static
83 // Return true if and only if the image is null or has alpha. 94 // Return true if and only if the image is null or has alpha.
84 bool HasAlpha(gfx::ImageSkia& image, views::Widget* widget) { 95 bool HasAlpha(gfx::ImageSkia& image, views::Widget* widget) {
85 // Determine which bitmap to use. 96 // Determine which bitmap to use.
86 ui::ScaleFactor factor = ui::SCALE_FACTOR_100P; 97 ui::ScaleFactor factor = ui::SCALE_FACTOR_100P;
87 if (widget) { 98 if (widget) {
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 true, paint); 227 true, paint);
217 } 228 }
218 } 229 }
219 } 230 }
220 231
221 gfx::Size ProportionalImageView::GetImageSizeForWidth(int width) { 232 gfx::Size ProportionalImageView::GetImageSizeForWidth(int width) {
222 gfx::Size size = visible() ? image_.size() : gfx::Size(); 233 gfx::Size size = visible() ? image_.size() : gfx::Size();
223 return message_center::GetImageSizeForWidth(width, size); 234 return message_center::GetImageSizeForWidth(width, size);
224 } 235 }
225 236
237 // NotificationProgressBar /////////////////////////////////////////////////////
238
239 class NotificationProgressBar : public views::ProgressBar {
240 public:
241 NotificationProgressBar();
242 virtual ~NotificationProgressBar();
243
244 private:
245 // Overriden from View
246 virtual gfx::Size GetPreferredSize() OVERRIDE;
247
248 DISALLOW_COPY_AND_ASSIGN(NotificationProgressBar);
249 };
250
251 NotificationProgressBar::NotificationProgressBar() {
252 }
253
254 NotificationProgressBar::~NotificationProgressBar() {
255 }
256
257 gfx::Size NotificationProgressBar::GetPreferredSize() {
258 gfx::Size pref_size(kProgressBarWidth, kProgressBarHeight);
259 gfx::Insets insets = GetInsets();
260 pref_size.Enlarge(insets.width(), insets.height());
261 return pref_size;
262 }
263
226 // NotificationButton ////////////////////////////////////////////////////////// 264 // NotificationButton //////////////////////////////////////////////////////////
227 265
228 // NotificationButtons render the action buttons of notifications. 266 // NotificationButtons render the action buttons of notifications.
229 class NotificationButton : public views::CustomButton { 267 class NotificationButton : public views::CustomButton {
230 public: 268 public:
231 NotificationButton(views::ButtonListener* listener); 269 NotificationButton(views::ButtonListener* listener);
232 virtual ~NotificationButton(); 270 virtual ~NotificationButton();
233 271
234 void SetIcon(const gfx::ImageSkia& icon); 272 void SetIcon(const gfx::ImageSkia& icon);
235 void SetTitle(const string16& title); 273 void SetTitle(const string16& title);
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 MessageView* NotificationView::Create(const Notification& notification, 376 MessageView* NotificationView::Create(const Notification& notification,
339 MessageCenter* message_center, 377 MessageCenter* message_center,
340 MessageCenterTray* tray, 378 MessageCenterTray* tray,
341 bool expanded, 379 bool expanded,
342 bool top_level) { 380 bool top_level) {
343 switch (notification.type()) { 381 switch (notification.type()) {
344 case NOTIFICATION_TYPE_BASE_FORMAT: 382 case NOTIFICATION_TYPE_BASE_FORMAT:
345 case NOTIFICATION_TYPE_IMAGE: 383 case NOTIFICATION_TYPE_IMAGE:
346 case NOTIFICATION_TYPE_MULTIPLE: 384 case NOTIFICATION_TYPE_MULTIPLE:
347 case NOTIFICATION_TYPE_SIMPLE: 385 case NOTIFICATION_TYPE_SIMPLE:
386 case NOTIFICATION_TYPE_PROGRESS:
348 break; 387 break;
349 default: 388 default:
350 // If the caller asks for an unrecognized kind of view (entirely possible 389 // If the caller asks for an unrecognized kind of view (entirely possible
351 // if an application is running on an older version of this code that 390 // if an application is running on an older version of this code that
352 // doesn't have the requested kind of notification template), we'll fall 391 // doesn't have the requested kind of notification template), we'll fall
353 // back to a notification instance that will provide at least basic 392 // back to a notification instance that will provide at least basic
354 // functionality. 393 // functionality.
355 LOG(WARNING) << "Unable to fulfill request for unrecognized " 394 LOG(WARNING) << "Unable to fulfill request for unrecognized "
356 << "notification type " << notification.type() << ". " 395 << "notification type " << notification.type() << ". "
357 << "Falling back to simple notification type."; 396 << "Falling back to simple notification type.";
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 ui::TruncateString(notification.message(), kMessageCharacterLimit)); 454 ui::TruncateString(notification.message(), kMessageCharacterLimit));
416 message_view_->SetLineHeight(kMessageLineHeight); 455 message_view_->SetLineHeight(kMessageLineHeight);
417 message_view_->SetVisible(!is_expanded() || !notification.items().size()); 456 message_view_->SetVisible(!is_expanded() || !notification.items().size());
418 message_view_->SetColors(message_center::kDimTextColor, 457 message_view_->SetColors(message_center::kDimTextColor,
419 kDimTextBackgroundColor); 458 kDimTextBackgroundColor);
420 message_view_->set_border(MakeTextBorder(padding, 4, 0)); 459 message_view_->set_border(MakeTextBorder(padding, 4, 0));
421 top_view_->AddChildView(message_view_); 460 top_view_->AddChildView(message_view_);
422 accessible_lines.push_back(notification.message()); 461 accessible_lines.push_back(notification.message());
423 } 462 }
424 463
464 // Create the progress bar view.
465 progress_bar_view_ = NULL;
466 if (notification.type() == NOTIFICATION_TYPE_PROGRESS) {
467 progress_bar_view_ = new NotificationProgressBar();
468 progress_bar_view_->set_border(MakeProgressBarBorder(
469 kProgressBarTopPadding, kProgressBarBottomPadding));
470 progress_bar_view_->SetValue(notification.progress() / 100.0);
471 top_view_->AddChildView(progress_bar_view_);
472 }
473
425 // Create the list item views (up to a maximum). 474 // Create the list item views (up to a maximum).
426 int padding = kMessageLineHeight - views::Label().font().GetHeight(); 475 int padding = kMessageLineHeight - views::Label().font().GetHeight();
427 std::vector<NotificationItem> items = notification.items(); 476 std::vector<NotificationItem> items = notification.items();
428 for (size_t i = 0; i < items.size() && i < kNotificationMaximumItems; ++i) { 477 for (size_t i = 0; i < items.size() && i < kNotificationMaximumItems; ++i) {
429 ItemView* item_view = new ItemView(items[i]); 478 ItemView* item_view = new ItemView(items[i]);
430 item_view->SetVisible(is_expanded()); 479 item_view->SetVisible(is_expanded());
431 item_view->set_border(MakeTextBorder(padding, i ? 0 : 4, 0)); 480 item_view->set_border(MakeTextBorder(padding, i ? 0 : 4, 0));
432 item_views_.push_back(item_view); 481 item_views_.push_back(item_view);
433 top_view_->AddChildView(item_view); 482 top_view_->AddChildView(item_view);
434 accessible_lines.push_back( 483 accessible_lines.push_back(
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 return message_view_ ? 724 return message_view_ ?
676 message_view_->GetLinesForWidthAndLimit(width, limit) : 0; 725 message_view_->GetLinesForWidthAndLimit(width, limit) : 0;
677 } 726 }
678 727
679 int NotificationView::GetMessageHeight(int width, int limit) { 728 int NotificationView::GetMessageHeight(int width, int limit) {
680 return message_view_ ? 729 return message_view_ ?
681 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0; 730 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0;
682 } 731 }
683 732
684 } // namespace message_center 733 } // namespace message_center
OLDNEW
« no previous file with comments | « ui/message_center/views/notification_view.h ('k') | ui/views/controls/progress_bar.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698