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

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

Issue 2329633003: Implement progress bar spec (determinate and indeterminate). (Closed)
Patch Set: self review Created 4 years, 3 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
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 11 matching lines...) Expand all
22 #include "ui/gfx/skia_util.h" 22 #include "ui/gfx/skia_util.h"
23 #include "ui/gfx/text_elider.h" 23 #include "ui/gfx/text_elider.h"
24 #include "ui/message_center/message_center.h" 24 #include "ui/message_center/message_center.h"
25 #include "ui/message_center/message_center_style.h" 25 #include "ui/message_center/message_center_style.h"
26 #include "ui/message_center/notification.h" 26 #include "ui/message_center/notification.h"
27 #include "ui/message_center/notification_types.h" 27 #include "ui/message_center/notification_types.h"
28 #include "ui/message_center/views/bounded_label.h" 28 #include "ui/message_center/views/bounded_label.h"
29 #include "ui/message_center/views/constants.h" 29 #include "ui/message_center/views/constants.h"
30 #include "ui/message_center/views/message_center_controller.h" 30 #include "ui/message_center/views/message_center_controller.h"
31 #include "ui/message_center/views/notification_button.h" 31 #include "ui/message_center/views/notification_button.h"
32 #include "ui/message_center/views/notification_progress_bar.h"
33 #include "ui/message_center/views/padded_button.h" 32 #include "ui/message_center/views/padded_button.h"
34 #include "ui/message_center/views/proportional_image_view.h" 33 #include "ui/message_center/views/proportional_image_view.h"
35 #include "ui/native_theme/native_theme.h" 34 #include "ui/native_theme/native_theme.h"
36 #include "ui/resources/grit/ui_resources.h" 35 #include "ui/resources/grit/ui_resources.h"
37 #include "ui/strings/grit/ui_strings.h" 36 #include "ui/strings/grit/ui_strings.h"
38 #include "ui/views/background.h" 37 #include "ui/views/background.h"
39 #include "ui/views/border.h" 38 #include "ui/views/border.h"
40 #include "ui/views/controls/button/image_button.h" 39 #include "ui/views/controls/button/image_button.h"
41 #include "ui/views/controls/image_view.h" 40 #include "ui/views/controls/image_view.h"
42 #include "ui/views/controls/label.h" 41 #include "ui/views/controls/label.h"
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 348
350 // Let the superclass handle everything else. 349 // Let the superclass handle everything else.
351 // Warning: This may cause the NotificationView itself to be deleted, 350 // Warning: This may cause the NotificationView itself to be deleted,
352 // so don't do anything afterwards. 351 // so don't do anything afterwards.
353 MessageView::ButtonPressed(sender, event); 352 MessageView::ButtonPressed(sender, event);
354 } 353 }
355 354
356 void NotificationView::CreateOrUpdateTitleView( 355 void NotificationView::CreateOrUpdateTitleView(
357 const Notification& notification) { 356 const Notification& notification) {
358 if (notification.title().empty()) { 357 if (notification.title().empty()) {
359 if (title_view_) { 358 // Deletion will also remove |title_view_| from its parent.
360 // Deletion will also remove |title_view_| from its parent. 359 delete title_view_;
361 delete title_view_; 360 title_view_ = nullptr;
362 title_view_ = NULL;
363 }
364 return; 361 return;
365 } 362 }
366 363
367 DCHECK(top_view_ != NULL); 364 DCHECK(top_view_);
368 365
369 const gfx::FontList& font_list = 366 const gfx::FontList& font_list =
370 views::Label().font_list().DeriveWithSizeDelta(2); 367 views::Label().font_list().DeriveWithSizeDelta(2);
371 368
372 int title_character_limit = 369 int title_character_limit =
373 kNotificationWidth * kMaxTitleLines / kMinPixelsPerTitleCharacter; 370 kNotificationWidth * kMaxTitleLines / kMinPixelsPerTitleCharacter;
374 371
375 base::string16 title = gfx::TruncateString(notification.title(), 372 base::string16 title = gfx::TruncateString(notification.title(),
376 title_character_limit, 373 title_character_limit,
377 gfx::WORD_BREAK); 374 gfx::WORD_BREAK);
378 if (!title_view_) { 375 if (!title_view_) {
379 int padding = kTitleLineHeight - font_list.GetHeight(); 376 int padding = kTitleLineHeight - font_list.GetHeight();
380 377
381 title_view_ = new BoundedLabel(title, font_list); 378 title_view_ = new BoundedLabel(title, font_list);
382 title_view_->SetLineHeight(kTitleLineHeight); 379 title_view_->SetLineHeight(kTitleLineHeight);
383 title_view_->SetLineLimit(kMaxTitleLines); 380 title_view_->SetLineLimit(kMaxTitleLines);
384 title_view_->SetColors(message_center::kRegularTextColor, 381 title_view_->SetColors(message_center::kRegularTextColor,
385 kRegularTextBackgroundColor); 382 kRegularTextBackgroundColor);
386 title_view_->SetBorder(MakeTextBorder(padding, 3, 0)); 383 title_view_->SetBorder(MakeTextBorder(padding, 3, 0));
387 top_view_->AddChildView(title_view_); 384 top_view_->AddChildView(title_view_);
388 } else { 385 } else {
389 title_view_->SetText(title); 386 title_view_->SetText(title);
390 } 387 }
391 } 388 }
392 389
393 void NotificationView::CreateOrUpdateMessageView( 390 void NotificationView::CreateOrUpdateMessageView(
394 const Notification& notification) { 391 const Notification& notification) {
395 if (notification.message().empty()) { 392 if (notification.message().empty()) {
396 if (message_view_) { 393 // Deletion will also remove |message_view_| from its parent.
397 // Deletion will also remove |message_view_| from its parent. 394 delete message_view_;
398 delete message_view_; 395 message_view_ = nullptr;
399 message_view_ = NULL;
400 }
401 return; 396 return;
402 } 397 }
403 398
404 DCHECK(top_view_ != NULL); 399 DCHECK(top_view_ != NULL);
405 400
406 base::string16 text = gfx::TruncateString(notification.message(), 401 base::string16 text = gfx::TruncateString(notification.message(),
407 kMessageCharacterLimit, 402 kMessageCharacterLimit,
408 gfx::WORD_BREAK); 403 gfx::WORD_BREAK);
409 if (!message_view_) { 404 if (!message_view_) {
410 int padding = kMessageLineHeight - views::Label().font_list().GetHeight(); 405 int padding = kMessageLineHeight - views::Label().font_list().GetHeight();
(...skipping 22 matching lines...) Expand all
433 } 428 }
434 429
435 return gfx::TruncateString(notification.context_message(), 430 return gfx::TruncateString(notification.context_message(),
436 kContextMessageCharacterLimit, gfx::WORD_BREAK); 431 kContextMessageCharacterLimit, gfx::WORD_BREAK);
437 } 432 }
438 433
439 void NotificationView::CreateOrUpdateContextMessageView( 434 void NotificationView::CreateOrUpdateContextMessageView(
440 const Notification& notification) { 435 const Notification& notification) {
441 if (notification.context_message().empty() && 436 if (notification.context_message().empty() &&
442 !notification.UseOriginAsContextMessage()) { 437 !notification.UseOriginAsContextMessage()) {
443 if (context_message_view_) { 438 // Deletion will also remove |context_message_view_| from its parent.
444 // Deletion will also remove |context_message_view_| from its parent. 439 delete context_message_view_;
445 delete context_message_view_; 440 context_message_view_ = nullptr;
446 context_message_view_ = NULL;
447 }
448 return; 441 return;
449 } 442 }
450 443
451 DCHECK(top_view_ != NULL); 444 DCHECK(top_view_ != NULL);
452 445
453 base::string16 message = FormatContextMessage(notification); 446 base::string16 message = FormatContextMessage(notification);
454 447
455 if (!context_message_view_) { 448 if (!context_message_view_) {
456 int padding = kMessageLineHeight - views::Label().font_list().GetHeight(); 449 int padding = kMessageLineHeight - views::Label().font_list().GetHeight();
457 context_message_view_ = new BoundedLabel(message); 450 context_message_view_ = new BoundedLabel(message);
458 context_message_view_->SetLineLimit( 451 context_message_view_->SetLineLimit(
459 message_center::kContextMessageLineLimit); 452 message_center::kContextMessageLineLimit);
460 context_message_view_->SetLineHeight(kMessageLineHeight); 453 context_message_view_->SetLineHeight(kMessageLineHeight);
461 context_message_view_->SetColors(message_center::kDimTextColor, 454 context_message_view_->SetColors(message_center::kDimTextColor,
462 kContextTextBackgroundColor); 455 kContextTextBackgroundColor);
463 context_message_view_->SetBorder(MakeTextBorder(padding, 4, 0)); 456 context_message_view_->SetBorder(MakeTextBorder(padding, 4, 0));
464 top_view_->AddChildView(context_message_view_); 457 top_view_->AddChildView(context_message_view_);
465 } else { 458 } else {
466 context_message_view_->SetText(message); 459 context_message_view_->SetText(message);
467 } 460 }
468 } 461 }
469 462
470 void NotificationView::CreateOrUpdateSettingsButtonView( 463 void NotificationView::CreateOrUpdateSettingsButtonView(
471 const Notification& notification) { 464 const Notification& notification) {
472 if (settings_button_view_) { 465 delete settings_button_view_;
473 delete settings_button_view_; 466 settings_button_view_ = nullptr;
474 settings_button_view_ = NULL;
475 }
476 467
477 if (!settings_button_view_ && notification.delegate() && 468 if (!settings_button_view_ && notification.delegate() &&
478 notification.delegate()->ShouldDisplaySettingsButton()) { 469 notification.delegate()->ShouldDisplaySettingsButton()) {
479 PaddedButton* settings = new PaddedButton(this); 470 PaddedButton* settings = new PaddedButton(this);
480 settings->SetPadding(-kNotificationSettingsPadding, 471 settings->SetPadding(-kNotificationSettingsPadding,
481 kNotificationSettingsPadding); 472 kNotificationSettingsPadding);
482 settings->SetNormalImage(IDR_NOTIFICATION_SETTINGS_BUTTON_ICON); 473 settings->SetNormalImage(IDR_NOTIFICATION_SETTINGS_BUTTON_ICON);
483 settings->SetHoveredImage(IDR_NOTIFICATION_SETTINGS_BUTTON_ICON_HOVER); 474 settings->SetHoveredImage(IDR_NOTIFICATION_SETTINGS_BUTTON_ICON_HOVER);
484 settings->SetPressedImage(IDR_NOTIFICATION_SETTINGS_BUTTON_ICON_PRESSED); 475 settings->SetPressedImage(IDR_NOTIFICATION_SETTINGS_BUTTON_ICON_PRESSED);
485 settings->set_animate_on_state_change(false); 476 settings->set_animate_on_state_change(false);
486 settings->SetAccessibleName(l10n_util::GetStringUTF16( 477 settings->SetAccessibleName(l10n_util::GetStringUTF16(
487 IDS_MESSAGE_NOTIFICATION_SETTINGS_BUTTON_ACCESSIBLE_NAME)); 478 IDS_MESSAGE_NOTIFICATION_SETTINGS_BUTTON_ACCESSIBLE_NAME));
488 settings->SetTooltipText(l10n_util::GetStringUTF16( 479 settings->SetTooltipText(l10n_util::GetStringUTF16(
489 IDS_MESSAGE_NOTIFICATION_SETTINGS_BUTTON_ACCESSIBLE_NAME)); 480 IDS_MESSAGE_NOTIFICATION_SETTINGS_BUTTON_ACCESSIBLE_NAME));
490 settings->SetFocusPainter(views::Painter::CreateSolidFocusPainter( 481 settings->SetFocusPainter(views::Painter::CreateSolidFocusPainter(
491 kFocusBorderColor, gfx::Insets(1, 2, 2, 2))); 482 kFocusBorderColor, gfx::Insets(1, 2, 2, 2)));
492 settings_button_view_ = settings; 483 settings_button_view_ = settings;
493 AddChildView(settings_button_view_); 484 AddChildView(settings_button_view_);
494 } 485 }
495 } 486 }
496 487
497 void NotificationView::CreateOrUpdateProgressBarView( 488 void NotificationView::CreateOrUpdateProgressBarView(
498 const Notification& notification) { 489 const Notification& notification) {
499 if (notification.type() != NOTIFICATION_TYPE_PROGRESS) { 490 if (notification.type() != NOTIFICATION_TYPE_PROGRESS) {
500 if (progress_bar_view_) { 491 // Deletion will also remove |progress_bar_view_| from its parent.
501 // Deletion will also remove |progress_bar_view_| from its parent. 492 delete progress_bar_view_;
502 delete progress_bar_view_; 493 progress_bar_view_ = nullptr;
503 progress_bar_view_ = NULL;
504 }
505 return; 494 return;
506 } 495 }
507 496
508 DCHECK(top_view_ != NULL); 497 DCHECK(top_view_);
509
510 bool is_indeterminate = (notification.progress() < 0);
511 if (progress_bar_view_ &&
512 progress_bar_view_->is_indeterminate() != is_indeterminate) {
513 delete progress_bar_view_;
514 progress_bar_view_ = NULL;
515 }
516 498
517 if (!progress_bar_view_) { 499 if (!progress_bar_view_) {
518 if (!is_indeterminate) 500 progress_bar_view_ = new views::ProgressBar();
519 progress_bar_view_ = new NotificationProgressBar();
520 else
521 progress_bar_view_ = new NotificationIndeterminateProgressBar();
522
523 progress_bar_view_->SetBorder(MakeProgressBarBorder( 501 progress_bar_view_->SetBorder(MakeProgressBarBorder(
524 message_center::kProgressBarTopPadding, kProgressBarBottomPadding)); 502 message_center::kProgressBarTopPadding, kProgressBarBottomPadding));
525 top_view_->AddChildView(progress_bar_view_); 503 top_view_->AddChildView(progress_bar_view_);
526 } 504 }
527 505
528 if (!is_indeterminate) 506 progress_bar_view_->SetValue(notification.progress() / 100.0);
529 progress_bar_view_->SetValue(notification.progress() / 100.0);
530
531 progress_bar_view_->SetVisible(notification.items().empty()); 507 progress_bar_view_->SetVisible(notification.items().empty());
532 } 508 }
533 509
534 void NotificationView::CreateOrUpdateListItemViews( 510 void NotificationView::CreateOrUpdateListItemViews(
535 const Notification& notification) { 511 const Notification& notification) {
536 for (size_t i = 0; i < item_views_.size(); ++i) 512 for (size_t i = 0; i < item_views_.size(); ++i)
537 delete item_views_[i]; 513 delete item_views_[i];
538 item_views_.clear(); 514 item_views_.clear();
539 515
540 int padding = kMessageLineHeight - views::Label().font_list().GetHeight(); 516 int padding = kMessageLineHeight - views::Label().font_list().GetHeight();
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 663
688 return message_line_limit; 664 return message_line_limit;
689 } 665 }
690 666
691 int NotificationView::GetMessageHeight(int width, int limit) const { 667 int NotificationView::GetMessageHeight(int width, int limit) const {
692 return message_view_ ? 668 return message_view_ ?
693 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0; 669 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0;
694 } 670 }
695 671
696 } // namespace message_center 672 } // namespace message_center
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698