Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Side by Side Diff: ui/message_center/message_popup_bubble.cc

Issue 11229022: Move ash/system/web_notification message_center to ui/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase again. Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/message_center/message_popup_bubble.h ('k') | ui/message_center/message_view.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/popup_bubble.h" 5 #include "ui/message_center/message_popup_bubble.h"
6 6
7 #include "ash/system/tray/tray_bubble_view.h" 7 #include "ui/message_center/message_view.h"
8 #include "ash/system/web_notification/web_notification_view.h" 8 #include "ui/views/bubble/tray_bubble_view.h"
9 #include "ui/views/layout/box_layout.h" 9 #include "ui/views/layout/box_layout.h"
10 #include "ui/views/view.h" 10 #include "ui/views/view.h"
11 #include "ui/views/widget/widget.h" 11 #include "ui/views/widget/widget.h"
12 12
13 namespace message_center { 13 namespace message_center {
14 14
15 const int kAutocloseDelaySeconds = 5; 15 const int kAutocloseDelaySeconds = 5;
16 16
17 // Popup notifications contents. 17 // Popup notifications contents.
18 class PopupBubbleContentsView : public views::View { 18 class PopupBubbleContentsView : public views::View {
19 public: 19 public:
20 explicit PopupBubbleContentsView( 20 explicit PopupBubbleContentsView(NotificationList::Delegate* list_delegate)
21 WebNotificationList::Delegate* list_delegate)
22 : list_delegate_(list_delegate) { 21 : list_delegate_(list_delegate) {
23 SetLayoutManager( 22 SetLayoutManager(
24 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1)); 23 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1));
25 24
26 content_ = new views::View; 25 content_ = new views::View;
27 content_->SetLayoutManager( 26 content_->SetLayoutManager(
28 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1)); 27 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1));
29 AddChildView(content_); 28 AddChildView(content_);
30 29
31 content_->SetPaintToLayer(true); 30 content_->SetPaintToLayer(true);
32 content_->SetFillsBoundsOpaquely(false); 31 content_->SetFillsBoundsOpaquely(false);
33 content_->layer()->SetMasksToBounds(true); 32 content_->layer()->SetMasksToBounds(true);
34 } 33 }
35 34
36 void Update(const WebNotificationList::Notifications& popup_notifications) { 35 void Update(const NotificationList::Notifications& popup_notifications) {
37 content_->RemoveAllChildViews(true); 36 content_->RemoveAllChildViews(true);
38 for (WebNotificationList::Notifications::const_iterator iter = 37 for (NotificationList::Notifications::const_iterator iter =
39 popup_notifications.begin(); 38 popup_notifications.begin();
40 iter != popup_notifications.end(); ++iter) { 39 iter != popup_notifications.end(); ++iter) {
41 WebNotificationView* view = new WebNotificationView( 40 MessageView* view = new MessageView(list_delegate_, *iter, 0);
42 list_delegate_, *iter, 0);
43 content_->AddChildView(view); 41 content_->AddChildView(view);
44 } 42 }
45 content_->SizeToPreferredSize(); 43 content_->SizeToPreferredSize();
46 content_->InvalidateLayout(); 44 content_->InvalidateLayout();
47 Layout(); 45 Layout();
48 if (GetWidget()) 46 if (GetWidget())
49 GetWidget()->GetRootView()->SchedulePaint(); 47 GetWidget()->GetRootView()->SchedulePaint();
50 } 48 }
51 49
52 size_t NumMessageViews() const { 50 size_t NumMessageViews() const {
53 return content_->child_count(); 51 return content_->child_count();
54 } 52 }
55 53
56 private: 54 private:
57 WebNotificationList::Delegate* list_delegate_; 55 NotificationList::Delegate* list_delegate_;
58 views::View* content_; 56 views::View* content_;
59 57
60 DISALLOW_COPY_AND_ASSIGN(PopupBubbleContentsView); 58 DISALLOW_COPY_AND_ASSIGN(PopupBubbleContentsView);
61 }; 59 };
62 60
63 // PopupBubble 61 // MessagePopupBubble
64 PopupBubble::PopupBubble(WebNotificationList::Delegate* delegate) : 62 MessagePopupBubble::MessagePopupBubble(NotificationList::Delegate* delegate)
65 WebNotificationBubble(delegate), 63 : MessageBubbleBase(delegate),
66 contents_view_(NULL), 64 contents_view_(NULL),
67 num_popups_(0) { 65 num_popups_(0) {
68 } 66 }
69 67
70 PopupBubble::~PopupBubble() { 68 MessagePopupBubble::~MessagePopupBubble() {
71 } 69 }
72 70
73 TrayBubbleView::InitParams PopupBubble::GetInitParams( 71 views::TrayBubbleView::InitParams MessagePopupBubble::GetInitParams(
74 TrayBubbleView::AnchorAlignment anchor_alignment) { 72 views::TrayBubbleView::AnchorAlignment anchor_alignment) {
75 TrayBubbleView::InitParams init_params = 73 views::TrayBubbleView::InitParams init_params =
76 GetDefaultInitParams(anchor_alignment); 74 GetDefaultInitParams(anchor_alignment);
77 init_params.top_color = kBackgroundColor; 75 init_params.top_color = kBackgroundColor;
78 init_params.arrow_color = kBackgroundColor; 76 init_params.arrow_color = kBackgroundColor;
79 init_params.close_on_deactivate = false; 77 init_params.close_on_deactivate = false;
80 return init_params; 78 return init_params;
81 } 79 }
82 80
83 void PopupBubble::InitializeContents(TrayBubbleView* bubble_view) { 81 void MessagePopupBubble::InitializeContents(
82 views::TrayBubbleView* bubble_view) {
84 bubble_view_ = bubble_view; 83 bubble_view_ = bubble_view;
85 contents_view_ = new PopupBubbleContentsView(list_delegate_); 84 contents_view_ = new PopupBubbleContentsView(list_delegate_);
86 bubble_view_->AddChildView(contents_view_); 85 bubble_view_->AddChildView(contents_view_);
87 UpdateBubbleView(); 86 UpdateBubbleView();
88 } 87 }
89 88
90 void PopupBubble::OnBubbleViewDestroyed() { 89 void MessagePopupBubble::OnBubbleViewDestroyed() {
91 contents_view_ = NULL; 90 contents_view_ = NULL;
92 } 91 }
93 92
94 void PopupBubble::UpdateBubbleView() { 93 void MessagePopupBubble::UpdateBubbleView() {
95 WebNotificationList::Notifications popup_notifications; 94 NotificationList::Notifications popup_notifications;
96 list_delegate_->GetNotificationList()->GetPopupNotifications( 95 list_delegate_->GetNotificationList()->GetPopupNotifications(
97 &popup_notifications); 96 &popup_notifications);
98 if (popup_notifications.size() == 0) { 97 if (popup_notifications.size() == 0) {
99 if (bubble_view()) 98 if (bubble_view())
100 bubble_view()->delegate()->HideBubble(bubble_view()); // deletes |this| 99 bubble_view()->delegate()->HideBubble(bubble_view()); // deletes |this|
101 return; 100 return;
102 } 101 }
103 // Only reset the timer when the number of visible notifications changes. 102 // Only reset the timer when the number of visible notifications changes.
104 if (num_popups_ != popup_notifications.size()) { 103 if (num_popups_ != popup_notifications.size()) {
105 num_popups_ = popup_notifications.size(); 104 num_popups_ = popup_notifications.size();
106 StartAutoCloseTimer(); 105 StartAutoCloseTimer();
107 } 106 }
108 contents_view_->Update(popup_notifications); 107 contents_view_->Update(popup_notifications);
109 bubble_view_->Show(); 108 bubble_view_->Show();
110 bubble_view_->UpdateBubble(); 109 bubble_view_->UpdateBubble();
111 } 110 }
112 111
113 void PopupBubble::OnMouseEnteredView() { 112 void MessagePopupBubble::OnMouseEnteredView() {
114 StopAutoCloseTimer(); 113 StopAutoCloseTimer();
115 } 114 }
116 115
117 void PopupBubble::OnMouseExitedView() { 116 void MessagePopupBubble::OnMouseExitedView() {
118 StartAutoCloseTimer(); 117 StartAutoCloseTimer();
119 } 118 }
120 119
121 void PopupBubble::StartAutoCloseTimer() { 120 void MessagePopupBubble::StartAutoCloseTimer() {
122 autoclose_.Start(FROM_HERE, 121 autoclose_.Start(FROM_HERE,
123 base::TimeDelta::FromSeconds( 122 base::TimeDelta::FromSeconds(
124 kAutocloseDelaySeconds), 123 kAutocloseDelaySeconds),
125 this, &PopupBubble::OnAutoClose); 124 this, &MessagePopupBubble::OnAutoClose);
126 } 125 }
127 126
128 void PopupBubble::StopAutoCloseTimer() { 127 void MessagePopupBubble::StopAutoCloseTimer() {
129 autoclose_.Stop(); 128 autoclose_.Stop();
130 } 129 }
131 130
132 void PopupBubble::OnAutoClose() { 131 void MessagePopupBubble::OnAutoClose() {
133 list_delegate_->GetNotificationList()->MarkPopupsAsShown(); 132 list_delegate_->GetNotificationList()->MarkPopupsAsShown();
134 num_popups_ = 0; 133 num_popups_ = 0;
135 UpdateBubbleView(); 134 UpdateBubbleView();
136 } 135 }
137 136
138 size_t PopupBubble::NumMessageViewsForTest() const { 137 size_t MessagePopupBubble::NumMessageViewsForTest() const {
139 return contents_view_->NumMessageViews(); 138 return contents_view_->NumMessageViews();
140 } 139 }
141 140
142 } // namespace message_center 141 } // namespace message_center
OLDNEW
« no previous file with comments | « ui/message_center/message_popup_bubble.h ('k') | ui/message_center/message_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698