| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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_control_buttons_view.h" | 5 #include "ui/message_center/views/notification_control_buttons_view.h" |
| 6 | 6 |
| 7 #include "ui/base/l10n/l10n_util.h" | 7 #include "ui/base/l10n/l10n_util.h" |
| 8 #include "ui/compositor/layer.h" | 8 #include "ui/compositor/layer.h" |
| 9 #include "ui/events/event.h" | 9 #include "ui/events/event.h" |
| 10 #include "ui/gfx/animation/linear_animation.h" | 10 #include "ui/gfx/animation/linear_animation.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 bgcolor_target_(kInitialBackgroundColor) { | 39 bgcolor_target_(kInitialBackgroundColor) { |
| 40 DCHECK(message_view); | 40 DCHECK(message_view); |
| 41 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal)); | 41 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal)); |
| 42 SetBackground(views::CreateSolidBackground(kInitialBackgroundColor)); | 42 SetBackground(views::CreateSolidBackground(kInitialBackgroundColor)); |
| 43 } | 43 } |
| 44 | 44 |
| 45 NotificationControlButtonsView::~NotificationControlButtonsView() = default; | 45 NotificationControlButtonsView::~NotificationControlButtonsView() = default; |
| 46 | 46 |
| 47 void NotificationControlButtonsView::ShowCloseButton(bool show) { | 47 void NotificationControlButtonsView::ShowCloseButton(bool show) { |
| 48 if (show && !close_button_) { | 48 if (show && !close_button_) { |
| 49 close_button_ = new message_center::PaddedButton(this); | 49 close_button_ = base::MakeUnique<message_center::PaddedButton>(this); |
| 50 close_button_->set_owned_by_client(); |
| 50 close_button_->SetImage(views::CustomButton::STATE_NORMAL, | 51 close_button_->SetImage(views::CustomButton::STATE_NORMAL, |
| 51 message_center::GetCloseIcon()); | 52 message_center::GetCloseIcon()); |
| 52 close_button_->SetAccessibleName(l10n_util::GetStringUTF16( | 53 close_button_->SetAccessibleName(l10n_util::GetStringUTF16( |
| 53 IDS_MESSAGE_CENTER_CLOSE_NOTIFICATION_BUTTON_ACCESSIBLE_NAME)); | 54 IDS_MESSAGE_CENTER_CLOSE_NOTIFICATION_BUTTON_ACCESSIBLE_NAME)); |
| 54 close_button_->SetTooltipText(l10n_util::GetStringUTF16( | 55 close_button_->SetTooltipText(l10n_util::GetStringUTF16( |
| 55 IDS_MESSAGE_CENTER_CLOSE_NOTIFICATION_BUTTON_TOOLTIP)); | 56 IDS_MESSAGE_CENTER_CLOSE_NOTIFICATION_BUTTON_TOOLTIP)); |
| 56 close_button_->SetBackground( | 57 close_button_->SetBackground( |
| 57 views::CreateSolidBackground(SK_ColorTRANSPARENT)); | 58 views::CreateSolidBackground(SK_ColorTRANSPARENT)); |
| 58 | 59 |
| 59 // Add the button at the last. | 60 // Add the button at the last. |
| 60 DCHECK_LE(child_count(), 1); | 61 DCHECK_LE(child_count(), 1); |
| 61 AddChildView(close_button_); | 62 AddChildView(close_button_.get()); |
| 62 } else if (!show && close_button_) { | 63 } else if (!show && close_button_) { |
| 63 RemoveChildView(close_button_); | 64 DCHECK(Contains(close_button_.get())); |
| 64 close_button_ = nullptr; | 65 close_button_.reset(); |
| 65 } | 66 } |
| 66 } | 67 } |
| 67 | 68 |
| 68 void NotificationControlButtonsView::ShowSettingsButton(bool show) { | 69 void NotificationControlButtonsView::ShowSettingsButton(bool show) { |
| 69 if (show && !settings_button_) { | 70 if (show && !settings_button_) { |
| 70 settings_button_ = new message_center::PaddedButton(this); | 71 settings_button_ = base::MakeUnique<message_center::PaddedButton>(this); |
| 72 settings_button_->set_owned_by_client(); |
| 71 settings_button_->SetImage(views::CustomButton::STATE_NORMAL, | 73 settings_button_->SetImage(views::CustomButton::STATE_NORMAL, |
| 72 message_center::GetSettingsIcon()); | 74 message_center::GetSettingsIcon()); |
| 73 settings_button_->SetAccessibleName(l10n_util::GetStringUTF16( | 75 settings_button_->SetAccessibleName(l10n_util::GetStringUTF16( |
| 74 IDS_MESSAGE_NOTIFICATION_SETTINGS_BUTTON_ACCESSIBLE_NAME)); | 76 IDS_MESSAGE_NOTIFICATION_SETTINGS_BUTTON_ACCESSIBLE_NAME)); |
| 75 settings_button_->SetTooltipText(l10n_util::GetStringUTF16( | 77 settings_button_->SetTooltipText(l10n_util::GetStringUTF16( |
| 76 IDS_MESSAGE_NOTIFICATION_SETTINGS_BUTTON_ACCESSIBLE_NAME)); | 78 IDS_MESSAGE_NOTIFICATION_SETTINGS_BUTTON_ACCESSIBLE_NAME)); |
| 77 settings_button_->SetBackground( | 79 settings_button_->SetBackground( |
| 78 views::CreateSolidBackground(SK_ColorTRANSPARENT)); | 80 views::CreateSolidBackground(SK_ColorTRANSPARENT)); |
| 79 | 81 |
| 80 // Add the button at the first. | 82 // Add the button at the first. |
| 81 DCHECK_LE(child_count(), 1); | 83 DCHECK_LE(child_count(), 1); |
| 82 AddChildViewAt(settings_button_, 0); | 84 AddChildViewAt(settings_button_.get(), 0); |
| 83 } else if (!show && settings_button_) { | 85 } else if (!show && settings_button_) { |
| 84 RemoveChildView(settings_button_); | 86 DCHECK(Contains(settings_button_.get())); |
| 85 settings_button_ = nullptr; | 87 settings_button_.reset(); |
| 86 } | 88 } |
| 87 } | 89 } |
| 88 | 90 |
| 89 void NotificationControlButtonsView::SetBackgroundColor( | 91 void NotificationControlButtonsView::SetBackgroundColor( |
| 90 const SkColor& target_bgcolor) { | 92 const SkColor& target_bgcolor) { |
| 91 if (background()->get_color() != target_bgcolor) { | 93 if (background()->get_color() != target_bgcolor) { |
| 92 bgcolor_origin_ = background()->get_color(); | 94 bgcolor_origin_ = background()->get_color(); |
| 93 bgcolor_target_ = target_bgcolor; | 95 bgcolor_target_ = target_bgcolor; |
| 94 | 96 |
| 95 if (bgcolor_animation_) | 97 if (bgcolor_animation_) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 106 } | 108 } |
| 107 | 109 |
| 108 bool NotificationControlButtonsView::IsCloseButtonFocused() const { | 110 bool NotificationControlButtonsView::IsCloseButtonFocused() const { |
| 109 return close_button_ && close_button_->HasFocus(); | 111 return close_button_ && close_button_->HasFocus(); |
| 110 } | 112 } |
| 111 | 113 |
| 112 bool NotificationControlButtonsView::IsSettingsButtonFocused() const { | 114 bool NotificationControlButtonsView::IsSettingsButtonFocused() const { |
| 113 return settings_button_ && settings_button_->HasFocus(); | 115 return settings_button_ && settings_button_->HasFocus(); |
| 114 } | 116 } |
| 115 | 117 |
| 118 message_center::PaddedButton* |
| 119 NotificationControlButtonsView::close_button_for_testing() const { |
| 120 return close_button_.get(); |
| 121 } |
| 122 |
| 123 message_center::PaddedButton* |
| 124 NotificationControlButtonsView::settings_button_for_testing() const { |
| 125 return settings_button_.get(); |
| 126 } |
| 127 |
| 116 const char* NotificationControlButtonsView::GetClassName() const { | 128 const char* NotificationControlButtonsView::GetClassName() const { |
| 117 return kViewClassName; | 129 return kViewClassName; |
| 118 } | 130 } |
| 119 | 131 |
| 120 void NotificationControlButtonsView::ButtonPressed(views::Button* sender, | 132 void NotificationControlButtonsView::ButtonPressed(views::Button* sender, |
| 121 const ui::Event& event) { | 133 const ui::Event& event) { |
| 122 if (close_button_ && sender == close_button_) { | 134 if (close_button_ && sender == close_button_.get()) { |
| 123 message_view_->OnCloseButtonPressed(); | 135 message_view_->OnCloseButtonPressed(); |
| 124 } else if (settings_button_ && sender == settings_button_) { | 136 } else if (settings_button_ && sender == settings_button_.get()) { |
| 125 message_view_->OnSettingsButtonPressed(); | 137 message_view_->OnSettingsButtonPressed(); |
| 126 } | 138 } |
| 127 } | 139 } |
| 128 | 140 |
| 129 void NotificationControlButtonsView::AnimationProgressed( | 141 void NotificationControlButtonsView::AnimationProgressed( |
| 130 const gfx::Animation* animation) { | 142 const gfx::Animation* animation) { |
| 131 DCHECK_EQ(animation, bgcolor_animation_.get()); | 143 DCHECK_EQ(animation, bgcolor_animation_.get()); |
| 132 | 144 |
| 133 const SkColor color = gfx::Tween::ColorValueBetween( | 145 const SkColor color = gfx::Tween::ColorValueBetween( |
| 134 animation->GetCurrentValue(), bgcolor_origin_, bgcolor_target_); | 146 animation->GetCurrentValue(), bgcolor_origin_, bgcolor_target_); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 147 const gfx::Animation* animation) { | 159 const gfx::Animation* animation) { |
| 148 // The animation is never cancelled explicitly. | 160 // The animation is never cancelled explicitly. |
| 149 NOTREACHED(); | 161 NOTREACHED(); |
| 150 | 162 |
| 151 bgcolor_origin_ = bgcolor_target_; | 163 bgcolor_origin_ = bgcolor_target_; |
| 152 SetBackground(views::CreateSolidBackground(bgcolor_target_)); | 164 SetBackground(views::CreateSolidBackground(bgcolor_target_)); |
| 153 SchedulePaint(); | 165 SchedulePaint(); |
| 154 } | 166 } |
| 155 | 167 |
| 156 } // namespace message_center | 168 } // namespace message_center |
| OLD | NEW |