Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(705)

Unified Diff: ui/message_center/views/custom_notification_view.cc

Issue 1979583003: Support notifications with custom content (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@messageview-close-button
Patch Set: fix mac build, attempt 2 Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/message_center/views/custom_notification_view.cc
diff --git a/ui/message_center/views/custom_notification_view.cc b/ui/message_center/views/custom_notification_view.cc
new file mode 100644
index 0000000000000000000000000000000000000000..5e53a4cbc501fbe2e8192f4f8ee6f23adf1be8c5
--- /dev/null
+++ b/ui/message_center/views/custom_notification_view.cc
@@ -0,0 +1,70 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/message_center/views/custom_notification_view.h"
+
+#include <algorithm>
+
+#include "ui/gfx/geometry/size.h"
+#include "ui/message_center/message_center_style.h"
+#include "ui/views/background.h"
+#include "ui/views/controls/button/image_button.h"
+#include "ui/views/controls/image_view.h"
+
+namespace message_center {
+
+CustomNotificationView::CustomNotificationView(
+ MessageCenterController* controller,
+ const Notification& notification)
+ : MessageView(controller, notification) {
+ DCHECK_EQ(NOTIFICATION_TYPE_CUSTOM, notification.type());
+
+ contents_view_ = notification.delegate()->CreateCustomContent().release();
+ DCHECK(contents_view_);
+ AddChildView(contents_view_);
+
+ if (contents_view_->background()) {
+ background_view()->background()->SetNativeControlColor(
+ contents_view_->background()->get_color());
+ }
+
+ AddChildView(small_image());
+
+ CreateOrUpdateCloseButtonView(notification);
+
+ // Use a layer for close button so that custom content does not eclipse it.
+ if (close_button())
+ close_button()->SetPaintToLayer(true);
+}
+
+CustomNotificationView::~CustomNotificationView() {}
+
+void CustomNotificationView::SetDrawBackgroundAsActive(bool active) {
+ // Do nothing if |contents_view_| has a background.
+ if (contents_view_->background())
+ return;
+
+ MessageView::SetDrawBackgroundAsActive(active);
+}
+
+gfx::Size CustomNotificationView::GetPreferredSize() const {
+ const gfx::Insets insets = GetInsets();
+ const int contents_width = kNotificationWidth - insets.width();
+ const int contents_height = contents_view_->GetHeightForWidth(contents_width);
+
+ const int kMaxHeight = 240;
+ const int kMinHeight = 100;
+ return gfx::Size(
+ kNotificationWidth,
+ std::max(kMinHeight,
+ std::min(kMaxHeight, contents_height + insets.height())));
+}
+
+void CustomNotificationView::Layout() {
+ MessageView::Layout();
+
+ contents_view_->SetBoundsRect(GetContentsBounds());
+}
+
+} // namespace message_center
« no previous file with comments | « ui/message_center/views/custom_notification_view.h ('k') | ui/message_center/views/custom_notification_view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698