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/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" |
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 | 459 |
460 // Create the top_view_, which collects into a vertical box all content | 460 // Create the top_view_, which collects into a vertical box all content |
461 // at the top of the notification (to the right of the icon) except for the | 461 // at the top of the notification (to the right of the icon) except for the |
462 // close button. | 462 // close button. |
463 top_view_ = new views::View(); | 463 top_view_ = new views::View(); |
464 top_view_->SetLayoutManager( | 464 top_view_->SetLayoutManager( |
465 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | 465 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
466 top_view_->set_border(MakeEmptyBorder( | 466 top_view_->set_border(MakeEmptyBorder( |
467 kTextTopPadding - 8, 0, kTextBottomPadding - 5, 0)); | 467 kTextTopPadding - 8, 0, kTextBottomPadding - 5, 0)); |
468 | 468 |
| 469 const gfx::FontList default_label_font_list = views::Label().font_list(); |
| 470 |
469 // Create the title view if appropriate. | 471 // Create the title view if appropriate. |
470 title_view_ = NULL; | 472 title_view_ = NULL; |
471 if (!notification.title().empty()) { | 473 if (!notification.title().empty()) { |
472 gfx::Font font = views::Label().font().DeriveFont(2); | 474 const gfx::FontList& font_list = |
473 int padding = kTitleLineHeight - font.GetHeight(); | 475 default_label_font_list.DeriveFontListWithSizeDelta(2); |
| 476 int padding = kTitleLineHeight - font_list.GetHeight(); |
474 title_view_ = new BoundedLabel( | 477 title_view_ = new BoundedLabel( |
475 gfx::TruncateString(notification.title(), kTitleCharacterLimit), font); | 478 gfx::TruncateString(notification.title(), kTitleCharacterLimit), |
| 479 font_list); |
476 title_view_->SetLineHeight(kTitleLineHeight); | 480 title_view_->SetLineHeight(kTitleLineHeight); |
477 title_view_->SetLineLimit(message_center::kTitleLineLimit); | 481 title_view_->SetLineLimit(message_center::kTitleLineLimit); |
478 title_view_->SetColors(message_center::kRegularTextColor, | 482 title_view_->SetColors(message_center::kRegularTextColor, |
479 kRegularTextBackgroundColor); | 483 kRegularTextBackgroundColor); |
480 title_view_->set_border(MakeTextBorder(padding, 3, 0)); | 484 title_view_->set_border(MakeTextBorder(padding, 3, 0)); |
481 top_view_->AddChildView(title_view_); | 485 top_view_->AddChildView(title_view_); |
482 accessible_lines.push_back(notification.title()); | 486 accessible_lines.push_back(notification.title()); |
483 } | 487 } |
484 | 488 |
485 // Create the message view if appropriate. | 489 // Create the message view if appropriate. |
486 message_view_ = NULL; | 490 message_view_ = NULL; |
487 if (!notification.message().empty()) { | 491 if (!notification.message().empty()) { |
488 int padding = kMessageLineHeight - views::Label().font().GetHeight(); | 492 int padding = kMessageLineHeight - default_label_font_list.GetHeight(); |
489 message_view_ = new BoundedLabel( | 493 message_view_ = new BoundedLabel( |
490 gfx::TruncateString(notification.message(), kMessageCharacterLimit)); | 494 gfx::TruncateString(notification.message(), kMessageCharacterLimit)); |
491 message_view_->SetLineHeight(kMessageLineHeight); | 495 message_view_->SetLineHeight(kMessageLineHeight); |
492 message_view_->SetVisible(!is_expanded() || !notification.items().size()); | 496 message_view_->SetVisible(!is_expanded() || !notification.items().size()); |
493 message_view_->SetColors(message_center::kRegularTextColor, | 497 message_view_->SetColors(message_center::kRegularTextColor, |
494 kDimTextBackgroundColor); | 498 kDimTextBackgroundColor); |
495 message_view_->set_border(MakeTextBorder(padding, 4, 0)); | 499 message_view_->set_border(MakeTextBorder(padding, 4, 0)); |
496 top_view_->AddChildView(message_view_); | 500 top_view_->AddChildView(message_view_); |
497 accessible_lines.push_back(notification.message()); | 501 accessible_lines.push_back(notification.message()); |
498 } | 502 } |
499 | 503 |
500 // Create the context message view if appropriate. | 504 // Create the context message view if appropriate. |
501 context_message_view_ = NULL; | 505 context_message_view_ = NULL; |
502 if (!notification.context_message().empty()) { | 506 if (!notification.context_message().empty()) { |
503 gfx::Font font = views::Label().font(); | 507 int padding = kMessageLineHeight - default_label_font_list.GetHeight(); |
504 int padding = kMessageLineHeight - font.GetHeight(); | |
505 context_message_view_ = | 508 context_message_view_ = |
506 new BoundedLabel(gfx::TruncateString(notification.context_message(), | 509 new BoundedLabel(gfx::TruncateString(notification.context_message(), |
507 kContextMessageCharacterLimit), | 510 kContextMessageCharacterLimit), |
508 font); | 511 default_label_font_list); |
509 context_message_view_->SetLineLimit( | 512 context_message_view_->SetLineLimit( |
510 message_center::kContextMessageLineLimit); | 513 message_center::kContextMessageLineLimit); |
511 context_message_view_->SetLineHeight(kMessageLineHeight); | 514 context_message_view_->SetLineHeight(kMessageLineHeight); |
512 context_message_view_->SetColors(message_center::kDimTextColor, | 515 context_message_view_->SetColors(message_center::kDimTextColor, |
513 kContextTextBackgroundColor); | 516 kContextTextBackgroundColor); |
514 context_message_view_->set_border(MakeTextBorder(padding, 4, 0)); | 517 context_message_view_->set_border(MakeTextBorder(padding, 4, 0)); |
515 top_view_->AddChildView(context_message_view_); | 518 top_view_->AddChildView(context_message_view_); |
516 accessible_lines.push_back(notification.context_message()); | 519 accessible_lines.push_back(notification.context_message()); |
517 } | 520 } |
518 | 521 |
519 // Create the progress bar view. | 522 // Create the progress bar view. |
520 progress_bar_view_ = NULL; | 523 progress_bar_view_ = NULL; |
521 if (notification.type() == NOTIFICATION_TYPE_PROGRESS) { | 524 if (notification.type() == NOTIFICATION_TYPE_PROGRESS) { |
522 progress_bar_view_ = new NotificationProgressBar(); | 525 progress_bar_view_ = new NotificationProgressBar(); |
523 progress_bar_view_->set_border(MakeProgressBarBorder( | 526 progress_bar_view_->set_border(MakeProgressBarBorder( |
524 message_center::kProgressBarTopPadding, kProgressBarBottomPadding)); | 527 message_center::kProgressBarTopPadding, kProgressBarBottomPadding)); |
525 progress_bar_view_->SetValue(notification.progress() / 100.0); | 528 progress_bar_view_->SetValue(notification.progress() / 100.0); |
526 top_view_->AddChildView(progress_bar_view_); | 529 top_view_->AddChildView(progress_bar_view_); |
527 } | 530 } |
528 | 531 |
529 // Create the list item views (up to a maximum). | 532 // Create the list item views (up to a maximum). |
530 int padding = kMessageLineHeight - views::Label().font().GetHeight(); | 533 int padding = kMessageLineHeight - default_label_font_list.GetHeight(); |
531 std::vector<NotificationItem> items = notification.items(); | 534 std::vector<NotificationItem> items = notification.items(); |
532 for (size_t i = 0; i < items.size() && i < kNotificationMaximumItems; ++i) { | 535 for (size_t i = 0; i < items.size() && i < kNotificationMaximumItems; ++i) { |
533 ItemView* item_view = new ItemView(items[i]); | 536 ItemView* item_view = new ItemView(items[i]); |
534 item_view->SetVisible(is_expanded()); | 537 item_view->SetVisible(is_expanded()); |
535 item_view->set_border(MakeTextBorder(padding, i ? 0 : 4, 0)); | 538 item_view->set_border(MakeTextBorder(padding, i ? 0 : 4, 0)); |
536 item_views_.push_back(item_view); | 539 item_views_.push_back(item_view); |
537 top_view_->AddChildView(item_view); | 540 top_view_->AddChildView(item_view); |
538 accessible_lines.push_back( | 541 accessible_lines.push_back( |
539 items[i].title + base::ASCIIToUTF16(" ") + items[i].message); | 542 items[i].title + base::ASCIIToUTF16(" ") + items[i].message); |
540 } | 543 } |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
780 return message_view_ ? | 783 return message_view_ ? |
781 message_view_->GetLinesForWidthAndLimit(width, limit) : 0; | 784 message_view_->GetLinesForWidthAndLimit(width, limit) : 0; |
782 } | 785 } |
783 | 786 |
784 int NotificationView::GetMessageHeight(int width, int limit) { | 787 int NotificationView::GetMessageHeight(int width, int limit) { |
785 return message_view_ ? | 788 return message_view_ ? |
786 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0; | 789 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0; |
787 } | 790 } |
788 | 791 |
789 } // namespace message_center | 792 } // namespace message_center |
OLD | NEW |