| 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 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 } | 528 } |
| 529 | 529 |
| 530 DCHECK(top_view_ != NULL); | 530 DCHECK(top_view_ != NULL); |
| 531 | 531 |
| 532 const gfx::FontList& font_list = | 532 const gfx::FontList& font_list = |
| 533 views::Label().font_list().DeriveWithSizeDelta(2); | 533 views::Label().font_list().DeriveWithSizeDelta(2); |
| 534 | 534 |
| 535 int title_character_limit = | 535 int title_character_limit = |
| 536 kNotificationWidth * kMaxTitleLines / kMinPixelsPerTitleCharacter; | 536 kNotificationWidth * kMaxTitleLines / kMinPixelsPerTitleCharacter; |
| 537 | 537 |
| 538 base::string16 title = gfx::TruncateString(notification.title(), |
| 539 title_character_limit, |
| 540 gfx::WORD_BREAK); |
| 538 if (!title_view_) { | 541 if (!title_view_) { |
| 539 int padding = kTitleLineHeight - font_list.GetHeight(); | 542 int padding = kTitleLineHeight - font_list.GetHeight(); |
| 540 | 543 |
| 541 title_view_ = new BoundedLabel( | 544 title_view_ = new BoundedLabel(title, font_list); |
| 542 gfx::TruncateString(notification.title(), title_character_limit), | |
| 543 font_list); | |
| 544 title_view_->SetLineHeight(kTitleLineHeight); | 545 title_view_->SetLineHeight(kTitleLineHeight); |
| 545 title_view_->SetLineLimit(kMaxTitleLines); | 546 title_view_->SetLineLimit(kMaxTitleLines); |
| 546 title_view_->SetColors(message_center::kRegularTextColor, | 547 title_view_->SetColors(message_center::kRegularTextColor, |
| 547 kRegularTextBackgroundColor); | 548 kRegularTextBackgroundColor); |
| 548 title_view_->SetBorder(MakeTextBorder(padding, 3, 0)); | 549 title_view_->SetBorder(MakeTextBorder(padding, 3, 0)); |
| 549 top_view_->AddChildView(title_view_); | 550 top_view_->AddChildView(title_view_); |
| 550 } else { | 551 } else { |
| 551 title_view_->SetText( | 552 title_view_->SetText(title); |
| 552 gfx::TruncateString(notification.title(), title_character_limit)); | |
| 553 } | 553 } |
| 554 } | 554 } |
| 555 | 555 |
| 556 void NotificationView::CreateOrUpdateMessageView( | 556 void NotificationView::CreateOrUpdateMessageView( |
| 557 const Notification& notification) { | 557 const Notification& notification) { |
| 558 if (notification.message().empty()) { | 558 if (notification.message().empty()) { |
| 559 if (message_view_) { | 559 if (message_view_) { |
| 560 // Deletion will also remove |message_view_| from its parent. | 560 // Deletion will also remove |message_view_| from its parent. |
| 561 delete message_view_; | 561 delete message_view_; |
| 562 message_view_ = NULL; | 562 message_view_ = NULL; |
| 563 } | 563 } |
| 564 return; | 564 return; |
| 565 } | 565 } |
| 566 | 566 |
| 567 DCHECK(top_view_ != NULL); | 567 DCHECK(top_view_ != NULL); |
| 568 | 568 |
| 569 base::string16 text = gfx::TruncateString(notification.message(), |
| 570 kMessageCharacterLimit, |
| 571 gfx::WORD_BREAK); |
| 569 if (!message_view_) { | 572 if (!message_view_) { |
| 570 int padding = kMessageLineHeight - views::Label().font_list().GetHeight(); | 573 int padding = kMessageLineHeight - views::Label().font_list().GetHeight(); |
| 571 message_view_ = new BoundedLabel( | 574 message_view_ = new BoundedLabel(text); |
| 572 gfx::TruncateString(notification.message(), kMessageCharacterLimit)); | |
| 573 message_view_->SetLineHeight(kMessageLineHeight); | 575 message_view_->SetLineHeight(kMessageLineHeight); |
| 574 message_view_->SetColors(message_center::kRegularTextColor, | 576 message_view_->SetColors(message_center::kRegularTextColor, |
| 575 kDimTextBackgroundColor); | 577 kDimTextBackgroundColor); |
| 576 message_view_->SetBorder(MakeTextBorder(padding, 4, 0)); | 578 message_view_->SetBorder(MakeTextBorder(padding, 4, 0)); |
| 577 top_view_->AddChildView(message_view_); | 579 top_view_->AddChildView(message_view_); |
| 578 } else { | 580 } else { |
| 579 message_view_->SetText( | 581 message_view_->SetText(text); |
| 580 gfx::TruncateString(notification.message(), kMessageCharacterLimit)); | |
| 581 } | 582 } |
| 582 | 583 |
| 583 message_view_->SetVisible(!notification.items().size()); | 584 message_view_->SetVisible(!notification.items().size()); |
| 584 } | 585 } |
| 585 | 586 |
| 586 void NotificationView::CreateOrUpdateContextMessageView( | 587 void NotificationView::CreateOrUpdateContextMessageView( |
| 587 const Notification& notification) { | 588 const Notification& notification) { |
| 588 if (notification.context_message().empty()) { | 589 if (notification.context_message().empty()) { |
| 589 if (context_message_view_) { | 590 if (context_message_view_) { |
| 590 // Deletion will also remove |context_message_view_| from its parent. | 591 // Deletion will also remove |context_message_view_| from its parent. |
| 591 delete context_message_view_; | 592 delete context_message_view_; |
| 592 context_message_view_ = NULL; | 593 context_message_view_ = NULL; |
| 593 } | 594 } |
| 594 return; | 595 return; |
| 595 } | 596 } |
| 596 | 597 |
| 597 DCHECK(top_view_ != NULL); | 598 DCHECK(top_view_ != NULL); |
| 598 | 599 |
| 600 base::string16 text = gfx::TruncateString(notification.context_message(), |
| 601 kContextMessageCharacterLimit, |
| 602 gfx::WORD_BREAK); |
| 599 if (!context_message_view_) { | 603 if (!context_message_view_) { |
| 600 int padding = kMessageLineHeight - views::Label().font_list().GetHeight(); | 604 int padding = kMessageLineHeight - views::Label().font_list().GetHeight(); |
| 601 context_message_view_ = new BoundedLabel(gfx::TruncateString( | 605 context_message_view_ = new BoundedLabel(text); |
| 602 notification.context_message(), kContextMessageCharacterLimit)); | |
| 603 context_message_view_->SetLineLimit( | 606 context_message_view_->SetLineLimit( |
| 604 message_center::kContextMessageLineLimit); | 607 message_center::kContextMessageLineLimit); |
| 605 context_message_view_->SetLineHeight(kMessageLineHeight); | 608 context_message_view_->SetLineHeight(kMessageLineHeight); |
| 606 context_message_view_->SetColors(message_center::kDimTextColor, | 609 context_message_view_->SetColors(message_center::kDimTextColor, |
| 607 kContextTextBackgroundColor); | 610 kContextTextBackgroundColor); |
| 608 context_message_view_->SetBorder(MakeTextBorder(padding, 4, 0)); | 611 context_message_view_->SetBorder(MakeTextBorder(padding, 4, 0)); |
| 609 top_view_->AddChildView(context_message_view_); | 612 top_view_->AddChildView(context_message_view_); |
| 610 } else { | 613 } else { |
| 611 context_message_view_->SetText(gfx::TruncateString( | 614 context_message_view_->SetText(text); |
| 612 notification.context_message(), kContextMessageCharacterLimit)); | |
| 613 } | 615 } |
| 614 } | 616 } |
| 615 | 617 |
| 616 void NotificationView::CreateOrUpdateProgressBarView( | 618 void NotificationView::CreateOrUpdateProgressBarView( |
| 617 const Notification& notification) { | 619 const Notification& notification) { |
| 618 if (notification.type() != NOTIFICATION_TYPE_PROGRESS) { | 620 if (notification.type() != NOTIFICATION_TYPE_PROGRESS) { |
| 619 if (progress_bar_view_) { | 621 if (progress_bar_view_) { |
| 620 // Deletion will also remove |progress_bar_view_| from its parent. | 622 // Deletion will also remove |progress_bar_view_| from its parent. |
| 621 delete progress_bar_view_; | 623 delete progress_bar_view_; |
| 622 progress_bar_view_ = NULL; | 624 progress_bar_view_ = NULL; |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 785 | 787 |
| 786 return message_line_limit; | 788 return message_line_limit; |
| 787 } | 789 } |
| 788 | 790 |
| 789 int NotificationView::GetMessageHeight(int width, int limit) const { | 791 int NotificationView::GetMessageHeight(int width, int limit) const { |
| 790 return message_view_ ? | 792 return message_view_ ? |
| 791 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0; | 793 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0; |
| 792 } | 794 } |
| 793 | 795 |
| 794 } // namespace message_center | 796 } // namespace message_center |
| OLD | NEW |