Separate Simple Backend creation from initialization.
[chromium-blink-merge.git] / ui / message_center / views / message_bubble_base.cc
blob4d35e310cf0070f98ece971a05e116b5ccf460f4
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"
7 #include "base/bind.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"
13 namespace {
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),
27 bubble_view_(NULL),
28 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)),
29 max_height_(kMessageBubbleBaseDefaultMaxHeight) {
32 MessageBubbleBase::~MessageBubbleBase() {
33 if (bubble_view_)
34 bubble_view_->reset_delegate();
37 void MessageBubbleBase::BubbleViewDestroyed() {
38 bubble_view_ = NULL;
39 OnBubbleViewDestroyed();
42 void MessageBubbleBase::ScheduleUpdate() {
43 weak_ptr_factory_.InvalidateWeakPtrs(); // Cancel any pending update.
44 MessageLoop::current()->PostDelayedTask(
45 FROM_HERE,
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())
58 return;
60 if (height == 0)
61 height = kMessageBubbleBaseDefaultMaxHeight;
62 if (height == max_height_)
63 return;
65 max_height_ = height;
66 if (bubble_view_)
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,
74 anchor_alignment,
75 kNotificationWidth,
76 kNotificationWidth);
77 init_params.arrow_color = kBackgroundDarkColor;
78 return init_params;
81 } // namespace message_center