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( |
| 303 base::UTF8ToUTF16(notification.context_message().message)); |
301 std::vector<NotificationItem> items = notification.items(); | 304 std::vector<NotificationItem> items = notification.items(); |
302 for (size_t i = 0; i < items.size() && i < kNotificationMaximumItems; ++i) { | 305 for (size_t i = 0; i < items.size() && i < kNotificationMaximumItems; ++i) { |
303 accessible_lines.push_back(items[i].title + base::ASCIIToUTF16(" ") + | 306 accessible_lines.push_back(items[i].title + base::ASCIIToUTF16(" ") + |
304 items[i].message); | 307 items[i].message); |
305 } | 308 } |
306 set_accessible_name( | 309 set_accessible_name( |
307 base::JoinString(accessible_lines, base::ASCIIToUTF16("\n"))); | 310 base::JoinString(accessible_lines, base::ASCIIToUTF16("\n"))); |
308 } | 311 } |
309 | 312 |
310 NotificationView::NotificationView(MessageCenterController* controller, | 313 NotificationView::NotificationView(MessageCenterController* controller, |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 kDimTextBackgroundColor); | 549 kDimTextBackgroundColor); |
547 message_view_->SetBorder(MakeTextBorder(padding, 4, 0)); | 550 message_view_->SetBorder(MakeTextBorder(padding, 4, 0)); |
548 top_view_->AddChildView(message_view_); | 551 top_view_->AddChildView(message_view_); |
549 } else { | 552 } else { |
550 message_view_->SetText(text); | 553 message_view_->SetText(text); |
551 } | 554 } |
552 | 555 |
553 message_view_->SetVisible(!notification.items().size()); | 556 message_view_->SetVisible(!notification.items().size()); |
554 } | 557 } |
555 | 558 |
| 559 base::string16 NotificationView::FormatContextMessage( |
| 560 const ContextMessage& context) const { |
| 561 if (context.is_origin) { |
| 562 GURL url(context.message); |
| 563 if (!url.is_valid()) |
| 564 return base::UTF8ToUTF16(url.possibly_invalid_spec()); |
| 565 return url_formatter::ElideHost(url, views::Label().font_list(), |
| 566 kContextMessageViewWidth); |
| 567 } |
| 568 |
| 569 return gfx::TruncateString( |
| 570 base::UTF8ToUTF16(context.message), |
| 571 kContextMessageCharacterLimit, gfx::WORD_BREAK); |
| 572 } |
| 573 |
556 void NotificationView::CreateOrUpdateContextMessageView( | 574 void NotificationView::CreateOrUpdateContextMessageView( |
557 const Notification& notification) { | 575 const Notification& notification) { |
558 if (notification.context_message().empty()) { | 576 if (notification.context_message().message.empty()) { |
559 if (context_message_view_) { | 577 if (context_message_view_) { |
560 // Deletion will also remove |context_message_view_| from its parent. | 578 // Deletion will also remove |context_message_view_| from its parent. |
561 delete context_message_view_; | 579 delete context_message_view_; |
562 context_message_view_ = NULL; | 580 context_message_view_ = NULL; |
563 } | 581 } |
564 return; | 582 return; |
565 } | 583 } |
566 | 584 |
567 DCHECK(top_view_ != NULL); | 585 DCHECK(top_view_ != NULL); |
568 | 586 |
569 base::string16 text = gfx::TruncateString(notification.context_message(), | 587 base::string16 message = FormatContextMessage(notification.context_message()); |
570 kContextMessageCharacterLimit, | 588 |
571 gfx::WORD_BREAK); | |
572 if (!context_message_view_) { | 589 if (!context_message_view_) { |
573 int padding = kMessageLineHeight - views::Label().font_list().GetHeight(); | 590 int padding = kMessageLineHeight - views::Label().font_list().GetHeight(); |
574 context_message_view_ = new BoundedLabel(text); | 591 context_message_view_ = new BoundedLabel(message); |
575 context_message_view_->SetLineLimit( | 592 context_message_view_->SetLineLimit( |
576 message_center::kContextMessageLineLimit); | 593 message_center::kContextMessageLineLimit); |
577 context_message_view_->SetLineHeight(kMessageLineHeight); | 594 context_message_view_->SetLineHeight(kMessageLineHeight); |
578 context_message_view_->SetColors(message_center::kDimTextColor, | 595 context_message_view_->SetColors(message_center::kDimTextColor, |
579 kContextTextBackgroundColor); | 596 kContextTextBackgroundColor); |
580 context_message_view_->SetBorder(MakeTextBorder(padding, 4, 0)); | 597 context_message_view_->SetBorder(MakeTextBorder(padding, 4, 0)); |
581 top_view_->AddChildView(context_message_view_); | 598 top_view_->AddChildView(context_message_view_); |
582 } else { | 599 } else { |
583 context_message_view_->SetText(text); | 600 context_message_view_->SetText(message); |
584 } | 601 } |
585 } | 602 } |
586 | 603 |
587 void NotificationView::CreateOrUpdateProgressBarView( | 604 void NotificationView::CreateOrUpdateProgressBarView( |
588 const Notification& notification) { | 605 const Notification& notification) { |
589 if (notification.type() != NOTIFICATION_TYPE_PROGRESS) { | 606 if (notification.type() != NOTIFICATION_TYPE_PROGRESS) { |
590 if (progress_bar_view_) { | 607 if (progress_bar_view_) { |
591 // Deletion will also remove |progress_bar_view_| from its parent. | 608 // Deletion will also remove |progress_bar_view_| from its parent. |
592 delete progress_bar_view_; | 609 delete progress_bar_view_; |
593 progress_bar_view_ = NULL; | 610 progress_bar_view_ = NULL; |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
770 | 787 |
771 return message_line_limit; | 788 return message_line_limit; |
772 } | 789 } |
773 | 790 |
774 int NotificationView::GetMessageHeight(int width, int limit) const { | 791 int NotificationView::GetMessageHeight(int width, int limit) const { |
775 return message_view_ ? | 792 return message_view_ ? |
776 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0; | 793 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0; |
777 } | 794 } |
778 | 795 |
779 } // namespace message_center | 796 } // namespace message_center |
OLD | NEW |