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/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
9 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
10 #include "grit/ui_resources.h" | 11 #include "grit/ui_resources.h" |
11 #include "grit/ui_strings.h" | 12 #include "grit/ui_strings.h" |
12 #include "ui/base/cursor/cursor.h" | 13 #include "ui/base/cursor/cursor.h" |
13 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" |
14 #include "ui/base/layout.h" | 15 #include "ui/base/layout.h" |
15 #include "ui/base/resource/resource_bundle.h" | 16 #include "ui/base/resource/resource_bundle.h" |
16 #include "ui/gfx/canvas.h" | 17 #include "ui/gfx/canvas.h" |
17 #include "ui/gfx/size.h" | 18 #include "ui/gfx/size.h" |
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
444 } | 445 } |
445 | 446 |
446 views::View* NotificationView::GetEventHandlerForRect(const gfx::Rect& rect) { | 447 views::View* NotificationView::GetEventHandlerForRect(const gfx::Rect& rect) { |
447 // TODO(tdanderson): Modify this function to support rect-based event | 448 // TODO(tdanderson): Modify this function to support rect-based event |
448 // targeting. Using the center point of |rect| preserves this function's | 449 // targeting. Using the center point of |rect| preserves this function's |
449 // expected behavior for the time being. | 450 // expected behavior for the time being. |
450 gfx::Point point = rect.CenterPoint(); | 451 gfx::Point point = rect.CenterPoint(); |
451 | 452 |
452 // Want to return this for underlying views, otherwise GetCursor is not | 453 // Want to return this for underlying views, otherwise GetCursor is not |
453 // called. But buttons are exceptions, they'll have their own event handlings. | 454 // called. But buttons are exceptions, they'll have their own event handlings. |
454 std::vector<views::View*> buttons(action_buttons_); | 455 std::vector<views::View*> buttons(action_buttons_.begin(), |
456 action_buttons_.end()); | |
455 buttons.push_back(close_button()); | 457 buttons.push_back(close_button()); |
456 | 458 |
457 for (size_t i = 0; i < buttons.size(); ++i) { | 459 for (size_t i = 0; i < buttons.size(); ++i) { |
458 gfx::Point point_in_child = point; | 460 gfx::Point point_in_child = point; |
459 ConvertPointToTarget(this, buttons[i], &point_in_child); | 461 ConvertPointToTarget(this, buttons[i], &point_in_child); |
460 if (buttons[i]->HitTestPoint(point_in_child)) | 462 if (buttons[i]->HitTestPoint(point_in_child)) |
461 return buttons[i]->GetEventHandlerForPoint(point_in_child); | 463 return buttons[i]->GetEventHandlerForPoint(point_in_child); |
462 } | 464 } |
463 | 465 |
464 return this; | 466 return this; |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
695 if (!notification.image().IsEmpty()) { | 697 if (!notification.image().IsEmpty()) { |
696 gfx::Size image_size(kNotificationPreferredImageWidth, | 698 gfx::Size image_size(kNotificationPreferredImageWidth, |
697 kNotificationPreferredImageHeight); | 699 kNotificationPreferredImageHeight); |
698 image_view_ = MakeNotificationImage(notification.image(), image_size); | 700 image_view_ = MakeNotificationImage(notification.image(), image_size); |
699 bottom_view_->AddChildView(image_view_); | 701 bottom_view_->AddChildView(image_view_); |
700 } | 702 } |
701 } | 703 } |
702 | 704 |
703 void NotificationView::CreateOrUpdateActionButtonViews( | 705 void NotificationView::CreateOrUpdateActionButtonViews( |
704 const Notification& notification) { | 706 const Notification& notification) { |
705 for (size_t i = 0; i < separators_.size(); ++i) | 707 std::vector<ButtonInfo> buttons = notification.buttons(); |
706 delete separators_[i]; | 708 bool new_buttons = action_buttons_.size() != buttons.size(); |
707 separators_.clear(); | |
708 | 709 |
709 for (size_t i = 0; i < action_buttons_.size(); ++i) | 710 if (new_buttons || buttons.size() == 0) { |
710 delete action_buttons_[i]; | 711 STLDeleteContainerPointers(separators_.begin(), separators_.end()); |
711 action_buttons_.clear(); | 712 separators_.clear(); |
Jun Mukai
2014/05/23 06:24:08
STLDeleteElements() invokes DeleteContainerPointer
dewittj
2014/05/23 17:32:41
Done.
| |
713 | |
714 STLDeleteContainerPointers(action_buttons_.begin(), action_buttons_.end()); | |
715 action_buttons_.clear(); | |
716 } | |
712 | 717 |
713 DCHECK(bottom_view_); | 718 DCHECK(bottom_view_); |
714 DCHECK_EQ(this, bottom_view_->parent()); | 719 DCHECK_EQ(this, bottom_view_->parent()); |
715 | 720 |
716 std::vector<ButtonInfo> buttons = notification.buttons(); | |
717 for (size_t i = 0; i < buttons.size(); ++i) { | 721 for (size_t i = 0; i < buttons.size(); ++i) { |
718 views::View* separator = new views::ImageView(); | |
719 separator->SetBorder(MakeSeparatorBorder(1, 0, kButtonSeparatorColor)); | |
720 separators_.push_back(separator); | |
721 bottom_view_->AddChildView(separator); | |
722 NotificationButton* button = new NotificationButton(this); | |
723 ButtonInfo button_info = buttons[i]; | 722 ButtonInfo button_info = buttons[i]; |
724 button->SetTitle(button_info.title); | 723 if (new_buttons) { |
725 button->SetIcon(button_info.icon.AsImageSkia()); | 724 views::View* separator = new views::ImageView(); |
726 action_buttons_.push_back(button); | 725 separator->SetBorder(MakeSeparatorBorder(1, 0, kButtonSeparatorColor)); |
727 bottom_view_->AddChildView(button); | 726 separators_.push_back(separator); |
727 bottom_view_->AddChildView(separator); | |
728 NotificationButton* button = new NotificationButton(this); | |
729 button->SetTitle(button_info.title); | |
730 button->SetIcon(button_info.icon.AsImageSkia()); | |
731 action_buttons_.push_back(button); | |
732 bottom_view_->AddChildView(button); | |
733 } else { | |
734 action_buttons_[i]->SetTitle(button_info.title); | |
735 action_buttons_[i]->SetIcon(button_info.icon.AsImageSkia()); | |
736 action_buttons_[i]->SchedulePaint(); | |
737 action_buttons_[i]->Layout(); | |
738 } | |
739 } | |
740 | |
741 if (new_buttons) { | |
742 Layout(); | |
743 views::Widget* widget = GetWidget(); | |
744 if (widget != NULL) { | |
745 widget->SetSize(widget->GetContentsView()->GetPreferredSize()); | |
746 GetWidget()->SynthesizeMouseMoveEvent(); | |
747 } | |
728 } | 748 } |
729 } | 749 } |
730 | 750 |
731 int NotificationView::GetMessageLineLimit(int title_lines, int width) { | 751 int NotificationView::GetMessageLineLimit(int title_lines, int width) { |
732 // Image notifications require that the image must be kept flush against | 752 // Image notifications require that the image must be kept flush against |
733 // their icons, but we can allow more text if no image. | 753 // their icons, but we can allow more text if no image. |
734 int effective_title_lines = std::max(0, title_lines - 1); | 754 int effective_title_lines = std::max(0, title_lines - 1); |
735 int line_reduction_from_title = (image_view_ ? 1 : 2) * effective_title_lines; | 755 int line_reduction_from_title = (image_view_ ? 1 : 2) * effective_title_lines; |
736 if (!image_view_) { | 756 if (!image_view_) { |
737 // Title lines are counted as twice as big as message lines for the purpose | 757 // Title lines are counted as twice as big as message lines for the purpose |
(...skipping 25 matching lines...) Expand all Loading... | |
763 | 783 |
764 return message_line_limit; | 784 return message_line_limit; |
765 } | 785 } |
766 | 786 |
767 int NotificationView::GetMessageHeight(int width, int limit) { | 787 int NotificationView::GetMessageHeight(int width, int limit) { |
768 return message_view_ ? | 788 return message_view_ ? |
769 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0; | 789 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0; |
770 } | 790 } |
771 | 791 |
772 } // namespace message_center | 792 } // namespace message_center |
OLD | NEW |