• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "ui/message_center/views/message_bubble_base.h"
6 
7 #include "base/bind.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"
11 
12 namespace {
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;
17 }
18 
19 namespace message_center {
20 
21 const SkColor MessageBubbleBase::kBackgroundColor =
22     SkColorSetRGB(0xfe, 0xfe, 0xfe);
23 
MessageBubbleBase(MessageCenter * message_center,MessageCenterTray * tray)24 MessageBubbleBase::MessageBubbleBase(MessageCenter* message_center,
25                                      MessageCenterTray* tray)
26     : message_center_(message_center),
27       tray_(tray),
28       bubble_view_(NULL),
29       max_height_(kMessageBubbleBaseDefaultMaxHeight),
30       weak_ptr_factory_(this) {
31 }
32 
~MessageBubbleBase()33 MessageBubbleBase::~MessageBubbleBase() {
34   if (bubble_view_)
35     bubble_view_->reset_delegate();
36 }
37 
BubbleViewDestroyed()38 void MessageBubbleBase::BubbleViewDestroyed() {
39   bubble_view_ = NULL;
40   OnBubbleViewDestroyed();
41 }
42 
ScheduleUpdate()43 void MessageBubbleBase::ScheduleUpdate() {
44   weak_ptr_factory_.InvalidateWeakPtrs();  // Cancel any pending update.
45   base::MessageLoop::current()->PostDelayedTask(
46       FROM_HERE,
47       base::Bind(&MessageBubbleBase::UpdateBubbleView,
48                  weak_ptr_factory_.GetWeakPtr()),
49       base::TimeDelta::FromMilliseconds(kUpdateDelayMs));
50 }
51 
IsVisible() const52 bool MessageBubbleBase::IsVisible() const {
53   return bubble_view() && bubble_view()->GetWidget()->IsVisible();
54 }
55 
SetMaxHeight(int height)56 void MessageBubbleBase::SetMaxHeight(int height) {
57   // Maximum height makes sense only for the new design.
58   if (height == 0)
59     height = kMessageBubbleBaseDefaultMaxHeight;
60   if (height == max_height_)
61     return;
62 
63   max_height_ = height;
64   if (bubble_view_)
65     bubble_view_->SetMaxHeight(max_height_);
66 }
67 
GetDefaultInitParams(views::TrayBubbleView::AnchorAlignment anchor_alignment)68 views::TrayBubbleView::InitParams MessageBubbleBase::GetDefaultInitParams(
69     views::TrayBubbleView::AnchorAlignment anchor_alignment) {
70   views::TrayBubbleView::InitParams init_params(
71       views::TrayBubbleView::ANCHOR_TYPE_TRAY,
72       anchor_alignment,
73       kNotificationWidth,
74       kNotificationWidth);
75   init_params.arrow_color = kBackgroundDarkColor;
76   return init_params;
77 }
78 
79 }  // namespace message_center
80