| 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 bool NotificationView::UseOriginAsContextMesssage( |
| 559 const Notification& notification) const { |
| 560 const GURL url = notification.origin_url(); |
| 561 return notification.context_message().empty() && url.is_valid() && |
| 562 url.SchemeIsHTTPOrHTTPS(); |
| 563 } |
| 564 |
| 565 base::string16 NotificationView::FormatContextMessage( |
| 566 const Notification& notification) const { |
| 567 const GURL url = notification.origin_url(); |
| 568 |
| 569 if (UseOriginAsContextMesssage(notification)) { |
| 570 return url_formatter::ElideHost(url, views::Label().font_list(), |
| 571 kContextMessageViewWidth); |
| 572 } |
| 573 |
| 574 return gfx::TruncateString(notification.context_message(), |
| 575 kContextMessageCharacterLimit, gfx::WORD_BREAK); |
| 576 } |
| 577 |
| 556 void NotificationView::CreateOrUpdateContextMessageView( | 578 void NotificationView::CreateOrUpdateContextMessageView( |
| 557 const Notification& notification) { | 579 const Notification& notification) { |
| 558 if (notification.context_message().empty()) { | 580 if (notification.context_message().empty() && |
| 581 !UseOriginAsContextMesssage(notification)) { |
| 559 if (context_message_view_) { | 582 if (context_message_view_) { |
| 560 // Deletion will also remove |context_message_view_| from its parent. | 583 // Deletion will also remove |context_message_view_| from its parent. |
| 561 delete context_message_view_; | 584 delete context_message_view_; |
| 562 context_message_view_ = NULL; | 585 context_message_view_ = NULL; |
| 563 } | 586 } |
| 564 return; | 587 return; |
| 565 } | 588 } |
| 566 | 589 |
| 567 DCHECK(top_view_ != NULL); | 590 DCHECK(top_view_ != NULL); |
| 568 | 591 |
| 569 base::string16 text = gfx::TruncateString(notification.context_message(), | 592 base::string16 message = FormatContextMessage(notification); |
| 570 kContextMessageCharacterLimit, | 593 |
| 571 gfx::WORD_BREAK); | |
| 572 if (!context_message_view_) { | 594 if (!context_message_view_) { |
| 573 int padding = kMessageLineHeight - views::Label().font_list().GetHeight(); | 595 int padding = kMessageLineHeight - views::Label().font_list().GetHeight(); |
| 574 context_message_view_ = new BoundedLabel(text); | 596 context_message_view_ = new BoundedLabel(message); |
| 575 context_message_view_->SetLineLimit( | 597 context_message_view_->SetLineLimit( |
| 576 message_center::kContextMessageLineLimit); | 598 message_center::kContextMessageLineLimit); |
| 577 context_message_view_->SetLineHeight(kMessageLineHeight); | 599 context_message_view_->SetLineHeight(kMessageLineHeight); |
| 578 context_message_view_->SetColors(message_center::kDimTextColor, | 600 context_message_view_->SetColors(message_center::kDimTextColor, |
| 579 kContextTextBackgroundColor); | 601 kContextTextBackgroundColor); |
| 580 context_message_view_->SetBorder(MakeTextBorder(padding, 4, 0)); | 602 context_message_view_->SetBorder(MakeTextBorder(padding, 4, 0)); |
| 581 top_view_->AddChildView(context_message_view_); | 603 top_view_->AddChildView(context_message_view_); |
| 582 } else { | 604 } else { |
| 583 context_message_view_->SetText(text); | 605 context_message_view_->SetText(message); |
| 584 } | 606 } |
| 585 } | 607 } |
| 586 | 608 |
| 587 void NotificationView::CreateOrUpdateProgressBarView( | 609 void NotificationView::CreateOrUpdateProgressBarView( |
| 588 const Notification& notification) { | 610 const Notification& notification) { |
| 589 if (notification.type() != NOTIFICATION_TYPE_PROGRESS) { | 611 if (notification.type() != NOTIFICATION_TYPE_PROGRESS) { |
| 590 if (progress_bar_view_) { | 612 if (progress_bar_view_) { |
| 591 // Deletion will also remove |progress_bar_view_| from its parent. | 613 // Deletion will also remove |progress_bar_view_| from its parent. |
| 592 delete progress_bar_view_; | 614 delete progress_bar_view_; |
| 593 progress_bar_view_ = NULL; | 615 progress_bar_view_ = NULL; |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 770 | 792 |
| 771 return message_line_limit; | 793 return message_line_limit; |
| 772 } | 794 } |
| 773 | 795 |
| 774 int NotificationView::GetMessageHeight(int width, int limit) const { | 796 int NotificationView::GetMessageHeight(int width, int limit) const { |
| 775 return message_view_ ? | 797 return message_view_ ? |
| 776 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0; | 798 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0; |
| 777 } | 799 } |
| 778 | 800 |
| 779 } // namespace message_center | 801 } // namespace message_center |
| OLD | NEW |