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" |
11 #include "ui/base/layout.h" | 11 #include "ui/base/layout.h" |
12 #include "ui/base/resource/resource_bundle.h" | 12 #include "ui/base/resource/resource_bundle.h" |
13 #include "ui/base/text/text_elider.h" | |
14 #include "ui/gfx/canvas.h" | 13 #include "ui/gfx/canvas.h" |
15 #include "ui/gfx/size.h" | 14 #include "ui/gfx/size.h" |
16 #include "ui/gfx/skia_util.h" | 15 #include "ui/gfx/skia_util.h" |
| 16 #include "ui/gfx/text_elider.h" |
17 #include "ui/message_center/message_center.h" | 17 #include "ui/message_center/message_center.h" |
18 #include "ui/message_center/message_center_style.h" | 18 #include "ui/message_center/message_center_style.h" |
19 #include "ui/message_center/message_center_switches.h" | 19 #include "ui/message_center/message_center_switches.h" |
20 #include "ui/message_center/message_center_util.h" | 20 #include "ui/message_center/message_center_util.h" |
21 #include "ui/message_center/notification.h" | 21 #include "ui/message_center/notification.h" |
22 #include "ui/message_center/notification_types.h" | 22 #include "ui/message_center/notification_types.h" |
23 #include "ui/message_center/views/bounded_label.h" | 23 #include "ui/message_center/views/bounded_label.h" |
24 #include "ui/native_theme/native_theme.h" | 24 #include "ui/native_theme/native_theme.h" |
25 #include "ui/views/controls/button/image_button.h" | 25 #include "ui/views/controls/button/image_button.h" |
26 #include "ui/views/controls/image_view.h" | 26 #include "ui/views/controls/image_view.h" |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 // Create the title view if appropriate. | 469 // Create the title view if appropriate. |
470 title_view_ = NULL; | 470 title_view_ = NULL; |
471 if (!notification.title().empty()) { | 471 if (!notification.title().empty()) { |
472 gfx::Font font = views::Label().font().DeriveFont(2); | 472 gfx::Font font = views::Label().font().DeriveFont(2); |
473 int padding = kTitleLineHeight - font.GetHeight(); | 473 int padding = kTitleLineHeight - font.GetHeight(); |
474 title_view_ = new BoundedLabel( | 474 title_view_ = new BoundedLabel( |
475 ui::TruncateString(notification.title(), kTitleCharacterLimit), font); | 475 gfx::TruncateString(notification.title(), kTitleCharacterLimit), font); |
476 title_view_->SetLineHeight(kTitleLineHeight); | 476 title_view_->SetLineHeight(kTitleLineHeight); |
477 title_view_->SetLineLimit(message_center::kTitleLineLimit); | 477 title_view_->SetLineLimit(message_center::kTitleLineLimit); |
478 title_view_->SetColors(message_center::kRegularTextColor, | 478 title_view_->SetColors(message_center::kRegularTextColor, |
479 kRegularTextBackgroundColor); | 479 kRegularTextBackgroundColor); |
480 title_view_->set_border(MakeTextBorder(padding, 3, 0)); | 480 title_view_->set_border(MakeTextBorder(padding, 3, 0)); |
481 top_view_->AddChildView(title_view_); | 481 top_view_->AddChildView(title_view_); |
482 accessible_lines.push_back(notification.title()); | 482 accessible_lines.push_back(notification.title()); |
483 } | 483 } |
484 | 484 |
485 // Create the message view if appropriate. | 485 // Create the message view if appropriate. |
486 message_view_ = NULL; | 486 message_view_ = NULL; |
487 if (!notification.message().empty()) { | 487 if (!notification.message().empty()) { |
488 int padding = kMessageLineHeight - views::Label().font().GetHeight(); | 488 int padding = kMessageLineHeight - views::Label().font().GetHeight(); |
489 message_view_ = new BoundedLabel( | 489 message_view_ = new BoundedLabel( |
490 ui::TruncateString(notification.message(), kMessageCharacterLimit)); | 490 gfx::TruncateString(notification.message(), kMessageCharacterLimit)); |
491 message_view_->SetLineHeight(kMessageLineHeight); | 491 message_view_->SetLineHeight(kMessageLineHeight); |
492 message_view_->SetVisible(!is_expanded() || !notification.items().size()); | 492 message_view_->SetVisible(!is_expanded() || !notification.items().size()); |
493 message_view_->SetColors(message_center::kRegularTextColor, | 493 message_view_->SetColors(message_center::kRegularTextColor, |
494 kDimTextBackgroundColor); | 494 kDimTextBackgroundColor); |
495 message_view_->set_border(MakeTextBorder(padding, 4, 0)); | 495 message_view_->set_border(MakeTextBorder(padding, 4, 0)); |
496 top_view_->AddChildView(message_view_); | 496 top_view_->AddChildView(message_view_); |
497 accessible_lines.push_back(notification.message()); | 497 accessible_lines.push_back(notification.message()); |
498 } | 498 } |
499 | 499 |
500 // Create the context message view if appropriate. | 500 // Create the context message view if appropriate. |
501 context_message_view_ = NULL; | 501 context_message_view_ = NULL; |
502 if (!notification.context_message().empty()) { | 502 if (!notification.context_message().empty()) { |
503 gfx::Font font = views::Label().font(); | 503 gfx::Font font = views::Label().font(); |
504 int padding = kMessageLineHeight - font.GetHeight(); | 504 int padding = kMessageLineHeight - font.GetHeight(); |
505 context_message_view_ = | 505 context_message_view_ = |
506 new BoundedLabel(ui::TruncateString(notification.context_message(), | 506 new BoundedLabel(gfx::TruncateString(notification.context_message(), |
507 kContextMessageCharacterLimit), | 507 kContextMessageCharacterLimit), |
508 font); | 508 font); |
509 context_message_view_->SetLineLimit( | 509 context_message_view_->SetLineLimit( |
510 message_center::kContextMessageLineLimit); | 510 message_center::kContextMessageLineLimit); |
511 context_message_view_->SetLineHeight(kMessageLineHeight); | 511 context_message_view_->SetLineHeight(kMessageLineHeight); |
512 context_message_view_->SetColors(message_center::kDimTextColor, | 512 context_message_view_->SetColors(message_center::kDimTextColor, |
513 kContextTextBackgroundColor); | 513 kContextTextBackgroundColor); |
514 context_message_view_->set_border(MakeTextBorder(padding, 4, 0)); | 514 context_message_view_->set_border(MakeTextBorder(padding, 4, 0)); |
515 top_view_->AddChildView(context_message_view_); | 515 top_view_->AddChildView(context_message_view_); |
516 accessible_lines.push_back(notification.context_message()); | 516 accessible_lines.push_back(notification.context_message()); |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
780 return message_view_ ? | 780 return message_view_ ? |
781 message_view_->GetLinesForWidthAndLimit(width, limit) : 0; | 781 message_view_->GetLinesForWidthAndLimit(width, limit) : 0; |
782 } | 782 } |
783 | 783 |
784 int NotificationView::GetMessageHeight(int width, int limit) { | 784 int NotificationView::GetMessageHeight(int width, int limit) { |
785 return message_view_ ? | 785 return message_view_ ? |
786 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0; | 786 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0; |
787 } | 787 } |
788 | 788 |
789 } // namespace message_center | 789 } // namespace message_center |
OLD | NEW |