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

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

Issue 381953002: New avatar button: Consolidate text elision between Mac and Win/Linux (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: use gfx::BreakType Created 6 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
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/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 514 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 if (!title_view_) { 531 if (!title_view_) {
532 int padding = kTitleLineHeight - font_list.GetHeight(); 532 int padding = kTitleLineHeight - font_list.GetHeight();
533 533
534 title_view_ = new BoundedLabel( 534 title_view_ = new BoundedLabel(
535 gfx::TruncateString(notification.title(), title_character_limit), 535 gfx::TruncateString(notification.title(),
msw 2014/07/21 15:26:07 nit: init a shared local |title| string outside th
Marc Treib 2014/07/21 16:43:52 Done.
536 title_character_limit,
537 gfx::WORD_BREAK),
536 font_list); 538 font_list);
537 title_view_->SetLineHeight(kTitleLineHeight); 539 title_view_->SetLineHeight(kTitleLineHeight);
538 title_view_->SetLineLimit(kMaxTitleLines); 540 title_view_->SetLineLimit(kMaxTitleLines);
539 title_view_->SetColors(message_center::kRegularTextColor, 541 title_view_->SetColors(message_center::kRegularTextColor,
540 kRegularTextBackgroundColor); 542 kRegularTextBackgroundColor);
541 title_view_->SetBorder(MakeTextBorder(padding, 3, 0)); 543 title_view_->SetBorder(MakeTextBorder(padding, 3, 0));
542 top_view_->AddChildView(title_view_); 544 top_view_->AddChildView(title_view_);
543 } else { 545 } else {
544 title_view_->SetText( 546 title_view_->SetText(
545 gfx::TruncateString(notification.title(), title_character_limit)); 547 gfx::TruncateString(notification.title(),
548 title_character_limit,
549 gfx::WORD_BREAK));
546 } 550 }
547 } 551 }
548 552
549 void NotificationView::CreateOrUpdateMessageView( 553 void NotificationView::CreateOrUpdateMessageView(
550 const Notification& notification) { 554 const Notification& notification) {
551 if (notification.message().empty()) { 555 if (notification.message().empty()) {
552 if (message_view_) { 556 if (message_view_) {
553 // Deletion will also remove |message_view_| from its parent. 557 // Deletion will also remove |message_view_| from its parent.
554 delete message_view_; 558 delete message_view_;
555 message_view_ = NULL; 559 message_view_ = NULL;
556 } 560 }
557 return; 561 return;
558 } 562 }
559 563
560 DCHECK(top_view_ != NULL); 564 DCHECK(top_view_ != NULL);
561 565
562 if (!message_view_) { 566 if (!message_view_) {
563 int padding = kMessageLineHeight - views::Label().font_list().GetHeight(); 567 int padding = kMessageLineHeight - views::Label().font_list().GetHeight();
564 message_view_ = new BoundedLabel( 568 message_view_ = new BoundedLabel(gfx::TruncateString(notification.message(),
msw 2014/07/21 15:26:07 ditto
Marc Treib 2014/07/21 16:43:52 Done.
565 gfx::TruncateString(notification.message(), kMessageCharacterLimit)); 569 kMessageCharacterLimit,
570 gfx::WORD_BREAK));
566 message_view_->SetLineHeight(kMessageLineHeight); 571 message_view_->SetLineHeight(kMessageLineHeight);
567 message_view_->SetColors(message_center::kRegularTextColor, 572 message_view_->SetColors(message_center::kRegularTextColor,
568 kDimTextBackgroundColor); 573 kDimTextBackgroundColor);
569 message_view_->SetBorder(MakeTextBorder(padding, 4, 0)); 574 message_view_->SetBorder(MakeTextBorder(padding, 4, 0));
570 top_view_->AddChildView(message_view_); 575 top_view_->AddChildView(message_view_);
571 } else { 576 } else {
572 message_view_->SetText( 577 message_view_->SetText(gfx::TruncateString(notification.message(),
573 gfx::TruncateString(notification.message(), kMessageCharacterLimit)); 578 kMessageCharacterLimit,
579 gfx::WORD_BREAK));
574 } 580 }
575 581
576 message_view_->SetVisible(!notification.items().size()); 582 message_view_->SetVisible(!notification.items().size());
577 } 583 }
578 584
579 void NotificationView::CreateOrUpdateContextMessageView( 585 void NotificationView::CreateOrUpdateContextMessageView(
580 const Notification& notification) { 586 const Notification& notification) {
581 if (notification.context_message().empty()) { 587 if (notification.context_message().empty()) {
582 if (context_message_view_) { 588 if (context_message_view_) {
583 // Deletion will also remove |context_message_view_| from its parent. 589 // Deletion will also remove |context_message_view_| from its parent.
584 delete context_message_view_; 590 delete context_message_view_;
585 context_message_view_ = NULL; 591 context_message_view_ = NULL;
586 } 592 }
587 return; 593 return;
588 } 594 }
589 595
590 DCHECK(top_view_ != NULL); 596 DCHECK(top_view_ != NULL);
591 597
592 if (!context_message_view_) { 598 if (!context_message_view_) {
593 int padding = kMessageLineHeight - views::Label().font_list().GetHeight(); 599 int padding = kMessageLineHeight - views::Label().font_list().GetHeight();
594 context_message_view_ = new BoundedLabel(gfx::TruncateString( 600 context_message_view_ =
595 notification.context_message(), kContextMessageCharacterLimit)); 601 new BoundedLabel(gfx::TruncateString(notification.context_message(),
msw 2014/07/21 15:26:07 ditto
Marc Treib 2014/07/21 16:43:52 Done.
602 kContextMessageCharacterLimit,
603 gfx::WORD_BREAK));
596 context_message_view_->SetLineLimit( 604 context_message_view_->SetLineLimit(
597 message_center::kContextMessageLineLimit); 605 message_center::kContextMessageLineLimit);
598 context_message_view_->SetLineHeight(kMessageLineHeight); 606 context_message_view_->SetLineHeight(kMessageLineHeight);
599 context_message_view_->SetColors(message_center::kDimTextColor, 607 context_message_view_->SetColors(message_center::kDimTextColor,
600 kContextTextBackgroundColor); 608 kContextTextBackgroundColor);
601 context_message_view_->SetBorder(MakeTextBorder(padding, 4, 0)); 609 context_message_view_->SetBorder(MakeTextBorder(padding, 4, 0));
602 top_view_->AddChildView(context_message_view_); 610 top_view_->AddChildView(context_message_view_);
603 } else { 611 } else {
604 context_message_view_->SetText(gfx::TruncateString( 612 context_message_view_->SetText(
605 notification.context_message(), kContextMessageCharacterLimit)); 613 gfx::TruncateString(notification.context_message(),
614 kContextMessageCharacterLimit,
615 gfx::WORD_BREAK));
606 } 616 }
607 } 617 }
608 618
609 void NotificationView::CreateOrUpdateProgressBarView( 619 void NotificationView::CreateOrUpdateProgressBarView(
610 const Notification& notification) { 620 const Notification& notification) {
611 if (notification.type() != NOTIFICATION_TYPE_PROGRESS) { 621 if (notification.type() != NOTIFICATION_TYPE_PROGRESS) {
612 if (progress_bar_view_) { 622 if (progress_bar_view_) {
613 // Deletion will also remove |progress_bar_view_| from its parent. 623 // Deletion will also remove |progress_bar_view_| from its parent.
614 delete progress_bar_view_; 624 delete progress_bar_view_;
615 progress_bar_view_ = NULL; 625 progress_bar_view_ = NULL;
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
778 788
779 return message_line_limit; 789 return message_line_limit;
780 } 790 }
781 791
782 int NotificationView::GetMessageHeight(int width, int limit) const { 792 int NotificationView::GetMessageHeight(int width, int limit) const {
783 return message_view_ ? 793 return message_view_ ?
784 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0; 794 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0;
785 } 795 }
786 796
787 } // namespace message_center 797 } // namespace message_center
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698