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/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
521 } | 521 } |
522 | 522 |
523 DCHECK(top_view_ != NULL); | 523 DCHECK(top_view_ != NULL); |
524 | 524 |
525 const gfx::FontList& font_list = | 525 const gfx::FontList& font_list = |
526 views::Label().font_list().DeriveWithSizeDelta(2); | 526 views::Label().font_list().DeriveWithSizeDelta(2); |
527 | 527 |
528 int title_character_limit = | 528 int title_character_limit = |
529 kNotificationWidth * kMaxTitleLines / kMinPixelsPerTitleCharacter; | 529 kNotificationWidth * kMaxTitleLines / kMinPixelsPerTitleCharacter; |
530 | 530 |
531 base::string16 title = gfx::TruncateString(notification.title(), | |
532 title_character_limit, | |
533 gfx::WORD_BREAK); | |
531 if (!title_view_) { | 534 if (!title_view_) { |
532 int padding = kTitleLineHeight - font_list.GetHeight(); | 535 int padding = kTitleLineHeight - font_list.GetHeight(); |
533 | 536 |
534 title_view_ = new BoundedLabel( | 537 title_view_ = new BoundedLabel(title, font_list); |
535 gfx::TruncateString(notification.title(), title_character_limit), | |
536 font_list); | |
537 title_view_->SetLineHeight(kTitleLineHeight); | 538 title_view_->SetLineHeight(kTitleLineHeight); |
538 title_view_->SetLineLimit(kMaxTitleLines); | 539 title_view_->SetLineLimit(kMaxTitleLines); |
539 title_view_->SetColors(message_center::kRegularTextColor, | 540 title_view_->SetColors(message_center::kRegularTextColor, |
540 kRegularTextBackgroundColor); | 541 kRegularTextBackgroundColor); |
541 title_view_->SetBorder(MakeTextBorder(padding, 3, 0)); | 542 title_view_->SetBorder(MakeTextBorder(padding, 3, 0)); |
542 top_view_->AddChildView(title_view_); | 543 top_view_->AddChildView(title_view_); |
543 } else { | 544 } else { |
544 title_view_->SetText( | 545 title_view_->SetText(title); |
545 gfx::TruncateString(notification.title(), title_character_limit)); | |
546 } | 546 } |
547 } | 547 } |
548 | 548 |
549 void NotificationView::CreateOrUpdateMessageView( | 549 void NotificationView::CreateOrUpdateMessageView( |
550 const Notification& notification) { | 550 const Notification& notification) { |
551 if (notification.message().empty()) { | 551 if (notification.message().empty()) { |
552 if (message_view_) { | 552 if (message_view_) { |
553 // Deletion will also remove |message_view_| from its parent. | 553 // Deletion will also remove |message_view_| from its parent. |
554 delete message_view_; | 554 delete message_view_; |
555 message_view_ = NULL; | 555 message_view_ = NULL; |
556 } | 556 } |
557 return; | 557 return; |
558 } | 558 } |
559 | 559 |
560 DCHECK(top_view_ != NULL); | 560 DCHECK(top_view_ != NULL); |
561 | 561 |
562 base::string16 title = gfx::TruncateString(notification.message(), | |
msw
2014/07/21 16:47:29
nit: rename this to |text|, since this isn't a |ti
Marc Treib
2014/07/22 08:12:48
Done.
| |
563 kMessageCharacterLimit, | |
564 gfx::WORD_BREAK); | |
562 if (!message_view_) { | 565 if (!message_view_) { |
563 int padding = kMessageLineHeight - views::Label().font_list().GetHeight(); | 566 int padding = kMessageLineHeight - views::Label().font_list().GetHeight(); |
564 message_view_ = new BoundedLabel( | 567 message_view_ = new BoundedLabel(title); |
565 gfx::TruncateString(notification.message(), kMessageCharacterLimit)); | |
566 message_view_->SetLineHeight(kMessageLineHeight); | 568 message_view_->SetLineHeight(kMessageLineHeight); |
567 message_view_->SetColors(message_center::kRegularTextColor, | 569 message_view_->SetColors(message_center::kRegularTextColor, |
568 kDimTextBackgroundColor); | 570 kDimTextBackgroundColor); |
569 message_view_->SetBorder(MakeTextBorder(padding, 4, 0)); | 571 message_view_->SetBorder(MakeTextBorder(padding, 4, 0)); |
570 top_view_->AddChildView(message_view_); | 572 top_view_->AddChildView(message_view_); |
571 } else { | 573 } else { |
572 message_view_->SetText( | 574 message_view_->SetText(title); |
573 gfx::TruncateString(notification.message(), kMessageCharacterLimit)); | |
574 } | 575 } |
575 | 576 |
576 message_view_->SetVisible(!notification.items().size()); | 577 message_view_->SetVisible(!notification.items().size()); |
577 } | 578 } |
578 | 579 |
579 void NotificationView::CreateOrUpdateContextMessageView( | 580 void NotificationView::CreateOrUpdateContextMessageView( |
580 const Notification& notification) { | 581 const Notification& notification) { |
581 if (notification.context_message().empty()) { | 582 if (notification.context_message().empty()) { |
582 if (context_message_view_) { | 583 if (context_message_view_) { |
583 // Deletion will also remove |context_message_view_| from its parent. | 584 // Deletion will also remove |context_message_view_| from its parent. |
584 delete context_message_view_; | 585 delete context_message_view_; |
585 context_message_view_ = NULL; | 586 context_message_view_ = NULL; |
586 } | 587 } |
587 return; | 588 return; |
588 } | 589 } |
589 | 590 |
590 DCHECK(top_view_ != NULL); | 591 DCHECK(top_view_ != NULL); |
591 | 592 |
593 base::string16 title = gfx::TruncateString(notification.context_message(), | |
msw
2014/07/21 16:47:29
ditto
Marc Treib
2014/07/22 08:12:48
Done.
| |
594 kContextMessageCharacterLimit, | |
595 gfx::WORD_BREAK); | |
592 if (!context_message_view_) { | 596 if (!context_message_view_) { |
593 int padding = kMessageLineHeight - views::Label().font_list().GetHeight(); | 597 int padding = kMessageLineHeight - views::Label().font_list().GetHeight(); |
594 context_message_view_ = new BoundedLabel(gfx::TruncateString( | 598 context_message_view_ = new BoundedLabel(title); |
595 notification.context_message(), kContextMessageCharacterLimit)); | |
596 context_message_view_->SetLineLimit( | 599 context_message_view_->SetLineLimit( |
597 message_center::kContextMessageLineLimit); | 600 message_center::kContextMessageLineLimit); |
598 context_message_view_->SetLineHeight(kMessageLineHeight); | 601 context_message_view_->SetLineHeight(kMessageLineHeight); |
599 context_message_view_->SetColors(message_center::kDimTextColor, | 602 context_message_view_->SetColors(message_center::kDimTextColor, |
600 kContextTextBackgroundColor); | 603 kContextTextBackgroundColor); |
601 context_message_view_->SetBorder(MakeTextBorder(padding, 4, 0)); | 604 context_message_view_->SetBorder(MakeTextBorder(padding, 4, 0)); |
602 top_view_->AddChildView(context_message_view_); | 605 top_view_->AddChildView(context_message_view_); |
603 } else { | 606 } else { |
604 context_message_view_->SetText(gfx::TruncateString( | 607 context_message_view_->SetText(title); |
605 notification.context_message(), kContextMessageCharacterLimit)); | |
606 } | 608 } |
607 } | 609 } |
608 | 610 |
609 void NotificationView::CreateOrUpdateProgressBarView( | 611 void NotificationView::CreateOrUpdateProgressBarView( |
610 const Notification& notification) { | 612 const Notification& notification) { |
611 if (notification.type() != NOTIFICATION_TYPE_PROGRESS) { | 613 if (notification.type() != NOTIFICATION_TYPE_PROGRESS) { |
612 if (progress_bar_view_) { | 614 if (progress_bar_view_) { |
613 // Deletion will also remove |progress_bar_view_| from its parent. | 615 // Deletion will also remove |progress_bar_view_| from its parent. |
614 delete progress_bar_view_; | 616 delete progress_bar_view_; |
615 progress_bar_view_ = NULL; | 617 progress_bar_view_ = NULL; |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
778 | 780 |
779 return message_line_limit; | 781 return message_line_limit; |
780 } | 782 } |
781 | 783 |
782 int NotificationView::GetMessageHeight(int width, int limit) const { | 784 int NotificationView::GetMessageHeight(int width, int limit) const { |
783 return message_view_ ? | 785 return message_view_ ? |
784 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0; | 786 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0; |
785 } | 787 } |
786 | 788 |
787 } // namespace message_center | 789 } // namespace message_center |
OLD | NEW |