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" |
| 11 #include "components/url_formatter/elide_url.h" |
11 #include "third_party/skia/include/core/SkPaint.h" | 12 #include "third_party/skia/include/core/SkPaint.h" |
12 #include "third_party/skia/include/core/SkPath.h" | 13 #include "third_party/skia/include/core/SkPath.h" |
13 #include "ui/base/cursor/cursor.h" | 14 #include "ui/base/cursor/cursor.h" |
14 #include "ui/base/layout.h" | 15 #include "ui/base/layout.h" |
15 #include "ui/gfx/canvas.h" | 16 #include "ui/gfx/canvas.h" |
16 #include "ui/gfx/geometry/size.h" | 17 #include "ui/gfx/geometry/size.h" |
17 #include "ui/gfx/skia_util.h" | 18 #include "ui/gfx/skia_util.h" |
18 #include "ui/gfx/text_elider.h" | 19 #include "ui/gfx/text_elider.h" |
19 #include "ui/message_center/message_center.h" | 20 #include "ui/message_center/message_center.h" |
20 #include "ui/message_center/message_center_style.h" | 21 #include "ui/message_center/message_center_style.h" |
(...skipping 13 matching lines...) Expand all Loading... |
34 #include "ui/views/controls/button/image_button.h" | 35 #include "ui/views/controls/button/image_button.h" |
35 #include "ui/views/controls/image_view.h" | 36 #include "ui/views/controls/image_view.h" |
36 #include "ui/views/controls/label.h" | 37 #include "ui/views/controls/label.h" |
37 #include "ui/views/controls/progress_bar.h" | 38 #include "ui/views/controls/progress_bar.h" |
38 #include "ui/views/layout/box_layout.h" | 39 #include "ui/views/layout/box_layout.h" |
39 #include "ui/views/layout/fill_layout.h" | 40 #include "ui/views/layout/fill_layout.h" |
40 #include "ui/views/native_cursor.h" | 41 #include "ui/views/native_cursor.h" |
41 #include "ui/views/painter.h" | 42 #include "ui/views/painter.h" |
42 #include "ui/views/view_targeter.h" | 43 #include "ui/views/view_targeter.h" |
43 #include "ui/views/widget/widget.h" | 44 #include "ui/views/widget/widget.h" |
| 45 #include "url/gurl.h" |
44 | 46 |
45 namespace { | 47 namespace { |
46 | 48 |
47 // Dimensions. | 49 // Dimensions. |
48 const int kProgressBarWidth = message_center::kNotificationWidth - | 50 const int kProgressBarWidth = message_center::kNotificationWidth - |
49 message_center::kTextLeftPadding - message_center::kTextRightPadding; | 51 message_center::kTextLeftPadding - message_center::kTextRightPadding; |
50 const int kProgressBarBottomPadding = 0; | 52 const int kProgressBarBottomPadding = 0; |
51 | 53 |
52 // static | 54 // static |
53 scoped_ptr<views::Border> MakeEmptyBorder(int top, | 55 scoped_ptr<views::Border> MakeEmptyBorder(int top, |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 if (buttons[i]->HitTestPoint(point_in_child)) | 280 if (buttons[i]->HitTestPoint(point_in_child)) |
279 return buttons[i]->GetEventHandlerForPoint(point_in_child); | 281 return buttons[i]->GetEventHandlerForPoint(point_in_child); |
280 } | 282 } |
281 | 283 |
282 return root; | 284 return root; |
283 } | 285 } |
284 | 286 |
285 void NotificationView::CreateOrUpdateViews(const Notification& notification) { | 287 void NotificationView::CreateOrUpdateViews(const Notification& notification) { |
286 CreateOrUpdateTitleView(notification); | 288 CreateOrUpdateTitleView(notification); |
287 CreateOrUpdateMessageView(notification); | 289 CreateOrUpdateMessageView(notification); |
288 CreateOrUpdateContextMessageView(notification); | |
289 CreateOrUpdateProgressBarView(notification); | 290 CreateOrUpdateProgressBarView(notification); |
290 CreateOrUpdateListItemViews(notification); | 291 CreateOrUpdateListItemViews(notification); |
291 CreateOrUpdateIconView(notification); | 292 CreateOrUpdateIconView(notification); |
292 CreateOrUpdateImageView(notification); | 293 CreateOrUpdateImageView(notification); |
| 294 CreateOrUpdateContextMessageView(notification); |
293 CreateOrUpdateActionButtonViews(notification); | 295 CreateOrUpdateActionButtonViews(notification); |
294 } | 296 } |
295 | 297 |
296 void NotificationView::SetAccessibleName(const Notification& notification) { | 298 void NotificationView::SetAccessibleName(const Notification& notification) { |
297 std::vector<base::string16> accessible_lines; | 299 std::vector<base::string16> accessible_lines; |
298 accessible_lines.push_back(notification.title()); | 300 accessible_lines.push_back(notification.title()); |
299 accessible_lines.push_back(notification.message()); | 301 accessible_lines.push_back(notification.message()); |
300 accessible_lines.push_back(notification.context_message()); | 302 accessible_lines.push_back(notification.context_message()); |
301 std::vector<NotificationItem> items = notification.items(); | 303 std::vector<NotificationItem> items = notification.items(); |
302 for (size_t i = 0; i < items.size() && i < kNotificationMaximumItems; ++i) { | 304 for (size_t i = 0; i < items.size() && i < kNotificationMaximumItems; ++i) { |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 kDimTextBackgroundColor); | 548 kDimTextBackgroundColor); |
547 message_view_->SetBorder(MakeTextBorder(padding, 4, 0)); | 549 message_view_->SetBorder(MakeTextBorder(padding, 4, 0)); |
548 top_view_->AddChildView(message_view_); | 550 top_view_->AddChildView(message_view_); |
549 } else { | 551 } else { |
550 message_view_->SetText(text); | 552 message_view_->SetText(text); |
551 } | 553 } |
552 | 554 |
553 message_view_->SetVisible(!notification.items().size()); | 555 message_view_->SetVisible(!notification.items().size()); |
554 } | 556 } |
555 | 557 |
| 558 base::string16 NotificationView::FormatContextMessage( |
| 559 const Notification& notification) const { |
| 560 if (notification.UseOriginAsContextMessage()) { |
| 561 const GURL url = notification.origin_url(); |
| 562 DCHECK(url.is_valid()); |
| 563 return url_formatter::ElideHost(url, views::Label().font_list(), |
| 564 kContextMessageViewWidth); |
| 565 } |
| 566 |
| 567 return gfx::TruncateString(notification.context_message(), |
| 568 kContextMessageCharacterLimit, gfx::WORD_BREAK); |
| 569 } |
| 570 |
556 void NotificationView::CreateOrUpdateContextMessageView( | 571 void NotificationView::CreateOrUpdateContextMessageView( |
557 const Notification& notification) { | 572 const Notification& notification) { |
558 if (notification.context_message().empty()) { | 573 if (notification.context_message().empty() && |
| 574 !notification.UseOriginAsContextMessage()) { |
559 if (context_message_view_) { | 575 if (context_message_view_) { |
560 // Deletion will also remove |context_message_view_| from its parent. | 576 // Deletion will also remove |context_message_view_| from its parent. |
561 delete context_message_view_; | 577 delete context_message_view_; |
562 context_message_view_ = NULL; | 578 context_message_view_ = NULL; |
563 } | 579 } |
564 return; | 580 return; |
565 } | 581 } |
566 | 582 |
567 DCHECK(top_view_ != NULL); | 583 DCHECK(top_view_ != NULL); |
568 | 584 |
569 base::string16 text = gfx::TruncateString(notification.context_message(), | 585 base::string16 message = FormatContextMessage(notification); |
570 kContextMessageCharacterLimit, | 586 |
571 gfx::WORD_BREAK); | |
572 if (!context_message_view_) { | 587 if (!context_message_view_) { |
573 int padding = kMessageLineHeight - views::Label().font_list().GetHeight(); | 588 int padding = kMessageLineHeight - views::Label().font_list().GetHeight(); |
574 context_message_view_ = new BoundedLabel(text); | 589 context_message_view_ = new BoundedLabel(message); |
575 context_message_view_->SetLineLimit( | 590 context_message_view_->SetLineLimit( |
576 message_center::kContextMessageLineLimit); | 591 message_center::kContextMessageLineLimit); |
577 context_message_view_->SetLineHeight(kMessageLineHeight); | 592 context_message_view_->SetLineHeight(kMessageLineHeight); |
578 context_message_view_->SetColors(message_center::kDimTextColor, | 593 context_message_view_->SetColors(message_center::kDimTextColor, |
579 kContextTextBackgroundColor); | 594 kContextTextBackgroundColor); |
580 context_message_view_->SetBorder(MakeTextBorder(padding, 4, 0)); | 595 context_message_view_->SetBorder(MakeTextBorder(padding, 4, 0)); |
581 top_view_->AddChildView(context_message_view_); | 596 top_view_->AddChildView(context_message_view_); |
582 } else { | 597 } else { |
583 context_message_view_->SetText(text); | 598 context_message_view_->SetText(message); |
584 } | 599 } |
585 } | 600 } |
586 | 601 |
587 void NotificationView::CreateOrUpdateProgressBarView( | 602 void NotificationView::CreateOrUpdateProgressBarView( |
588 const Notification& notification) { | 603 const Notification& notification) { |
589 if (notification.type() != NOTIFICATION_TYPE_PROGRESS) { | 604 if (notification.type() != NOTIFICATION_TYPE_PROGRESS) { |
590 if (progress_bar_view_) { | 605 if (progress_bar_view_) { |
591 // Deletion will also remove |progress_bar_view_| from its parent. | 606 // Deletion will also remove |progress_bar_view_| from its parent. |
592 delete progress_bar_view_; | 607 delete progress_bar_view_; |
593 progress_bar_view_ = NULL; | 608 progress_bar_view_ = NULL; |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
770 | 785 |
771 return message_line_limit; | 786 return message_line_limit; |
772 } | 787 } |
773 | 788 |
774 int NotificationView::GetMessageHeight(int width, int limit) const { | 789 int NotificationView::GetMessageHeight(int width, int limit) const { |
775 return message_view_ ? | 790 return message_view_ ? |
776 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0; | 791 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0; |
777 } | 792 } |
778 | 793 |
779 } // namespace message_center | 794 } // namespace message_center |
OLD | NEW |