| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/custom_notification_view.h" | 5 #include "ui/message_center/views/custom_notification_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "ui/gfx/geometry/size.h" | 9 #include "ui/gfx/geometry/size.h" |
| 10 #include "ui/message_center/message_center_style.h" | 10 #include "ui/message_center/message_center_style.h" |
| 11 #include "ui/views/background.h" | 11 #include "ui/views/background.h" |
| 12 #include "ui/views/controls/button/image_button.h" | 12 #include "ui/views/controls/button/image_button.h" |
| 13 #include "ui/views/controls/image_view.h" | 13 #include "ui/views/controls/image_view.h" |
| 14 | 14 |
| 15 namespace message_center { | 15 namespace message_center { |
| 16 | 16 |
| 17 CustomNotificationView::CustomNotificationView( | 17 CustomNotificationView::CustomNotificationView( |
| 18 MessageCenterController* controller, | 18 MessageCenterController* controller, |
| 19 const Notification& notification) | 19 const Notification& notification) |
| 20 : MessageView(controller, notification) { | 20 : MessageView(controller, notification) { |
| 21 DCHECK_EQ(NOTIFICATION_TYPE_CUSTOM, notification.type()); | 21 DCHECK_EQ(NOTIFICATION_TYPE_CUSTOM, notification.type()); |
| 22 | 22 |
| 23 contents_view_ = notification.delegate()->CreateCustomContent().release(); | 23 auto custom_content = notification.delegate()->CreateCustomContent(); |
| 24 |
| 25 contents_view_ = custom_content->view.release(); |
| 24 DCHECK(contents_view_); | 26 DCHECK(contents_view_); |
| 25 AddChildView(contents_view_); | 27 AddChildView(contents_view_); |
| 26 | 28 |
| 29 contents_view_delegate_ = std::move(custom_content->delegate); |
| 30 DCHECK(contents_view_delegate_); |
| 31 |
| 27 if (contents_view_->background()) { | 32 if (contents_view_->background()) { |
| 28 background_view()->background()->SetNativeControlColor( | 33 background_view()->background()->SetNativeControlColor( |
| 29 contents_view_->background()->get_color()); | 34 contents_view_->background()->get_color()); |
| 30 } | 35 } |
| 31 | 36 |
| 32 AddChildView(small_image()); | 37 AddChildView(small_image()); |
| 33 | |
| 34 CreateOrUpdateCloseButtonView(notification); | |
| 35 } | 38 } |
| 36 | 39 |
| 37 CustomNotificationView::~CustomNotificationView() {} | 40 CustomNotificationView::~CustomNotificationView() {} |
| 38 | 41 |
| 39 void CustomNotificationView::SetDrawBackgroundAsActive(bool active) { | 42 void CustomNotificationView::SetDrawBackgroundAsActive(bool active) { |
| 40 // Do nothing if |contents_view_| has a background. | 43 // Do nothing if |contents_view_| has a background. |
| 41 if (contents_view_->background()) | 44 if (contents_view_->background()) |
| 42 return; | 45 return; |
| 43 | 46 |
| 44 MessageView::SetDrawBackgroundAsActive(active); | 47 MessageView::SetDrawBackgroundAsActive(active); |
| 45 } | 48 } |
| 46 | 49 |
| 50 bool CustomNotificationView::IsCloseButtonFocused() const { |
| 51 if (!contents_view_delegate_) |
| 52 return false; |
| 53 return contents_view_delegate_->IsCloseButtonFocused(); |
| 54 } |
| 55 |
| 56 void CustomNotificationView::RequestFocusOnCloseButton() { |
| 57 if (contents_view_delegate_) |
| 58 contents_view_delegate_->RequestFocusOnCloseButton(); |
| 59 } |
| 60 |
| 61 bool CustomNotificationView::IsPinned() const { |
| 62 if (!contents_view_delegate_) |
| 63 return false; |
| 64 return contents_view_delegate_->IsPinned(); |
| 65 } |
| 66 |
| 47 gfx::Size CustomNotificationView::GetPreferredSize() const { | 67 gfx::Size CustomNotificationView::GetPreferredSize() const { |
| 48 const gfx::Insets insets = GetInsets(); | 68 const gfx::Insets insets = GetInsets(); |
| 49 const int contents_width = kNotificationWidth - insets.width(); | 69 const int contents_width = kNotificationWidth - insets.width(); |
| 50 const int contents_height = contents_view_->GetHeightForWidth(contents_width); | 70 const int contents_height = contents_view_->GetHeightForWidth(contents_width); |
| 51 | 71 |
| 52 constexpr int kMaxContentHeight = 256; | 72 constexpr int kMaxContentHeight = 256; |
| 53 constexpr int kMinContentHeight = 64; | 73 constexpr int kMinContentHeight = 64; |
| 54 return gfx::Size(kNotificationWidth, | 74 return gfx::Size(kNotificationWidth, |
| 55 std::max(kMinContentHeight + insets.height(), | 75 std::max(kMinContentHeight + insets.height(), |
| 56 std::min(kMaxContentHeight + insets.height(), | 76 std::min(kMaxContentHeight + insets.height(), |
| 57 contents_height + insets.height()))); | 77 contents_height + insets.height()))); |
| 58 } | 78 } |
| 59 | 79 |
| 60 void CustomNotificationView::Layout() { | 80 void CustomNotificationView::Layout() { |
| 61 MessageView::Layout(); | 81 MessageView::Layout(); |
| 62 | 82 |
| 63 contents_view_->SetBoundsRect(GetContentsBounds()); | 83 contents_view_->SetBoundsRect(GetContentsBounds()); |
| 64 } | 84 } |
| 65 | 85 |
| 66 } // namespace message_center | 86 } // namespace message_center |
| OLD | NEW |