Chromium Code Reviews| 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()) { | |
|
yoshiki
2016/05/16 03:31:09
nit: no need for braces.
xiyuan
2016/05/16 16:15:37
Done.
| |
| 46 return; | |
| 47 } | |
| 48 | |
| 49 MessageView::SetDrawBackgroundAsActive(active); | |
| 50 } | |
| 51 | |
| 52 gfx::Size CustomNotificationView::GetPreferredSize() const { | |
| 53 const gfx::Insets insets = GetInsets(); | |
| 54 const int contents_width = kNotificationWidth - insets.width(); | |
| 55 const int contents_height = contents_view_->GetHeightForWidth(contents_width); | |
| 56 | |
| 57 const int kMaxHeight = 240; | |
| 58 const int kMinHeight = 100; | |
| 59 return gfx::Size( | |
| 60 kNotificationWidth, | |
| 61 std::max(kMinHeight, | |
| 62 std::min(kMaxHeight, contents_height + insets.height()))); | |
| 63 } | |
| 64 | |
| 65 void CustomNotificationView::Layout() { | |
| 66 MessageView::Layout(); | |
| 67 | |
| 68 contents_view_->SetBoundsRect(GetContentsBounds()); | |
| 69 } | |
| 70 | |
| 71 } // namespace message_center | |
| OLD | NEW |