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_style.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 MessageCenterTray
* tray
)
27 : message_center_(message_center
),
30 weak_ptr_factory_(this),
31 max_height_(kMessageBubbleBaseDefaultMaxHeight
) {
34 MessageBubbleBase::~MessageBubbleBase() {
36 bubble_view_
->reset_delegate();
39 void MessageBubbleBase::BubbleViewDestroyed() {
41 OnBubbleViewDestroyed();
44 void MessageBubbleBase::ScheduleUpdate() {
45 weak_ptr_factory_
.InvalidateWeakPtrs(); // Cancel any pending update.
46 base::MessageLoop::current()->PostDelayedTask(
48 base::Bind(&MessageBubbleBase::UpdateBubbleView
,
49 weak_ptr_factory_
.GetWeakPtr()),
50 base::TimeDelta::FromMilliseconds(kUpdateDelayMs
));
53 bool MessageBubbleBase::IsVisible() const {
54 return bubble_view() && bubble_view()->GetWidget()->IsVisible();
57 void MessageBubbleBase::SetMaxHeight(int height
) {
58 // Maximum height makes sense only for the new design.
60 height
= kMessageBubbleBaseDefaultMaxHeight
;
61 if (height
== max_height_
)
66 bubble_view_
->SetMaxHeight(max_height_
);
69 views::TrayBubbleView::InitParams
MessageBubbleBase::GetDefaultInitParams(
70 views::TrayBubbleView::AnchorAlignment anchor_alignment
) {
71 views::TrayBubbleView::InitParams
init_params(
72 views::TrayBubbleView::ANCHOR_TYPE_TRAY
,
76 init_params
.arrow_color
= kBackgroundDarkColor
;
80 } // namespace message_center