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

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 TruncateString 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(), title_character_limit, true),
536 font_list); 536 font_list);
537 title_view_->SetLineHeight(kTitleLineHeight); 537 title_view_->SetLineHeight(kTitleLineHeight);
538 title_view_->SetLineLimit(kMaxTitleLines); 538 title_view_->SetLineLimit(kMaxTitleLines);
539 title_view_->SetColors(message_center::kRegularTextColor, 539 title_view_->SetColors(message_center::kRegularTextColor,
540 kRegularTextBackgroundColor); 540 kRegularTextBackgroundColor);
541 title_view_->SetBorder(MakeTextBorder(padding, 3, 0)); 541 title_view_->SetBorder(MakeTextBorder(padding, 3, 0));
542 top_view_->AddChildView(title_view_); 542 top_view_->AddChildView(title_view_);
543 } else { 543 } else {
544 title_view_->SetText( 544 title_view_->SetText(
545 gfx::TruncateString(notification.title(), title_character_limit)); 545 gfx::TruncateString(notification.title(), title_character_limit, true));
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 if (!message_view_) { 562 if (!message_view_) {
563 int padding = kMessageLineHeight - views::Label().font_list().GetHeight(); 563 int padding = kMessageLineHeight - views::Label().font_list().GetHeight();
564 message_view_ = new BoundedLabel( 564 message_view_ = new BoundedLabel(gfx::TruncateString(notification.message(),
565 gfx::TruncateString(notification.message(), kMessageCharacterLimit)); 565 kMessageCharacterLimit,
566 true));
566 message_view_->SetLineHeight(kMessageLineHeight); 567 message_view_->SetLineHeight(kMessageLineHeight);
567 message_view_->SetColors(message_center::kRegularTextColor, 568 message_view_->SetColors(message_center::kRegularTextColor,
568 kDimTextBackgroundColor); 569 kDimTextBackgroundColor);
569 message_view_->SetBorder(MakeTextBorder(padding, 4, 0)); 570 message_view_->SetBorder(MakeTextBorder(padding, 4, 0));
570 top_view_->AddChildView(message_view_); 571 top_view_->AddChildView(message_view_);
571 } else { 572 } else {
572 message_view_->SetText( 573 message_view_->SetText(gfx::TruncateString(notification.message(),
573 gfx::TruncateString(notification.message(), kMessageCharacterLimit)); 574 kMessageCharacterLimit,
575 true));
574 } 576 }
575 577
576 message_view_->SetVisible(!notification.items().size()); 578 message_view_->SetVisible(!notification.items().size());
577 } 579 }
578 580
579 void NotificationView::CreateOrUpdateContextMessageView( 581 void NotificationView::CreateOrUpdateContextMessageView(
580 const Notification& notification) { 582 const Notification& notification) {
581 if (notification.context_message().empty()) { 583 if (notification.context_message().empty()) {
582 if (context_message_view_) { 584 if (context_message_view_) {
583 // Deletion will also remove |context_message_view_| from its parent. 585 // Deletion will also remove |context_message_view_| from its parent.
584 delete context_message_view_; 586 delete context_message_view_;
585 context_message_view_ = NULL; 587 context_message_view_ = NULL;
586 } 588 }
587 return; 589 return;
588 } 590 }
589 591
590 DCHECK(top_view_ != NULL); 592 DCHECK(top_view_ != NULL);
591 593
592 if (!context_message_view_) { 594 if (!context_message_view_) {
593 int padding = kMessageLineHeight - views::Label().font_list().GetHeight(); 595 int padding = kMessageLineHeight - views::Label().font_list().GetHeight();
594 context_message_view_ = new BoundedLabel(gfx::TruncateString( 596 context_message_view_ = new BoundedLabel(gfx::TruncateString(
595 notification.context_message(), kContextMessageCharacterLimit)); 597 notification.context_message(), kContextMessageCharacterLimit, true));
596 context_message_view_->SetLineLimit( 598 context_message_view_->SetLineLimit(
597 message_center::kContextMessageLineLimit); 599 message_center::kContextMessageLineLimit);
598 context_message_view_->SetLineHeight(kMessageLineHeight); 600 context_message_view_->SetLineHeight(kMessageLineHeight);
599 context_message_view_->SetColors(message_center::kDimTextColor, 601 context_message_view_->SetColors(message_center::kDimTextColor,
600 kContextTextBackgroundColor); 602 kContextTextBackgroundColor);
601 context_message_view_->SetBorder(MakeTextBorder(padding, 4, 0)); 603 context_message_view_->SetBorder(MakeTextBorder(padding, 4, 0));
602 top_view_->AddChildView(context_message_view_); 604 top_view_->AddChildView(context_message_view_);
603 } else { 605 } else {
604 context_message_view_->SetText(gfx::TruncateString( 606 context_message_view_->SetText(gfx::TruncateString(
605 notification.context_message(), kContextMessageCharacterLimit)); 607 notification.context_message(), kContextMessageCharacterLimit, true));
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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698