Chromium Code Reviews| 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" |
| (...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 444 } | 444 } |
| 445 | 445 |
| 446 views::View* NotificationView::GetEventHandlerForRect(const gfx::Rect& rect) { | 446 views::View* NotificationView::GetEventHandlerForRect(const gfx::Rect& rect) { |
| 447 // TODO(tdanderson): Modify this function to support rect-based event | 447 // TODO(tdanderson): Modify this function to support rect-based event |
| 448 // targeting. Using the center point of |rect| preserves this function's | 448 // targeting. Using the center point of |rect| preserves this function's |
| 449 // expected behavior for the time being. | 449 // expected behavior for the time being. |
| 450 gfx::Point point = rect.CenterPoint(); | 450 gfx::Point point = rect.CenterPoint(); |
| 451 | 451 |
| 452 // Want to return this for underlying views, otherwise GetCursor is not | 452 // Want to return this for underlying views, otherwise GetCursor is not |
| 453 // called. But buttons are exceptions, they'll have their own event handlings. | 453 // called. But buttons are exceptions, they'll have their own event handlings. |
| 454 std::vector<views::View*> buttons(action_buttons_); | 454 std::vector<View*> buttons(action_buttons_.begin(), action_buttons_.end()); |
|
Jun Mukai
2014/05/13 07:23:23
I think omitting views:: namespace leads to a comp
dewittj
2014/05/20 18:32:13
Pretty sure I compiled this :) but I'll check
dewittj
2014/05/21 21:13:30
Done.
| |
| 455 buttons.push_back(close_button()); | 455 buttons.push_back(close_button()); |
| 456 | 456 |
| 457 for (size_t i = 0; i < buttons.size(); ++i) { | 457 for (size_t i = 0; i < buttons.size(); ++i) { |
| 458 gfx::Point point_in_child = point; | 458 gfx::Point point_in_child = point; |
| 459 ConvertPointToTarget(this, buttons[i], &point_in_child); | 459 ConvertPointToTarget(this, buttons[i], &point_in_child); |
| 460 if (buttons[i]->HitTestPoint(point_in_child)) | 460 if (buttons[i]->HitTestPoint(point_in_child)) |
| 461 return buttons[i]->GetEventHandlerForPoint(point_in_child); | 461 return buttons[i]->GetEventHandlerForPoint(point_in_child); |
| 462 } | 462 } |
| 463 | 463 |
| 464 return this; | 464 return this; |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 695 if (!notification.image().IsEmpty()) { | 695 if (!notification.image().IsEmpty()) { |
| 696 gfx::Size image_size(kNotificationPreferredImageWidth, | 696 gfx::Size image_size(kNotificationPreferredImageWidth, |
| 697 kNotificationPreferredImageHeight); | 697 kNotificationPreferredImageHeight); |
| 698 image_view_ = MakeNotificationImage(notification.image(), image_size); | 698 image_view_ = MakeNotificationImage(notification.image(), image_size); |
| 699 bottom_view_->AddChildView(image_view_); | 699 bottom_view_->AddChildView(image_view_); |
| 700 } | 700 } |
| 701 } | 701 } |
| 702 | 702 |
| 703 void NotificationView::CreateOrUpdateActionButtonViews( | 703 void NotificationView::CreateOrUpdateActionButtonViews( |
| 704 const Notification& notification) { | 704 const Notification& notification) { |
| 705 for (size_t i = 0; i < separators_.size(); ++i) | 705 std::vector<ButtonInfo> buttons = notification.buttons(); |
|
Jun Mukai
2014/05/13 07:23:23
const &?
dewittj
2014/05/20 18:32:13
I don't like marking the result of a method call a
| |
| 706 delete separators_[i]; | 706 bool new_buttons = action_buttons_.size() != buttons.size(); |
| 707 separators_.clear(); | |
| 708 | 707 |
| 709 for (size_t i = 0; i < action_buttons_.size(); ++i) | 708 if (new_buttons || buttons.size() == 0) { |
|
Jun Mukai
2014/05/13 07:23:23
Does this means that if the hover state will be lo
dewittj
2014/05/20 18:32:13
It does mean this. However for frequent updates,
| |
| 710 delete action_buttons_[i]; | 709 for (size_t i = 0; i < separators_.size(); ++i) |
| 711 action_buttons_.clear(); | 710 delete separators_[i]; |
| 711 separators_.clear(); | |
|
Jun Mukai
2014/05/13 07:23:23
I think STLDeleteElements(&separators_); (in base/
dewittj
2014/05/20 18:32:13
Will do!
| |
| 712 | |
| 713 for (size_t i = 0; i < action_buttons_.size(); ++i) | |
| 714 delete action_buttons_[i]; | |
| 715 action_buttons_.clear(); | |
|
Jun Mukai
2014/05/13 07:23:23
ditto
dewittj
2014/05/21 21:13:30
Done.
| |
| 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 } | |
| 728 } | 739 } |
| 729 } | 740 } |
| 730 | 741 |
| 731 int NotificationView::GetMessageLineLimit(int title_lines, int width) { | 742 int NotificationView::GetMessageLineLimit(int title_lines, int width) { |
| 732 // Image notifications require that the image must be kept flush against | 743 // Image notifications require that the image must be kept flush against |
| 733 // their icons, but we can allow more text if no image. | 744 // their icons, but we can allow more text if no image. |
| 734 int effective_title_lines = std::max(0, title_lines - 1); | 745 int effective_title_lines = std::max(0, title_lines - 1); |
| 735 int line_reduction_from_title = (image_view_ ? 1 : 2) * effective_title_lines; | 746 int line_reduction_from_title = (image_view_ ? 1 : 2) * effective_title_lines; |
| 736 if (!image_view_) { | 747 if (!image_view_) { |
| 737 // Title lines are counted as twice as big as message lines for the purpose | 748 // Title lines are counted as twice as big as message lines for the purpose |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 763 | 774 |
| 764 return message_line_limit; | 775 return message_line_limit; |
| 765 } | 776 } |
| 766 | 777 |
| 767 int NotificationView::GetMessageHeight(int width, int limit) { | 778 int NotificationView::GetMessageHeight(int width, int limit) { |
| 768 return message_view_ ? | 779 return message_view_ ? |
| 769 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0; | 780 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0; |
| 770 } | 781 } |
| 771 | 782 |
| 772 } // namespace message_center | 783 } // namespace message_center |
| OLD | NEW |