1 // Copyright (c) 2012 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.
5 #include "ui/message_center/views/message_bubble_base.h"
8 #include "ui/message_center/message_center_constants.h"
9 #include "ui/message_center/message_center_util.h"
10 #include "ui/views/widget/widget.h"
11 #include "ui/views/widget/widget_observer.h"
14 // Delay laying out the MessageBubbleBase until all notifications have been
15 // added and icons have had a chance to load.
16 const int kUpdateDelayMs
= 50;
17 const int kMessageBubbleBaseDefaultMaxHeight
= 400;
20 namespace message_center
{
22 const SkColor
MessageBubbleBase::kBackgroundColor
=
23 SkColorSetRGB(0xfe, 0xfe, 0xfe);
25 MessageBubbleBase::MessageBubbleBase(MessageCenter
* message_center
)
26 : message_center_(message_center
),
28 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)),
29 max_height_(kMessageBubbleBaseDefaultMaxHeight
) {
32 MessageBubbleBase::~MessageBubbleBase() {
34 bubble_view_
->reset_delegate();
37 void MessageBubbleBase::BubbleViewDestroyed() {
39 OnBubbleViewDestroyed();
42 void MessageBubbleBase::ScheduleUpdate() {
43 weak_ptr_factory_
.InvalidateWeakPtrs(); // Cancel any pending update.
44 MessageLoop::current()->PostDelayedTask(
46 base::Bind(&MessageBubbleBase::UpdateBubbleView
,
47 weak_ptr_factory_
.GetWeakPtr()),
48 base::TimeDelta::FromMilliseconds(kUpdateDelayMs
));
51 bool MessageBubbleBase::IsVisible() const {
52 return bubble_view() && bubble_view()->GetWidget()->IsVisible();
55 void MessageBubbleBase::SetMaxHeight(int height
) {
56 // Maximum height makes sense only for the new design.
57 if (!message_center::IsRichNotificationEnabled())
61 height
= kMessageBubbleBaseDefaultMaxHeight
;
62 if (height
== max_height_
)
67 bubble_view_
->SetMaxHeight(max_height_
);
70 views::TrayBubbleView::InitParams
MessageBubbleBase::GetDefaultInitParams(
71 views::TrayBubbleView::AnchorAlignment anchor_alignment
) {
72 views::TrayBubbleView::InitParams
init_params(
73 views::TrayBubbleView::ANCHOR_TYPE_TRAY
,
77 init_params
.arrow_color
= kBackgroundDarkColor
;
81 } // namespace message_center