OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/system/web_notification/web_notification_bubble.h" | 5 #include "ui/message_center/message_bubble_base.h" |
6 | 6 |
7 #include "ash/system/web_notification/web_notification_view.h" | |
8 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "ui/message_center/message_view.h" |
9 #include "ui/views/widget/widget.h" | 9 #include "ui/views/widget/widget.h" |
10 #include "ui/views/widget/widget_observer.h" | 10 #include "ui/views/widget/widget_observer.h" |
11 | 11 |
12 namespace { | 12 namespace { |
13 // Delay laying out the WebNotificationBubble until all notifications have been | 13 // Delay laying out the MessageBubbleBase until all notifications have been |
14 // added and icons have had a chance to load. | 14 // added and icons have had a chance to load. |
15 const int kUpdateDelayMs = 50; | 15 const int kUpdateDelayMs = 50; |
16 const int kNotificationBubbleWidth = 300; | 16 const int kNotificationBubbleWidth = 300; |
17 } | 17 } |
18 | 18 |
19 namespace message_center { | 19 namespace message_center { |
20 | 20 |
21 const SkColor WebNotificationBubble::kBackgroundColor = | 21 const SkColor MessageBubbleBase::kBackgroundColor = |
22 SkColorSetRGB(0xfe, 0xfe, 0xfe); | 22 SkColorSetRGB(0xfe, 0xfe, 0xfe); |
23 const SkColor WebNotificationBubble::kHeaderBackgroundColorLight = | 23 const SkColor MessageBubbleBase::kHeaderBackgroundColorLight = |
24 SkColorSetRGB(0xf1, 0xf1, 0xf1); | 24 SkColorSetRGB(0xf1, 0xf1, 0xf1); |
25 const SkColor WebNotificationBubble::kHeaderBackgroundColorDark = | 25 const SkColor MessageBubbleBase::kHeaderBackgroundColorDark = |
26 SkColorSetRGB(0xe7, 0xe7, 0xe7); | 26 SkColorSetRGB(0xe7, 0xe7, 0xe7); |
27 | 27 |
28 WebNotificationBubble::WebNotificationBubble( | 28 MessageBubbleBase::MessageBubbleBase(NotificationList::Delegate* list_delegate) |
29 WebNotificationList::Delegate* list_delegate) | |
30 : list_delegate_(list_delegate), | 29 : list_delegate_(list_delegate), |
31 bubble_view_(NULL), | 30 bubble_view_(NULL), |
32 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { | 31 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |
33 } | 32 } |
34 | 33 |
35 WebNotificationBubble::~WebNotificationBubble() { | 34 MessageBubbleBase::~MessageBubbleBase() { |
36 if (bubble_view_) | 35 if (bubble_view_) |
37 bubble_view_->reset_delegate(); | 36 bubble_view_->reset_delegate(); |
38 } | 37 } |
39 | 38 |
40 void WebNotificationBubble::BubbleViewDestroyed() { | 39 void MessageBubbleBase::BubbleViewDestroyed() { |
41 bubble_view_ = NULL; | 40 bubble_view_ = NULL; |
42 OnBubbleViewDestroyed(); | 41 OnBubbleViewDestroyed(); |
43 } | 42 } |
44 | 43 |
45 void WebNotificationBubble::ScheduleUpdate() { | 44 void MessageBubbleBase::ScheduleUpdate() { |
46 weak_ptr_factory_.InvalidateWeakPtrs(); // Cancel any pending update. | 45 weak_ptr_factory_.InvalidateWeakPtrs(); // Cancel any pending update. |
47 MessageLoop::current()->PostDelayedTask( | 46 MessageLoop::current()->PostDelayedTask( |
48 FROM_HERE, | 47 FROM_HERE, |
49 base::Bind(&WebNotificationBubble::UpdateBubbleView, | 48 base::Bind(&MessageBubbleBase::UpdateBubbleView, |
50 weak_ptr_factory_.GetWeakPtr()), | 49 weak_ptr_factory_.GetWeakPtr()), |
51 base::TimeDelta::FromMilliseconds(kUpdateDelayMs)); | 50 base::TimeDelta::FromMilliseconds(kUpdateDelayMs)); |
52 } | 51 } |
53 | 52 |
54 bool WebNotificationBubble::IsVisible() const { | 53 bool MessageBubbleBase::IsVisible() const { |
55 return bubble_view() && bubble_view()->GetWidget()->IsVisible(); | 54 return bubble_view() && bubble_view()->GetWidget()->IsVisible(); |
56 } | 55 } |
57 | 56 |
58 TrayBubbleView::InitParams WebNotificationBubble::GetDefaultInitParams( | 57 views::TrayBubbleView::InitParams MessageBubbleBase::GetDefaultInitParams( |
59 TrayBubbleView::AnchorAlignment anchor_alignment) { | 58 views::TrayBubbleView::AnchorAlignment anchor_alignment) { |
60 TrayBubbleView::InitParams init_params(TrayBubbleView::ANCHOR_TYPE_TRAY, | 59 views::TrayBubbleView::InitParams init_params( |
61 anchor_alignment, | 60 views::TrayBubbleView::ANCHOR_TYPE_TRAY, |
62 kNotificationBubbleWidth); | 61 anchor_alignment, |
| 62 kNotificationBubbleWidth); |
63 init_params.top_color = kBackgroundColor; | 63 init_params.top_color = kBackgroundColor; |
64 init_params.arrow_color = kHeaderBackgroundColorDark; | 64 init_params.arrow_color = kHeaderBackgroundColorDark; |
65 init_params.bubble_width = kWebNotificationWidth; | 65 init_params.bubble_width = kWebNotificationWidth; |
66 return init_params; | 66 return init_params; |
67 } | 67 } |
68 | 68 |
69 } // namespace message_center | 69 } // namespace message_center |
OLD | NEW |