1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/system/web_notification/web_notification_bubble.h"
#include "ash/system/web_notification/web_notification_contents_view.h"
#include "ash/system/web_notification/web_notification_tray.h"
#include "ash/system/web_notification/web_notification_view.h"
#include "base/bind.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_observer.h"
namespace ash {
using internal::TrayBubbleView;
namespace message_center {
// Delay laying out the WebNotificationBubble until all notifications have been
// added and icons have had a chance to load.
const int kUpdateDelayMs = 50;
WebNotificationBubble::WebNotificationBubble(WebNotificationTray* tray)
: tray_(tray),
bubble_view_(NULL),
bubble_widget_(NULL),
ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
}
void WebNotificationBubble::Initialize(
WebNotificationContentsView* contents_view) {
DCHECK(bubble_view_);
bubble_view_->AddChildView(contents_view);
bubble_widget_ = views::BubbleDelegateView::CreateBubble(bubble_view_);
bubble_widget_->AddObserver(this);
InitializeAndShowBubble(bubble_widget_, bubble_view_, tray_);
UpdateBubbleView();
}
WebNotificationBubble::~WebNotificationBubble() {
if (bubble_view_)
bubble_view_->reset_host();
if (bubble_widget_) {
bubble_widget_->RemoveObserver(this);
bubble_widget_->Close();
}
}
void WebNotificationBubble::ScheduleUpdate() {
weak_ptr_factory_.InvalidateWeakPtrs(); // Cancel any pending update.
MessageLoop::current()->PostDelayedTask(
FROM_HERE,
base::Bind(&WebNotificationBubble::UpdateBubbleView,
weak_ptr_factory_.GetWeakPtr()),
base::TimeDelta::FromMilliseconds(kUpdateDelayMs));
}
bool WebNotificationBubble::IsVisible() const {
return bubble_widget_ && bubble_widget_->IsVisible();
}
void WebNotificationBubble::BubbleViewDestroyed() {
bubble_view_ = NULL;
}
void WebNotificationBubble::OnMouseEnteredView() {
}
void WebNotificationBubble::OnMouseExitedView() {
}
void WebNotificationBubble::OnClickedOutsideView() {
// May delete |this|.
tray_->HideMessageCenterBubble();
}
string16 WebNotificationBubble::GetAccessibleName() {
return tray_->GetAccessibleName();
}
// Overridden from views::WidgetObserver:
void WebNotificationBubble::OnWidgetClosing(views::Widget* widget) {
CHECK_EQ(bubble_widget_, widget);
bubble_widget_ = NULL;
tray_->HideBubble(this); // Will destroy |this|.
}
TrayBubbleView::InitParams WebNotificationBubble::GetInitParams() {
TrayBubbleView::InitParams init_params(TrayBubbleView::ANCHOR_TYPE_TRAY,
tray_->shelf_alignment());
init_params.bubble_width = kWebNotificationWidth;
if (tray_->shelf_alignment() == SHELF_ALIGNMENT_BOTTOM) {
views::View* anchor = tray_->tray_container();
gfx::Point bounds(anchor->width() / 2, 0);
views::View::ConvertPointToWidget(anchor, &bounds);
init_params.arrow_offset = bounds.x();
}
return init_params;
}
} // namespace message_center
} // namespace ash
|