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/views/widget/widget.h"
10 #include "ui/views/widget/widget_observer.h"
13 // Delay laying out the MessageBubbleBase until all notifications have been
14 // added and icons have had a chance to load.
15 const int kUpdateDelayMs
= 50;
16 const int kMessageBubbleBaseDefaultMaxHeight
= 400;
19 namespace message_center
{
21 const SkColor
MessageBubbleBase::kBackgroundColor
=
22 SkColorSetRGB(0xfe, 0xfe, 0xfe);
24 MessageBubbleBase::MessageBubbleBase(MessageCenter
* message_center
,
25 MessageCenterTray
* tray
)
26 : message_center_(message_center
),
29 max_height_(kMessageBubbleBaseDefaultMaxHeight
),
30 weak_ptr_factory_(this) {
33 MessageBubbleBase::~MessageBubbleBase() {
35 bubble_view_
->reset_delegate();
38 void MessageBubbleBase::BubbleViewDestroyed() {
40 OnBubbleViewDestroyed();
43 void MessageBubbleBase::ScheduleUpdate() {
44 weak_ptr_factory_
.InvalidateWeakPtrs(); // Cancel any pending update.
45 base::MessageLoop::current()->PostDelayedTask(
47 base::Bind(&MessageBubbleBase::UpdateBubbleView
,
48 weak_ptr_factory_
.GetWeakPtr()),
49 base::TimeDelta::FromMilliseconds(kUpdateDelayMs
));
52 bool MessageBubbleBase::IsVisible() const {
53 return bubble_view() && bubble_view()->GetWidget()->IsVisible();
56 void MessageBubbleBase::SetMaxHeight(int height
) {
57 // Maximum height makes sense only for the new design.
59 height
= kMessageBubbleBaseDefaultMaxHeight
;
60 if (height
== max_height_
)
65 bubble_view_
->SetMaxHeight(max_height_
);
68 views::TrayBubbleView::InitParams
MessageBubbleBase::GetDefaultInitParams(
69 views::TrayBubbleView::AnchorAlignment anchor_alignment
) {
70 views::TrayBubbleView::InitParams
init_params(
71 views::TrayBubbleView::ANCHOR_TYPE_TRAY
,
75 init_params
.arrow_color
= kBackgroundDarkColor
;
79 } // namespace message_center