| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ui/message_center/views/custom_notification_view.h" |
| 6 |
| 7 #include <algorithm> |
| 8 |
| 9 #include "ui/gfx/geometry/size.h" |
| 10 #include "ui/message_center/message_center_style.h" |
| 11 #include "ui/views/background.h" |
| 12 #include "ui/views/controls/button/image_button.h" |
| 13 #include "ui/views/controls/image_view.h" |
| 14 |
| 15 namespace message_center { |
| 16 |
| 17 CustomNotificationView::CustomNotificationView( |
| 18 MessageCenterController* controller, |
| 19 const Notification& notification) |
| 20 : MessageView(controller, notification) { |
| 21 DCHECK_EQ(NOTIFICATION_TYPE_CUSTOM, notification.type()); |
| 22 |
| 23 contents_view_ = notification.delegate()->CreateCustomContent().release(); |
| 24 DCHECK(contents_view_); |
| 25 AddChildView(contents_view_); |
| 26 |
| 27 if (contents_view_->background()) { |
| 28 background_view()->background()->SetNativeControlColor( |
| 29 contents_view_->background()->get_color()); |
| 30 } |
| 31 |
| 32 AddChildView(small_image()); |
| 33 |
| 34 CreateOrUpdateCloseButtonView(notification); |
| 35 |
| 36 // Use a layer for close button so that custom content does not eclipse it. |
| 37 if (close_button()) |
| 38 close_button()->SetPaintToLayer(true); |
| 39 } |
| 40 |
| 41 CustomNotificationView::~CustomNotificationView() {} |
| 42 |
| 43 void CustomNotificationView::SetDrawBackgroundAsActive(bool active) { |
| 44 // Do nothing if |contents_view_| has a background. |
| 45 if (contents_view_->background()) |
| 46 return; |
| 47 |
| 48 MessageView::SetDrawBackgroundAsActive(active); |
| 49 } |
| 50 |
| 51 gfx::Size CustomNotificationView::GetPreferredSize() const { |
| 52 const gfx::Insets insets = GetInsets(); |
| 53 const int contents_width = kNotificationWidth - insets.width(); |
| 54 const int contents_height = contents_view_->GetHeightForWidth(contents_width); |
| 55 |
| 56 const int kMaxHeight = 240; |
| 57 const int kMinHeight = 100; |
| 58 return gfx::Size( |
| 59 kNotificationWidth, |
| 60 std::max(kMinHeight, |
| 61 std::min(kMaxHeight, contents_height + insets.height()))); |
| 62 } |
| 63 |
| 64 void CustomNotificationView::Layout() { |
| 65 MessageView::Layout(); |
| 66 |
| 67 contents_view_->SetBoundsRect(GetContentsBounds()); |
| 68 } |
| 69 |
| 70 } // namespace message_center |
| OLD | NEW |