OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "ui/message_center/message_popup_collection.h" | 5 #include "ui/message_center/message_popup_collection.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/timer.h" | 10 #include "base/timer.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 } | 74 } |
75 | 75 |
76 void StartTimer() { | 76 void StartTimer() { |
77 start_time_ = base::Time::Now(); | 77 start_time_ = base::Time::Now(); |
78 timer_.Start(FROM_HERE, | 78 timer_.Start(FROM_HERE, |
79 delay_, | 79 delay_, |
80 base::Bind(&views::Widget::Close, | 80 base::Bind(&views::Widget::Close, |
81 base::Unretained(GetWidget()))); | 81 base::Unretained(GetWidget()))); |
82 } | 82 } |
83 | 83 |
84 // views::WidgetDelegate overrides: | 84 // Overridden from views::WidgetDelegate: |
85 virtual views::View* GetContentsView() OVERRIDE { | 85 virtual views::View* GetContentsView() OVERRIDE { |
86 return this; | 86 return this; |
87 } | 87 } |
88 | 88 |
89 virtual void WindowClosing() OVERRIDE { | 89 virtual void WindowClosing() OVERRIDE { |
90 if (timer_.IsRunning()) | 90 if (timer_.IsRunning()) |
91 SuspendTimer(); | 91 SuspendTimer(); |
92 } | 92 } |
93 | 93 |
94 virtual bool CanActivate() const OVERRIDE { | 94 virtual bool CanActivate() const OVERRIDE { |
95 return false; | 95 return false; |
96 } | 96 } |
97 | 97 |
98 // views::View overrides: | 98 // Overridden from views::View: |
99 virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE { | 99 virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE { |
100 collection_->OnMouseEntered(); | 100 collection_->OnMouseEntered(); |
101 } | 101 } |
102 | 102 |
103 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE { | 103 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE { |
104 collection_->OnMouseExited(); | 104 collection_->OnMouseExited(); |
105 } | 105 } |
106 | 106 |
107 private: | 107 private: |
108 base::TimeDelta delay_; | 108 base::TimeDelta delay_; |
109 base::Time start_time_; | 109 base::Time start_time_; |
110 base::OneShotTimer<views::Widget> timer_; | 110 base::OneShotTimer<views::Widget> timer_; |
111 MessagePopupCollection* collection_; | 111 MessagePopupCollection* collection_; |
112 | 112 |
113 DISALLOW_COPY_AND_ASSIGN(ToastContentsView); | 113 DISALLOW_COPY_AND_ASSIGN(ToastContentsView); |
114 }; | 114 }; |
115 | 115 |
116 MessagePopupCollection::MessagePopupCollection( | 116 MessagePopupCollection::MessagePopupCollection(gfx::NativeView context, |
117 gfx::NativeView context, | 117 MessageCenter* message_center) |
118 NotificationList::Delegate* list_delegate) | |
119 : context_(context), | 118 : context_(context), |
120 list_delegate_(list_delegate) { | 119 message_center_(message_center) { |
121 DCHECK(list_delegate_); | 120 DCHECK(message_center_); |
122 } | 121 } |
123 | 122 |
124 MessagePopupCollection::~MessagePopupCollection() { | 123 MessagePopupCollection::~MessagePopupCollection() { |
125 CloseAllWidgets(); | 124 CloseAllWidgets(); |
126 } | 125 } |
127 | 126 |
128 void MessagePopupCollection::UpdatePopups() { | 127 void MessagePopupCollection::UpdatePopups() { |
129 NotificationList::PopupNotifications popups = | 128 NotificationList::PopupNotifications popups = |
130 list_delegate_->GetNotificationList()->GetPopupNotifications(); | 129 message_center_->notification_list()->GetPopupNotifications(); |
131 | 130 |
132 if (popups.empty()) { | 131 if (popups.empty()) { |
133 CloseAllWidgets(); | 132 CloseAllWidgets(); |
134 return; | 133 return; |
135 } | 134 } |
136 | 135 |
137 gfx::Screen* screen = gfx::Screen::GetScreenFor(context_); | 136 gfx::Screen* screen = gfx::Screen::GetScreenFor(context_); |
138 gfx::Rect work_area = screen->GetDisplayNearestWindow(context_).work_area(); | 137 gfx::Rect work_area = screen->GetDisplayNearestWindow(context_).work_area(); |
139 | 138 |
140 std::set<std::string> old_toast_ids; | 139 std::set<std::string> old_toast_ids; |
141 for (ToastContainer::iterator iter = toasts_.begin(); iter != toasts_.end(); | 140 for (ToastContainer::iterator iter = toasts_.begin(); iter != toasts_.end(); |
142 ++iter) { | 141 ++iter) { |
143 old_toast_ids.insert(iter->first); | 142 old_toast_ids.insert(iter->first); |
144 } | 143 } |
145 | 144 |
146 int total_height = 0; | 145 int total_height = 0; |
147 std::vector<views::Widget*> widgets; | 146 std::vector<views::Widget*> widgets; |
148 for (NotificationList::PopupNotifications::const_iterator iter = | 147 for (NotificationList::PopupNotifications::const_iterator iter = |
149 popups.begin(); iter != popups.end(); ++iter) { | 148 popups.begin(); iter != popups.end(); ++iter) { |
150 ToastContainer::iterator toast_iter = toasts_.find((*iter)->id()); | 149 ToastContainer::iterator toast_iter = toasts_.find((*iter)->id()); |
151 views::Widget* widget = NULL; | 150 views::Widget* widget = NULL; |
152 if (toast_iter != toasts_.end()) { | 151 if (toast_iter != toasts_.end()) { |
153 widget = toast_iter->second->GetWidget(); | 152 widget = toast_iter->second->GetWidget(); |
154 old_toast_ids.erase((*iter)->id()); | 153 old_toast_ids.erase((*iter)->id()); |
155 } else { | 154 } else { |
156 MessageView* view = NotificationView::Create(*(*iter), list_delegate_); | 155 // NotificationViews are expanded by default here because |
| 156 // MessagePopupCollection hasn't been tested yet with changing subview |
| 157 // sizes, and such changes could come if those subviews were initially |
| 158 // collapsed and allowed to be expanded by users. TODO(dharcourt): Fix. |
| 159 MessageView* view = NotificationView::Create(*(*iter), message_center_, |
| 160 true); |
157 ToastContentsView* toast = new ToastContentsView(*iter, view, this); | 161 ToastContentsView* toast = new ToastContentsView(*iter, view, this); |
158 widget = toast->CreateWidget(context_); | 162 widget = toast->CreateWidget(context_); |
159 widget->AddObserver(this); | 163 widget->AddObserver(this); |
160 toast->StartTimer(); | 164 toast->StartTimer(); |
161 toasts_[(*iter)->id()] = toast; | 165 toasts_[(*iter)->id()] = toast; |
162 } | 166 } |
163 if (widget) { | 167 if (widget) { |
164 gfx::Rect bounds = widget->GetWindowBoundsInScreen(); | 168 gfx::Rect bounds = widget->GetWindowBoundsInScreen(); |
165 int new_height = total_height + bounds.height() + kMarginBetweenItems; | 169 int new_height = total_height + bounds.height() + kMarginBetweenItems; |
166 if (new_height < work_area.height()) { | 170 if (new_height < work_area.height()) { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 widget->Close(); | 229 widget->Close(); |
226 } | 230 } |
227 toasts_.clear(); | 231 toasts_.clear(); |
228 } | 232 } |
229 | 233 |
230 void MessagePopupCollection::OnWidgetDestroying(views::Widget* widget) { | 234 void MessagePopupCollection::OnWidgetDestroying(views::Widget* widget) { |
231 widget->RemoveObserver(this); | 235 widget->RemoveObserver(this); |
232 for (ToastContainer::iterator iter = toasts_.begin(); | 236 for (ToastContainer::iterator iter = toasts_.begin(); |
233 iter != toasts_.end(); ++iter) { | 237 iter != toasts_.end(); ++iter) { |
234 if (iter->second->GetWidget() == widget) { | 238 if (iter->second->GetWidget() == widget) { |
235 list_delegate_->GetNotificationList()->MarkSinglePopupAsShown( | 239 message_center_->notification_list()->MarkSinglePopupAsShown( |
236 iter->first, false); | 240 iter->first, false); |
237 toasts_.erase(iter); | 241 toasts_.erase(iter); |
238 break; | 242 break; |
239 } | 243 } |
240 } | 244 } |
241 UpdatePopups(); | 245 UpdatePopups(); |
242 } | 246 } |
243 | 247 |
244 } // namespace message_center | 248 } // namespace message_center |
OLD | NEW |