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